String Trimming Utilities
Functions
omni::extras::ltrim: Performs an in-place left-trim on a given string.
omni::extras::rtrim: Performs an in-place right-trim on a given string.
omni::extras::trim: Performs an in-place trim (from both sides) on a given string.
omni::extras::trimCopy: Performs a trim (from both sides) on a given string, returning a copy.
Variables
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
t
from the left side ofs
. e.g. givens
=" asdf "
with the defaultt
value,s
would 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
s
for 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
t
from the right side ofs
. e.g. givens
=" asdf "
with the defaultt
value,s
would 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
s
for 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
t
from both sides ofs
. e.g. givens
=" asdf "
with the defaultt
value,s
would 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
s
for 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
t
from both sides ofs
. e.g. givens
=" asdf "
with the defaultt
value,"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