RedFlame v0.1.1
A high intensity flame eminating from software
Loading...
Searching...
No Matches
Gen::StringUtils Class Reference

Some useful static functions for working with std::strings. More...

#include <StringUtils.h>

Static Public Member Functions

Modifers
static std::string toUpper (const std::string &s1)
 
static std::string toLower (const std::string &s1)
 
static void trim (std::string &s1, const std::string &s2=StringUtils::whiteSpace)
 
static void trim (std::string &s1, const char *pChars)
 
static void trim (std::string &s1, char c)
 
static void trimFront (std::string &s1, const std::string &s2=StringUtils::whiteSpace)
 
static void trimFront (std::string &s1, const char *pChars)
 
static void trimFront (std::string &s1, char c)
 
static void trimEnd (std::string &s1, const std::string &s2=StringUtils::whiteSpace)
 
static void trimEnd (std::string &s1, const char *pChars)
 
static void trimEnd (std::string &s1, char c)
 
static void prepend (std::string &s1, const std::string &s2)
 
static void prepend (std::string &s1, const char *pChars)
 
static void prepend (std::string &s1, char c)
 
static void replace (std::string &s1, const std::string &oldSubstring, const std::string &newSubstring)
 
static void replace (std::string &s1, const char *oldSubstring, const char *newSubstring)
 
Observers
static std::string toString (const char *pFmt,...)
 
static bool startsWith (const std::string &s1, const std::string &s2)
 
static bool startsWith (const std::string &s1, const char *pChars)
 
static bool startsWith (const std::string &s1, char c)
 
static bool startsWithAnyOf (const std::string &s1, const std::string &s2)
 
static bool startsWithAnyOf (const std::string &s1, const char *pChars)
 
static bool endsWith (const std::string &s1, const std::string &s2)
 
static bool endsWith (const std::string &s1, const char *pChars)
 
static bool endsWith (const std::string &s1, char c)
 
static bool endsWithAnyOf (const std::string &s1, const std::string &s2)
 
static bool endsWithAnyOf (const std::string &s1, const char *pChars)
 
static bool containsAnyOf (const std::string &s1, const std::string &s2)
 
static bool containsAnyOf (const std::string &s1, const char *pChars)
 
static bool insensitiveEquals (const std::string &s1, const std::string &s2)
 
static bool insensitivePredicate (const std::string::value_type &s1, const std::string::value_type &s2)
 
static int countCharInString (const std::string &s1, char c)
 

Static Public Attributes

static const std::string whiteSpace
 these chars " \t\v\f\r\n"
 

Detailed Description

Some useful static functions for working with std::strings.

Most of these functions change the string in-place.

Member Function Documentation

◆ containsAnyOf() [1/2]

bool Gen::StringUtils::containsAnyOf ( const std::string & s1,
const char * pChars )
inlinestatic

Determine if a string contains any characters in the given C-style string.

Parameters
[in]s1The string to operate on.
[in]pCharsThe C-style string to look for in s1.
Returns
True if s1 contains the characters in pChars, otherwise false.

◆ containsAnyOf() [2/2]

bool StringUtils::containsAnyOf ( const std::string & s1,
const std::string & any )
static

Determine if a string contains any characters in the given string.

Parameters
[in]s1The string to operate on.
[in]anyThe characters to look for in s.
Returns
True if s1 contains and characters in any, otherwise false.

◆ countCharInString()

int StringUtils::countCharInString ( const std::string & s1,
char c )
static

Return the total number of occurrences of c in s1.

Parameters
[in]s1The string to operate on.
[in]cThe character to count.
Returns
The total number of occurrences of c in s1.

◆ endsWith() [1/3]

bool Gen::StringUtils::endsWith ( const std::string & s1,
char c )
inlinestatic

Determine if the string ends with the given character.

Parameters
[in]s1The string to operate on.
[in]cThe character to look for.
Returns
True if s1 ends with c, otherwise false.

◆ endsWith() [2/3]

bool Gen::StringUtils::endsWith ( const std::string & s1,
const char * pChars )
inlinestatic

Determine if the string ends with the given C-style string.

Parameters
[in]s1The string to operate on.
[in]pCharsThe C-style string to look for.
Returns
True if s1 ends with pChar, otherwise false.

◆ endsWith() [3/3]

bool StringUtils::endsWith ( const std::string & s1,
const std::string & s2 )
static

Determine if the string ends with the given string.

Parameters
[in]s1The string to operate on.
[in]s2The string to look for.
Returns
True if s1 ends with s2, otherwise false.

◆ endsWithAnyOf() [1/2]

bool Gen::StringUtils::endsWithAnyOf ( const std::string & s1,
const char * pChars )
inlinestatic

Determine if a string ends with any of the characters in the given C-style string.

Parameters
[in]s1The string to operate on.
[in]pCharsThe characters to look for as a C-style.
Returns
True if s1 ends with any of the characters in pChars, otherwise false.

◆ endsWithAnyOf() [2/2]

bool StringUtils::endsWithAnyOf ( const std::string & s1,
const std::string & any )
static

Determine if a string ends with any of the characters in a given string.

Parameters
[in]s1The string to operate on.
[in]anyThe characters to look for as a std::string.
Returns
True if s1 ends with any of the characters in any, otherwise false.

◆ insensitiveEquals()

bool StringUtils::insensitiveEquals ( const std::string & s1,
const std::string & s2 )
static

Case insensitive comparison of two string objects.

Parameters
[in]s1The first string to use for comparison.
[in]s2The second string to use for comparison.
Returns
True, if the strings have the same case-insensitive content, otherwise false.

◆ insensitivePredicate()

bool StringUtils::insensitivePredicate ( const std::string::value_type & s1,
const std::string::value_type & s2 )
static

Predicate for insensitive comparison of string objects.

Parameters
[in]s1The first character to use for comparison.
[in]s2The second character to use for comparison.
Returns
True if the characters have the same case-insensitive content, otherwise false.

◆ prepend() [1/3]

void Gen::StringUtils::prepend ( std::string & s1,
char c )
inlinestatic

Prepend character c to the string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]cThe character to prepend.

◆ prepend() [2/3]

void Gen::StringUtils::prepend ( std::string & s1,
const char * pChars )
inlinestatic

Prepend C-style string to the string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]pCharsThe C-style string to prepend.

◆ prepend() [3/3]

void Gen::StringUtils::prepend ( std::string & s1,
const std::string & s2 )
inlinestatic

Prepend string s2 to s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]s2The string to prepend.

◆ replace() [1/2]

void Gen::StringUtils::replace ( std::string & s1,
const char * substringOld,
const char * substringNew )
inlinestatic

Replace all occurences of one substring with another.

Parameters
[in,out]s1The string to operate on.
[in]substringOldThe C-style substring within s1 that needs replacing.
[in]substringNewThe C-style replacement substring.

◆ replace() [2/2]

void StringUtils::replace ( std::string & s1,
const std::string & substringOld,
const std::string & substringNew )
static

Replace all occurences of one substring with another.

Parameters
[in,out]s1The string to operate on.
[in]substringOldThe substring within s that needs replacing.
[in]substringNewThe replacement substring.

◆ startsWith() [1/3]

bool Gen::StringUtils::startsWith ( const std::string & s1,
char c )
inlinestatic

Determine if a string starts with the given character.

Parameters
[in]s1The string to search.
[in]cThe character to look for.
Returns
True if s1 starts with the given character, otherwise false.

◆ startsWith() [2/3]

bool Gen::StringUtils::startsWith ( const std::string & s1,
const char * pChars )
inlinestatic

Determine if a string starts with the given C-style string.

Parameters
[in]s1The string to search.
[in]pCharsThe C-style string to look for.
Returns
True if s1 starts with the given string, otherwise false.

◆ startsWith() [3/3]

bool StringUtils::startsWith ( const std::string & s1,
const std::string & s2 )
static

Determine if a string starts with the given string.

Parameters
[in]s1The string to operate on.
[in]s2The string to look for.
Returns
True if s1 starts with s2, otherwise false.

◆ startsWithAnyOf() [1/2]

bool Gen::StringUtils::startsWithAnyOf ( const std::string & s1,
const char * pChars )
inlinestatic

Determine if a string starts with any of the characters in a given C-style string.

Parameters
[in]s1The string to operator on.
[in]pCharsThe characters to look for as a C-style string.
Returns
True if s1 starts with any characters in pChars, otherwise false.

◆ startsWithAnyOf() [2/2]

bool StringUtils::startsWithAnyOf ( const std::string & s1,
const std::string & any )
static

Determine if a string starts with any of the characters in a given string.

Parameters
[in]s1The string to operate on.
[in]anyThe characters to look for as a std::string.
Returns
True if s1 starts with any characters in any, otherwise false.

◆ toLower()

std::string StringUtils::toLower ( const std::string & s1)
static

Returns a new string converted to lower case.

Parameters
[in]s1The string to convert.
Returns
The converted string.

◆ toString()

std::string StringUtils::toString ( const char * pFmt,
... )
static

Returns a std::string formated with printf style arguments.

Parameters
[in]pFmtThe format specification.
Returns
Formatted string.

◆ toUpper()

std::string StringUtils::toUpper ( const std::string & s1)
static

Returns a new string converted to upper case.

Parameters
[in]s1The string to convert.
Returns
The converted string.

◆ trim() [1/3]

void StringUtils::trim ( std::string & s1,
char c )
static

Removes the given character from the front and back of string in-place.

Parameters
[in,out]s1The string to operate on.
[in]cThe character to remove.

◆ trim() [2/3]

void StringUtils::trim ( std::string & s1,
const char * pChars )
static

Removes the C-style substring from the front and back of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]pCharsThe C-style substring to remove.

◆ trim() [3/3]

void StringUtils::trim ( std::string & s1,
const std::string & s2 = StringUtils::whiteSpace )
static

Removes the substring s2 from the front and back of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]s2The substring to remove.

◆ trimEnd() [1/3]

void Gen::StringUtils::trimEnd ( std::string & s1,
char c )
inlinestatic

Removes the character from the end of string s1 in-place.

Parameters
[in,out]s1The string to operator on.
[in]cThe character to remove.

◆ trimEnd() [2/3]

void Gen::StringUtils::trimEnd ( std::string & s1,
const char * pChars )
inlinestatic

Removes the C-style string from the end of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]pCharsThe C-style string to remove.

◆ trimEnd() [3/3]

void StringUtils::trimEnd ( std::string & s1,
const std::string & s2 = StringUtils::whiteSpace )
static

Removes the substring s2 from the back of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]s2The substring to remove.

◆ trimFront() [1/3]

void Gen::StringUtils::trimFront ( std::string & s1,
char c )
inlinestatic

Removes the character c from the front of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]cThe character to remove.

◆ trimFront() [2/3]

void Gen::StringUtils::trimFront ( std::string & s1,
const char * pChars )
inlinestatic

Removes the C-style string from the front of string s1 in-place.

Parameters
[in,out]s1The string to operator on.
[in]pCharsThe character to remove.

◆ trimFront() [3/3]

void StringUtils::trimFront ( std::string & s1,
const std::string & s2 = StringUtils::whiteSpace )
static

Removes the substring s2 from the front of string s1 in-place.

Parameters
[in,out]s1The string to operate on.
[in]s2The substring to remove.

The documentation for this class was generated from the following files: