Skip to content

Commit f212775

Browse files
committed
ext/strmatch: Add prepared string matching and replacement
Introduce independent final Str\Matcher and Str\Replacer classes for reusing fixed keyword dictionaries across subjects. Build hybrid Aho-Corasick automata with dense and packed sparse transitions. Use byte-based matching and reversed matching for leftmost-longest replacement, while retaining shared keyword strings. Check state, count and result limits, reject repeated initialization, and keep prepared objects uncloneable, non-serializable and incomparable. Include Unix and Windows build configuration, CI coverage and 24 PHPT tests for API semantics, binary input, overlapping matches and lifecycle.
1 parent 758c9ac commit f212775

39 files changed

Lines changed: 1996 additions & 0 deletions

‎.github/actions/configure-alpine/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ runs:
5151
--with-openssl \
5252
--with-gmp \
5353
--enable-bcmath \
54+
--enable-strmatch \
5455
--enable-calendar \
5556
--enable-ftp \
5657
${{ inputs.skipSlow == 'false' && '--with-enchant=/usr' || '' }} \

‎.github/actions/configure-gentoo/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ runs:
5252
--with-openssl \
5353
--with-gmp \
5454
--enable-bcmath \
55+
--enable-strmatch \
5556
--enable-calendar \
5657
--enable-ftp \
5758
${{ inputs.skipSlow == 'false' && '--with-enchant=/usr' || '' }} \

‎.github/actions/configure-macos/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ runs:
5656
--with-gmp="$BREW_OPT"/gmp \
5757
--with-iconv="$BREW_OPT"/libiconv \
5858
--enable-bcmath \
59+
--enable-strmatch \
5960
--enable-calendar \
6061
--enable-ftp \
6162
--enable-sysvmsg \

‎.github/actions/configure-x32/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ runs:
5252
--with-openssl \
5353
--with-gmp \
5454
--enable-bcmath \
55+
--enable-strmatch \
5556
--enable-calendar \
5657
--enable-ftp \
5758
--enable-sysvmsg \

‎.github/actions/configure-x64/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ runs:
5454
--with-openssl \
5555
--with-gmp \
5656
--enable-bcmath \
57+
--enable-strmatch \
5758
--enable-calendar \
5859
--enable-ftp \
5960
${{ inputs.skipSlow == 'false' && '--with-enchant=/usr' || '' }} \

‎.github/actions/freebsd/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ runs:
8080
--with-openssl \
8181
--with-iconv=/usr/local \
8282
--enable-bcmath \
83+
--enable-strmatch \
8384
--enable-calendar \
8485
--enable-ftp \
8586
--with-ffi \

‎.github/actions/solaris/action.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ runs:
5151
--enable-sockets \
5252
--with-openssl \
5353
--enable-bcmath \
54+
--enable-strmatch \
5455
--enable-calendar \
5556
--enable-ftp \
5657
--enable-zend-test \

‎.github/scripts/windows/build_task.bat‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if "%CLANG_TOOLSET%" equ "1" (
4141

4242
cmd /c configure.bat ^
4343
--enable-snapshot-build ^
44+
--enable-strmatch ^
4445
--disable-debug-pack ^
4546
--without-analyzer ^
4647
--enable-object-out-dir=%PHP_BUILD_OBJ_DIR% ^

‎.github/workflows/test-suite.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ jobs:
767767
--disable-mbregex \
768768
--enable-sockets \
769769
--enable-bcmath \
770+
--enable-strmatch \
770771
--enable-calendar \
771772
--enable-ftp \
772773
--enable-zend-test \

‎ext/strmatch/config.m4‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PHP_ARG_ENABLE([strmatch],
2+
[whether to enable strmatch support],
3+
[AS_HELP_STRING([--enable-strmatch],
4+
[Enable multi-pattern string matching (Str\Matcher / Str\Replacer)])],
5+
[no])
6+
7+
AS_VAR_IF([PHP_STRMATCH], [no],, [
8+
AC_DEFINE([HAVE_STRMATCH], [1],
9+
[Define to 1 if the PHP extension strmatch is available.])
10+
PHP_NEW_EXTENSION([strmatch], [strmatch.c], [$ext_shared])
11+
])

0 commit comments

Comments
 (0)