|
| 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 string tstring::removeEnclosingChar |
( |
const string & |
str, |
|
|
const char |
o, |
|
|
const char |
c, |
|
|
bool |
allowMissing = false |
|
) |
| |
|
inlinestatic |
Removes characters enclosing a string.
Can be used to remove parenthesis/brackets or trailing whitespace characters.
- Parameters
-
| str | the string |
| o | the opening (front) character |
| c | the closing (back) character |
| allowMissing | if trus, allows to ignore a missing enclosing character |
361 first = s.find_first_of(o, 0);
364 error(
"tstring::removeEnclosingChar:: string \"%s\" not starting with \"%c\"\n.", s.c_str(), o);
370 last = s.find_last_of(c);
371 if(last != s.length()-1 || last == string::npos) {
373 error(
"tstring::removeEnclosingChar:: string \"%s\" not ending with \"%c\"\n.", s.c_str(), c);
References error().
Referenced by ParamsParser::concat(), ParamsParser::diag_matrix(), ParamsParser::getMacroSepParamChar(), ParamsParser::matrix(), Param::parseArgument(), ParamsParser::rep(), LCE_BreedAssortativeMating::setParameters(), ParamsParser::sym_matrix(), and ParamsParser::tempseq().
| 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 |
158 if(str.find_first_of(encloser) == string::npos)
return split(str, delim);
160 string::size_type open, delim_pos, next_index = 0;
161 string pair, block, tail(str);
162 vector<string> tokens;
164 while (tail.find(delim) != string::npos) {
166 delim_pos = tail.find_first_of(delim);
169 open = tail.find_first_of(encloser);
172 while (open < delim_pos) {
174 block =
getBlock(tail.substr(open, string::npos), tail.at(open));
176 next_index = open + block.size();
178 pair += tail.substr(0, next_index);
180 tail = tail.substr(next_index);
182 delim_pos = tail.find_first_of(delim);
184 open = tail.find_first_of(encloser);
187 pair += tail.substr(0, delim_pos);
191 tokens.push_back(pair);
194 if(delim_pos != string::npos) tail = tail.substr(delim_pos + 1);
198 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:128
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:213
Referenced by ParamsParser::getMacroArgs(), ParamsParser::getMacroParamValue(), ParamsParser::getMacroSepParamChar(), Param::parseArgument(), ParamsParser::rbernoul(), ParamsParser::rexp(), ParamsParser::rgamma(), ParamsParser::rlognorm(), ParamsParser::rnorm(), ParamsParser::rpoiss(), and ParamsParser::runif().