ExchangeFileContents
Loading...
Searching...
No Matches
eut::StdStringFunctions Namespace Reference

Help functions for the processing of strings. More...

Enumerations

enum  EnCoutColor {
  eCOLOR_DEFAULT = 0 , eCOLOR_BLACK = 1 , eCOLOR_BLUE = 2 , eCOLOR_GREEN = 3 ,
  eCOLOR_LIGHTBLUE = 4 , eCOLOR_RED = 5 , eCOLOR_MAGENTA = 6 , eCOLOR_YELLOW = 7 ,
  eCOLOR_LIGHTGRAY = 8 , eCOLOR_GRAY = 9 , eCOLOR_WHITE = 10
}
 
enum  EnStrPos { eBEFORE , eBEHIND , eBOTH }
 

Functions

template<typename T >
std::string toHexstr (const T &rValue, std::size_t hex_len=sizeof(T)<< 1)
 
__tool_export_dll bool isAnInteger (const std::string &rstr)
 
__tool_export_dll void fillString (std::string &rstr, char cFillItem, std::size_t nNumber, EnStrPos ePos)
 
__tool_export_dll char * getFilledString (const char *pch, char cFillItem, std::size_t nNumber, EnStrPos ePos)
 
__tool_export_dll std::string getFilledString (const std::string &rstr, char cFillItem, std::size_t nNumber, EnStrPos ePos)
 
__tool_export_dll void tokenizeString (const std::string &rstrSource, std::vector< std::string > &rTokensVector, const std::string &rstrDelimiters=" ")
 
__tool_export_dll void tokenizeString (const std::string &rstrSource, std::vector< std::string > &rTokensVector, const char &rcDelimiters=' ')
 
__tool_export_dll void tokenizeString (const std::wstring &rwsSource, std::vector< std::wstring > &rTokensVector, wchar_t wcDelimiters=L' ')
 
__tool_export_dll std::size_t replaceAll (std::string &rstrText, const char pzOriginal, const char pzNew)
 
__tool_export_dll std::size_t replaceAll (std::string &rstrText, std::vector< std::size_t > &rPosVector, const char pzOriginal, const char pzNew)
 
__tool_export_dll std::wstring string2wstring (const std::string &rsSourceString)
 
__tool_export_dll std::string wstring2string (const std::wstring &rwsSourceString)
 
__tool_export_dll WORD setColorConsoleCout (EnCoutColor eForeGroundColor, EnCoutColor eBackGroundColor)
 
__tool_export_dll void resetColorConsoleCout (WORD wScreenBufferInfo)
 
__tool_export_dll std::string toLower (const std::string &rstr)
 Converts all uppercase letters of the passed string to lowercase.
 
__tool_export_dll std::wstring toLower (const std::wstring &rstr)
 Converts all uppercase letters of the passed string to lowercase.
 
__tool_export_dll std::string toUpper (const std::string &rstr)
 Converts all lowercase letters of the passed string to uppercase.
 
__tool_export_dll std::wstring toUpper (const std::wstring &rstr)
 Converts all lowercase letters of the passed string to uppercase.
 
__tool_export_dll void trimString (std::string &rstr, char c=' ', EnStrPos ePos=eBEFORE)
 Trim for std::string inspired by:
 
__tool_export_dll void trimString (std::wstring &rstr, wchar_t c=' ', EnStrPos ePos=eBEFORE)
 Trim for std::string inspired by:
 
__tool_export_dll bool insertIfNotAvailable (std::string &rsText, std::size_t nPos, const std::string &rsIns)
 Inserts a string at the position passed, if not already present.
 
__tool_export_dll bool insertIfNotAvailable (std::wstring &rsText, std::size_t nPos, const std::wstring &rsIns)
 Inserts a string at the position passed, if not already present.
 
__tool_export_dll std::size_t replaceAll (std::string &rsText, const std::string &rsFnd, const std::string &rsRep)
 Exchanges all searched substrings in a string with another passed string.
 
__tool_export_dll std::size_t replaceAll (std::wstring &rsText, const std::wstring &rsFnd, const std::wstring &rsRep)
 Exchanges all searched substrings in a string with another passed string.
 
__tool_export_dll bool compareWildcardString (const std::string &rsSearchString, const std::string &rsString)
 Compares two std::string's.
 
__tool_export_dll bool compareWildcardString (const std::wstring &rsSearchString, const std::wstring &rsString)
 Compares two std::string's.
 
__tool_export_dll void colorConsoleCout (const std::string &rsCoutText, EnCoutColor eForeGroundColor, EnCoutColor eBackGroundColor)
 Outputs a string to the console in color.
 
__tool_export_dll void colorConsoleCout (const std::wstring &rsCoutText, EnCoutColor eForeGroundColor, EnCoutColor eBackGroundColor)
 Outputs a string to the console in color.
 

Detailed Description

Help functions for the processing of strings.

Author
Helmut Jakoby

Enumeration Type Documentation

◆ EnCoutColor

Color codes for std::cout output in the console.

Enumerator
eCOLOR_DEFAULT 
eCOLOR_BLACK 
eCOLOR_BLUE 
eCOLOR_GREEN 
eCOLOR_LIGHTBLUE 
eCOLOR_RED 
eCOLOR_MAGENTA 
eCOLOR_YELLOW 
eCOLOR_LIGHTGRAY 
eCOLOR_GRAY 
eCOLOR_WHITE 

◆ EnStrPos

Positioning in the string for StdStringFunctions::fillString(std::string&, char, std::size_t, EnStrPos)

Enumerator
eBEFORE 

It should be inserted or removed at the beginning.

eBEHIND 

It should be inserted or removed at the end.

eBOTH 

It should be inserted or removed at the beginning and at the end.

Function Documentation

◆ colorConsoleCout() [1/2]

__tool_export_dll void eut::StdStringFunctions::colorConsoleCout ( const std::string & rsCoutText,
EnCoutColor eForeGroundColor,
EnCoutColor eBackGroundColor )

Outputs a string to the console in color.

Parameters
[in]rsCoutTextThe text to be output.
[in]eForeGroundColorThe foreground, i.e. text color.
[in]eBackGroundColorThe background color.

◆ colorConsoleCout() [2/2]

__tool_export_dll void eut::StdStringFunctions::colorConsoleCout ( const std::wstring & rsCoutText,
EnCoutColor eForeGroundColor,
EnCoutColor eBackGroundColor )

Outputs a string to the console in color.

Parameters
[in]rsCoutTextThe text to be output.
[in]eForeGroundColorThe foreground, i.e. text color.
[in]eBackGroundColorThe background color.

◆ compareWildcardString() [1/2]

__tool_export_dll bool eut::StdStringFunctions::compareWildcardString ( const std::string & rsSearchString,
const std::string & rsString )

Compares two std::string's.

The search string can contain wildcards ('*' and '?').

Written by Jack Handy - jakkhandy@hotmail.com

See also
https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing

Example:

Parameters
[in]rsSearchStringThe search string with wildcards if necessary.
[in]rsStringThe comparison string with which the search string is compared.
Returns
If true, the search string corresponds to the comparison string passed.
Author
Jack Handy

◆ compareWildcardString() [2/2]

__tool_export_dll bool eut::StdStringFunctions::compareWildcardString ( const std::wstring & rsSearchString,
const std::wstring & rsString )

Compares two std::string's.

The search string can contain wildcards ('*' and '?').

Written by Jack Handy - jakkhandy@hotmail.com

See also
https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing

Example:

Parameters
[in]rsSearchStringThe search string with wildcards if necessary.
[in]rsStringThe comparison string with which the search string is compared.
Returns
If true, the search string corresponds to the comparison string passed.
Author
Jack Handy

◆ fillString()

__tool_export_dll void eut::StdStringFunctions::fillString ( std::string & rstr,
char cFillItem,
std::size_t nNumber,
EnStrPos ePos )

Fills the string passed with characters at the beginning or end.

Parameters
[in,out]rstrReference to the string to be padded.
[in]cFillItemThe character to be padded.
[in]nNumberThe targeted string length.
[in]ePosSpecifies whether to fill at the beginning and/or at the end.
Note
StdStringFunctions::eBOTH is interpreted as StdStringFunctions::eBEHIND!

◆ getFilledString() [1/2]

__tool_export_dll char * eut::StdStringFunctions::getFilledString ( const char * pch,
char cFillItem,
std::size_t nNumber,
EnStrPos ePos )

Fills a passed 0-terminated Char-Array with characters at the beginning or end.

Parameters
[in,out]pchPointer to the 0-terminated char array to be added.
[in]cFillItemThe character to be filled with.
[in]nNumberThe targeted string length.
[in]ePosSpecifies whether to fill at the beginning or at the end.
Returns
The resulting 0-terminated char array.
Note
StdStringFunctions::rBOTH is interpreted as StdStringFunctions::eBEHIND!
Attention
If a valid pointer is supplied, the calling instance must remove the char array from memory using delete[]!

◆ getFilledString() [2/2]

__tool_export_dll std::string eut::StdStringFunctions::getFilledString ( const std::string & rstr,
char cFillItem,
std::size_t nNumber,
EnStrPos ePos )

Fills a passed std::string with characters at the beginning or end.

Parameters
[in,out]rstrString to be added.
[in]cFillItemThe character to be filled with.
[in]nNumberThe targeted string length.
[in]ePosSpecifies whether to fill at the beginning or at the end.
Returns
The resulting 0-terminated char array.
Note
StdStringFunctions::rBOTH is interpreted as StdStringFunctions::eBEHIND!

◆ insertIfNotAvailable() [1/2]

__tool_export_dll bool eut::StdStringFunctions::insertIfNotAvailable ( std::string & rsText,
std::size_t nPos,
const std::string & rsIns )

Inserts a string at the position passed, if not already present.

Parameters
[in,out]rsTextIn this string, the string rsIns is inserted at the position nPos passed, if not already present.
[in]nPosThe position in rsText where is checked and inserted if necessary.
[in]rsInsThe character string to be checked and inserted if necessary.
Returns
If true, rsIns was inserted, otherwise nothing happened.

◆ insertIfNotAvailable() [2/2]

__tool_export_dll bool eut::StdStringFunctions::insertIfNotAvailable ( std::wstring & rsText,
std::size_t nPos,
const std::wstring & rsIns )

Inserts a string at the position passed, if not already present.

Parameters
[in,out]rsTextIn this string, the string rsIns is inserted at the position nPos passed, if not already present.
[in]nPosThe position in rsText where is checked and inserted if necessary.
[in]rsInsThe character string to be checked and inserted if necessary.
Returns
If true, rsIns was inserted, otherwise nothing happened.

◆ isAnInteger()

__tool_export_dll bool eut::StdStringFunctions::isAnInteger ( const std::string & rstr)

Checks the passed string whether it represents an integer.

Parameters
[in]rstrReference to the string to be checked.
Returns
If 'true', sthe passed string represents an integer.

◆ replaceAll() [1/4]

__tool_export_dll std::size_t eut::StdStringFunctions::replaceAll ( std::string & rsText,
const std::string & rsFnd,
const std::string & rsRep )

Exchanges all searched substrings in a string with another passed string.

Parameters
[in,out]rsTextIn this string, all strings from strFnd are removed and the string from strRep is inserted instead.
[in]rsFndThe string to be exchanged.
[in]rsRepThe string to be inserted.
Returns
A return value > 0 is the number of characters exchanged. A return value == 0 means that nothing was exchanged.

◆ replaceAll() [2/4]

__tool_export_dll std::size_t eut::StdStringFunctions::replaceAll ( std::string & rstrText,
const char pzOriginal,
const char pzNew )

Exchanges all searched characters in a string with another passed character.

Parameters
[in,out]rstrTextIn this string, all characters from pzOriginal are removed and the string from pzNew is inserted instead.
[in]pzOriginalThe character to be exchanged.
[in]pzNewThe character to be inserted.
Returns
A return value > 0 is the number of characters exchanged. A return value == 0 means that nothing was exchanged.

◆ replaceAll() [3/4]

__tool_export_dll std::size_t eut::StdStringFunctions::replaceAll ( std::string & rstrText,
std::vector< std::size_t > & rPosVector,
const char pzOriginal,
const char pzNew )

Exchanges all searched characters in a string with another passed character and enters the respective positions in passed vector.

Parameters
[in,out]rstrTextIn this string, all characters from pzOriginal are removed and the string from pzNew is inserted instead.
[in,out]rPosVectorThe positions with the exchanged characters.
[in]pzOriginalThe character to be exchanged.
[in]pzNewThe character to be inserted.
Returns
A return value > 0 is the number of characters exchanged. A return value == 0 means that nothing was exchanged.

◆ replaceAll() [4/4]

__tool_export_dll std::size_t eut::StdStringFunctions::replaceAll ( std::wstring & rsText,
const std::wstring & rsFnd,
const std::wstring & rsRep )

Exchanges all searched substrings in a string with another passed string.

Parameters
[in,out]rsTextIn this string, all strings from strFnd are removed and the string from strRep is inserted instead.
[in]rsFndThe string to be exchanged.
[in]rsRepThe string to be inserted.
Returns
A return value > 0 is the number of characters exchanged. A return value == 0 means that nothing was exchanged.

◆ resetColorConsoleCout()

__tool_export_dll void eut::StdStringFunctions::resetColorConsoleCout ( WORD wScreenBufferInfo)

Sets font to a color of the console to the default color for the next output.

Parameters
[in]wScreenBufferInfoThe CONSOLE_SCREEN_BUFFER_INFO Attribute.

◆ setColorConsoleCout()

__tool_export_dll WORD eut::StdStringFunctions::setColorConsoleCout ( EnCoutColor eForeGroundColor,
EnCoutColor eBackGroundColor )

Sets font to a color of the console to a color for the next output.

Parameters
[in]eForeGroundColorThe foreground, i.e. text color.
[in]eBackGroundColorThe background color.
Returns
The original CONSOLE_SCREEN_BUFFER_INFO attribute is needed to restore the previous state.

◆ string2wstring()

__tool_export_dll std::wstring eut::StdStringFunctions::string2wstring ( const std::string & rsSourceString)

Converts a std::string into a std::wstring.

Parameters
[in]rsSourceStringThe std::string to be converted.
Returns
The resulting std::wstring.
Exceptions
A"range_error" can be thrown when UTF-16 characters ate passed.

◆ toHexstr()

template<typename T >
std::string eut::StdStringFunctions::toHexstr ( const T & rValue,
std::size_t hex_len = sizeof(T) << 1 )

Convert the given integer number value to a hex string.
Found: https://newbedev.com/integer-to-hex-string-in-c

Parameters
[in]rValueThe number value.
[in]hex_lenThe size of the number value.
Returns
The passed number value in the hexadecimal representation in a std::string.

◆ tokenizeString() [1/3]

__tool_export_dll void eut::StdStringFunctions::tokenizeString ( const std::string & rstrSource,
std::vector< std::string > & rTokensVector,
const char & rcDelimiters = ' ' )

Returns from a string all substrings, which are separated by a character, in one vector.

Parameters
[in]rstrSourceThe source string from which substrings are supplied.
[in,out]rTokensVectorThe vector in which the substrings are delivered.
[in]rcDelimitersThe character that divides the source string into substrings.
See also
Taken from https://stackoverflow.com/questions/9823263/string-tokenization-in-c-including-delimiter-characters.

◆ tokenizeString() [2/3]

__tool_export_dll void eut::StdStringFunctions::tokenizeString ( const std::string & rstrSource,
std::vector< std::string > & rTokensVector,
const std::string & rstrDelimiters = " " )

Returns from a string all substrings, which are separated by a character, in one vector.

Parameters
[in]rstrSourceThe source string from which substrings are supplied.
[in,out]rTokensVectorThe vector in which the substrings are delivered.
[in]rstrDelimitersThe character that divides the source string into substrings.
See also
Taken from https://stackoverflow.com/questions/9823263/string-tokenization-in-c-including-delimiter-characters.

◆ tokenizeString() [3/3]

__tool_export_dll void eut::StdStringFunctions::tokenizeString ( const std::wstring & rwsSource,
std::vector< std::wstring > & rTokensVector,
wchar_t wcDelimiters = L' ' )

Returns from a wstring all substrings, which are separated by a character, in one vector.

Parameters
[in]rwsSourceThe source string from which substrings are supplied.
[in,out]rTokensVectorThe vector in which the substrings are delivered.
[in]wcDelimitersThe character that divides the source string into substrings.

◆ toLower() [1/2]

__tool_export_dll std::string eut::StdStringFunctions::toLower ( const std::string & rstr)

Converts all uppercase letters of the passed string to lowercase.

Parameters
[in,out]rstrThe reference to the string to be processed.
Returns
The lowercase equivalent of rstr.

◆ toLower() [2/2]

__tool_export_dll std::wstring eut::StdStringFunctions::toLower ( const std::wstring & rstr)

Converts all uppercase letters of the passed string to lowercase.

Parameters
[in,out]rstrThe reference to the string to be processed.
Returns
The lowercase equivalent of rstr.

◆ toUpper() [1/2]

__tool_export_dll std::string eut::StdStringFunctions::toUpper ( const std::string & rstr)

Converts all lowercase letters of the passed string to uppercase.

Parameters
[in,out]rstrThe reference to the string to be processed.
Returns
The uppercase equivalent of rstr.

◆ toUpper() [2/2]

__tool_export_dll std::wstring eut::StdStringFunctions::toUpper ( const std::wstring & rstr)

Converts all lowercase letters of the passed string to uppercase.

Parameters
[in,out]rstrThe reference to the string to be processed.
Returns
The uppercase equivalent of rstr.

◆ trimString() [1/2]

__tool_export_dll void eut::StdStringFunctions::trimString ( std::string & rstr,
char c = ' ',
EnStrPos ePos = eBEFORE )

Trim for std::string inspired by:

Rodrigo C F Dias

Software Engineering Degree

Living in Natal, Brazil

See also
http://www.codeproject.com/Articles/10880/A-trim-implementation-for-std-string
Parameters
[in,out]rstrReference to the string to be freed from leading and trailing characters.
[in]cThe character to be removed. If rstr == "XXXTestX" and c =='X' and ePos == eBOTH, rstr == becomes "Test".
[in]ePosSpecifies whether to remove at the beginning and/or the end.
Author
Rodrigo C F Dias

◆ trimString() [2/2]

__tool_export_dll void eut::StdStringFunctions::trimString ( std::wstring & rstr,
wchar_t c = ' ',
EnStrPos ePos = eBEFORE )

Trim for std::string inspired by:

Rodrigo C F Dias

Software Engineering Degree

Living in Natal, Brazil

See also
http://www.codeproject.com/Articles/10880/A-trim-implementation-for-std-string
Parameters
[in,out]rstrReference to the string to be freed from leading and trailing characters.
[in]cThe character to be removed. If rstr == "XXXTestX" and c =='X' and ePos == eBOTH, rstr == becomes "Test".
[in]ePosSpecifies whether to remove at the beginning and/or the end.
Author
Rodrigo C F Dias

◆ wstring2string()

__tool_export_dll std::string eut::StdStringFunctions::wstring2string ( const std::wstring & rwsSourceString)

Converts a std::wstring into a std::string.

Parameters
[in]rwsSourceStringThe std::wstring to be converted.
Returns
The resulting std::string.
Note
It is not convertetd to UTF-8 or any other code page, only the bytes are transferred.