]> git.lyx.org Git - lyx.git/blob - src/support/regex.h
Use explicit macro to declare that we want to use C++11
[lyx.git] / src / support / regex.h
1 // -*- C++ -*-
2 /**
3  * \file regexp.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Peter Kümmel
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_REGEXP_H
13 #define LYX_REGEXP_H
14
15 #if defined(LYX_USE_CXX11) && defined(LYX_USE_STD_REGEX)
16 #  include <regex>
17 #  ifdef _MSC_VER
18 namespace lyx {
19   // inheriting 'private' to see which functions are used and if there are
20   // other ECMAScrip defaults
21   // FIXME: Is this really needed?
22   //        If yes, then the MSVC regex implementation is not standard-conforming.
23   class regex : private std::regex
24   {
25   public:
26     regex() {}
27     regex(const regex& rhs) : std::regex(rhs) {}
28     template<class T>
29     regex(T t) : std::regex(t, std::regex_constants::grep) {}
30     template<class T>
31     void assign(T t) { std::regex::assign(t, std::regex_constants::grep); }
32     template<class T, class V>
33     void assign(T t, V v) { std::regex::assign(t, v); }
34     const std::regex& toStd() const { return *this; }
35   };
36   template<class T>
37   bool regex_match(T t, const regex& r) { return std::regex_match(t, r.toStd()); }
38   template<class T, class V>
39   bool regex_match(T t, V v, const regex& r) { return std::regex_match(t, v, r.toStd()); }
40   template<class T, class V, class U, class H>
41   bool regex_match(T t, V v, H h, const regex& r, U u) { return std::regex_match(t, v, h, r.toStd(), u); }
42   template<class T, class V>
43   std::string regex_replace(T t, const regex& r, V v) { return std::regex_replace(t, r.toStd(), v); }
44   //template<class T, class V, class U, class H>
45   //std::string regex_replace(T t, V v, U u, const regex& r, H h) { return std::regex_replace(t, v, u, r.toStd(), h); }
46   template<class T>
47   bool regex_search(T t, const regex& r) { return std::regex_search(t, r.toStd()); }
48   template<class T, class V>
49   bool regex_search(T t, V v, const regex& r) { return std::regex_search(t, v, r.toStd()); }
50   template<class T, class V, class U>
51   bool regex_search(T t, V v, U u, const regex& r) { return std::regex_search(t, v, u, r.toStd()); }
52
53   struct sregex_iterator : std::sregex_iterator
54   {
55     sregex_iterator() {}
56     template<class T, class V>
57     sregex_iterator(T t, V v, const regex& r) : std::sregex_iterator(t, v, r.toStd()) {}
58   };
59 }
60 #  else
61 // <regex> in gcc is unusable in versions less than 4.9.0
62 // see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631
63 #  define LR_NS std
64 namespace lyx {
65 using LR_NS::regex;
66 using LR_NS::regex_match;
67 using LR_NS::sregex_iterator;
68 }
69 #  endif
70 #else
71 #  include <boost/regex.hpp>
72 #  define LR_NS boost
73 namespace lyx {
74 using LR_NS::regex;
75 using LR_NS::regex_match;
76 using LR_NS::sregex_iterator;
77 }
78 #endif
79
80 namespace lyx {
81 using LR_NS::smatch;
82 using LR_NS::regex_replace;
83 using LR_NS::basic_regex;
84 using LR_NS::regex_error;
85 using LR_NS::regex_search;
86 using LR_NS::match_results;
87
88 namespace regex_constants
89 {
90 using namespace LR_NS::regex_constants;
91 using LR_NS::regex_constants::match_flag_type;
92 }
93
94 }
95
96 #undef LR_NS
97
98 #endif