split_by_regex.h
Go to the documentation of this file.
1 #ifndef cetlib_split_by_regex_h
2 #define cetlib_split_by_regex_h
3 
4 // ======================================================================
5 //
6 // split_by_regex: Obtain substrings at a string's specified boundaries,
7 // defined according to a regex delimiter set.
8 //
9 // This is a high-powered method of tokenizing that uses
10 // the C++ regex library to split into substrings.
11 //
12 // Examples of splitting with ":" as the separator:
13 // input result
14 // "" [""] # Different behavior than split.h
15 // "a" ["a"]
16 // "a:" ["a"]
17 // ":boo" ["","boo"] # Different behavior than split.h
18 // "a:b" ["a","b"]
19 // "a::b" ["a","","b"] # Different behavior than split.h
20 //
21 // More complicated example splitting by "::" and "().":
22 //
23 // split_by_regex("namespace::class::static_function().value",
24 // "(::|\\(\\)\\.)")
25 //
26 // returns ["namespace","class","static_function","value"]
27 //
28 // ======================================================================
29 
30 #include <regex>
31 #include <string>
32 #include <vector>
33 
34 namespace cet {
35  std::vector<std::string> split_by_regex(std::string const& str,
36  std::regex const& re);
37 
38  // Forms regular expression given pattern via a string.
39  std::vector<std::string> split_by_regex(std::string const& str,
40  std::string const& delimSet);
41 }
42 
43 #endif /* cetlib_split_by_regex_h */
44 
45 // Local variables:
46 // mode: c++
47 // End:
std::string string
Definition: nybbler.cc:12
std::vector< std::string > split_by_regex(std::string const &str, std::regex const &reDelimSet)
static QCString str