Class StrExt

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class StrExt

Summary
Public Properties
Public Methods
static vector tokenize(input, delimiter)
static vector split(input, delimiter, honorEscape)
static string getTokenAt(input, delimiter, pos, honorEscape)
static vector tokenizeWords(input, excludeStopWords, includePunctuation)
static string concat(list, delimiter, escapeDelimeter)
static inline string concat(list, delimiter, escapeDelimeter)
static inline string concat(list)
static int tokenCount(input, token)
static bool contains(input, delim)
static int subStringCount(input, token)
static string delAdjDelimiters(input, delimiter)
static string delTrailingDelimiters(input, delimiter)
static string delLeadingDelimiters(input, delimiter)
static string& stripLeading(strToStrip, charsToStrip)
static string& stripLeadingWhitespace(strToStrip)
static string& stripTrailing(strToStrip, charsToStrip)
static string& stripTrailingWhitespace(strToStrip)
static string& stripLeadingTrailing(strToStrip, charsToStrip)
static string& stripLeadingTrailingWhitespace(strToStrip)
static string leftString(input, len)
static string midString(input, start, len)
static string rightString(input, len)
static bool startsWith(input, start)
static bool endsWith(input, ending)
static string nextToken(input)
static string extractToken(input, trimWhite)
static string nextTokenBefore(input, delim)
static string nextIdentifier(input, allowClass)
static string extractIdentifier(input, trimWhite, allowClass)
static string nextKeyword(input, allowed)
static string extractKeyword(input, allowed, trimWhite)
static string nextQuotedToken(input, removeQuotes)
static string extractQuotedToken(input, removeQuotes)
static string nextParenToken(input)
static string extractParenToken(input)
static string extractParenContents(input, removeParens)
static string nextFloatToken(input)
static string extractFloatToken(input, trimWhite)
static vector parseCSVList(input, separator, trimWhite)
static string trimLeft(input, length)
static string trimRight(input, length)
static string trimToken(input, token, trimWhite)
static string trimQuotedToken(input, token, trimWhite)
static string trimIfLeading(input, textToTrim)
static string trimIfTrailing(input, textToTrim)
static unsigned int multiTokenize(retVal, input, delims, maxTokens)
static unsigned int whitespaceTokenize(retVal, input, maxTokens)
static string readLine(f)
static string& findAndReplace(input, findThis, replaceWith, startNdx, maxReplacements)
static string& findAndReplace(input, findThis, replaceWith, startNdx, maxReplacements)
static string translate(input, findTheseChars, translateToTheseChars, startNdx, maxTranslations)
static string swapNybbleBitOrder(hexAsciiDigits)
static string swapAdjacentChars(stringToSwap)
static string swapBitOrder(stringToSwap)
static string removeChars(input, charsToRemove)
static char toChar(input)
static short toShort(input)
static long toInt(input)
static long toLong(input)
static float toFloat(input)
static double toDouble(input)
static bool toBool(input)
static string toUpper(input)
static string toLower(input)
static string capitalize(input, allWords)
static bool cmp_noCase(s1, s2, fStripLdTrlWhitespace)
static string reverse(input)
static bool isNumeric(s)
static bool properFloat(s, explanation)
static bool isSignedNumeric(s)
static string replaceKeys(formatString, string, substitutionMap, startChar, endChar)
static string deQuote(stringToDequote)
static string escapeNewline(stringToEscape)
static string unescapeNewline(stringToUnescape)
static bool hasWildcard(text)
static bool wildMatch(pattern, text)

#include <StrExt.h >

Summary

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.

Public Properties

static const string whitespaceChars

The set of characters that count as whitespace, e.g. space, tab, return, newline, and form feed.


Public Methods

static vector <string > tokenize(input, delimiter)

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

static vector <string > split(input, delimiter, honorEscape)

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

static string getTokenAt(input, delimiter, pos, honorEscape)

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

static vector <string > tokenizeWords(input, excludeStopWords, includePunctuation)

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

static string concat(list, delimiter, escapeDelimeter)

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

static inline string concat(list, delimiter, escapeDelimeter)

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

static inline string concat(list)

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

static int tokenCount(input, token)

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

static bool contains(input, delim)

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

static int subStringCount(input, token)

const string& input

the string to analyze

char token

the delimiter to between the strings


How many strings are separated by the token

static string delAdjDelimiters(input, delimiter)

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.

static string delTrailingDelimiters(input, delimiter)

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.

static string delLeadingDelimiters(input, delimiter)

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.

static string& stripLeading(strToStrip, charsToStrip)

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

static string& stripLeadingWhitespace(strToStrip)

string& strToStrip

the string to be stripped (in place)


Strip whitespace from beginning of string

Return value: ref to string passed in, now stripped

static string& stripTrailing(strToStrip, charsToStrip)

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

static string& stripTrailingWhitespace(strToStrip)

string& strToStrip

the string to be stripped (in place)


Strip whitespace from end of string

Return value: ref to string passed in, now stripped

static string& stripLeadingTrailing(strToStrip, charsToStrip)

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

static string& stripLeadingTrailingWhitespace(strToStrip)

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

static string leftString(input, len)

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

static string midString(input, start, len)

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

static string rightString(input, len)

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

static bool startsWith(input, start)

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

static bool endsWith(input, ending)

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

static string nextToken(input)

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.

static string extractToken(input, trimWhite)

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.

static string nextTokenBefore(input, delim)

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.

static string nextIdentifier(input, allowClass)

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.

static string extractIdentifier(input, trimWhite, allowClass)

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.

static string nextKeyword(input, allowed)

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.

static string extractKeyword(input, allowed, trimWhite)

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.

static string nextQuotedToken(input, removeQuotes)

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.

static string extractQuotedToken(input, removeQuotes)

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.

static string nextParenToken(input)

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.

static string extractParenToken(input)

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.

static string extractParenContents(input, removeParens)

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.

static string nextFloatToken(input)

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.

static string extractFloatToken(input, trimWhite)

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.

static vector <string > parseCSVList(input, separator, trimWhite)

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.

static string trimLeft(input, length)

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

static string trimRight(input, length)

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

static string trimToken(input, token, trimWhite)

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

static string trimQuotedToken(input, token, trimWhite)

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

static string trimIfLeading(input, textToTrim)

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

static string trimIfTrailing(input, textToTrim)

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

static unsigned int multiTokenize(retVal, input, delims, maxTokens)

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

static unsigned int whitespaceTokenize(retVal, input, maxTokens)

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

static string readLine(f)

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

static string& findAndReplace(input, findThis, replaceWith, startNdx, maxReplacements)

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

static string& findAndReplace(input, findThis, replaceWith, startNdx, maxReplacements)

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

static string translate(input, findTheseChars, translateToTheseChars, startNdx, maxTranslations)

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

static string swapNybbleBitOrder(hexAsciiDigits)

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

static string swapAdjacentChars(stringToSwap)

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

static string swapBitOrder(stringToSwap)

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

static string removeChars(input, charsToRemove)

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

static char toChar(input)

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

static short toShort(input)

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

static long toInt(input)

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

static long toLong(input)

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

static float toFloat(input)

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

static double toDouble(input)

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

static bool toBool(input)

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

static string toUpper(input)

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

static string toLower(input)

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

static string capitalize(input, allWords)

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

static bool cmp_noCase(s1, s2, fStripLdTrlWhitespace)

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

static string reverse(input)

const string& input

the string to reverse


Reverse the order of the characters in the string

Return value: the reversed string

static bool isNumeric(s)

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

static bool properFloat(s, explanation)

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

static bool isSignedNumeric(s)

const string& s

the string to check


Utility function; Same as isNumeric, but first char may optionally be a '+' or '-' char

static string replaceKeys(formatString, string, substitutionMap, startChar, endChar)

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.

static string deQuote(stringToDequote)

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

static string escapeNewline(stringToEscape)

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

static string unescapeNewline(stringToUnescape)

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

static bool hasWildcard(text)

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

static bool wildMatch(pattern, text)

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