23 auto pred=[](
char c){
return std::isspace(
c); };
25 std::string::const_iterator left
26 =std::find_if_not(s.begin(), s.end(),
pred);
30 std::string::size_type i=std::distance(s.begin(), left);
32 std::string::const_reverse_iterator right
33 =std::find_if_not(s.rbegin(), s.rend(),
pred);
34 std::string::size_type j=std::distance(right, s.rend())-1;
36 return s.substr(i, (j-i+1));
42 std::vector<std::string> &result,
57 std::string::size_type
n=s.length();
58 INVARIANT(
n > 0,
"Empty string case should already be handled");
60 std::string::size_type start=0;
61 std::string::size_type i;
67 std::string
new_s=s.substr(start, i-start);
73 result.push_back(
new_s);
79 std::string
new_s=s.substr(start,
n-start);
85 result.push_back(
new_s);
103 if(result.size() != 2)
106 "' to contain two substrings "
108 delim +
" but has " +
109 std::to_string(result.size())};
117 const std::string &s,
122 std::vector<std::string> result;
128 const std::string &s,
132 const size_t index=s.find_last_of(
delim);
133 if(index!=std::string::npos)
134 result=s.substr(0, index);
142 for(std::size_t i=0; i<s.size(); i++)
144 if(s[i]==
'\\' || s[i]==
'"')
165 const int uch{
static_cast<unsigned char>(
ch)};
171 escaped <<
'_' << std::hex << std::setfill(
'0') << std::setw(2) <<
uch;
185 const std::string &line,
187 const std::size_t width)
193 std::string::const_iterator left,
194 std::string::const_iterator right,
196 const std::size_t width)
203 auto distance = std::distance(left, right);
211 result.append(left, right);
223 auto rit_r = std::reverse_iterator<decltype(it)>(it) - 1;
243 result.append(left, right);
247 }
while(
static_cast<std::size_t
>(std::distance(
it_line_begin, right)) >
virtual void clear()
Reset the abstract state.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
#define CHECK_RETURN(CONDITION)
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
std::string trim_from_last_delimiter(const std::string &s, const char delim)
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
std::string escape(const std::string &s)
Generic escaping of strings; this is not meant to be a particular programming language.
std::string escape_non_alnum(const std::string &to_escape)
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
std::string wrap_line(const std::string &line, const std::size_t left_margin, const std::size_t width)
Wrap line at spaces to not extend past the right margin, and include given padding with spaces to the...
std::string capitalize(const std::string &str)