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(const std::string &s, char delim);
34 
35 std::string trim_from_last_delimiter(
36  const std::string &s,
37  const char delim);
38 
47 template<typename Stream, typename It, typename Delimiter>
48 Stream &join_strings(
49  Stream &os,
50  const It b,
51  const It e,
52  const Delimiter &delimiter)
53 {
54  if(b==e)
55  {
56  return os;
57  }
58  os << *b;
59  for(auto it=std::next(b); it!=e; ++it)
60  {
61  os << delimiter << *it;
62  }
63  return os;
64 }
65 
68 std::string escape(const std::string &);
69 
70 void replace_all(std::string &, const std::string &, const std::string &);
71 
72 #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:48
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.