|
| static unsigned int | str2uint (const string &str) |
| | Converts a string into an unsigned integer. More...
|
| |
| static unsigned long | str2ulong (const string &str) |
| | Converts a string into an unsigned integer. More...
|
| |
| static int | str2int (const string &str) |
| | Converts a string into an integer. More...
|
| |
| static double | str2dble (const string &str) |
| | Converts a string into a double. More...
|
| |
| static string | int2str (const int i) |
| | Writes an integer value into a string. More...
|
| |
| static string | ulong2str (const unsigned long i) |
| | Writes an integer value into a string. More...
|
| |
| static string | dble2str (const double d) |
| | Writes a floating-point value into a string. More...
|
| |
| static vector< string > | split (const string &str, const char delim, bool splitOnce=false) |
| | splits a string into substrings (tokens) delimited by a single character. More...
|
| |
| static vector< string > | splitExcludeEnclosedDelimiters (const string &str, const char delim=',', const string &encloser="([{\"") |
| | Splits a string into substrings (tokens) delimited by a single character. More...
|
| |
| static string | getBlock (const string &str, const char start_c, const char end_c='\0', bool includeEnclosing=true) |
| | Reads a substring delimited by two enclosing character from a string. More...
|
| |
| static string | __get_block (istringstream &IN, const char start_c, const char end_c) |
| | Internal function used by getBlock to recursively read nested blocks. More...
|
| |
| static string | removeChar (const string &str, const char c) |
| | Removes a given character from a string. More...
|
| |
| static string | removeFirstCharOf (const string &str, const char c) |
| | Removes the first of a character found in a string. More...
|
| |
| static string | removeLastCharOf (const string &str, const char c) |
| | Removes the last of a character found in a string. More...
|
| |
| static string | removeEnclosingChar (const string &str, const char o, const char c, bool allowMissing=false) |
| | Removes characters enclosing a string. More...
|
| |
| static string | removeLeadingWhiteSpace (const string &str) |
| |
| static string | replaceChar (const string &str, const char target, const char replacement) |
| |
| static bool | isanumber (const string &str) |
| | Check whether the string is a number. More...
|
| |
| static bool | isNA (const string &str) |
| | Check whether the string is NA | NaN. More...
|
| |
A global class to handle string conversions and operations.
Allows to parse the parameters argument strings into various tokens and to remove encolsing characters from a string.
| static vector<string> tstring::splitExcludeEnclosedDelimiters |
( |
const string & |
str, |
|
|
const char |
delim = ',', |
|
|
const string & |
encloser = "([{\"" |
|
) |
| |
|
inlinestatic |
Splits a string into substrings (tokens) delimited by a single character.
The tokens may contain the delimiter character if it is enclosed. For instance: ‘(@g0 {{0,1,0,10}}, @g10 {{1,0,2,2}})’ --> [0] = ‘@g0 {{0,1,0,10}}’ and [1] = ‘@g10 {{1,0,2,2}}’
- Parameters
-
| str | the input string |
| delim | the token delimiter, is a comma by default |
| encloser | the character that starts an enclosed string |
157 if(str.find_first_of(encloser) == string::npos)
return split(str, delim);
159 string::size_type open, delim_pos, next_index = 0;
160 string pair, block, tail(str);
161 vector<string> tokens;
163 while (tail.find(delim) != string::npos) {
165 delim_pos = tail.find_first_of(delim);
168 open = tail.find_first_of(encloser);
171 while (open < delim_pos) {
173 block =
getBlock(tail.substr(open, string::npos), tail.at(open));
175 next_index = open + block.size();
177 pair += tail.substr(0, next_index);
179 tail = tail.substr(next_index);
181 delim_pos = tail.find_first_of(delim);
183 open = tail.find_first_of(encloser);
186 pair += tail.substr(0, delim_pos);
190 tokens.push_back(pair);
193 if(delim_pos != string::npos) tail = tail.substr(delim_pos + 1);
197 if(tail.size() != 0) {
static vector< string > split(const string &str, const char delim, bool splitOnce=false)
splits a string into substrings (tokens) delimited by a single character.
Definition: tstring.h:127
static string getBlock(const string &str, const char start_c, const char end_c='\0', bool includeEnclosing=true)
Reads a substring delimited by two enclosing character from a string.
Definition: tstring.h:212
Referenced by ParamManager::build_records(), ParamsParser::getMacroArgs(), ParamsParser::getMacroParamValue(), ParamsParser::getMacroSepParamChar(), Param::parseArgument(), ParamsParser::rbernoul(), ParamsParser::rexp(), ParamsParser::rgamma(), ParamsParser::rlognorm(), ParamsParser::rnorm(), ParamsParser::rpoiss(), and ParamsParser::runif().