cprover
string_utils.cpp File Reference
#include "string_utils.h"
#include "invariant.h"
#include <cassert>
#include <cctype>
#include <algorithm>
Include dependency graph for string_utils.cpp:

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, bool remove_empty)
 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)
 
std::vector< std::string > split_string (const std::string &s, char delim)
 
std::string trim_from_last_delimiter (const std::string &s, const char delim)
 
std::string escape (const std::string &s)
 Generic escaping of strings; this is not meant to be a particular programming language. 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 137 of file string_utils.cpp.

Referenced by lispexprt::expr2string(), and format_rec().

◆ split_string() [1/3]

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

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

Definition at line 48 of file string_utils.cpp.

References INVARIANT, PRECONDITION, size_type(), and strip_string().

Referenced by generate_function_bodies_factory(), gcc_versiont::get(), parse_caller_callee(), unwindsett::parse_unwindset(), configt::set_classpath(), split_string(), and unwrap_exception().

◆ split_string() [2/3]

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

Definition at line 99 of file string_utils.cpp.

References PRECONDITION, and split_string().

◆ split_string() [3/3]

std::vector<std::string> split_string ( const std::string &  s,
char  delim 
)

Definition at line 119 of file string_utils.cpp.

References split_string().

◆ 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 20 of file string_utils.cpp.

References size_type().

Referenced by find_pattern(), and split_string().

◆ trim_from_last_delimiter()

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

Definition at line 126 of file string_utils.cpp.

Referenced by java_class_to_package().