23
23
"$" : "\\ $" ,
24
24
"\n " : "" ,
25
25
" " : "\\ " ,
26
- '\\ ' : '\\ \\ '
26
+ '\\ ' : '\\ \\ ' ,
27
+ "?" : "\\ ?"
27
28
}
28
29
29
30
RECOMBINE = {
@@ -218,13 +219,14 @@ def _preprocess_brackets_content(self, bracket_content):
218
219
bracket_content_temp = []
219
220
previous_is_valid_for_range = False
220
221
for i , symbol in enumerate (bracket_content ):
221
- if ( symbol == "-" and not self . _should_escape_next_symbol (
222
- bracket_content_temp ) ):
223
- if ( not previous_is_valid_for_range
224
- or i == len ( bracket_content ) - 1 ):
222
+ # We have a range
223
+ if symbol == "-" and not self . _should_escape_next_symbol ( bracket_content_temp ):
224
+ if not previous_is_valid_for_range or i == len ( bracket_content ) - 1 :
225
+ # False alarm, no range
225
226
bracket_content_temp .append ("-" )
226
227
previous_is_valid_for_range = True
227
228
else :
229
+ # We insert all the characters in the range
228
230
bracket_content [i - 1 ] = self ._recombine (bracket_content [i - 1 ])
229
231
for j in range (ord (bracket_content [i - 1 ][- 1 ]) + 1 ,
230
232
ord (bracket_content [i + 1 ][- 1 ])):
@@ -244,10 +246,18 @@ def _preprocess_brackets_content(self, bracket_content):
244
246
previous_is_valid_for_range = False
245
247
else :
246
248
previous_is_valid_for_range = True
249
+ bracket_content_temp = self ._preprocess_negation (bracket_content_temp )
247
250
bracket_content_temp = self ._insert_or (bracket_content_temp )
248
251
bracket_content_temp = self ._recombine (bracket_content_temp )
249
252
return bracket_content_temp
250
253
254
+ @staticmethod
255
+ def _preprocess_negation (bracket_content ):
256
+ if not bracket_content or bracket_content [0 ] != "^" :
257
+ return bracket_content
258
+ # We inverse everything
259
+ return [x for x in ESCAPED_PRINTABLES if x not in bracket_content ]
260
+
251
261
@staticmethod
252
262
def _insert_or (l_to_modify ):
253
263
res = []
0 commit comments