37
37
*/
38
38
class Builder extends TestMethodProvider
39
39
{
40
- const NON_LITERAL_CHARACTERS = '[ \\^$.|?*+() ' ;
41
40
const METHOD_TYPE_BEGIN = 0b00001 ;
42
41
const METHOD_TYPE_CHARACTER = 0b00010 ;
43
42
const METHOD_TYPE_GROUP = 0b00100 ;
@@ -170,7 +169,6 @@ public function oneOf(string $chars)
170
169
$ this ->validateAndAddMethodType (self ::METHOD_TYPE_CHARACTER , self ::METHOD_TYPES_ALLOWED_FOR_CHARACTERS );
171
170
172
171
$ chars = $ this ->escape ($ chars );
173
- $ chars = $ this ->escapeRangeSpecificChars ($ chars );
174
172
175
173
return $ this ->add ('[ ' . $ chars . '] ' );
176
174
}
@@ -186,7 +184,6 @@ public function notOneOf(string $chars)
186
184
$ this ->validateAndAddMethodType (self ::METHOD_TYPE_CHARACTER , self ::METHOD_TYPES_ALLOWED_FOR_CHARACTERS );
187
185
188
186
$ chars = $ this ->escape ($ chars );
189
- $ chars = $ this ->escapeRangeSpecificChars ($ chars );
190
187
191
188
return $ this ->add ('[^ ' . $ chars . '] ' );
192
189
}
@@ -576,28 +573,7 @@ public function until($toCondition) : self
576
573
*/
577
574
protected function escape (string $ chars )
578
575
{
579
- return implode ('' , array_map ([$ this , 'escapeChar ' ], str_split ($ chars )));
580
- }
581
-
582
- /**
583
- * Escape specific character.
584
- *
585
- * @param string $char
586
- * @return string
587
- */
588
- protected function escapeChar (string $ char )
589
- {
590
- return (strpos (static ::NON_LITERAL_CHARACTERS , $ char ) !== false ? '\\' : '' ) . $ char ;
591
- }
592
-
593
- /**
594
- * Escape '-' and ']' in string to be used in range.
595
- *
596
- * @return string
597
- */
598
- protected function escapeRangeSpecificChars (string $ chars )
599
- {
600
- return str_replace (['- ' , '] ' ], ['\\- ' , '\\] ' ], $ chars );
576
+ return preg_quote ($ chars );
601
577
}
602
578
603
579
/**
0 commit comments