Class StrExt
#include <StrExt.h >
Provides class scope for extensions to the STL string class. This file defines conversion, parsing and other useful additions to the STL string class. Member functions defined in this class should be all static. These functions were wrapped by this class for organization purposes, mainly to provide an extra level of scope to the functions.
static const string whitespaceChars |
The set of characters that count as whitespace, e.g. space, tab, return, newline, and form feed. |
const string& input |
the text string to split apart |
char delimiter |
the text separator |
Tokenize a string using the char parameter as a delimiter, and put each sub string into a vector of strings.
Repated delimiters (or blank parts) are ignored.
Return value: the vector of strings
const string& input |
the text string to split apart |
const string& delimiter |
the text separator |
bool honorEscape |
if true and separator is preceded by \, then it's not a separator; note that the \ is removed from the result Default value: false |
Tokenize a string using the char parameter as a delimiter, and put each sub string into a vector of strings.
Return value: the vector of strings
const string& input |
the text string to split apart |
const string& delimiter |
the text separator |
int pos |
the token to return, e.g. 0+. If it doesn't exist, null string returned |
bool honorEscape |
if true and separator is preceded by \, then it's not a separator; note that the \ is removed from the result Default value: false |
Tokenize a string using split() and then return the nth token at pos.
Return value: the nth token from input string; or null string
const string& input |
the text with words |
bool excludeStopWords |
Flag: true to ignore stop words (e.g. the, an, etc.), false to keep them Default value: true |
bool includePunctuation |
Flag: true to include punctuation, false to ignore it Default value: false |
Tokenize a string as words, ignoring punctuation (or not). Words are separated by whitespace and punctuation.
Put each word into a vector of strings.
Return value: the words
const vector <string > list |
a series of strings to combine |
const string& delimiter |
the delimiter to insert between the strings |
bool escapeDelimeter |
if an element in the list contains the delimiter, the delimiter is escaped with a backslash Default value: false |
Combine an array of strings and insert delimiters between them.
This is the complement of split().
Return value: a single string
const vector <string > list |
a series of strings to combine |
char delimiter |
the delimiter to insert between the strings |
bool escapeDelimeter |
if an element in the list contains the delimiter, the delimiter is escaped with a backslash Default value: false |
Combine an array of strings and insert delimiters between them.
This is the complement of split().
Return value: a single string
const vector <string > list |
a series of strings to combine |
Combine an array of strings.
This is the complement of split().
Return value: a single string
const string& input |
the string to analyze |
char token |
the token that separates the tokens |
How many tokens are in this string?
Return value: the count of the number of tokens; if the string is blank, 0 is returned
const string& input |
the string to analyze |
char delim |
the delimiter to between the strings |
Does this string contain this character delimiter.
Return value: true if the input contains at least one delim char
const string& input |
the string to analyze |
char token |
the delimiter to between the strings |
How many strings are separated by the token
const string& input |
the string to analyze |
char delimiter |
the delimiter to between the strings |
Takes out any adjacent duplicate delimiters.
Return value: the modified string.
const string& input |
the string to analyze |
char delimiter |
the delimiter to between the strings |
Takes out any trailing delimiters.
Return value: the modified string.
const string& input |
the string to analyze |
char delimiter |
the delimiter to between the strings |
Takes out any leading delimiters.
Return value: the modified string.
string& strToStrip |
the string to be stripped (in place) |
const string& charsToStrip |
contains all chars to be stripped |
Strip specified chars from beginning of string
Return value: ref to string passed in, now stripped
string& strToStrip |
the string to be stripped (in place) |
Strip whitespace from beginning of string
Return value: ref to string passed in, now stripped
string& strToStrip |
the string to be stripped (in place) |
const string& charsToStrip |
contains all chars to be stripped |
Strip specified chars from end of string
Return value: ref to string passed in, now stripped
string& strToStrip |
the string to be stripped (in place) |
Strip whitespace from end of string
Return value: ref to string passed in, now stripped
string& strToStrip |
the string to be stripped (in place) |
const string& charsToStrip |
contains all chars to be stripped |
Strip specified chars from beginning and end of string
Return value: ref to string passed in, now stripped
string& strToStrip |
the string to be stripped (in place) |
Strip whitespace from beginning and end of string
Return value: ref to string passed in, now stripped
const string& input |
a long string |
string::size_type len |
the amount of leftmost characters to pull |
Grab the left most characters of a string
Return value: ref string with leftmost characters
const string& input |
a long string |
unsigned int start |
the starting position (starting at 0) where the substring begins |
long len |
the amount of characters to extract (npos means to end of string) Default value: string::npos |
Grab the middle characters of a string
Return value: ref string with leftmost characters
const string& input |
a long string |
string::size_type len |
the amount of rightmost characters to pull |
Grab the right most characters of a string
Return value: ref string with rightmost characters
const string& input |
the long string |
const string& start |
the text to match at start |
Check if input tring starts with text that matches
Return value: T/F if input string starts with /start/ string
const string& input |
the long string |
const string& ending |
the text to match at start |
Check if input tring ends with text that matches
Return value: T/F if input string starts with /start/ string
const string& input |
the string being parsed |
Get first/next token (up to whitespace) in input string
Use trimToken() to remove the token; token not removed from input.
Return value: the first token in the string.
string& input |
the string being parsed and token removed (in place) |
bool trimWhite |
flag to remove whitespace after removed token Default value: true |
Extract and return first/next token (up to whitespace) in input string
Convenience over using nextToken() and trimToken().
Return value: the first token in the string.
const string& input |
the string being parsed |
char delim |
the token delimiter |
Get first/next token (up to delimiter) in input string
If delimiter is not found, null string returned.
Use trimToken() to remove the token.
Return value: the first token in the string.
const string& input |
the string being parsed |
bool allowClass |
flag to allow classname:: to precede identifier; if true, class name and identifier are returned Default value: false |
Get first/next identifier in input string. An identifier starts with an alphabetic character (or _) and is optionally followed by more characters, which may be alphanumeric or _.
Use trimToken() to remove the token; token not removed from input.
Return value: the first identifier in the string.
string& input |
the string being parsed and token removed (in place) |
bool trimWhite |
flag to remove whitespace after removed identifer Default value: true |
bool allowClass |
flag to allow classname:: to precede identifier; if true, class name and identifier are returned Default value: false |
Extract and return first/next identifier in input string.
Convenience over using nextIdentifier() and trimToken().
Return value: the first identifier in the string.
const string& input |
the string being parsed |
const string& allowed |
the characters allowed in keyword (in addition to alphanumeric chars) Default value: "" |
Get first/next keyword in input string. A keyword may have allowed characters in addition to alphanumeric characters (and _), like "this-one"".
Use trimToken() to remove the token; token not removed from input.
Return value: the first identifier in the string.
string& input |
the string being parsed and token removed (in place) |
const string& allowed |
the characters allowed in keyword (in addition to alphanumeric chars) Default value: "" |
bool trimWhite |
flag to remove whitespace after removed identifer Default value: true |
Extract and return first/next identifier in input string
Convenience over using nextKeyword() and trimToken().
Return value: the first identifier in the string.
const string& input |
the string being parsed |
bool removeQuotes |
Default value: true |
Get first/next token in input string that may be quote contained.
No quotes means just call nextToken(). Quotes may be " or '.
Quotes inside quoted string must be escaped.
Use trimToken() to remove the token; token not removed from input.
Return value: the first token in the string.
string& input |
the string being parsed and token removed (in place) |
bool removeQuotes |
specify whether to remove the quotes from result Default value: true |
Extract and return first/next quoted string in input string
Convenience over using nextQuotedToken() and trimToken(). Quotes may be " or '.
Quotes inside quoted string must be escaped.
Return value: the first token in the string.
const string& input |
the string being parsed |
Get first/next token in input string that may be parenthesis contained.
No parens means just call nextToken(). Parens may be (), [], {}.
Use trimToken() to remove the token; token not removed from input.
Return value: the first token in the string.
string& input |
the string being parsed and token removed (in place) |
Extract and return first/next parenthesis token in input string
Convenience over using nextParenToken() and trimToken(). Parens may be (), [], {}.
Return value: the first token in the string.
string& input |
the string being parsed and token removed (in place) |
bool removeParens |
specify whether to remove the parenthesis from result Default value: true |
Extract and return first/next parenthesized string in input string
Parens may be (), [], {}.
Embedded parens and double quotes are tracked and must be paired.
Return value: the first token in the string.
const string& input |
the string being parsed |
Get first/next floating point number token in input string
Use trimToken() to remove the token; token not removed from input.
Return value: the first token in the string.
string& input |
the string being parsed and token removed (in place) |
bool trimWhite |
flag to remove whitespace after removed token Default value: true |
Extract and return first/next floating point number token in input string
Convenience over using nextToken() and trimToken().
Return value: the first token in the string.
const string& input |
the string being parsed and token removed (in place) |
const string& separator |
specify separator between items, e.g. comma Default value: "," |
bool trimWhite |
true to trim off leading and trailing whitespace from list items Default value: true |
Out a list of items separated by a separator and possibly eliminate whisespace.
Return value: the first token in the string.
const string& input |
input string being reduced |
string::size_type length |
the number of characters to remove from the front |
Remove characters from beginning of input string.
Return value: the input string minus strlen(token) off the front
const string& input |
input string being reduced |
string::size_type length |
the number of characters to remove from the end |
Remove characters from end of input string.
Return value: the input string minus strlen(token) off the end
const string& input |
input string being reduced |
const string& token |
the token string being removed from input string |
bool trimWhite |
flag to remove whitespace after removed token Default value: true |
Remove token from beginning of input string.
Note, no matching is performed to see if token really begins
the string or not. This is simply a convenience for length counting.
Return value: the input string minus strlen(token) off the front
const string& input |
input string being reduced |
const string& token |
the token string being removed from input string |
bool trimWhite |
Default value: true |
Remove token from nextQuotedToken() from beginning of input string.
Note, no matching is performed to see if token really begins
the string or not. This is simply a convenience for length counting.
A check is performed, however, to see if input string has quotes; if so,
2 extra characters are trimmed in addition to token.
Return value: the input string minus strlen(token) off the front
const string& input |
input string being reduced |
const string& textToTrim |
the token string being removed from input string |
Remove leading text from input string if text present, otherwise
leave input string alone. This is just like the ksh(1)
feature of
Return value: the input string minus textToTrim off the front
const string& input |
input string being reduced |
const string& textToTrim |
the token string being removed from input string |
Remove trailing text from input string if text present, otherwise
leave input string alone. This is just like the ksh(1)
feature of
Return value: the input string minus textToTrim off the front
vector retVal |
tokens are returned in this vector, one token per string |
const string& input |
the string to be parsed |
const string& delims |
the chars to use as single character delimiters |
unsigned int maxTokens |
max number of tokens to return, 0 means no limit. Default value: 0 |
Tokenize a string whose tokens are delimited by one ormore delimiter chars, filtering out zero length tokens, and optionally limiting the number of tokens
Return value: the number of tokens returned in retVal
vector retVal |
tokens are returned in this vector, one token per string |
const string& input |
the string to be parsed |
unsigned int maxTokens |
max number of tokens to return, 0 means no limit. Default value: 0 |
Tokenize a string whose tokens are delimited by one or more whitespace chars, filtering out zero length tokens, and optionally limiting the number of tokens
Return value: the number of tokens returned in retVal
FILE* f |
input stream to read from |
Read a line of text from an input stream.
Return value: string of read line. Note: \n removed from line
string& input |
string to be modified |
const string& findThis |
the substring to search for in input |
const string& replaceWith |
the substring to replace findThis with |
unsigned int startNdx |
the index into input at which to begin searching Default value: 0 |
unsigned int maxReplacements |
the max number of replacements to perform, zero means replace all Default value: 0 |
Replace occurences of a specified substring within a string with another string
Return value: reference to input string, now potentially modified
string& input |
string to be modified |
char findThis |
the char to search for in input |
char replaceWith |
the char to replace findThis with |
unsigned int startNdx |
the index into input at which to begin searching Default value: 0 |
unsigned int maxReplacements |
the max number of replacements to perform, zero means replace all Default value: 0 |
Replace occurences of a specified character within a string with another character
Return value: reference to input string, now potentially modified
const string& input |
string to be modified |
const string& findTheseChars |
the chars to search for in input |
const string& translateToTheseChars |
the chars to replace the found chars with |
unsigned int startNdx |
the index into input at which to begin searching Default value: 0 |
unsigned int maxTranslations |
the max number of translations to perform, zero means translate all Default value: 0 |
Translate occurences of a specified set of characters within a string to the corresponding character from another set of characters of equal size
Return value: the translated string
const string& hexAsciiDigits |
string of hex Ascii chars 0-F to be swapped |
Change order of lsb to msb, for example 0001 becomes 1000
Return value: the swapped string
const string& stringToSwap |
string to be swapped containing an even number of chars |
Iterate through the string by 2 and swap the i'th and i+1'th chars
Return value: the resulting swapped string
const string& stringToSwap |
the string to be swapped which should contain an |
Swap the Nybble bit order and the adjacent chars of a string
Return value: the swapped string
const string& input |
the string from which to remove the chars |
const string& charsToRemove |
the chars to remove |
Remove specified chars from a string
Return value: the string with the chars removed
const string& input |
the string to extract the char from |
Convert the string to a char. The string must actually be string representation of a char or 0 will be returned.
Return value: the resulting char, 0 on error
const string& input |
the string to extract the short fromto extract the char from |
Convert the string to a short. The string must actually be string representation of a short or 0 will be returned.
Return value: the resulting short, 0 on error
const string& input |
the string to extract the int from |
Convert the string to a int. The string must actually be string representation of a int or 0 will be returned.
Return value: the resulting short, 0 on error
const string& input |
the string to extract the long from |
Convert the string to a long. The string must actually be string representation of a long or 0 will be returned.
Return value: the resulting short, 0 on error
const string& input |
the string to extract the float from |
Convert the string to a float. The string must actually be string representation of a float or 0 will be returned.
Return value: the resulting short, 0 on error
const string& input |
the string to extract the double from |
Convert the string to a double. The string must actually be string representation of a double or 0 will be returned.
Return value: the resulting short, 0 on errorrn
const string& input |
the string to extract the bool from |
Convert the string to a bool. The string must actually be string representation of a bool or false will be returned.
True is when the first character is T, Y, or 1.
Return value: the resulting short, false on error
const string& input |
the string to convert to upper case |
Convert any lower case letters in the string to upper case
Return value: the upper case string
const string& input |
the string to convert to lower case |
Convert any upper case letters in the string to lower case
Return value: the lower case string
const string& input |
a string with words separated by spaces |
bool allWords |
if true, capitalize all words; if false, capitalize the first word Default value: false |
Capitalize one or more words
const string& s1 |
first string to compare |
const string& s2 |
second string to compare |
bool fStripLdTrlWhitespace |
true means ignore leading/trailing whitespace Default value: false |
Compare input string s to this string, ignoring any differences
in upper/lower case
Return value: the resulting string
const string& input |
the string to reverse |
Reverse the order of the characters in the string
Return value: the reversed string
const string& s |
the string to check |
Utility function; returns true if string is composed of one or more numeric characters and only numeric characters, and false otherwise
Return value: true if s is numeric, false if it is not
const string& s |
the string to check |
string& explanation |
(output) reason why s is not a float |
Returns true if the string can be converted into a floating point number. If it can't, the explanation is stored in the 'explanation'
string
Return value: true if is a proper float
const string& s |
the string to check |
Utility function; Same as isNumeric, but first char may optionally be a '+' or '-' char
const string& formatString |
A string with substrings of the form {key} |
const map <string string |
|
string >& substitutionMap |
|
char startChar |
Default value: '{' |
char endChar |
Default value: '}' |
Substitute substrings of the form {key} with the value corresponding to key in the map.
const string& stringToDequote |
string to remove the quotes from |
Remove leading and trailing single or double quotes from a string. Also, unescape any imbedded quotes if string is quoted.
Return value: the string with quotes removed. If the string was not quoted or not quoted properly, the original string is returned unchanged
string& stringToEscape |
string with \n (modified) |
Escape any newline characters.
This converts the new line character to the two characters "\n".
And converts the two characters "\n" to "\\n".
And converts the three characters "\\n" to "\\\n". Etc.
Return value: the string with \n's removed and escaped
string& stringToUnescape |
escaped string (modified) |
Unescape any newline characters.
This converts the two characters "\n" to the new line character.
And converts the three characters "\\n" to "\n".
And converts the four characters "\\\n" to "\\n". Etc.
Return value: the string with \n's escaped
const string& text |
the text string to check |
Determine if string has a wildcard (*) character.
Return value: true ifex a wildcard is in the string
const string& pattern |
the pattern that contains the wildcard(s) |
const string& text |
the text string to check |
Determine if string has a wildcard (*) character.
Return value: true if a wildcard is in the string