@@ -19,7 +19,7 @@ function __construct($raw, $utf8) {
1919
2020 /** @return TextPregexes */
2121 static function make_empty () {
22- return new TextPregexes (' (?!) ' , '(?!) ' );
22+ return new TextPregexes (null , '(?!) ' );
2323 }
2424
2525 /** @return bool */
@@ -28,23 +28,44 @@ function is_empty() {
2828 }
2929
3030 /** @param string $text
31- * @param ?string $deaccented_text
3231 * @return bool */
33- function match ($ text, $ deaccented_text ) {
32+ function match_raw ($ text ) {
3433 if ($ this ->preg_raw === null ) {
3534 return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ text );
36- } else if ((string ) $ deaccented_text !== "" && $ deaccented_text !== $ text ) {
37- return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ deaccented_text );
38- } else {
39- return !!preg_match ("{ {$ this ->preg_raw }}i " , $ text );
4035 }
36+ return !!preg_match ("{ {$ this ->preg_raw }}i " , $ text );
37+ }
38+
39+ /** @param string $text
40+ * @return bool */
41+ function match ($ text ) {
42+ if ($ this ->preg_raw === null ) {
43+ return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ text );
44+ } else if (($ text_da = UnicodeHelper::maybe_deaccent ($ text )) !== null ) {
45+ return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ text_da );
46+ }
47+ return !!preg_match ("{ {$ this ->preg_raw }}i " , $ text );
48+ }
49+
50+ /** @param string $text
51+ * @param ?string $text_da
52+ * @return bool */
53+ function match_da ($ text , $ text_da ) {
54+ if ($ this ->preg_raw === null ) {
55+ return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ text );
56+ } else if ((string ) $ text_da !== "" && $ text_da !== $ text ) {
57+ return !!preg_match ("{ {$ this ->preg_utf8 }}ui " , $ text_da );
58+ }
59+ return !!preg_match ("{ {$ this ->preg_raw }}i " , $ text );
4160 }
4261
4362 function add_matches (TextPregexes $ r ) {
44- if ($ this ->is_empty ()) {
63+ if ($ r ->is_empty ()) {
64+ // do nothing
65+ } else if ($ this ->is_empty ()) {
4566 $ this ->preg_utf8 = $ r ->preg_utf8 ;
4667 $ this ->preg_raw = $ r ->preg_raw ;
47- } else if (! $ r -> is_empty ()) {
68+ } else {
4869 $ this ->preg_utf8 .= "| {$ r ->preg_utf8 }" ;
4970 if ($ r ->preg_raw === null ) {
5071 $ this ->preg_raw = null ;
@@ -338,9 +359,8 @@ static function utf8_word_regex($word, $literal = false) {
338359 return ($ aw ? self ::UTF8_INITIAL_NONLETTERDIGIT : '' )
339360 . str_replace (" " , $ sp , preg_quote ($ word ))
340361 . ($ zw ? self ::UTF8_FINAL_NONLETTERDIGIT : '' );
341- } else {
342- return self ::utf8_word_regex (convert_to_utf8 ($ word ));
343362 }
363+ return self ::utf8_word_regex (convert_to_utf8 ($ word ));
344364 }
345365
346366 /** @param string $word
@@ -373,9 +393,10 @@ static function star_text_pregexes($word, $literal = false) {
373393 /** @param ?TextPregexes $reg
374394 * @param string $text
375395 * @param ?string $deaccented_text
376- * @return bool */
396+ * @return bool
397+ * @deprecated */
377398 static function match_pregexes ($ reg , $ text , $ deaccented_text ) {
378- return $ reg && $ reg ->match ($ text , $ deaccented_text );
399+ return $ reg && $ reg ->match_da ($ text , $ deaccented_text );
379400 }
380401
381402
0 commit comments