-
Notifications
You must be signed in to change notification settings - Fork 1
/
regex.h
60 lines (44 loc) · 1.5 KB
/
regex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef RO_REGEX_H
#define RO_REGEX_H
#include <regex>
using std::regex;
using std::match_results;
using std::cmatch;
using std::smatch;
using std::regex_match;
using std::regex_search;
using std::regex_replace;
using std::regex_token_iterator;
using std::sregex_token_iterator;
using std::cregex_token_iterator;
#include <ro/range.h>
namespace {
namespace ro {
__attribute__((unused))
std::regex operator "" _R (const char* p, size_t n) { return std::regex(p); };
template<typename S>
eIF<is_string<S>::value, bool>
operator == (const S s, const std::regex &e) { return std::regex_match(s.begin(), s.end(), e); };
// specialization for c-string
__attribute__((unused)) bool
operator == (const char *p, const std::regex &e) { return std::regex_match(p,e); };
// regex_search (does not work) - not yet implemented in LIBSTDC++
template<typename S>
eIF<is_string<S>::value, bool>
operator %= (const S s, const std::regex &e) { return std::regex_search(s.begin(), s.end(), e); };
/*
// convert to regex operator
template<typename S>
typename std::enable_if<is_string_t<S>::value, std::regex>::type
operator ~ (const S e) { return std::regex(e.begin(), e.end()); };
*/
/*
//#define R std::regex
#define RM std::regex_match
//#define RS std::regex_search
#define RR std::regex_replace
// usage: scc 'str s="aa bb"; RR(s, R("(\\w+)"),"*\\1*")'
*/
};
};
#endif // LVV_REGEX_H