17
17
#include < nonstd/expected.hpp>
18
18
19
19
#include < list>
20
- #include < regex>
21
20
#include < sstream>
22
21
#include < string>
23
22
#include < vector>
24
23
24
+ #ifdef JINJA2CPP_USE_REGEX_BOOST
25
+ #include < boost/regex.hpp>
26
+ template <typename CharType>
27
+ using BasicRegex = boost::basic_regex<CharType>;
28
+ using Regex = boost::regex;
29
+ using WideRegex = boost::wregex;
30
+ template <typename CharIterator>
31
+ using RegexIterator = boost::regex_iterator<CharIterator>;
32
+ #else
33
+ #include < regex>
34
+ template <typename CharType>
35
+ using BasicRegex = std::basic_regex<CharType>;
36
+ using Regex = std::regex;
37
+ using WideRegex = std::wregex;
38
+ template <typename CharIterator>
39
+ using RegexIterator = std::regex_iterator<CharIterator>;
40
+ #endif
41
+
25
42
namespace jinja2
26
43
{
27
44
template <typename CharT>
@@ -58,9 +75,9 @@ MultiStringLiteral ParserTraitsBase<T>::s_regexp = UNIVERSAL_STR(
58
75
template <>
59
76
struct ParserTraits <char > : public ParserTraitsBase<>
60
77
{
61
- static std::regex GetRoughTokenizer ()
62
- { return std::regex (s_regexp.GetValueStr <char >()); }
63
- static std::regex GetKeywords ()
78
+ static Regex GetRoughTokenizer ()
79
+ { return Regex (s_regexp.GetValueStr <char >()); }
80
+ static Regex GetKeywords ()
64
81
{
65
82
std::string pattern;
66
83
std::string prefix (" (^" );
@@ -76,7 +93,7 @@ struct ParserTraits<char> : public ParserTraitsBase<>
76
93
77
94
pattern += prefix + info.name .charValue + postfix;
78
95
}
79
- return std::regex (pattern);
96
+ return Regex (pattern);
80
97
}
81
98
static std::string GetAsString (const std::string& str, CharRange range) { return str.substr (range.startOffset , range.size ()); }
82
99
static InternalValue RangeToNum (const std::string& str, CharRange range, Token::Type hint)
@@ -109,9 +126,9 @@ struct ParserTraits<char> : public ParserTraitsBase<>
109
126
template <>
110
127
struct ParserTraits <wchar_t > : public ParserTraitsBase<>
111
128
{
112
- static std::wregex GetRoughTokenizer ()
113
- { return std::wregex (s_regexp.GetValueStr <wchar_t >()); }
114
- static std::wregex GetKeywords ()
129
+ static WideRegex GetRoughTokenizer ()
130
+ { return WideRegex (s_regexp.GetValueStr <wchar_t >()); }
131
+ static WideRegex GetKeywords ()
115
132
{
116
133
std::wstring pattern;
117
134
std::wstring prefix (L" (^" );
@@ -127,7 +144,7 @@ struct ParserTraits<wchar_t> : public ParserTraitsBase<>
127
144
128
145
pattern += prefix + info.name .wcharValue + postfix;
129
146
}
130
- return std::wregex (pattern);
147
+ return WideRegex (pattern);
131
148
}
132
149
static std::string GetAsString (const std::wstring& str, CharRange range)
133
150
{
@@ -248,7 +265,7 @@ class TemplateParser : public LexerHelper
248
265
public:
249
266
using string_t = std::basic_string<CharT>;
250
267
using traits_t = ParserTraits<CharT>;
251
- using sregex_iterator = std::regex_iterator <typename string_t ::const_iterator>;
268
+ using sregex_iterator = RegexIterator <typename string_t ::const_iterator>;
252
269
using ErrorInfo = ErrorInfoTpl<CharT>;
253
270
using ParseResult = nonstd::expected<RendererPtr, std::vector<ErrorInfo>>;
254
271
@@ -437,7 +454,7 @@ class TemplateParser : public LexerHelper
437
454
FinishCurrentLine (match.position () + 2 );
438
455
return MakeParseError (ErrorCode::UnexpectedCommentEnd, MakeToken (Token::CommentEnd, { matchStart, matchStart + 2 }));
439
456
}
440
-
457
+
441
458
m_currentBlockInfo.range .startOffset = FinishCurrentBlock (matchStart, TextBlockType::RawText);
442
459
break ;
443
460
case RM_ExprBegin:
@@ -925,8 +942,8 @@ class TemplateParser : public LexerHelper
925
942
std::string m_templateName;
926
943
const Settings& m_settings;
927
944
TemplateEnv* m_env = nullptr ;
928
- std::basic_regex <CharT> m_roughTokenizer;
929
- std::basic_regex <CharT> m_keywords;
945
+ BasicRegex <CharT> m_roughTokenizer;
946
+ BasicRegex <CharT> m_keywords;
930
947
std::vector<LineInfo> m_lines;
931
948
std::vector<TextBlockInfo> m_textBlocks;
932
949
LineInfo m_currentLineInfo = {};
0 commit comments