1 #ifndef REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 11 #include "streamcharsource.h" 12 #include "stringsource.h" 16 inline bool RegEx::Matches(
char ch)
const {
22 inline bool RegEx::Matches(
const std::string& str)
const {
23 return Match(str) >= 0;
26 inline bool RegEx::Matches(
const Stream& in)
const {
return Match(in) >= 0; }
28 template <
typename Source>
29 inline bool RegEx::Matches(
const Source& source)
const {
30 return Match(source) >= 0;
40 inline int RegEx::Match(
const std::string& str)
const {
41 StringCharSource source(str.c_str(), str.size());
45 inline int RegEx::Match(
const Stream& in)
const {
46 StreamCharSource source(in);
50 template <
typename Source>
51 inline bool RegEx::IsValidSource(
const Source& source)
const {
56 inline bool RegEx::IsValidSource<StringCharSource>(
57 const StringCharSource& source)
const {
67 template <
typename Source>
68 inline int RegEx::Match(
const Source& source)
const {
69 return IsValidSource(source) ? MatchUnchecked(source) : -1;
72 template <
typename Source>
73 inline int RegEx::MatchUnchecked(
const Source& source)
const {
76 return MatchOpEmpty(source);
78 return MatchOpMatch(source);
80 return MatchOpRange(source);
82 return MatchOpOr(source);
84 return MatchOpAnd(source);
86 return MatchOpNot(source);
88 return MatchOpSeq(source);
101 template <
typename Source>
102 inline int RegEx::MatchOpEmpty(
const Source& source)
const {
103 return source[0] == Stream::eof() ? 0 : -1;
107 inline int RegEx::MatchOpEmpty<StringCharSource>(
108 const StringCharSource& source)
const {
109 return !source ? 0 : -1;
114 template <
typename Source>
115 inline int RegEx::MatchOpMatch(
const Source& source)
const {
116 if (source[0] != m_a)
122 template <
typename Source>
123 inline int RegEx::MatchOpRange(
const Source& source)
const {
124 if (m_a > source[0] || m_z < source[0])
130 template <
typename Source>
131 inline int RegEx::MatchOpOr(
const Source& source)
const {
132 for (
const RegEx& param : m_params) {
133 int n = param.MatchUnchecked(source);
144 template <
typename Source>
145 inline int RegEx::MatchOpAnd(
const Source& source)
const {
147 for (std::size_t i = 0; i < m_params.size(); i++) {
148 int n = m_params[i].MatchUnchecked(source);
158 template <
typename Source>
159 inline int RegEx::MatchOpNot(
const Source& source)
const {
160 if (m_params.empty())
162 if (m_params[0].MatchUnchecked(source) >= 0)
168 template <
typename Source>
169 inline int RegEx::MatchOpSeq(
const Source& source)
const {
171 for (
const RegEx& param : m_params) {
172 int n = param.Match(source + offset);
185 #endif // REGEXIMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66