#include <string>
#include <string_view>
#include <vector>
+ Include dependency graph for string_utils.h:
+ This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Remove all whitespace characters from either end of a string.
Given a string s, split into a sequence of substrings when separated by specified delimiter.
Prints items to an stream, separated by a constant delimiter.
Prints items to an stream, separated by a constant delimiter.
std::string
escape (std::string_view s)
Generic escaping of strings; this is not meant to be a particular programming language.
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
Wrap line at spaces to not extend past the right margin, and include given padding with spaces to the left.
Wrap line at spaces to not extend past the right margin, and include given padding with spaces to the left.
Function Documentation
◆ capitalize()
std::string capitalize
(
std::string_view
s )
◆ escape()
std::string escape
(
std::string_view
s )
Generic escaping of strings; this is not meant to be a particular programming language.
Definition at line 140 of file string_utils.cpp.
◆ escape_non_alnum()
std::string escape_non_alnum
(
std::string_view
to_escape )
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
Underscores are replaced by __.
- Parameters
-
to_escape string to escape
- Returns
- string with non-alphanumeric characters escaped
Definition at line 155 of file string_utils.cpp.
◆ join_strings() [1/2]
Prints items to an stream, separated by a constant delimiter.
- Template Parameters
-
It An iterator type
Delimiter A delimiter type which supports printing to ostreams
- Parameters
-
os An ostream to write to
b Iterator pointing to first item to print
e Iterator pointing past last item to print
delimiter Object to print between each item in the iterator range
- Returns
- A reference to the ostream that was passed in
Definition at line 89 of file string_utils.h.
◆ join_strings() [2/2]
Prints items to an stream, separated by a constant delimiter.
- Template Parameters
-
It An iterator type
Delimiter A delimiter type which supports printing to ostreams
- Parameters
-
os An ostream to write to
b Iterator pointing to first item to print
e Iterator pointing past last item to print
delimiter Object to print between each item in the iterator range
transform_func Transform to apply to the value returned by the iterator
- Returns
- A reference to the ostream that was passed in
Definition at line 60 of file string_utils.h.
◆ split_string() [1/2]
std::vector< std::string > split_string
(
std::string_view
s,
)
Given a string s, split into a sequence of substrings when separated by specified delimiter.
- Parameters
-
s The string to split up
delim The character to use as the delimiter
strip If true, strip_string will be used on each element, removing whitespace from the beginning and end of each element
remove_empty If true, all empty-string elements will be removed. This is applied after strip so whitespace only elements will be removed if both are set to true.
Definition at line 124 of file string_utils.cpp.
◆ split_string() [2/2]
void split_string
(
std::string_view
s,
std::string &
left,
std::string &
right,
)
◆ strip_string()
std::string strip_string
(
std::string_view
s )
Remove all whitespace characters from either end of a string.
Whitespace in the middle of the string is left unchanged
- Parameters
-
s the string to strip
- Returns
- The stripped string
Definition at line 21 of file string_utils.cpp.
◆ trim_from_last_delimiter()
std::string trim_from_last_delimiter
(
std::string_view
s,
)
◆ wrap_line() [1/2]
std::string wrap_line
(
const std::string &
line,
const std::size_t
left_margin =
0,
const std::size_t
width =
80
)
Wrap line at spaces to not extend past the right margin, and include given padding with spaces to the left.
The given string should not contain any newlines.
- Parameters
-
line line to wrap, should not contain newlines
left_margin each line will be padded to the left with left_margin spaces
width width of the resulting text, i.e., right margin
- Returns
- resulting string such that each line has length less or equal to
width, and each line includes left_margin spaces to the left; if the given line cannot be wrapped (i.e., it cannot be broken up at spaces such that every resulting line fits within the margin), the given line is returned unchanged
Definition at line 187 of file string_utils.cpp.
◆ wrap_line() [2/2]
std::string wrap_line
(
const std::string::const_iterator
left,
const std::string::const_iterator
right,
const std::size_t
left_margin =
0,
const std::size_t
width =
80
)
Wrap line at spaces to not extend past the right margin, and include given padding with spaces to the left.
The given string should not contain any newlines.
- Parameters
-
left iterator to beginning of string
right iterator to end of string
left_margin each line will be padded to the left with left_margin spaces
width width of the resulting text, i.e., right margin
- Returns
- resulting string such that each line has length less or equal to
width, and each line includes left_margin spaces to the left; if the given line cannot be wrapped (i.e., it cannot be broken up at spaces such that every resulting line fits within the margin), the given line is returned unchanged
Definition at line 195 of file string_utils.cpp.