diff --git a/src/sst/core/util/smartTextFormatter.cc b/src/sst/core/util/smartTextFormatter.cc index f17b49aee..35aeb7e07 100644 --- a/src/sst/core/util/smartTextFormatter.cc +++ b/src/sst/core/util/smartTextFormatter.cc @@ -27,17 +27,18 @@ namespace Util { void SmartTextFormatter::clear() { - output.clear(); - spaces.clear(); - word.clear(); - currentPosition = 0; + output_.clear(); + spaces_.clear(); + word_.clear(); + current_position_ = 0; - indent.clear(); - indent.push_back(0); + indent_.clear(); + indent_.push_back(0); } -SmartTextFormatter::SmartTextFormatter(const std::vector& tabStops, int repeat) : terminalWidth(getTerminalWidth()) +SmartTextFormatter::SmartTextFormatter(const std::vector& tabStops, int repeat) : + terminal_width_(getTerminalWidth()) { setTabStops(tabStops, repeat); } @@ -47,7 +48,7 @@ void SmartTextFormatter::setTabStops(const std::vector& stops, int repeat) { if ( repeat < 1 ) { - tabStops = stops; + tab_stops_ = stops; return; } @@ -60,7 +61,7 @@ SmartTextFormatter::setTabStops(const std::vector& stops, int repeat) } // Clear current tabstops - tabStops.clear(); + tab_stops_.clear(); // Track the index where the repeat will start each time through size_t repeat_index = stops.size() - repeat; @@ -69,11 +70,11 @@ SmartTextFormatter::setTabStops(const std::vector& stops, int repeat) size_t index = 0; int position = distances[0]; do { - tabStops.push_back(position); + tab_stops_.push_back(position); index++; if ( index == distances.size() ) { index = repeat_index; } position = position + distances[index]; - } while ( position < terminalWidth ); + } while ( position < terminal_width_ ); } @@ -82,36 +83,36 @@ SmartTextFormatter::append(const std::string& input) { for ( size_t i = 0; i < input.length(); ++i ) { - unsigned char currentChar = input[i]; + unsigned char current_char = input[i]; - if ( std::isspace(currentChar) ) { + if ( std::isspace(current_char) ) { // First, check to see if we were most recently // collecting a word. If so, we need to add it to the // formatted string, then we can proceed to processing // the current character. - if ( word.size() > 0 ) { - if ( currentPosition < terminalWidth ) { + if ( word_.size() > 0 ) { + if ( current_position_ < terminal_width_ ) { // We can put the word on this line. Put in // all the spaces we collected plus the word - output += spaces; - output += word; - spaces = ""; - word = ""; + output_ += spaces_; + output_ += word_; + spaces_ = ""; + word_ = ""; } else { // Need to wrap the word. Throw away any // preceeding spaces, put in a newline, do the // indent, then add the word - output += '\n'; - spaces = ""; + output_ += '\n'; + spaces_ = ""; - output += std::string(indent.back(), ' '); - currentPosition = indent.back(); + output_ += std::string(indent_.back(), ' '); + current_position_ = indent_.back(); - output += word; - currentPosition += word.size(); - word = ""; + output_ += word_; + current_position_ += word_.size(); + word_ = ""; } } @@ -120,78 +121,78 @@ SmartTextFormatter::append(const std::string& input) // case. All other whitespace will become space. // Handle tab characters - if ( currentChar == '\t' ) { - last_char_vert_tab = false; - int num_spaces = nextTabStop(currentPosition); + if ( current_char == '\t' ) { + last_char_vert_tab_ = false; + int num_spaces = nextTabStop(current_position_); if ( num_spaces == -1 ) { // Hit end of line, just wrap to next line, // obeying indent - output += '\n'; - spaces = ""; - if ( indent.back() != 0 ) output += std::string(indent.back(), ' '); - currentPosition = indent.back(); + output_ += '\n'; + spaces_ = ""; + if ( indent_.back() != 0 ) output_ += std::string(indent_.back(), ' '); + current_position_ = indent_.back(); continue; } // Add to the spaces object - spaces += std::string(num_spaces, ' '); - currentPosition += num_spaces; + spaces_ += std::string(num_spaces, ' '); + current_position_ += num_spaces; } // Handle vertical tab characters. This will simply set // the indent to the currentPosition - else if ( currentChar == '\v' ) { - if ( last_char_vert_tab ) { + else if ( current_char == '\v' ) { + if ( last_char_vert_tab_ ) { // If the last character was a vertical tab, // then we were actually supposed to pop the // current indent. However, we actually added // another indent so need to pop two. - indent.pop_back(); + indent_.pop_back(); // If someone put in two \v's before a \v, // then we will have an empty vector if we pop // again. Need to check for that. - if ( indent.size() != 1 ) indent.pop_back(); - last_char_vert_tab = false; + if ( indent_.size() != 1 ) indent_.pop_back(); + last_char_vert_tab_ = false; } else { - indent.push_back(currentPosition); - last_char_vert_tab = true; + indent_.push_back(current_position_); + last_char_vert_tab_ = true; } - for ( size_t i = 0; i < indent.size(); ++i ) {} + for ( size_t i = 0; i < indent_.size(); ++i ) {} continue; } // Handle carriage return characters, which will cause // a new line that returns to the indent point - else if ( currentChar == '\r' ) { - last_char_vert_tab = false; - output += '\n'; - output += std::string(indent.back(), ' '); - spaces = ""; - currentPosition = indent.back(); + else if ( current_char == '\r' ) { + last_char_vert_tab_ = false; + output_ += '\n'; + output_ += std::string(indent_.back(), ' '); + spaces_ = ""; + current_position_ = indent_.back(); } // Handle new line characters - else if ( currentChar == '\n' ) { - output += '\n'; - spaces = ""; - currentPosition = 0; + else if ( current_char == '\n' ) { + output_ += '\n'; + spaces_ = ""; + current_position_ = 0; // Explicit new line wipes the indent - indent.clear(); - indent.push_back(0); + indent_.clear(); + indent_.push_back(0); } // All others become a single space else { - last_char_vert_tab = false; - spaces += ' '; - currentPosition++; + last_char_vert_tab_ = false; + spaces_ += ' '; + current_position_++; } } else { // For non space characters, we just add to the current word - last_char_vert_tab = false; - word += currentChar; - currentPosition++; + last_char_vert_tab_ = false; + word_ += current_char; + current_position_++; } } } @@ -200,22 +201,22 @@ SmartTextFormatter::append(const std::string& input) std::string SmartTextFormatter::str() { - std::string ret = output; + std::string ret = output_; // Need to handle any left over word - if ( word.size() > 0 ) { - if ( currentPosition < terminalWidth ) { + if ( word_.size() > 0 ) { + if ( current_position_ < terminal_width_ ) { // We can put the word on this line. Put in // all the spaces we collected plus the word - ret += spaces; - ret += word; + ret += spaces_; + ret += word_; } else { // Need to wrap the word. Throw away an // preceeding spaces, put in a newline, do the // indent, then add the word ret += '\n'; - ret += std::string(indent.back(), ' '); - ret += word; + ret += std::string(indent_.back(), ' '); + ret += word_; } } return ret; @@ -224,7 +225,7 @@ SmartTextFormatter::str() int SmartTextFormatter::nextTabStop(int position) { - for ( int tab : tabStops ) { + for ( int tab : tab_stops_ ) { if ( tab > position ) { return tab - position; } } // If no more tab stops, return -1 diff --git a/src/sst/core/util/smartTextFormatter.h b/src/sst/core/util/smartTextFormatter.h index 5728509ec..49fe1b378 100644 --- a/src/sst/core/util/smartTextFormatter.h +++ b/src/sst/core/util/smartTextFormatter.h @@ -33,46 +33,46 @@ class SmartTextFormatter /** List of tab stops */ - std::vector tabStops; + std::vector tab_stops_; /** Width of the terminal. Lines will be wrapped at this width */ - int terminalWidth; + int terminal_width_; /** The output string that is being built up with calls to append */ - std::string output; + std::string output_; /** Used to hold the current whitespace between words */ - std::string spaces; + std::string spaces_; /** Used to hold the current word */ - std::string word; + std::string word_; /** Position (column) that the next character will write at in the current line */ - int currentPosition = 0; + int current_position_ = 0; /** True if the last character was a vertical tab. This is needed because two vertical tabs in a row will pop the most recent indent */ - bool last_char_vert_tab = false; + bool last_char_vert_tab_ = false; /** Stack of indents. Add an indent at the currentPosition by using \v. Pop the most recent indent with \v\v. */ - std::vector indent = { 0 }; + std::vector indent_ = { 0 }; public: /**