cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
string_utils.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: 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 <vector>
15
16
std::string
strip_string
(
const
std::string &s);
17
18
std::string
capitalize
(
const
std::string &str);
19
20
void
split_string
(
21
const
std::string &s,
22
char
delim,
23
std::string &left,
24
std::string &right,
25
bool
strip =
false
);
26
36
std::vector<std::string>
split_string
(
37
const
std::string &s,
38
char
delim,
39
bool
strip =
false
,
40
bool
remove_empty =
false
);
41
42
std::string
trim_from_last_delimiter
(
43
const
std::string &s,
44
const
char
delim);
45
56
template
<
57
typename
Stream,
58
typename
It,
59
typename
Delimiter,
60
typename
TransformFunc>
61
Stream &
join_strings
(
62
Stream &&os,
63
const
It b,
64
const
It e,
65
const
Delimiter &delimiter,
66
TransformFunc &&transform_func)
67
{
68
if
(b==e)
69
{
70
return
os;
71
}
72
os << transform_func(*b);
73
for
(
auto
it=std::next(b); it!=e; ++it)
74
{
75
os << delimiter << transform_func(*it);
76
}
77
return
os;
78
}
79
88
template
<
typename
Stream,
typename
It,
typename
Delimiter>
89
Stream &
90
join_strings
(Stream &&os,
const
It b,
const
It e,
const
Delimiter &delimiter)
91
{
92
using
value_type =
decltype
(*b);
93
// Call auxiliary function with identity function
94
return
join_strings
(
95
os, b, e, delimiter, [](
const
value_type &x) {
return
x; });
96
}
97
100
std::string
escape
(
const
std::string &);
101
106
std::string
escape_non_alnum
(
const
std::string &to_escape);
107
122
std::string
wrap_line
(
123
const
std::string &line,
124
const
std::size_t left_margin = 0,
125
const
std::size_t width = 80);
126
142
std::string
wrap_line
(
143
const
std::string::const_iterator left,
144
const
std::string::const_iterator right,
145
const
std::size_t left_margin = 0,
146
const
std::size_t width = 80);
147
148
#endif
join_strings
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.
Definition
string_utils.h:61
wrap_line
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...
Definition
string_utils.cpp:184
split_string
void split_string(const std::string &s, char delim, std::string &left, std::string &right, bool strip=false)
Definition
string_utils.cpp:91
trim_from_last_delimiter
std::string trim_from_last_delimiter(const std::string &s, const char delim)
Definition
string_utils.cpp:127
strip_string
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
Definition
string_utils.cpp:21
escape_non_alnum
std::string escape_non_alnum(const std::string &to_escape)
Replace non-alphanumeric characters with _xx escapes, where xx are hex digits.
Definition
string_utils.cpp:153
escape
std::string escape(const std::string &)
Generic escaping of strings; this is not meant to be a particular programming language.
Definition
string_utils.cpp:138
capitalize
std::string capitalize(const std::string &str)
Definition
string_utils.cpp:175
util
string_utils.h
Generated by
1.17.0