3737 */
3838class Builder extends TestMethodProvider
3939{
40- const NON_LITERAL_CHARACTERS = '[ \\^$.|?*+() ' ;
4140 const METHOD_TYPE_BEGIN = 0b00001 ;
4241 const METHOD_TYPE_CHARACTER = 0b00010 ;
4342 const METHOD_TYPE_GROUP = 0b00100 ;
@@ -170,7 +169,6 @@ public function oneOf(string $chars)
170169 $ this ->validateAndAddMethodType (self ::METHOD_TYPE_CHARACTER , self ::METHOD_TYPES_ALLOWED_FOR_CHARACTERS );
171170
172171 $ chars = $ this ->escape ($ chars );
173- $ chars = $ this ->escapeRangeSpecificChars ($ chars );
174172
175173 return $ this ->add ('[ ' . $ chars . '] ' );
176174 }
@@ -186,7 +184,6 @@ public function notOneOf(string $chars)
186184 $ this ->validateAndAddMethodType (self ::METHOD_TYPE_CHARACTER , self ::METHOD_TYPES_ALLOWED_FOR_CHARACTERS );
187185
188186 $ chars = $ this ->escape ($ chars );
189- $ chars = $ this ->escapeRangeSpecificChars ($ chars );
190187
191188 return $ this ->add ('[^ ' . $ chars . '] ' );
192189 }
@@ -576,28 +573,7 @@ public function until($toCondition) : self
576573 */
577574 protected function escape (string $ chars )
578575 {
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 );
601577 }
602578
603579 /**
0 commit comments