cprover
string_utils.h File Reference
#include "deprecate.h"
#include <iosfwd>
#include <string>
#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.

Functions

std::string strip_string (const std::string &s)
 Remove all whitespace characters from either end of a string. More...
 
void split_string (const std::string &s, char delim, std::vector< std::string > &result, bool strip=false, bool remove_empty=false)
 Given a string s, split into a sequence of substrings when separated by specified delimiter. More...
 
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)
 
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...
 

Function Documentation

◆ escape()

std::string escape ( const std::string &  )

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 ( const std::string &  to_escape)

Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.

Underscores are replaced by __.

Parameters
to_escapestring to escape
Returns
string with non-alphanumeric characters escaped

Definition at line 155 of file string_utils.cpp.

◆ join_strings() [1/2]

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.

Template Parameters
ItAn iterator type
DelimiterA delimiter type which supports printing to ostreams
Parameters
osAn ostream to write to
bIterator pointing to first item to print
eIterator pointing past last item to print
delimiterObject to print between each item in the iterator range
Returns
A reference to the ostream that was passed in

Definition at line 104 of file string_utils.h.

◆ join_strings() [2/2]

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.

Template Parameters
ItAn iterator type
DelimiterA delimiter type which supports printing to ostreams
Parameters
osAn ostream to write to
bIterator pointing to first item to print
eIterator pointing past last item to print
delimiterObject to print between each item in the iterator range
transform_funcTransform to apply to the value returned by the iterator
Returns
A reference to the ostream that was passed in

Definition at line 75 of file string_utils.h.

◆ split_string() [1/3]

std::vector<std::string> split_string ( const std::string &  s,
char  delim,
bool  strip = false,
bool  remove_empty = false 
)

Definition at line 118 of file string_utils.cpp.

◆ split_string() [2/3]

void split_string ( const std::string &  s,
char  delim,
std::string &  left,
std::string &  right,
bool  strip = false 
)

Definition at line 92 of file string_utils.cpp.

◆ split_string() [3/3]

void split_string ( const std::string &  s,
char  delim,
std::vector< std::string > &  result,
bool  strip = false,
bool  remove_empty = false 
)

Given a string s, split into a sequence of substrings when separated by specified delimiter.

Parameters
sThe string to split up
delimThe character to use as the delimiter
[out]resultThe sub strings. Must be empty.
stripIf true, strip_string will be used on each element, removing whitespace from the beginning and end of each element
remove_emptyIf 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.
Deprecated:
"deprecated since " "2019" "-" "11" "-" "14" "; " "use split_string(s, delim, strip, remove_empty) instead"

Definition at line 40 of file string_utils.cpp.

◆ strip_string()

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

Parameters
sthe string to strip
Returns
The stripped string

Definition at line 22 of file string_utils.cpp.

◆ trim_from_last_delimiter()

std::string trim_from_last_delimiter ( const std::string &  s,
const char  delim 
)

Definition at line 129 of file string_utils.cpp.