@@ -22,6 +22,7 @@ pub struct RegexOptions {
22
22
pub swap_greed : bool ,
23
23
pub ignore_whitespace : bool ,
24
24
pub unicode : bool ,
25
+ pub octal : bool ,
25
26
}
26
27
27
28
impl Default for RegexOptions {
@@ -37,6 +38,7 @@ impl Default for RegexOptions {
37
38
swap_greed : false ,
38
39
ignore_whitespace : false ,
39
40
unicode : true ,
41
+ octal : false ,
40
42
}
41
43
}
42
44
}
@@ -142,6 +144,26 @@ impl RegexBuilder {
142
144
self
143
145
}
144
146
147
+ /// Whether to support octal syntax or not.
148
+ ///
149
+ /// Octal syntax is a little-known way of uttering Unicode codepoints in
150
+ /// a regular expression. For example, `a`, `\x61`, `\u0061` and
151
+ /// `\141` are all equivalent regular expressions, where the last example
152
+ /// shows octal syntax.
153
+ ///
154
+ /// While supporting octal syntax isn't in and of itself a problem, it does
155
+ /// make good error messages harder. That is, in PCRE based regex engines,
156
+ /// syntax like `\0` invokes a backreference, which is explicitly
157
+ /// unsupported in Rust's regex engine. However, many users expect it to
158
+ /// be supported. Therefore, when octal support is disabled, the error
159
+ /// message will explicitly mention that backreferences aren't supported.
160
+ ///
161
+ /// Octal syntax is disabled by default.
162
+ pub fn octal( & mut self , yes: bool ) -> & mut RegexBuilder {
163
+ self . 0 . octal = yes;
164
+ self
165
+ }
166
+
145
167
/// Set the approximate size limit of the compiled regular expression.
146
168
///
147
169
/// This roughly corresponds to the number of bytes occupied by a single
@@ -283,6 +305,26 @@ impl RegexSetBuilder {
283
305
self
284
306
}
285
307
308
+ /// Whether to support octal syntax or not.
309
+ ///
310
+ /// Octal syntax is a little-known way of uttering Unicode codepoints in
311
+ /// a regular expression. For example, `a`, `\x61`, `\u0061` and
312
+ /// `\141` are all equivalent regular expressions, where the last example
313
+ /// shows octal syntax.
314
+ ///
315
+ /// While supporting octal syntax isn't in and of itself a problem, it does
316
+ /// make good error messages harder. That is, in PCRE based regex engines,
317
+ /// syntax like `\0` invokes a backreference, which is explicitly
318
+ /// unsupported in Rust's regex engine. However, many users expect it to
319
+ /// be supported. Therefore, when octal support is disabled, the error
320
+ /// message will explicitly mention that backreferences aren't supported.
321
+ ///
322
+ /// Octal syntax is disabled by default.
323
+ pub fn octal( & mut self , yes: bool ) -> & mut RegexSetBuilder {
324
+ self . 0 . octal = yes;
325
+ self
326
+ }
327
+
286
328
/// Set the approximate size limit of the compiled regular expression.
287
329
///
288
330
/// This roughly corresponds to the number of bytes occupied by a single
0 commit comments