C++ Common
Functions
StrUtils Namespace Reference

Utility functions focusing on string. More...

Functions

std::string removeCharFromStr (const std::string &s, const char ch)
 Remove character from a string. More...
 
std::string toUpper (const std::string &s)
 Convert string to all uppercase. More...
 
std::string toLower (const std::string &s)
 Convert string to all lowercase. More...
 
std::string trimSpecific (const std::string &s, const std::string &nonPrintCharsToRemove, bool removeWS)
 Clean up a string of specified non-printing characters. More...
 
std::string trim (const std::string &s)
 Clean up a string. More...
 
std::vector< std::string > trimSpecificVec (const std::vector< std::string > &vec, const std::string &nonPrintCharsToRemove, bool removeWS)
 Calls trimSpecific on all string in the vector using the specific charsToRemove string. More...
 
std::vector< std::string > trimStrVec (const std::vector< std::string > &vec)
 Calls trim on all strings in the vector. More...
 
std::vector< std::string > parseOnCharDelim (const std::string &line, const char delim)
 Splits a string into vector based on a specific character. More...
 
bool endsWithString (const std::string &str, const std::string &end)
 Determine if string ends with another string. More...
 
bool startsWithString (const std::string &str, const std::string &start)
 Determine if string starts with another string. More...
 
bool contains (const std::string &theString, const std::string &theSubString)
 Returns true is theSubString is a substring of theString. More...
 

Detailed Description

Utility functions focusing on string.

Author
Sean Grimes, spg63.nosp@m.@cs..nosp@m.drexe.nosp@m.l.ed.nosp@m.u
Date
11-26-15

Function Documentation

◆ contains()

bool StrUtils::contains ( const std::string &  theString,
const std::string &  theSubString 
)
inline

Returns true is theSubString is a substring of theString.

Parameters
theStringThe full string to be searched
theSubStringThe substring to look for in theString
Returns
True if theSubString is a substring of theString

◆ endsWithString()

bool StrUtils::endsWithString ( const std::string &  str,
const std::string &  end 
)
inline

Determine if string ends with another string.

Parameters
strThe string to be searched
endThe string to search for
Returns
True if str ends with end, false otherwise

◆ parseOnCharDelim()

std::vector< std::string > StrUtils::parseOnCharDelim ( const std::string &  line,
const char  delim 
)
inline

Splits a string into vector based on a specific character.

Check FileUtils::csvToMatrix to see how this can be used in a useful manner

Parameters
lineThe string to be parsed
delimThe character to split the string on

◆ removeCharFromStr()

std::string StrUtils::removeCharFromStr ( const std::string &  s,
const char  ch 
)
inline

Remove character from a string.

Parameters
sThe string to be modified
chThe character to search for and remove

◆ startsWithString()

bool StrUtils::startsWithString ( const std::string &  str,
const std::string &  start 
)
inline

Determine if string starts with another string.

Parameters
strThe string to be searched
startThe string to search for
Returns
True if str starts with start, false otherwise

◆ toLower()

std::string StrUtils::toLower ( const std::string &  s)
inline

Convert string to all lowercase.

Parameters
sThe string to be lowercase'd
Returns
A new string, all lowercase

◆ toUpper()

std::string StrUtils::toUpper ( const std::string &  s)
inline

Convert string to all uppercase.

Parameters
sThe string to be uppercase'd
Returns
A new string, all uppercase

◆ trim()

std::string StrUtils::trim ( const std::string &  s)
inline

Clean up a string.

trim removes leading and trailing whitespace and all non-printing characters using the erase/remove idiom

Parameters
sThe string to be cleaned up
Returns
The cleaned string

◆ trimSpecific()

std::string StrUtils::trimSpecific ( const std::string &  s,
const std::string &  nonPrintCharsToRemove,
bool  removeWS 
)
inline

Clean up a string of specified non-printing characters.

trimSpecific removes the specified non-printing characters throughout the entire string, will remove leading and trailing whitespace (spaces) if removeWS is true.

Parameters
sThe string to be cleaned up
nonPrintCharsToRemoveA string of non-printing characters to remove
removeWSWill remove leading and trailing whitespace if true
Returns
The cleaned string

◆ trimSpecificVec()

std::vector< std::string > StrUtils::trimSpecificVec ( const std::vector< std::string > &  vec,
const std::string &  nonPrintCharsToRemove,
bool  removeWS 
)
inline

Calls trimSpecific on all string in the vector using the specific charsToRemove string.

Parameters
vecThe vector of strings to be cleaned
nonPrintCharsToRemoveA string of non-printing characters to remove
removeWSWill remove leading and trailing whitespace if true
Returns
A vector of cleaned strings

◆ trimStrVec()

std::vector< std::string > StrUtils::trimStrVec ( const std::vector< std::string > &  v)
inline

Calls trim on all strings in the vector.

Parameters
vThe vector of strings to be cleaned
Returns
A vector of cleaned strings