String Trimming Utilities#
Functions#
- std::string & omni::extras::ltrim(std::string &s, const char *t=kTrimCharsDefault)
Performs an in-place left-trim on a given string.
- std::string & omni::extras::rtrim(std::string &s, const char *t=kTrimCharsDefault)
Performs an in-place right-trim on a given string.
- std::string & omni::extras::trim(std::string &s, const char *t=kTrimCharsDefault)
Performs an in-place trim (from both sides) on a given string.
- std::string omni::extras::trimCopy(std::string s, const char *t=kTrimCharsDefault)
Performs a trim (from both sides) on a given string, returning a copy.
Variables#
- constexpr char omni::extras::kTrimCharsDefault
Default whitespace characters for string trimming functions.
Functions#
- inline std::string &omni::extras::ltrim(
- std::string &s,
- const char *t = kTrimCharsDefault,
Performs an in-place left-trim on a given string.
This will trim the characters in
tfrom the left side ofs. e.g. givens=" asdf "with the defaulttvalue,swould be modified to contain"asdf ". This is effectivelys.erase(0, s.find_first_not_of(t)).See also
- Parameters:
s – The string to trim in-place
t – A string containing the list of characters to trim (such as kTrimCharsDefault)
- Returns:
sfor convenience
- inline std::string &omni::extras::rtrim(
- std::string &s,
- const char *t = kTrimCharsDefault,
Performs an in-place right-trim on a given string.
This will trim the characters in
tfrom the right side ofs. e.g. givens=" asdf "with the defaulttvalue,swould be modified to contain" asdf". This is effectivelys.erase(s.find_last_not_of(t) + 1).See also
- Parameters:
s – The string to trim in-place
t – A string containing the list of characters to trim (such as kTrimCharsDefault)
- Returns:
sfor convenience
- inline std::string &omni::extras::trim(
- std::string &s,
- const char *t = kTrimCharsDefault,
Performs an in-place trim (from both sides) on a given string.
This will trim the characters in
tfrom both sides ofs. e.g. givens=" asdf "with the defaulttvalue,swould be modified to contain"asdf". This is effectivelyltrim(rtrim(s, t), t).See also
- Parameters:
s – The string to trim in-place
t – A string containing the list of characters to trim (such as kTrimCharsDefault)
- Returns:
sfor convenience
- inline std::string omni::extras::trimCopy(
- std::string s,
- const char *t = kTrimCharsDefault,
Performs a trim (from both sides) on a given string, returning a copy.
This will trim the characters in
tfrom both sides ofs. e.g. givens=" asdf "with the defaulttvalue,"asdf"would be returned. This is effectivelystd::string copy(s); return trim(copy);.- Parameters:
s – The string to trim
t – A string containing the list of characters to trim (such as kTrimCharsDefault)
- Returns:
The trimmed string