SST/macro
regexp.h
Go to the documentation of this file.
1 #ifndef sprockit_regexp_h
2 #define sprockit_regexp_h
3 
4 #include <sprockit/spkt_config.h>
5 #if !SPKT_DISABLE_REGEXP
6 
7 #include <string>
8 #include <vector>
9 
15  ////////////////////////////////////////////////////////
16  // Not available in C++11 (and also not currently used):
18  ////////////////////////////////////////////////////////
20 };
21 
22 /**
23  * Extracts a double precision number from text.
24  * @param regexp The regular expression containing the (captured) number.
25  * @param text The text to apply the RegEx to.
26  * @param flags An integer comprising bitwise options (see the PyFlags enum).
27  * @return The value as a double.
28  */
29 double get_regexp_double(const std::string &regexp, const std::string &text, int flags = 0);
30 
31 /**
32  * Extracts a string from text.
33  * @param regexp The regular expression containing the (captured) string.
34  * @param text The text to apply the RegEx to.
35  * @param flags An integer comprising bitwise options (see the PyFlags enum).
36  * @return The string.
37  */
38 std::string get_regexp_string(const std::string &regexp, const std::string &text, int flags = 0);
39 
40 /**
41  * Extracts an array of doubles from text, according to a given RegEx.
42  * Memory is allocated by the function and ownership is passed to calling routine.
43  * @param regexp The regular expression containing the (captured) values.
44  * @param text The text to apply the RegEx to.
45  * @param flags An integer comprising bitwise options (see the PyFlags enum).
46  * @return an array of all captured values.
47  */
48 double* get_regexp_double_array(const std::string& regexp, const std::string &text, size_t& length, int flags = 0);
49 
50 /**
51  * Extracts strings from text, according to a given RegEx.
52  * @param matches The vector of strings to hold the results.
53  * @param regexp The regular expression containing the (captured) strings.
54  * @param text The text to apply the RegEx to.
55  * @param flags An integer comprising bitwise options (see the PyFlags enum).
56  */
57 void
58 findmatch(std::vector<std::string>& matches, const std::string &regexp, const std::string &text, int flags = 0);
59 
60 bool
61 get_regexp_integer(const std::string& string, int& ret);
62 
63 inline bool
64 is_regexp_integer(const std::string& str){
65  int ignore;
66  return get_regexp_integer(str, ignore);
67 }
68 
69 /**
70  * Tests a string to see if it contains a certain RegEx.
71  * @param regexp The regular expression to test.
72  * @param text The text to apply the RegEx to.
73  * @param flags An integer comprising bitwise options (see the PyFlags enum).
74  * @return whether the text contains a match.
75  */
76 bool has_regexp_match(const std::string& regexp, const std::string& text, int flags = 0);
77 
78 
79 #endif
80 
81 #endif
bool get_regexp_integer(const std::string &string, int &ret)
double get_regexp_double(const std::string &regexp, const std::string &text, int flags=0)
Extracts a double precision number from text.
Definition: regexp.h:13
void findmatch(std::vector< std::string > &matches, const std::string &regexp, const std::string &text, int flags=0)
Extracts strings from text, according to a given RegEx.
bool is_regexp_integer(const std::string &str)
Definition: regexp.h:64
bool has_regexp_match(const std::string &regexp, const std::string &text, int flags=0)
Tests a string to see if it contains a certain RegEx.
std::string get_regexp_string(const std::string &regexp, const std::string &text, int flags=0)
Extracts a string from text.
double * get_regexp_double_array(const std::string &regexp, const std::string &text, size_t &length, int flags=0)
Extracts an array of doubles from text, according to a given RegEx.
RegexpFlags
Definition: regexp.h:10