cprover
Loading...
Searching...
No Matches
string_utils.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Poetzl
6
7\*******************************************************************/
8
9
10#ifndef CPROVER_UTIL_STRING_UTILS_H
11#define CPROVER_UTIL_STRING_UTILS_H
12
13#include <iosfwd>
14#include <string>
15#include <vector>
16
17std::string strip_string(const std::string &s);
18
19std::string capitalize(const std::string &str);
20
21void split_string(
22 const std::string &s,
23 char delim,
24 std::string &left,
25 std::string &right,
26 bool strip = false);
27
37std::vector<std::string> split_string(
38 const std::string &s,
39 char delim,
40 bool strip = false,
41 bool remove_empty = false);
42
43std::string trim_from_last_delimiter(
44 const std::string &s,
45 const char delim);
46
57template <
58 typename Stream,
59 typename It,
60 typename Delimiter,
61 typename TransformFunc>
63 Stream &&os,
64 const It b,
65 const It e,
66 const Delimiter &delimiter,
68{
69 if(b==e)
70 {
71 return os;
72 }
73 os << transform_func(*b);
74 for(auto it=std::next(b); it!=e; ++it)
75 {
76 os << delimiter << transform_func(*it);
77 }
78 return os;
79}
80
89template <typename Stream, typename It, typename Delimiter>
90Stream &
91join_strings(Stream &&os, const It b, const It e, const Delimiter &delimiter)
92{
93 using value_type = decltype(*b);
94 // Call auxiliary function with identity function
95 return join_strings(
96 os, b, e, delimiter, [](const value_type &x) { return x; });
97}
98
101std::string escape(const std::string &);
102
107std::string escape_non_alnum(const std::string &to_escape);
108
123std::string wrap_line(
124 const std::string &line,
125 const std::size_t left_margin = 0,
126 const std::size_t width = 80);
127
143std::string wrap_line(
144 const std::string::const_iterator left,
145 const std::string::const_iterator right,
146 const std::size_t left_margin = 0,
147 const std::size_t width = 80);
148
149#endif
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
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.
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...
void split_string(const std::string &s, char delim, std::string &left, std::string &right, bool strip=false)
std::string trim_from_last_delimiter(const std::string &s, const char delim)
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
std::string escape_non_alnum(const std::string &to_escape)
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
std::string escape(const std::string &)
Generic escaping of strings; this is not meant to be a particular programming language.
std::string capitalize(const std::string &str)