CBMC
|
#include <string>
#include <vector>
Go to the source code of this file.
Functions | |
std::string | strip_string (const std::string &s) |
Remove all whitespace characters from either end of a string. More... | |
std::string | capitalize (const std::string &str) |
void | split_string (const std::string &s, char delim, std::string &left, std::string &right, bool strip=false) |
std::vector< std::string > | split_string (const std::string &s, char delim, bool strip=false, bool remove_empty=false) |
Given a string s, split into a sequence of substrings when separated by specified delimiter. More... | |
std::string | trim_from_last_delimiter (const std::string &s, const char delim) |
template<typename Stream , typename It , typename Delimiter , typename TransformFunc > | |
Stream & | join_strings (Stream &&os, const It b, const It e, const Delimiter &delimiter, TransformFunc &&transform_func) |
Prints items to an stream, separated by a constant delimiter. More... | |
template<typename Stream , typename It , typename Delimiter > | |
Stream & | join_strings (Stream &&os, const It b, const It e, const Delimiter &delimiter) |
Prints items to an stream, separated by a constant delimiter. More... | |
std::string | escape (const std::string &) |
Generic escaping of strings; this is not meant to be a particular programming language. More... | |
std::string | escape_non_alnum (const std::string &to_escape) |
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits. More... | |
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. More... | |
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. More... | |
std::string capitalize | ( | const std::string & | str | ) |
Definition at line 175 of file string_utils.cpp.
std::string escape | ( | const std::string & | s | ) |
Generic escaping of strings; this is not meant to be a particular programming language.
Definition at line 138 of file string_utils.cpp.
std::string escape_non_alnum | ( | const std::string & | to_escape | ) |
Replace non-alphanumeric characters with _xx
escapes, where xx are hex digits.
Underscores are replaced by __
.
to_escape | string to escape |
Definition at line 153 of file string_utils.cpp.
Stream& join_strings | ( | Stream && | os, |
const It | b, | ||
const It | e, | ||
const Delimiter & | delimiter | ||
) |
Prints items to an stream, separated by a constant delimiter.
It | An iterator type |
Delimiter | A delimiter type which supports printing to ostreams |
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 |
Definition at line 90 of file string_utils.h.
Stream& join_strings | ( | Stream && | os, |
const It | b, | ||
const It | e, | ||
const Delimiter & | delimiter, | ||
TransformFunc && | transform_func | ||
) |
Prints items to an stream, separated by a constant delimiter.
It | An iterator type |
Delimiter | A delimiter type which supports printing to ostreams |
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 |
Definition at line 61 of file string_utils.h.
std::vector<std::string> split_string | ( | const std::string & | s, |
char | delim, | ||
bool | strip = false , |
||
bool | remove_empty = false |
||
) |
Given a string s, split into a sequence of substrings when separated by specified delimiter.
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 116 of file string_utils.cpp.
void split_string | ( | const std::string & | s, |
char | delim, | ||
std::string & | left, | ||
std::string & | right, | ||
bool | strip = false |
||
) |
Definition at line 91 of file string_utils.cpp.
std::string strip_string | ( | const std::string & | s | ) |
Remove all whitespace characters from either end of a string.
Whitespace in the middle of the string is left unchanged
s | the string to strip |
Definition at line 21 of file string_utils.cpp.
std::string trim_from_last_delimiter | ( | const std::string & | s, |
const char | delim | ||
) |
Definition at line 127 of file string_utils.cpp.
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.
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 |
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 184 of file string_utils.cpp.
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.
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 |
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 192 of file string_utils.cpp.