String Trimming Utilities

Functions

Variables

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 of s. e.g. given s = "  asdf  " with the default t value, s would be modified to contain "asdf  ". This is effectively s.erase(0, s.find_first_not_of(t)).

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 of s. e.g. given s = "  asdf  " with the default t value, s would be modified to contain "  asdf". This is effectively s.erase(s.find_last_not_of(t) + 1).

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 of s. e.g. given s = "  asdf  " with the default t value, s would be modified to contain "asdf". This is effectively ltrim(rtrim(s, t), t).

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 of s. e.g. given s = "  asdf  " with the default t value, "asdf" would be returned. This is effectively std::string copy(s); return trim(copy);.

See also

ltrim(), rtrim(), trim()

Parameters
  • s – The string to trim

  • t – A string containing the list of characters to trim (such as kTrimCharsDefault)

Returns

The trimmed string

Variables

constexpr char omni::extras::kTrimCharsDefault[] = " \t\n\r\f\v"

Default whitespace characters for string trimming functions.