TrueReality  v0.1.1912
trUtil::StringUtils Namespace Reference

Classes

class  IsDelimeter
 Generic string delimeter check function class. More...
 
class  IsSlash
 Determines if the current character is a forward slash. More...
 
class  IsSpace
 A functor which tests if a character is whitespace. More...
 
struct  StrCompareFunc
 A functor for using std::find or whatever that will compare two strings case sensitive or insensitive. More...
 
class  StringTokenizer
 The predicate should evaluate to true when applied to a separator. More...
 

Functions

static const std::string STR_BLANK ("")
 Constant value for a blank String. More...
 
TR_UTIL_EXPORT const std::string & Trim (std::string &toTrim)
 Trims whitespace off the front and end of a string. More...
 
TR_UTIL_EXPORT int StrCompare (const std::string &one, const std::string &two, bool caseSensitive=true)
 Compares strings like strcmp or stricmp or strcasecmp. More...
 
TR_UTIL_EXPORT void ToLowerCase (std::string &str)
 Converts the whole string to lower case. More...
 
TR_UTIL_EXPORT std::string ToLowerCase (const std::string &str)
 Converts the whole string to lower case, slower version. More...
 
TR_UTIL_EXPORT void ToUpperCase (std::string &str)
 Converts the whole string to upper case. More...
 
TR_UTIL_EXPORT std::string ToUpperCase (const std::string &str)
 Converts the whole string to upper case, slower version. More...
 
template<class VecType >
bool ParseVec (const std::string &value, VecType &vec, unsigned size, unsigned numberPrecision=16)
 A templated function for taking any of the osg vector types and reading the data from a string. More...
 
template<typename T >
std::string ToString (const T &t, int precision=-1)
 A utility function to convert a basic type into a string. More...
 
template<typename T >
FromString (const std::string &u)
 Converts a string to a specified type. More...
 
template<>
bool TR_UTIL_EXPORT FromString< bool > (const std::string &u)
 Special exception for bool where things like "True", "TRUE", and "true" should be accepted. More...
 
bool TR_UTIL_EXPORT Match (const char *wildCards, const char *str)
 Matches. More...
 
void TR_UTIL_EXPORT MakeIndexString (unsigned index, std::string &toFill, unsigned paddedLength=4)
 Makes index string. More...
 
bool TR_UTIL_EXPORT TakeToken (std::string &data, std::string &outToken, char openChar, char closeChar)
 Reads the next token fromm the given string data. More...
 
void TR_UTIL_EXPORT FindAndReplace (std::string &modifiedString, const std::string &findWhat, const std::string &replaceWith)
 Finds all instances of the findWhat string in the string modifiedString and replaces them with the replaceWith string. More...
 
template<>
bool FromString< bool > (const std::string &u)
 Special exception for bool where things like "True", "TRUE", and "true" should be accepted. More...
 
static bool Scan (const char *&wildCards, const char *&str)
 
static bool WildMatch (const char *wildCards, const char *str)
 

Function Documentation

◆ FindAndReplace()

void trUtil::StringUtils::FindAndReplace ( std::string &  modifiedString,
const std::string &  findWhat,
const std::string &  replaceWith 
)

Finds all instances of the findWhat string in the string modifiedString and replaces them with the replaceWith string.

Parameters
[out]modifiedStringThe string we are modifying.
[in]findWhatThe string we want to remove from modifiedString.
[in]replaceWithThe string we want to put in modifiedString.

Definition at line 310 of file StringUtils.cpp.

References LOG_E.

Referenced by FromString(), and trUtil::VersionUtil::GetCurrentCommitNum().

Here is the caller graph for this function:

◆ FromString()

template<typename T >
T trUtil::StringUtils::FromString ( const std::string &  u)

Converts a string to a specified type.

Parameters
ustring to be converted to the specified template argument type.
Returns
the type that you specify as the template argument.
     Typical use:
std::string mystring("0");
float myfloat = StringUtils::FromString&lt;float&gt;( mystring );
.

Definition at line 362 of file StringUtils.h.

References FindAndReplace(), FromString< bool >(), MakeIndexString(), Match(), and TakeToken().

Here is the call graph for this function:

◆ FromString< bool >() [1/2]

template<>
bool trUtil::StringUtils::FromString< bool > ( const std::string &  u)

Special exception for bool where things like "True", "TRUE", and "true" should be accepted.

Template Parameters
boolType of the bool.
Parameters
uThe std::string to process.
Returns
True if it succeeds, false if it fails.

Definition at line 126 of file StringUtils.cpp.

Referenced by FromString().

Here is the caller graph for this function:

◆ FromString< bool >() [2/2]

template<>
bool trUtil::StringUtils::FromString< bool > ( const std::string &  u)

Special exception for bool where things like "True", "TRUE", and "true" should be accepted.

Template Parameters
boolType of the bool.
Parameters
uThe std::string to process.
Returns
True if it succeeds, false if it fails.

Definition at line 126 of file StringUtils.cpp.

Referenced by FromString().

Here is the caller graph for this function:

◆ MakeIndexString()

void trUtil::StringUtils::MakeIndexString ( unsigned  index,
std::string &  toFill,
unsigned  paddedLength = 4 
)

Makes index string.

Returns
a string with text as an int value padded to the size specified.
Parameters
indexZero-based index of the.
[in,out]toFillto fill.
paddedLength(Optional) Length of the padded.

Definition at line 222 of file StringUtils.cpp.

Referenced by FromString().

Here is the caller graph for this function:

◆ Match()

bool trUtil::StringUtils::Match ( const char *  wildCards,
const char *  str 
)

Matches.

Parameters
wildCardsThe wild cards.
strThe string.
Returns
True if it succeeds, false if it fails.

Definition at line 216 of file StringUtils.cpp.

References WildMatch().

Referenced by FromString(), and Scan().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseVec()

template<class VecType >
bool trUtil::StringUtils::ParseVec ( const std::string &  value,
VecType &  vec,
unsigned  size,
unsigned  numberPrecision = 16 
)

A templated function for taking any of the osg vector types and reading the data from a string.

If the string is empty or "NULL" it will set the vector to all 0s. It expects the data to be the proper number floating point values. The function will fail if there are not enough values.

Parameters
valuethe string data.
[in,out]vecthe vector to fill.
sizethe length of the vector since the osg types have no way to query that.
numberPrecision(Optional) This value indicates how much precision the numbers will contain when read from the string. (setprecision on std::istream)
Returns
true if reading the data was successful or false if not.

Definition at line 287 of file StringUtils.h.

◆ Scan()

static bool trUtil::StringUtils::Scan ( const char *&  wildCards,
const char *&  str 
)
static

Definition at line 133 of file StringUtils.cpp.

References Match().

Referenced by WildMatch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ STR_BLANK()

static const std::string trUtil::StringUtils::STR_BLANK ( ""  )
static

Constant value for a blank String.

Referenced by trUtil::VersionUtil::GetCurrentCommitNum(), and trUtil::PathUtils::GetDataPath().

Here is the caller graph for this function:

◆ StrCompare()

int trUtil::StringUtils::StrCompare ( const std::string &  one,
const std::string &  two,
bool  caseSensitive = true 
)

Compares strings like strcmp or stricmp or strcasecmp.

Parameters
onethe first string to compare.
twothe string to compare one to.
caseSensitive(Optional) optional parameter to specify case sensitivity, which defaults to on.
Returns
0 for equal, negative for one less that two, and positive for one > two.

Definition at line 74 of file StringUtils.cpp.

References strCmp.

Referenced by trUtil::FileUtils::DirGetFiles(), and trUtil::StringUtils::StrCompareFunc::operator()().

Here is the caller graph for this function:

◆ TakeToken()

bool trUtil::StringUtils::TakeToken ( std::string &  data,
std::string &  outToken,
char  openChar,
char  closeChar 
)

Reads the next token fromm the given string data.

This will also remove the token from the data string and return you the token (with the open and close characters removed). The beginning of the data string must always begin with an opening character or this will cause problems.

Parameters
[in]dataThe string data.
[out]outTokenThe first token from the string data.
[in]openCharThe character that starts the token.
[in]closeCharThe character that ends the token.
Returns
true if a token was found.

Definition at line 231 of file StringUtils.cpp.

Referenced by FromString().

Here is the caller graph for this function:

◆ ToLowerCase() [1/2]

void trUtil::StringUtils::ToLowerCase ( std::string &  str)

Converts the whole string to lower case.

Parameters
[in,out]strThe string.

Definition at line 89 of file StringUtils.cpp.

Referenced by ToLowerCase().

Here is the caller graph for this function:

◆ ToLowerCase() [2/2]

std::string trUtil::StringUtils::ToLowerCase ( const std::string &  str)

Converts the whole string to lower case, slower version.

Parameters
strThe string.
Returns
Str as a std::string.

Definition at line 98 of file StringUtils.cpp.

References ToLowerCase().

Here is the call graph for this function:

◆ ToString()

template<typename T >
std::string trUtil::StringUtils::ToString ( const T &  t,
int  precision = -1 
)

A utility function to convert a basic type into a string.

Use template argument T for the type you'd like to convert.

Parameters
tthe instance of the type to converted.
                 Typical use:
float num = 5.67f;
std::string mynum = StringUtils::ToString( num );
.
precision(Optional) The precision.
Returns
A std::string that represents this object.

Definition at line 334 of file StringUtils.h.

Referenced by trUtil::hash< trBase::UniqueId >::operator()(), trUtil::hash< const trBase::UniqueId >::operator()(), and trUtil::DateTime::TimeFormat::TimeFormat().

Here is the caller graph for this function:

◆ ToUpperCase() [1/2]

void trUtil::StringUtils::ToUpperCase ( std::string &  str)

Converts the whole string to upper case.

Parameters
[in,out]strThe string.

Definition at line 107 of file StringUtils.cpp.

Referenced by ToUpperCase().

Here is the caller graph for this function:

◆ ToUpperCase() [2/2]

std::string trUtil::StringUtils::ToUpperCase ( const std::string &  str)

Converts the whole string to upper case, slower version.

Parameters
strThe string.
Returns
Str as a std::string.

Definition at line 116 of file StringUtils.cpp.

References ToUpperCase().

Here is the call graph for this function:

◆ Trim()

const std::string & trUtil::StringUtils::Trim ( std::string &  toTrim)

Trims whitespace off the front and end of a string.

Parameters
[in,out]toTrimthe string to trim.
Returns
A reference to a const std::string.

Definition at line 58 of file StringUtils.cpp.

◆ WildMatch()

static bool trUtil::StringUtils::WildMatch ( const char *  wildCards,
const char *  str 
)
static

Definition at line 187 of file StringUtils.cpp.

References Scan().

Referenced by Match().

Here is the call graph for this function:
Here is the caller graph for this function: