cxWidgets 1.0
Functions
cxStringUtils Namespace Reference

String utility functions. More...

Functions

void SplitStringRegex (const std::string &input, const std::string &regex, std::vector< std::string > &resultContainer)
 
bool Find (const std::string &input, const std::string &regex, bool useBasicRegex=false)
 
void Find (const std::string &input, const std::string &regex, std::string &output)
 
bool Replace (std::string &srcStr, const std::string &regexStr, const std::string &replacementStr)
 
std::string replace (const std::string &input, const std::string &search, const std::string &replace)
 Replaces substrings of a string with another string.
 
int stringTo (const std::string &s)
 Converts a string to another type.
 
long stringToLong (const std::string &s)
 
unsigned stringToUnsigned (const std::string &s)
 
double stringToDouble (const std::string &s)
 
long double stringToLongDouble (const std::string &s)
 
std::string stringToString (const std::string &s)
 
void test_stringTo ()
 
std::string toString (const int &x)
 Converts an object to a string, i.e.:
 
std::string toString (const long &x)
 
std::string toString (const double &x)
 
std::string toString (const long double &x)
 
std::string toString (const unsigned &x)
 
std::string toString (const unsigned long &x)
 
std::string toString (const cx::eReturnCode &x)
 
std::string toString (const cx::eInputOptions &x)
 
std::string toString (const cx::eBorderStyle &x)
 
std::string toString (const void *x)
 
void test_toString ()
 
bool startsWithNumber (const std::string &pStr)
 
bool isPrintable (const int &pKey)
 Returns whether or not a key is printable. This should be used.
 
int indexOfLastCap (const std::string &pStr)
 Returns the index of the last capital letter in a string. Returns -1 if there are no capital letters.
 
void toUpper (std::string &theString)
 Converts a string to upper-case.
 
std::string stripNewlines (const std::string &pStr)
 Strips newlines characters from a string and returns.
 
std::string replaceNewlines (const std::string &pStr, const char &pChar)
 Replaces newlines in a string with another character.
 
void insertUnderline (std::string &pStr, char pChar, bool pAll=false)
 Inserts an underline character into.
 
std::string removeChar (const std::string &pString, const int pPos)
 Removes a character from a string.
 
std::string strToUpper (const std::string &theString)
 conver the string to upper case
 
std::string strToLower (const std::string &theString)
 conver the string to lower case
 
void TrimSpaces (std::string &str)
 Trims leading & trailing spaces from a string.
 
void splitStringOnNewlines (const std::string &pStr, std::list< std::string > &pStrings)
 Splits a string on newlines.
 

Detailed Description

String utility functions.

Function Documentation

◆ Find() [1/2]

bool cxStringUtils::Find ( const std::string &  input,
const std::string &  regex,
bool  useBasicRegex = false 
)

Performs a regular expression search on a string. Returns true or false, depending on whether or not the regex was found.

Parameters
inputThe string to search
regexRegular expression to search for
useBasicRegexSpecifies whether to use basic regular expressions (when false, extended regular exprssions are used).
Returns
Indicates whether expression found

References Find().

Referenced by Find(), and Find().

◆ Find() [2/2]

void cxStringUtils::Find ( const std::string &  input,
const std::string &  regex,
std::string &  output 
)

Performs a regular expression search on a string and copies the resulting string into output.

Parameters
inputThe string to search
regexRegular expression to search for
outputResult string copied here

References Find().

◆ indexOfLastCap()

int cxStringUtils::indexOfLastCap ( const std::string &  pStr)

Returns the index of the last capital letter in a string. Returns -1 if there are no capital letters.

Parameters
pStrThe string to search
Returns
The index of the last capital letter in pStr, or -1 if there isn't one.

References indexOfLastCap().

Referenced by indexOfLastCap().

◆ insertUnderline()

void cxStringUtils::insertUnderline ( std::string &  pStr,
char  pChar,
bool  pAll = false 
)

Inserts an underline character into.

a string for a character.

Parameters
pStrThe string into which to insert an underline
pCharThe character for which to insert an underline character
pAllWhether or not to underline all occurances of the character in the string (defaults to false)

◆ isPrintable()

bool cxStringUtils::isPrintable ( const int &  pKey)

Returns whether or not a key is printable. This should be used.

instead of isprint() because isprint() returns true for some keys

that cxWidgets does not consider printable, such as pageUp,

pageDown, insert, and mouse clicks.

Parameters
pKeyA key to check
Returns
Whether or not the key is printable

References PAGE_DOWN, and PAGE_UP.

Referenced by startsWithNumber().

◆ removeChar()

std::string cxStringUtils::removeChar ( const std::string &  pString,
const int  pPos 
)

Removes a character from a string.

Parameters
pStringThe string to remove the character from
pPosThe index of the character to remove
Returns
The new string with the character removed

◆ replace()

std::string cxStringUtils::replace ( const std::string &  input,
const std::string &  search,
const std::string &  replace 
)

Replaces substrings of a string with another string.

Parameters
inputThe string to be modified
searchThe substring to be replaced
replaceThe string to replace the search string
Returns
The resulting string with replacements done

References stringTo(), stringToLong(), stringToLongDouble(), and toString().

◆ Replace()

bool cxStringUtils::Replace ( std::string &  srcStr,
const std::string &  regexStr,
const std::string &  replacementStr 
)

Performs a search & replace basd on a regular expression search pattern & a replacement string (the replacemnt string supports backquoting of named paranthetical buffers, i.e. \1, \2, etc.). Returns whether or not the regular expression string was found.

Parameters
srcStrThe string on which to perform the search/replace operation
regexStrRegular expression to search for
replacementStrString to replace target with
Returns
Indicates whether regular expression found

Referenced by test_Replace().

◆ replaceNewlines()

std::string cxStringUtils::replaceNewlines ( const std::string &  pStr,
const char &  pChar 
)

Replaces newlines in a string with another character.

Parameters
pStrThe string to process
pCharThe character to replace newlines with
Returns
A copy of pStr with newlines replaced with pChar.

◆ splitStringOnNewlines()

void cxStringUtils::splitStringOnNewlines ( const std::string &  pStr,
std::list< std::string > &  pStrings 
)

Splits a string on newlines.

Parameters
pStrThe string to split
pStrings(OUT) This will contain the resulting lines

◆ SplitStringRegex()

void cxStringUtils::SplitStringRegex ( const std::string &  input,
const std::string &  regex,
std::vector< std::string > &  resultContainer 
)

Splits a string based on a regular expression, similar to Perl's split function.

Parameters
inputString to split
regexRegular expression used to split string
resultContainerConainer for strings split off from input

References SplitStringRegex().

Referenced by cx::cxWindow::init(), SplitStringRegex(), and wrapText().

◆ startsWithNumber()

bool cxStringUtils::startsWithNumber ( const std::string &  pStr)

Returns whether a string starts with a number (positive or negative).

Parameters
pStrThe string to test
Returns
Whether or not the string starts with a number

References isPrintable().

◆ stringTo()

int cxStringUtils::stringTo ( const std::string &  s)

Converts a string to another type.

Parameters
sA string to be converted.
Returns
The value of the string converted to the given type

Referenced by replace(), and test_stringTo().

◆ stringToDouble()

double cxStringUtils::stringToDouble ( const std::string &  s)

Referenced by test_stringTo().

◆ stringToLong()

long cxStringUtils::stringToLong ( const std::string &  s)

Referenced by replace(), and test_stringTo().

◆ stringToLongDouble()

long double cxStringUtils::stringToLongDouble ( const std::string &  s)

Referenced by replace().

◆ stringToString()

string cxStringUtils::stringToString ( const std::string &  s)

Referenced by test_stringTo().

◆ stringToUnsigned()

unsigned cxStringUtils::stringToUnsigned ( const std::string &  s)

Referenced by fKeySort(), and test_stringTo().

◆ stripNewlines()

std::string cxStringUtils::stripNewlines ( const std::string &  pStr)

Strips newlines characters from a string and returns.

the new version of the string.

Parameters
pStrA string to process
Returns
A version of pStr without newline characters

◆ strToLower()

std::string cxStringUtils::strToLower ( const std::string &  theString)

conver the string to lower case

Parameters
theStringto convert
Returns
the converted string

References strToLower().

Referenced by strToLower(), and test_strToLower().

◆ strToUpper()

std::string cxStringUtils::strToUpper ( const std::string &  theString)

conver the string to upper case

Parameters
theStringto convert
Returns
the converted string

Referenced by test_strToUpper().

◆ test_stringTo()

void cxStringUtils::test_stringTo ( )

◆ test_toString()

void cxStringUtils::test_toString ( )

◆ toString() [1/10]

std::string cxStringUtils::toString ( const cx::eBorderStyle x)

◆ toString() [2/10]

std::string cxStringUtils::toString ( const cx::eInputOptions x)

◆ toString() [3/10]

std::string cxStringUtils::toString ( const cx::eReturnCode x)

◆ toString() [4/10]

std::string cxStringUtils::toString ( const double &  x)

◆ toString() [5/10]

std::string cxStringUtils::toString ( const int &  x)

◆ toString() [6/10]

std::string cxStringUtils::toString ( const long &  x)

◆ toString() [7/10]

std::string cxStringUtils::toString ( const long double &  x)

◆ toString() [8/10]

std::string cxStringUtils::toString ( const unsigned &  x)

◆ toString() [9/10]

std::string cxStringUtils::toString ( const unsigned long &  x)

◆ toString() [10/10]

std::string cxStringUtils::toString ( const void *  x)

◆ toUpper()

void cxStringUtils::toUpper ( std::string &  theString)

Converts a string to upper-case.

Parameters
theStringThe string to be converted

References toUpper().

Referenced by toUpper().

◆ TrimSpaces()

void cxStringUtils::TrimSpaces ( std::string &  str)

Trims leading & trailing spaces from a string.

Parameters
str(INOUT) This string will get its leading & trailing spaces trimmed.

References TrimSpaces().

Referenced by test_TrimSpaces(), and TrimSpaces().