@@ -1889,6 +1889,54 @@ void test_gh_5490() {
18891889 }
18901890}
18911891
1892+ void test_gh_5509 () {
1893+ // GH-5509 extended the matcher's skip optimization
1894+ // to regexes starting with a loop with at least one repetition,
1895+ // speeding up searches for such regexes
1896+
1897+ {
1898+ test_regex char_plus_regex (&g_regexTester, " (a+)" );
1899+ char_plus_regex.should_search_match_capture_groups (" blwerofaaweraf" , " aa" , match_default, {{7 , 9 }});
1900+ char_plus_regex.should_search_fail (" blwerofwerf" );
1901+ }
1902+
1903+ {
1904+ test_regex charclass_plus_regex (&g_regexTester, " ([fa]+)" );
1905+ charclass_plus_regex.should_search_match_capture_groups (" blwerofaaweraf" , " faa" , match_default, {{6 , 9 }});
1906+ charclass_plus_regex.should_search_fail (" blwerower" );
1907+ }
1908+
1909+ {
1910+ test_regex string_plus_regex (&g_regexTester, " ((?:aw)+)" );
1911+ string_plus_regex.should_search_match_capture_groups (" blwerofaawaweraf" , " awaw" , match_default, {{8 , 12 }});
1912+ string_plus_regex.should_search_fail (" blwerofaerwaf" );
1913+ }
1914+
1915+ {
1916+ test_regex anchored_string_plus_regex (&g_regexTester, " ((?:^aw)+)" );
1917+ anchored_string_plus_regex.should_search_match_capture_groups (
1918+ " blwerofa\n awaweraf" , " aw" , match_default, {{9 , 11 }});
1919+ anchored_string_plus_regex.should_search_fail (" blwerof\n aerwaf" );
1920+ }
1921+
1922+ {
1923+ test_regex anchored_string_plus_regex (&g_regexTester, " ((?:$\n aw)+)" );
1924+ anchored_string_plus_regex.should_search_match_capture_groups (
1925+ " blwerofa\n awaweraf" , " \n aw" , match_default, {{8 , 11 }});
1926+ anchored_string_plus_regex.should_search_fail (" blwerof\n aerwaf" );
1927+ }
1928+
1929+ {
1930+ test_regex string_star_string_regex (&g_regexTester, " ((?:aw)*fa)" );
1931+ string_star_string_regex.should_search_match_capture_groups (
1932+ " blwerofaawawfaeraf" , " fa" , match_default, {{6 , 8 }});
1933+ string_star_string_regex.should_search_match_capture_groups (
1934+ " blweroawawfaeraf" , " awawfa" , match_default, {{6 , 12 }});
1935+ string_star_string_regex.should_search_match (" blwerofaerwaf" , " fa" );
1936+ string_star_string_regex.should_search_fail (" blweroerwaf" );
1937+ }
1938+ }
1939+
18921940int main () {
18931941 test_dev10_449367_case_insensitivity_should_work ();
18941942 test_dev11_462743_regex_collate_should_not_disable_regex_icase ();
@@ -1936,6 +1984,7 @@ int main() {
19361984 test_gh_5374 ();
19371985 test_gh_5377 ();
19381986 test_gh_5490 ();
1987+ test_gh_5509 ();
19391988
19401989 return g_regexTester.result ();
19411990}
0 commit comments