Utility functions focusing on string.
More...
|
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...
|
|
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
◆ contains()
bool StrUtils::contains |
( |
const std::string & |
theString, |
|
|
const std::string & |
theSubString |
|
) |
| |
|
inline |
Returns true is theSubString is a substring of theString.
- Parameters
-
theString | The full string to be searched |
theSubString | The 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
-
str | The string to be searched |
end | The 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
-
line | The string to be parsed |
delim | The 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
-
s | The string to be modified |
ch | The 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
-
str | The string to be searched |
start | The 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
-
s | The 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
-
s | The 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
-
s | The 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
-
s | The string to be cleaned up |
nonPrintCharsToRemove | A string of non-printing characters to remove |
removeWS | Will 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
-
vec | The vector of strings to be cleaned |
nonPrintCharsToRemove | A string of non-printing characters to remove |
removeWS | Will 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
-
v | The vector of strings to be cleaned |
- Returns
- A vector of cleaned strings