Classes | |
| class | kmp |
| Exact pattern finding with the Knuth-Morris-Pratt's algorithm. More... | |
Functions | |
| template<typename StreamType, typename StringType> | |
| StreamType & | getline (StreamType &is, StringType &str) |
| A portable version of std::getline( is, str, ' ' ) that removes a tailing ''. | |
| template<class StringType> | |
| void | trim_left (StringType &str, const typename StringType::value_type *const s) |
| Remove characters at the begining of a string. | |
| template<class StringType> | |
| void | trim_right (StringType &str, const typename StringType::value_type *const s) |
| Remove characters at the end of a string. | |
| template<class StringType> | |
| void | trim (StringType &str, const typename StringType::value_type *const s) |
| Remove characters at the begining end at the end of a string. | |
| template<class StringType> | |
| void | squeeze (StringType &str, const typename StringType::value_type *const s) |
| Squeeze successive characters of a string into one character. | |
| template<typename T, class StringType> | |
| bool | is_of_type (const StringType &str) |
| Test if the content of a string is immediately convertible to a type. | |
| template<class BackInsertion, class StringType> | |
| void | split (BackInsertion &sequence, const StringType &str, const typename StringType::value_type sep) |
| Split a string into several substrings, according to a given separator. | |
| StreamType & claw::text::getline | ( | StreamType & | is, | |
| StringType & | str | |||
| ) | [inline] |
A portable version of std::getline( is, str, '
' ) that removes a tailing ''.
| is | The stream in which we read. | |
| str | The line read from the stream. |
Definition at line 40 of file string_algorithm.tpp.
Referenced by claw::configuration_file::get_line(), claw::graphic::xbm::reader::read_line(), claw::graphic::xbm::reader::remove_comments(), and split().
00041 { 00042 std::getline( is, str ); 00043 00044 if ( !str.empty() ) 00045 if ( str[ str.size() - 1 ] == typename StringType::value_type('\r') ) 00046 str.erase( str.size() - 1 ); 00047 00048 return is; 00049 } // getline()
| bool claw::text::is_of_type | ( | const StringType & | str | ) | [inline] |
Test if the content of a string is immediately convertible to a type.
| str | The string to test. |
Definition at line 146 of file string_algorithm.tpp.
00147 { 00148 std::basic_istringstream< typename StringType::value_type, 00149 typename StringType::traits_type, 00150 typename StringType::allocator_type > iss(str); 00151 00152 T val; 00153 bool result = false; 00154 00155 if ( iss >> val ) 00156 result = iss.eof(); 00157 00158 return result; 00159 } // is_of_type()
| void claw::text::split | ( | BackInsertion & | sequence, | |
| const StringType & | str, | |||
| const typename StringType::value_type | sep | |||
| ) | [inline] |
Split a string into several substrings, according to a given separator.
| sequence | A back insertion sequence in which the substrings are added. | |
| str | The string to split. | |
| sep | The separator on which the string is splitted. |
Definition at line 170 of file string_algorithm.tpp.
References getline().
00172 { 00173 StringType line; 00174 std::basic_istringstream< typename StringType::value_type, 00175 typename StringType::traits_type, 00176 typename StringType::allocator_type > iss(str); 00177 00178 while ( std::getline(iss, line, sep) ) 00179 sequence.push_back(line); 00180 } // split()
| void claw::text::squeeze | ( | StringType & | str, | |
| const typename StringType::value_type *const | s | |||
| ) | [inline] |
Squeeze successive characters of a string into one character.
| str | The string to modify. | |
| s | The characters to remove. |
std::string s("word aaa bbb abab"); claw::squeeze( s, "ab" ); std::cout << s << std::end; // result is "word a b abab"
Definition at line 114 of file string_algorithm.tpp.
00116 { 00117 typedef typename StringType::size_type size_type; 00118 00119 size_type first(0); 00120 00121 do 00122 { 00123 first = str.find_first_of(s, first); 00124 00125 if ( first != StringType::npos ) 00126 { 00127 size_type last = str.find_first_not_of(str[first], first+1); 00128 00129 if ( last == StringType::npos ) 00130 str = str.substr(0, first+1); 00131 else if ( last - first > 1 ) 00132 str = str.substr(0, first+1) + str.substr(last); 00133 00134 ++first; 00135 } 00136 } 00137 while ( (first != StringType::npos) && (first != str.length()) ); 00138 } // squeeze()
| void claw::text::trim | ( | StringType & | str, | |
| const typename StringType::value_type *const | s | |||
| ) | [inline] |
Remove characters at the begining end at the end of a string.
| str | The string to modify. | |
| s | The characters to remove. |
Definition at line 90 of file string_algorithm.tpp.
Referenced by claw::configuration_file::process_line(), claw::graphic::xbm::reader::read_line(), and claw::graphic::xbm::reader::remove_comments().
00092 { 00093 typename StringType::size_type first = str.find_first_not_of(s); 00094 typename StringType::size_type last = str.find_last_not_of(s); 00095 00096 if (first != StringType::npos) 00097 str = str.substr( first, last - first + 1 ); 00098 } // trim()
| void claw::text::trim_left | ( | StringType & | str, | |
| const typename StringType::value_type *const | s | |||
| ) | [inline] |
Remove characters at the begining of a string.
| str | The string to modify. | |
| s | The characters to remove. |
Definition at line 58 of file string_algorithm.tpp.
Referenced by claw::configuration_file::get_line().
00060 { 00061 typename StringType::size_type p = str.find_first_not_of(s); 00062 00063 if (p != StringType::npos) 00064 str = str.substr(p); 00065 } // trim_left()
| void claw::text::trim_right | ( | StringType & | str, | |
| const typename StringType::value_type *const | s | |||
| ) | [inline] |
Remove characters at the end of a string.
| str | The string to modify. | |
| s | The characters to remove. |
Definition at line 74 of file string_algorithm.tpp.
Referenced by claw::configuration_file::open().
00076 { 00077 typename StringType::size_type p = str.find_last_not_of(s); 00078 00079 if (p != StringType::npos) 00080 str = str.substr( 0, p+1 ); 00081 } // trim_right()
1.5.5