22 auto pred=[](
char c){
return std::isspace(c); };
24 std::string::const_iterator left
25 =std::find_if_not(s.begin(), s.end(), pred);
31 std::string::const_reverse_iterator right
32 =std::find_if_not(s.rbegin(), s.rend(), pred);
35 return s.substr(i, (j-i+1));
51 std::vector<std::string> &result,
66 INVARIANT(n > 0,
"Empty string case should already be handled");
75 std::string new_s=s.substr(start, i-start);
80 if(!remove_empty || !new_s.empty())
81 result.push_back(new_s);
87 std::string new_s=s.substr(start, n-start);
92 if(!remove_empty || !new_s.empty())
93 result.push_back(new_s);
100 const std::string &s,
109 std::vector<std::string> result;
113 throw "split string did not generate exactly 2 parts";
119 std::vector<std::string>
split_string(
const std::string &s,
char delim)
121 std::vector<std::string> result;
127 const std::string &s,
130 std::string result=
"";
131 const size_t index=s.find_last_of(delim);
132 if(index!=std::string::npos)
133 result=s.substr(0, index);
141 for(std::size_t i=0; i<s.size(); i++)
143 if(s[i]==
'\\' || s[i]==
'"')
162 const std::string &from,
163 const std::string &to)
165 size_t start_pos = 0;
166 while((start_pos = str.find(from, start_pos)) != std::string::npos)
168 str.replace(start_pos, from.length(), to);
169 start_pos += to.length();
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
unsignedbv_typet size_type()
#define INVARIANT(CONDITION, REASON)
void replace_all(std::string &str, const std::string &from, const std::string &to)
Replace all occurrences of a string inside a string.
#define PRECONDITION(CONDITION)
std::string escape(const std::string &s)
Generic escaping of strings; this is not meant to be a particular programming language.
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...
std::string trim_from_last_delimiter(const std::string &s, const char delim)