cprover
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 <iosfwd>
14 #include <string>
15 #include <vector>
16 
17 std::string strip_string(const std::string &s);
18 
19 void split_string(
20  const std::string &s,
21  char delim,
22  std::vector<std::string> &result,
23  bool strip = false,
24  bool remove_empty = false);
25 
26 void split_string(
27  const std::string &s,
28  char delim,
29  std::string &left,
30  std::string &right,
31  bool strip=false);
32 
33 std::vector<std::string> split_string(
34  const std::string &s,
35  char delim,
36  bool strip = false,
37  bool remove_empty = false);
38 
39 std::string trim_from_last_delimiter(
40  const std::string &s,
41  const char delim);
42 
51 template<typename Stream, typename It, typename Delimiter>
52 Stream &join_strings(
53  Stream &os,
54  const It b,
55  const It e,
56  const Delimiter &delimiter)
57 {
58  if(b==e)
59  {
60  return os;
61  }
62  os << *b;
63  for(auto it=std::next(b); it!=e; ++it)
64  {
65  os << delimiter << *it;
66  }
67  return os;
68 }
69 
72 std::string escape(const std::string &);
73 
74 void replace_all(std::string &, const std::string &, const std::string &);
75 
76 #endif
void replace_all(std::string &, const std::string &, const std::string &)
Replace all occurrences of a string inside a string.
Stream & join_strings(Stream &os, const It b, const It e, const Delimiter &delimiter)
Prints items to an stream, separated by a constant delimiter.
Definition: string_utils.h:52
std::string escape(const std::string &)
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=false, bool remove_empty=false)
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)
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.