CBMC
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 <string>
14#include <string_view>
15#include <vector>
16
17std::string strip_string(std::string_view s);
18
19std::string capitalize(std::string_view s);
20
21void split_string(
22 std::string_view s,
23 char delim,
24 std::string &left,
25 std::string &right,
26 bool strip = false);
27
37std::vector<std::string> split_string(
38 std::string_view s,
39 char delim,
40 bool strip = false,
41 bool remove_empty = false);
42
43std::string trim_from_last_delimiter(std::string_view s, const char delim);
44
55template <
56 typename Stream,
57 typename It,
58 typename Delimiter,
59 typename TransformFunc>
61 Stream &&os,
62 const It b,
63 const It e,
64 const Delimiter &delimiter,
66{
67 if(b==e)
68 {
69 return os;
70 }
71 os << transform_func(*b);
72 for(auto it=std::next(b); it!=e; ++it)
73 {
74 os << delimiter << transform_func(*it);
75 }
76 return os;
77}
78
87template <typename Stream, typename It, typename Delimiter>
88Stream &
89join_strings(Stream &&os, const It b, const It e, const Delimiter &delimiter)
90{
91 using value_type = decltype(*b);
92 // Call auxiliary function with identity function
93 return join_strings(
94 os, b, e, delimiter, [](const value_type &x) { return x; });
95}
96
99std::string escape(std::string_view s);
100
105std::string escape_non_alnum(std::string_view to_escape);
106
121std::string wrap_line(
122 const std::string &line,
123 const std::size_t left_margin = 0,
124 const std::size_t width = 80);
125
141std::string wrap_line(
142 const std::string::const_iterator left,
143 const std::string::const_iterator right,
144 const std::size_t left_margin = 0,
145 const std::size_t width = 80);
146
147#endif
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
std::string capitalize(std::string_view s)
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 escape_non_alnum(std::string_view 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=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...
std::string trim_from_last_delimiter(std::string_view s, const char delim)
void split_string(std::string_view s, char delim, std::string &left, std::string &right, bool strip=false)
std::string escape(std::string_view s)
Generic escaping of strings; this is not meant to be a particular programming language.
std::string strip_string(std::string_view s)
Remove all whitespace characters from either end of a string.