summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2008-07-17 14:27:54 +0000
committerNuno Lopes <nlopess@php.net>2008-07-17 14:27:54 +0000
commitb23f3cd8624c88c7129d97c66221c57b2ca0a1cf (patch)
treeb0f0e3885f87996329d1e7dcf1d1c3161b92daa1
parentbc9bdc928ecc6f189edd6f1a57a29d9a1e3341fc (diff)
downloadphp-git-b23f3cd8624c88c7129d97c66221c57b2ca0a1cf.tar.gz
upgrade PCRE to 7.7 + one additional patch to fix a security bug
-rw-r--r--NEWS3
-rw-r--r--ext/pcre/config0.m411
-rw-r--r--ext/pcre/pcrelib/AUTHORS6
-rw-r--r--ext/pcre/pcrelib/COPYING65
-rw-r--r--ext/pcre/pcrelib/ChangeLog756
-rw-r--r--ext/pcre/pcrelib/HACKING (renamed from ext/pcre/pcrelib/doc/Tech.Notes)36
-rw-r--r--ext/pcre/pcrelib/LICENCE6
-rw-r--r--ext/pcre/pcrelib/NEWS122
-rw-r--r--ext/pcre/pcrelib/NON-UNIX-USE505
-rw-r--r--ext/pcre/pcrelib/README669
-rw-r--r--ext/pcre/pcrelib/config.h318
-rw-r--r--ext/pcre/pcrelib/dftables.c54
-rw-r--r--ext/pcre/pcrelib/doc/pcre.txt3300
-rw-r--r--ext/pcre/pcrelib/libpcre.def20
-rw-r--r--ext/pcre/pcrelib/libpcreposix.def25
-rw-r--r--ext/pcre/pcrelib/pcre.def29
-rw-r--r--ext/pcre/pcrelib/pcre.h134
-rw-r--r--ext/pcre/pcrelib/pcre_chartables.c39
-rw-r--r--ext/pcre/pcrelib/pcre_compile.c1605
-rw-r--r--ext/pcre/pcrelib/pcre_config.c14
-rw-r--r--ext/pcre/pcrelib/pcre_exec.c1320
-rw-r--r--ext/pcre/pcrelib/pcre_fullinfo.c26
-rw-r--r--ext/pcre/pcrelib/pcre_get.c6
-rw-r--r--ext/pcre/pcrelib/pcre_globals.c35
-rw-r--r--ext/pcre/pcrelib/pcre_info.c10
-rw-r--r--ext/pcre/pcrelib/pcre_internal.h505
-rw-r--r--ext/pcre/pcrelib/pcre_maketables.c5
-rw-r--r--ext/pcre/pcrelib/pcre_newline.c47
-rw-r--r--ext/pcre/pcrelib/pcre_ord2utf8.c7
-rw-r--r--ext/pcre/pcrelib/pcre_printint.src38
-rw-r--r--ext/pcre/pcrelib/pcre_refcount.c7
-rw-r--r--ext/pcre/pcrelib/pcre_scanner.cc194
-rw-r--r--ext/pcre/pcrelib/pcre_scanner.h171
-rw-r--r--ext/pcre/pcrelib/pcre_scanner_unittest.cc152
-rw-r--r--ext/pcre/pcrelib/pcre_stringpiece.cc39
-rw-r--r--ext/pcre/pcrelib/pcre_stringpiece.h172
-rw-r--r--ext/pcre/pcrelib/pcre_stringpiece_unittest.cc145
-rw-r--r--ext/pcre/pcrelib/pcre_study.c21
-rw-r--r--ext/pcre/pcrelib/pcre_tables.c335
-rw-r--r--ext/pcre/pcrelib/pcre_try_flipped.c5
-rw-r--r--ext/pcre/pcrelib/pcre_ucp_searchfuncs.c8
-rw-r--r--ext/pcre/pcrelib/pcre_valid_utf8.c48
-rw-r--r--ext/pcre/pcrelib/pcre_version.c6
-rw-r--r--ext/pcre/pcrelib/pcre_xclass.c4
-rw-r--r--ext/pcre/pcrelib/pcrecpp.cc857
-rw-r--r--ext/pcre/pcrelib/pcrecpp.h695
-rw-r--r--ext/pcre/pcrelib/pcrecpp_unittest.cc1227
-rw-r--r--ext/pcre/pcrelib/pcrecpparg.h171
-rw-r--r--ext/pcre/pcrelib/pcredemo.c24
-rw-r--r--ext/pcre/pcrelib/pcregrep.c1993
-rw-r--r--ext/pcre/pcrelib/pcreposix.c55
-rw-r--r--ext/pcre/pcrelib/pcreposix.h44
-rw-r--r--ext/pcre/pcrelib/pcretest.c2305
-rw-r--r--ext/pcre/pcrelib/testdata/grepinputx7
-rw-r--r--ext/pcre/pcrelib/testdata/grepoutput67
-rw-r--r--ext/pcre/pcrelib/testdata/grepoutputN22
-rw-r--r--ext/pcre/pcrelib/testdata/testinput132
-rw-r--r--ext/pcre/pcrelib/testdata/testinput10124
-rw-r--r--ext/pcre/pcrelib/testdata/testinput21576
-rw-r--r--ext/pcre/pcrelib/testdata/testinput32
-rw-r--r--ext/pcre/pcrelib/testdata/testinput486
-rw-r--r--ext/pcre/pcrelib/testdata/testinput5274
-rw-r--r--ext/pcre/pcrelib/testdata/testinput6177
-rw-r--r--ext/pcre/pcrelib/testdata/testinput7177
-rw-r--r--ext/pcre/pcrelib/testdata/testinput882
-rw-r--r--ext/pcre/pcrelib/testdata/testinput916
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput152
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput10669
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput24867
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput314
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput4153
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput51230
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput6395
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput7318
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput8154
-rw-r--r--ext/pcre/pcrelib/testdata/testoutput920
-rw-r--r--ext/pcre/pcrelib/ucpinternal.h2
-rw-r--r--ext/pcre/pcrelib/ucptable.h (renamed from ext/pcre/pcrelib/ucptable.c)52
-rw-r--r--ext/pcre/upgrade-pcre.php117
79 files changed, 15199 insertions, 13880 deletions
diff --git a/NEWS b/NEWS
index d46f706092..6a0320c401 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+?? ?? 2008, Version 4.4.9
+- Updated PCRE to version 7.7. (Nuno)
+
03 Jan 2008, Version 4.4.8
- Improved fix for MOPB-02-2007. (Ilia)
- Fixed an integer overflow inside chunk_split(). Identified by Gerhard Wagner.
diff --git a/ext/pcre/config0.m4 b/ext/pcre/config0.m4
index e359837ad1..67b8f23a27 100644
--- a/ext/pcre/config0.m4
+++ b/ext/pcre/config0.m4
@@ -13,7 +13,14 @@ PHP_ARG_WITH(pcre-regex,for PCRE support,
if test "$PHP_PCRE_REGEX" != "no"; then
if test "$PHP_PCRE_REGEX" = "yes"; then
- PHP_NEW_EXTENSION(pcre, pcrelib/pcre_chartables.c pcrelib/pcre_ucp_searchfuncs.c pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_exec.c pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c pcrelib/pcre_info.c pcrelib/pcre_maketables.c pcrelib/pcre_newline.c pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_valid_utf8.c pcrelib/pcre_version.c pcrelib/pcre_xclass.c php_pcre.c, $ext_shared,,-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000 -DEBCDIC=0 -I@ext_srcdir@/pcrelib)
+ pcrelib_sources="pcrelib/pcre_chartables.c pcrelib/pcre_ucp_searchfuncs.c \
+ pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_exec.c \
+ pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c \
+ pcrelib/pcre_info.c pcrelib/pcre_maketables.c pcrelib/pcre_newline.c \
+ pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c \
+ pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_valid_utf8.c \
+ pcrelib/pcre_version.c pcrelib/pcre_xclass.c"
+ PHP_NEW_EXTENSION(pcre, $pcrelib_sources php_pcre.c, $ext_shared,,-I@ext_srcdir@/pcrelib)
PHP_ADD_BUILD_DIR($ext_builddir/pcrelib)
AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ])
else
@@ -50,7 +57,7 @@ if test "$PHP_PCRE_REGEX" != "no"; then
AC_DEFINE(HAVE_PCRE, 1, [ ])
PHP_ADD_INCLUDE($PCRE_INCDIR)
- PHP_NEW_EXTENSION(pcre, php_pcre.c, $ext_shared,,-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000)
+ PHP_NEW_EXTENSION(pcre, php_pcre.c, $ext_shared)
fi
PHP_SUBST(PCRE_SHARED_LIBADD)
fi
diff --git a/ext/pcre/pcrelib/AUTHORS b/ext/pcre/pcrelib/AUTHORS
index adb4fc4019..88b993b698 100644
--- a/ext/pcre/pcrelib/AUTHORS
+++ b/ext/pcre/pcrelib/AUTHORS
@@ -6,9 +6,9 @@ Email local part: ph10
Email domain: cam.ac.uk
University of Cambridge Computing Service,
-Cambridge, England. Phone: +44 1223 334714.
+Cambridge, England.
-Copyright (c) 1997-2006 University of Cambridge
+Copyright (c) 1997-2008 University of Cambridge
All rights reserved
@@ -17,7 +17,7 @@ THE C++ WRAPPER LIBRARY
Written by: Google Inc.
-Copyright (c) 2006 Google Inc
+Copyright (c) 2007-2008 Google Inc
All rights reserved
####
diff --git a/ext/pcre/pcrelib/COPYING b/ext/pcre/pcrelib/COPYING
index 58241b2bda..58eed01b61 100644
--- a/ext/pcre/pcrelib/COPYING
+++ b/ext/pcre/pcrelib/COPYING
@@ -1,68 +1,5 @@
PCRE LICENCE
-------------
-PCRE is a library of functions to support regular expressions whose syntax
-and semantics are as close as possible to those of the Perl 5 language.
-
-Release 7 of PCRE is distributed under the terms of the "BSD" licence, as
-specified below. The documentation for PCRE, supplied in the "doc"
-directory, is distributed under the same terms as the software itself.
-
-The basic library functions are written in C and are freestanding. Also
-included in the distribution is a set of C++ wrapper functions.
-
-
-THE BASIC LIBRARY FUNCTIONS
----------------------------
-
-Written by: Philip Hazel
-Email local part: ph10
-Email domain: cam.ac.uk
-
-University of Cambridge Computing Service,
-Cambridge, England. Phone: +44 1223 334714.
-
-Copyright (c) 1997-2006 University of Cambridge
-All rights reserved.
-
-
-THE C++ WRAPPER FUNCTIONS
--------------------------
-
-Contributed by: Google Inc.
-
-Copyright (c) 2006, Google Inc.
-All rights reserved.
-
-
-THE "BSD" LICENCE
------------------
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- * Neither the name of the University of Cambridge nor the name of Google
- Inc. nor the names of their contributors may be used to endorse or
- promote products derived from this software without specific prior
- written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
+Please see the file LICENCE in the PCRE distribution for licensing details.
End
diff --git a/ext/pcre/pcrelib/ChangeLog b/ext/pcre/pcrelib/ChangeLog
index 7d32804d05..88c69f93eb 100644
--- a/ext/pcre/pcrelib/ChangeLog
+++ b/ext/pcre/pcrelib/ChangeLog
@@ -1,6 +1,762 @@
ChangeLog for PCRE
------------------
+Version 7.7 07-May-08
+---------------------
+
+1. Applied Craig's patch to sort out a long long problem: "If we can't convert
+ a string to a long long, pretend we don't even have a long long." This is
+ done by checking for the strtoq, strtoll, and _strtoi64 functions.
+
+2. Applied Craig's patch to pcrecpp.cc to restore ABI compatibility with
+ pre-7.6 versions, which defined a global no_arg variable instead of putting
+ it in the RE class. (See also #8 below.)
+
+3. Remove a line of dead code, identified by coverity and reported by Nuno
+ Lopes.
+
+4. Fixed two related pcregrep bugs involving -r with --include or --exclude:
+
+ (1) The include/exclude patterns were being applied to the whole pathnames
+ of files, instead of just to the final components.
+
+ (2) If there was more than one level of directory, the subdirectories were
+ skipped unless they satisfied the include/exclude conditions. This is
+ inconsistent with GNU grep (and could even be seen as contrary to the
+ pcregrep specification - which I improved to make it absolutely clear).
+ The action now is always to scan all levels of directory, and just
+ apply the include/exclude patterns to regular files.
+
+5. Added the --include_dir and --exclude_dir patterns to pcregrep, and used
+ --exclude_dir in the tests to avoid scanning .svn directories.
+
+6. Applied Craig's patch to the QuoteMeta function so that it escapes the
+ NUL character as backslash + 0 rather than backslash + NUL, because PCRE
+ doesn't support NULs in patterns.
+
+7. Added some missing "const"s to declarations of static tables in
+ pcre_compile.c and pcre_dfa_exec.c.
+
+8. Applied Craig's patch to pcrecpp.cc to fix a problem in OS X that was
+ caused by fix #2 above. (Subsequently also a second patch to fix the
+ first patch. And a third patch - this was a messy problem.)
+
+9. Applied Craig's patch to remove the use of push_back().
+
+10. Applied Alan Lehotsky's patch to add REG_STARTEND support to the POSIX
+ matching function regexec().
+
+11. Added support for the Oniguruma syntax \g<name>, \g<n>, \g'name', \g'n',
+ which, however, unlike Perl's \g{...}, are subroutine calls, not back
+ references. PCRE supports relative numbers with this syntax (I don't think
+ Oniguruma does).
+
+12. Previously, a group with a zero repeat such as (...){0} was completely
+ omitted from the compiled regex. However, this means that if the group
+ was called as a subroutine from elsewhere in the pattern, things went wrong
+ (an internal error was given). Such groups are now left in the compiled
+ pattern, with a new opcode that causes them to be skipped at execution
+ time.
+
+13. Added the PCRE_JAVASCRIPT_COMPAT option. This makes the following changes
+ to the way PCRE behaves:
+
+ (a) A lone ] character is dis-allowed (Perl treats it as data).
+
+ (b) A back reference to an unmatched subpattern matches an empty string
+ (Perl fails the current match path).
+
+ (c) A data ] in a character class must be notated as \] because if the
+ first data character in a class is ], it defines an empty class. (In
+ Perl it is not possible to have an empty class.) The empty class []
+ never matches; it forces failure and is equivalent to (*FAIL) or (?!).
+ The negative empty class [^] matches any one character, independently
+ of the DOTALL setting.
+
+14. A pattern such as /(?2)[]a()b](abc)/ which had a forward reference to a
+ non-existent subpattern following a character class starting with ']' and
+ containing () gave an internal compiling error instead of "reference to
+ non-existent subpattern". Fortunately, when the pattern did exist, the
+ compiled code was correct. (When scanning forwards to check for the
+ existencd of the subpattern, it was treating the data ']' as terminating
+ the class, so got the count wrong. When actually compiling, the reference
+ was subsequently set up correctly.)
+
+15. The "always fail" assertion (?!) is optimzed to (*FAIL) by pcre_compile;
+ it was being rejected as not supported by pcre_dfa_exec(), even though
+ other assertions are supported. I have made pcre_dfa_exec() support
+ (*FAIL).
+
+16. The implementation of 13c above involved the invention of a new opcode,
+ OP_ALLANY, which is like OP_ANY but doesn't check the /s flag. Since /s
+ cannot be changed at match time, I realized I could make a small
+ improvement to matching performance by compiling OP_ALLANY instead of
+ OP_ANY for "." when DOTALL was set, and then removing the runtime tests
+ on the OP_ANY path.
+
+17. Compiling pcretest on Windows with readline support failed without the
+ following two fixes: (1) Make the unistd.h include conditional on
+ HAVE_UNISTD_H; (2) #define isatty and fileno as _isatty and _fileno.
+
+18. Changed CMakeLists.txt and cmake/FindReadline.cmake to arrange for the
+ ncurses library to be included for pcretest when ReadLine support is
+ requested, but also to allow for it to be overridden. This patch came from
+ Daniel Bergström.
+
+19. There was a typo in the file ucpinternal.h where f0_rangeflag was defined
+ as 0x00f00000 instead of 0x00800000. Luckily, this would not have caused
+ any errors with the current Unicode tables. Thanks to Peter Kankowski for
+ spotting this.
+
+
+Version 7.6 28-Jan-08
+---------------------
+
+1. A character class containing a very large number of characters with
+ codepoints greater than 255 (in UTF-8 mode, of course) caused a buffer
+ overflow.
+
+2. Patch to cut out the "long long" test in pcrecpp_unittest when
+ HAVE_LONG_LONG is not defined.
+
+3. Applied Christian Ehrlicher's patch to update the CMake build files to
+ bring them up to date and include new features. This patch includes:
+
+ - Fixed PH's badly added libz and libbz2 support.
+ - Fixed a problem with static linking.
+ - Added pcredemo. [But later removed - see 7 below.]
+ - Fixed dftables problem and added an option.
+ - Added a number of HAVE_XXX tests, including HAVE_WINDOWS_H and
+ HAVE_LONG_LONG.
+ - Added readline support for pcretest.
+ - Added an listing of the option settings after cmake has run.
+
+4. A user submitted a patch to Makefile that makes it easy to create
+ "pcre.dll" under mingw when using Configure/Make. I added stuff to
+ Makefile.am that cause it to include this special target, without
+ affecting anything else. Note that the same mingw target plus all
+ the other distribution libraries and programs are now supported
+ when configuring with CMake (see 6 below) instead of with
+ Configure/Make.
+
+5. Applied Craig's patch that moves no_arg into the RE class in the C++ code.
+ This is an attempt to solve the reported problem "pcrecpp::no_arg is not
+ exported in the Windows port". It has not yet been confirmed that the patch
+ solves the problem, but it does no harm.
+
+6. Applied Sheri's patch to CMakeLists.txt to add NON_STANDARD_LIB_PREFIX and
+ NON_STANDARD_LIB_SUFFIX for dll names built with mingw when configured
+ with CMake, and also correct the comment about stack recursion.
+
+7. Remove the automatic building of pcredemo from the ./configure system and
+ from CMakeLists.txt. The whole idea of pcredemo.c is that it is an example
+ of a program that users should build themselves after PCRE is installed, so
+ building it automatically is not really right. What is more, it gave
+ trouble in some build environments.
+
+8. Further tidies to CMakeLists.txt from Sheri and Christian.
+
+
+Version 7.5 10-Jan-08
+---------------------
+
+1. Applied a patch from Craig: "This patch makes it possible to 'ignore'
+ values in parens when parsing an RE using the C++ wrapper."
+
+2. Negative specials like \S did not work in character classes in UTF-8 mode.
+ Characters greater than 255 were excluded from the class instead of being
+ included.
+
+3. The same bug as (2) above applied to negated POSIX classes such as
+ [:^space:].
+
+4. PCRECPP_STATIC was referenced in pcrecpp_internal.h, but nowhere was it
+ defined or documented. It seems to have been a typo for PCRE_STATIC, so
+ I have changed it.
+
+5. The construct (?&) was not diagnosed as a syntax error (it referenced the
+ first named subpattern) and a construct such as (?&a) would reference the
+ first named subpattern whose name started with "a" (in other words, the
+ length check was missing). Both these problems are fixed. "Subpattern name
+ expected" is now given for (?&) (a zero-length name), and this patch also
+ makes it give the same error for \k'' (previously it complained that that
+ was a reference to a non-existent subpattern).
+
+6. The erroneous patterns (?+-a) and (?-+a) give different error messages;
+ this is right because (?- can be followed by option settings as well as by
+ digits. I have, however, made the messages clearer.
+
+7. Patterns such as (?(1)a|b) (a pattern that contains fewer subpatterns
+ than the number used in the conditional) now cause a compile-time error.
+ This is actually not compatible with Perl, which accepts such patterns, but
+ treats the conditional as always being FALSE (as PCRE used to), but it
+ seems to me that giving a diagnostic is better.
+
+8. Change "alphameric" to the more common word "alphanumeric" in comments
+ and messages.
+
+9. Fix two occurrences of "backslash" in comments that should have been
+ "backspace".
+
+10. Remove two redundant lines of code that can never be obeyed (their function
+ was moved elsewhere).
+
+11. The program that makes PCRE's Unicode character property table had a bug
+ which caused it to generate incorrect table entries for sequences of
+ characters that have the same character type, but are in different scripts.
+ It amalgamated them into a single range, with the script of the first of
+ them. In other words, some characters were in the wrong script. There were
+ thirteen such cases, affecting characters in the following ranges:
+
+ U+002b0 - U+002c1
+ U+0060c - U+0060d
+ U+0061e - U+00612
+ U+0064b - U+0065e
+ U+0074d - U+0076d
+ U+01800 - U+01805
+ U+01d00 - U+01d77
+ U+01d9b - U+01dbf
+ U+0200b - U+0200f
+ U+030fc - U+030fe
+ U+03260 - U+0327f
+ U+0fb46 - U+0fbb1
+ U+10450 - U+1049d
+
+12. The -o option (show only the matching part of a line) for pcregrep was not
+ compatible with GNU grep in that, if there was more than one match in a
+ line, it showed only the first of them. It now behaves in the same way as
+ GNU grep.
+
+13. If the -o and -v options were combined for pcregrep, it printed a blank
+ line for every non-matching line. GNU grep prints nothing, and pcregrep now
+ does the same. The return code can be used to tell if there were any
+ non-matching lines.
+
+14. Added --file-offsets and --line-offsets to pcregrep.
+
+15. The pattern (?=something)(?R) was not being diagnosed as a potentially
+ infinitely looping recursion. The bug was that positive lookaheads were not
+ being skipped when checking for a possible empty match (negative lookaheads
+ and both kinds of lookbehind were skipped).
+
+16. Fixed two typos in the Windows-only code in pcregrep.c, and moved the
+ inclusion of <windows.h> to before rather than after the definition of
+ INVALID_FILE_ATTRIBUTES (patch from David Byron).
+
+17. Specifying a possessive quantifier with a specific limit for a Unicode
+ character property caused pcre_compile() to compile bad code, which led at
+ runtime to PCRE_ERROR_INTERNAL (-14). Examples of patterns that caused this
+ are: /\p{Zl}{2,3}+/8 and /\p{Cc}{2}+/8. It was the possessive "+" that
+ caused the error; without that there was no problem.
+
+18. Added --enable-pcregrep-libz and --enable-pcregrep-libbz2.
+
+19. Added --enable-pcretest-libreadline.
+
+20. In pcrecpp.cc, the variable 'count' was incremented twice in
+ RE::GlobalReplace(). As a result, the number of replacements returned was
+ double what it should be. I removed one of the increments, but Craig sent a
+ later patch that removed the other one (the right fix) and added unit tests
+ that check the return values (which was not done before).
+
+21. Several CMake things:
+
+ (1) Arranged that, when cmake is used on Unix, the libraries end up with
+ the names libpcre and libpcreposix, not just pcre and pcreposix.
+
+ (2) The above change means that pcretest and pcregrep are now correctly
+ linked with the newly-built libraries, not previously installed ones.
+
+ (3) Added PCRE_SUPPORT_LIBREADLINE, PCRE_SUPPORT_LIBZ, PCRE_SUPPORT_LIBBZ2.
+
+22. In UTF-8 mode, with newline set to "any", a pattern such as .*a.*=.b.*
+ crashed when matching a string such as a\x{2029}b (note that \x{2029} is a
+ UTF-8 newline character). The key issue is that the pattern starts .*;
+ this means that the match must be either at the beginning, or after a
+ newline. The bug was in the code for advancing after a failed match and
+ checking that the new position followed a newline. It was not taking
+ account of UTF-8 characters correctly.
+
+23. PCRE was behaving differently from Perl in the way it recognized POSIX
+ character classes. PCRE was not treating the sequence [:...:] as a
+ character class unless the ... were all letters. Perl, however, seems to
+ allow any characters between [: and :], though of course it rejects as
+ unknown any "names" that contain non-letters, because all the known class
+ names consist only of letters. Thus, Perl gives an error for [[:1234:]],
+ for example, whereas PCRE did not - it did not recognize a POSIX character
+ class. This seemed a bit dangerous, so the code has been changed to be
+ closer to Perl. The behaviour is not identical to Perl, because PCRE will
+ diagnose an unknown class for, for example, [[:l\ower:]] where Perl will
+ treat it as [[:lower:]]. However, PCRE does now give "unknown" errors where
+ Perl does, and where it didn't before.
+
+24. Rewrite so as to remove the single use of %n from pcregrep because in some
+ Windows environments %n is disabled by default.
+
+
+Version 7.4 21-Sep-07
+---------------------
+
+1. Change 7.3/28 was implemented for classes by looking at the bitmap. This
+ means that a class such as [\s] counted as "explicit reference to CR or
+ LF". That isn't really right - the whole point of the change was to try to
+ help when there was an actual mention of one of the two characters. So now
+ the change happens only if \r or \n (or a literal CR or LF) character is
+ encountered.
+
+2. The 32-bit options word was also used for 6 internal flags, but the numbers
+ of both had grown to the point where there were only 3 bits left.
+ Fortunately, there was spare space in the data structure, and so I have
+ moved the internal flags into a new 16-bit field to free up more option
+ bits.
+
+3. The appearance of (?J) at the start of a pattern set the DUPNAMES option,
+ but did not set the internal JCHANGED flag - either of these is enough to
+ control the way the "get" function works - but the PCRE_INFO_JCHANGED
+ facility is supposed to tell if (?J) was ever used, so now (?J) at the
+ start sets both bits.
+
+4. Added options (at build time, compile time, exec time) to change \R from
+ matching any Unicode line ending sequence to just matching CR, LF, or CRLF.
+
+5. doc/pcresyntax.html was missing from the distribution.
+
+6. Put back the definition of PCRE_ERROR_NULLWSLIMIT, for backward
+ compatibility, even though it is no longer used.
+
+7. Added macro for snprintf to pcrecpp_unittest.cc and also for strtoll and
+ strtoull to pcrecpp.cc to select the available functions in WIN32 when the
+ windows.h file is present (where different names are used). [This was
+ reversed later after testing - see 16 below.]
+
+8. Changed all #include <config.h> to #include "config.h". There were also
+ some further <pcre.h> cases that I changed to "pcre.h".
+
+9. When pcregrep was used with the --colour option, it missed the line ending
+ sequence off the lines that it output.
+
+10. It was pointed out to me that arrays of string pointers cause lots of
+ relocations when a shared library is dynamically loaded. A technique of
+ using a single long string with a table of offsets can drastically reduce
+ these. I have refactored PCRE in four places to do this. The result is
+ dramatic:
+
+ Originally: 290
+ After changing UCP table: 187
+ After changing error message table: 43
+ After changing table of "verbs" 36
+ After changing table of Posix names 22
+
+ Thanks to the folks working on Gregex for glib for this insight.
+
+11. --disable-stack-for-recursion caused compiling to fail unless -enable-
+ unicode-properties was also set.
+
+12. Updated the tests so that they work when \R is defaulted to ANYCRLF.
+
+13. Added checks for ANY and ANYCRLF to pcrecpp.cc where it previously
+ checked only for CRLF.
+
+14. Added casts to pcretest.c to avoid compiler warnings.
+
+15. Added Craig's patch to various pcrecpp modules to avoid compiler warnings.
+
+16. Added Craig's patch to remove the WINDOWS_H tests, that were not working,
+ and instead check for _strtoi64 explicitly, and avoid the use of snprintf()
+ entirely. This removes changes made in 7 above.
+
+17. The CMake files have been updated, and there is now more information about
+ building with CMake in the NON-UNIX-USE document.
+
+
+Version 7.3 28-Aug-07
+---------------------
+
+ 1. In the rejigging of the build system that eventually resulted in 7.1, the
+ line "#include <pcre.h>" was included in pcre_internal.h. The use of angle
+ brackets there is not right, since it causes compilers to look for an
+ installed pcre.h, not the version that is in the source that is being
+ compiled (which of course may be different). I have changed it back to:
+
+ #include "pcre.h"
+
+ I have a vague recollection that the change was concerned with compiling in
+ different directories, but in the new build system, that is taken care of
+ by the VPATH setting the Makefile.
+
+ 2. The pattern .*$ when run in not-DOTALL UTF-8 mode with newline=any failed
+ when the subject happened to end in the byte 0x85 (e.g. if the last
+ character was \x{1ec5}). *Character* 0x85 is one of the "any" newline
+ characters but of course it shouldn't be taken as a newline when it is part
+ of another character. The bug was that, for an unlimited repeat of . in
+ not-DOTALL UTF-8 mode, PCRE was advancing by bytes rather than by
+ characters when looking for a newline.
+
+ 3. A small performance improvement in the DOTALL UTF-8 mode .* case.
+
+ 4. Debugging: adjusted the names of opcodes for different kinds of parentheses
+ in debug output.
+
+ 5. Arrange to use "%I64d" instead of "%lld" and "%I64u" instead of "%llu" for
+ long printing in the pcrecpp unittest when running under MinGW.
+
+ 6. ESC_K was left out of the EBCDIC table.
+
+ 7. Change 7.0/38 introduced a new limit on the number of nested non-capturing
+ parentheses; I made it 1000, which seemed large enough. Unfortunately, the
+ limit also applies to "virtual nesting" when a pattern is recursive, and in
+ this case 1000 isn't so big. I have been able to remove this limit at the
+ expense of backing off one optimization in certain circumstances. Normally,
+ when pcre_exec() would call its internal match() function recursively and
+ immediately return the result unconditionally, it uses a "tail recursion"
+ feature to save stack. However, when a subpattern that can match an empty
+ string has an unlimited repetition quantifier, it no longer makes this
+ optimization. That gives it a stack frame in which to save the data for
+ checking that an empty string has been matched. Previously this was taken
+ from the 1000-entry workspace that had been reserved. So now there is no
+ explicit limit, but more stack is used.
+
+ 8. Applied Daniel's patches to solve problems with the import/export magic
+ syntax that is required for Windows, and which was going wrong for the
+ pcreposix and pcrecpp parts of the library. These were overlooked when this
+ problem was solved for the main library.
+
+ 9. There were some crude static tests to avoid integer overflow when computing
+ the size of patterns that contain repeated groups with explicit upper
+ limits. As the maximum quantifier is 65535, the maximum group length was
+ set at 30,000 so that the product of these two numbers did not overflow a
+ 32-bit integer. However, it turns out that people want to use groups that
+ are longer than 30,000 bytes (though not repeat them that many times).
+ Change 7.0/17 (the refactoring of the way the pattern size is computed) has
+ made it possible to implement the integer overflow checks in a much more
+ dynamic way, which I have now done. The artificial limitation on group
+ length has been removed - we now have only the limit on the total length of
+ the compiled pattern, which depends on the LINK_SIZE setting.
+
+10. Fixed a bug in the documentation for get/copy named substring when
+ duplicate names are permitted. If none of the named substrings are set, the
+ functions return PCRE_ERROR_NOSUBSTRING (7); the doc said they returned an
+ empty string.
+
+11. Because Perl interprets \Q...\E at a high level, and ignores orphan \E
+ instances, patterns such as [\Q\E] or [\E] or even [^\E] cause an error,
+ because the ] is interpreted as the first data character and the
+ terminating ] is not found. PCRE has been made compatible with Perl in this
+ regard. Previously, it interpreted [\Q\E] as an empty class, and [\E] could
+ cause memory overwriting.
+
+10. Like Perl, PCRE automatically breaks an unlimited repeat after an empty
+ string has been matched (to stop an infinite loop). It was not recognizing
+ a conditional subpattern that could match an empty string if that
+ subpattern was within another subpattern. For example, it looped when
+ trying to match (((?(1)X|))*) but it was OK with ((?(1)X|)*) where the
+ condition was not nested. This bug has been fixed.
+
+12. A pattern like \X?\d or \P{L}?\d in non-UTF-8 mode could cause a backtrack
+ past the start of the subject in the presence of bytes with the top bit
+ set, for example "\x8aBCD".
+
+13. Added Perl 5.10 experimental backtracking controls (*FAIL), (*F), (*PRUNE),
+ (*SKIP), (*THEN), (*COMMIT), and (*ACCEPT).
+
+14. Optimized (?!) to (*FAIL).
+
+15. Updated the test for a valid UTF-8 string to conform to the later RFC 3629.
+ This restricts code points to be within the range 0 to 0x10FFFF, excluding
+ the "low surrogate" sequence 0xD800 to 0xDFFF. Previously, PCRE allowed the
+ full range 0 to 0x7FFFFFFF, as defined by RFC 2279. Internally, it still
+ does: it's just the validity check that is more restrictive.
+
+16. Inserted checks for integer overflows during escape sequence (backslash)
+ processing, and also fixed erroneous offset values for syntax errors during
+ backslash processing.
+
+17. Fixed another case of looking too far back in non-UTF-8 mode (cf 12 above)
+ for patterns like [\PPP\x8a]{1,}\x80 with the subject "A\x80".
+
+18. An unterminated class in a pattern like (?1)\c[ with a "forward reference"
+ caused an overrun.
+
+19. A pattern like (?:[\PPa*]*){8,} which had an "extended class" (one with
+ something other than just ASCII characters) inside a group that had an
+ unlimited repeat caused a loop at compile time (while checking to see
+ whether the group could match an empty string).
+
+20. Debugging a pattern containing \p or \P could cause a crash. For example,
+ [\P{Any}] did so. (Error in the code for printing property names.)
+
+21. An orphan \E inside a character class could cause a crash.
+
+22. A repeated capturing bracket such as (A)? could cause a wild memory
+ reference during compilation.
+
+23. There are several functions in pcre_compile() that scan along a compiled
+ expression for various reasons (e.g. to see if it's fixed length for look
+ behind). There were bugs in these functions when a repeated \p or \P was
+ present in the pattern. These operators have additional parameters compared
+ with \d, etc, and these were not being taken into account when moving along
+ the compiled data. Specifically:
+
+ (a) A item such as \p{Yi}{3} in a lookbehind was not treated as fixed
+ length.
+
+ (b) An item such as \pL+ within a repeated group could cause crashes or
+ loops.
+
+ (c) A pattern such as \p{Yi}+(\P{Yi}+)(?1) could give an incorrect
+ "reference to non-existent subpattern" error.
+
+ (d) A pattern like (\P{Yi}{2}\277)? could loop at compile time.
+
+24. A repeated \S or \W in UTF-8 mode could give wrong answers when multibyte
+ characters were involved (for example /\S{2}/8g with "A\x{a3}BC").
+
+25. Using pcregrep in multiline, inverted mode (-Mv) caused it to loop.
+
+26. Patterns such as [\P{Yi}A] which include \p or \P and just one other
+ character were causing crashes (broken optimization).
+
+27. Patterns such as (\P{Yi}*\277)* (group with possible zero repeat containing
+ \p or \P) caused a compile-time loop.
+
+28. More problems have arisen in unanchored patterns when CRLF is a valid line
+ break. For example, the unstudied pattern [\r\n]A does not match the string
+ "\r\nA" because change 7.0/46 below moves the current point on by two
+ characters after failing to match at the start. However, the pattern \nA
+ *does* match, because it doesn't start till \n, and if [\r\n]A is studied,
+ the same is true. There doesn't seem any very clean way out of this, but
+ what I have chosen to do makes the common cases work: PCRE now takes note
+ of whether there can be an explicit match for \r or \n anywhere in the
+ pattern, and if so, 7.0/46 no longer applies. As part of this change,
+ there's a new PCRE_INFO_HASCRORLF option for finding out whether a compiled
+ pattern has explicit CR or LF references.
+
+29. Added (*CR) etc for changing newline setting at start of pattern.
+
+
+Version 7.2 19-Jun-07
+---------------------
+
+ 1. If the fr_FR locale cannot be found for test 3, try the "french" locale,
+ which is apparently normally available under Windows.
+
+ 2. Re-jig the pcregrep tests with different newline settings in an attempt
+ to make them independent of the local environment's newline setting.
+
+ 3. Add code to configure.ac to remove -g from the CFLAGS default settings.
+
+ 4. Some of the "internals" tests were previously cut out when the link size
+ was not 2, because the output contained actual offsets. The recent new
+ "Z" feature of pcretest means that these can be cut out, making the tests
+ usable with all link sizes.
+
+ 5. Implemented Stan Switzer's goto replacement for longjmp() when not using
+ stack recursion. This gives a massive performance boost under BSD, but just
+ a small improvement under Linux. However, it saves one field in the frame
+ in all cases.
+
+ 6. Added more features from the forthcoming Perl 5.10:
+
+ (a) (?-n) (where n is a string of digits) is a relative subroutine or
+ recursion call. It refers to the nth most recently opened parentheses.
+
+ (b) (?+n) is also a relative subroutine call; it refers to the nth next
+ to be opened parentheses.
+
+ (c) Conditions that refer to capturing parentheses can be specified
+ relatively, for example, (?(-2)... or (?(+3)...
+
+ (d) \K resets the start of the current match so that everything before
+ is not part of it.
+
+ (e) \k{name} is synonymous with \k<name> and \k'name' (.NET compatible).
+
+ (f) \g{name} is another synonym - part of Perl 5.10's unification of
+ reference syntax.
+
+ (g) (?| introduces a group in which the numbering of parentheses in each
+ alternative starts with the same number.
+
+ (h) \h, \H, \v, and \V match horizontal and vertical whitespace.
+
+ 7. Added two new calls to pcre_fullinfo(): PCRE_INFO_OKPARTIAL and
+ PCRE_INFO_JCHANGED.
+
+ 8. A pattern such as (.*(.)?)* caused pcre_exec() to fail by either not
+ terminating or by crashing. Diagnosed by Viktor Griph; it was in the code
+ for detecting groups that can match an empty string.
+
+ 9. A pattern with a very large number of alternatives (more than several
+ hundred) was running out of internal workspace during the pre-compile
+ phase, where pcre_compile() figures out how much memory will be needed. A
+ bit of new cunning has reduced the workspace needed for groups with
+ alternatives. The 1000-alternative test pattern now uses 12 bytes of
+ workspace instead of running out of the 4096 that are available.
+
+10. Inserted some missing (unsigned int) casts to get rid of compiler warnings.
+
+11. Applied patch from Google to remove an optimization that didn't quite work.
+ The report of the bug said:
+
+ pcrecpp::RE("a*").FullMatch("aaa") matches, while
+ pcrecpp::RE("a*?").FullMatch("aaa") does not, and
+ pcrecpp::RE("a*?\\z").FullMatch("aaa") does again.
+
+12. If \p or \P was used in non-UTF-8 mode on a character greater than 127
+ it matched the wrong number of bytes.
+
+
+Version 7.1 24-Apr-07
+---------------------
+
+ 1. Applied Bob Rossi and Daniel G's patches to convert the build system to one
+ that is more "standard", making use of automake and other Autotools. There
+ is some re-arrangement of the files and adjustment of comments consequent
+ on this.
+
+ 2. Part of the patch fixed a problem with the pcregrep tests. The test of -r
+ for recursive directory scanning broke on some systems because the files
+ are not scanned in any specific order and on different systems the order
+ was different. A call to "sort" has been inserted into RunGrepTest for the
+ approprate test as a short-term fix. In the longer term there may be an
+ alternative.
+
+ 3. I had an email from Eric Raymond about problems translating some of PCRE's
+ man pages to HTML (despite the fact that I distribute HTML pages, some
+ people do their own conversions for various reasons). The problems
+ concerned the use of low-level troff macros .br and .in. I have therefore
+ removed all such uses from the man pages (some were redundant, some could
+ be replaced by .nf/.fi pairs). The 132html script that I use to generate
+ HTML has been updated to handle .nf/.fi and to complain if it encounters
+ .br or .in.
+
+ 4. Updated comments in configure.ac that get placed in config.h.in and also
+ arranged for config.h to be included in the distribution, with the name
+ config.h.generic, for the benefit of those who have to compile without
+ Autotools (compare pcre.h, which is now distributed as pcre.h.generic).
+
+ 5. Updated the support (such as it is) for Virtual Pascal, thanks to Stefan
+ Weber: (1) pcre_internal.h was missing some function renames; (2) updated
+ makevp.bat for the current PCRE, using the additional files
+ makevp_c.txt, makevp_l.txt, and pcregexp.pas.
+
+ 6. A Windows user reported a minor discrepancy with test 2, which turned out
+ to be caused by a trailing space on an input line that had got lost in his
+ copy. The trailing space was an accident, so I've just removed it.
+
+ 7. Add -Wl,-R... flags in pcre-config.in for *BSD* systems, as I'm told
+ that is needed.
+
+ 8. Mark ucp_table (in ucptable.h) and ucp_gentype (in pcre_ucp_searchfuncs.c)
+ as "const" (a) because they are and (b) because it helps the PHP
+ maintainers who have recently made a script to detect big data structures
+ in the php code that should be moved to the .rodata section. I remembered
+ to update Builducptable as well, so it won't revert if ucptable.h is ever
+ re-created.
+
+ 9. Added some extra #ifdef SUPPORT_UTF8 conditionals into pcretest.c,
+ pcre_printint.src, pcre_compile.c, pcre_study.c, and pcre_tables.c, in
+ order to be able to cut out the UTF-8 tables in the latter when UTF-8
+ support is not required. This saves 1.5-2K of code, which is important in
+ some applications.
+
+ Later: more #ifdefs are needed in pcre_ord2utf8.c and pcre_valid_utf8.c
+ so as not to refer to the tables, even though these functions will never be
+ called when UTF-8 support is disabled. Otherwise there are problems with a
+ shared library.
+
+10. Fixed two bugs in the emulated memmove() function in pcre_internal.h:
+
+ (a) It was defining its arguments as char * instead of void *.
+
+ (b) It was assuming that all moves were upwards in memory; this was true
+ a long time ago when I wrote it, but is no longer the case.
+
+ The emulated memove() is provided for those environments that have neither
+ memmove() nor bcopy(). I didn't think anyone used it these days, but that
+ is clearly not the case, as these two bugs were recently reported.
+
+11. The script PrepareRelease is now distributed: it calls 132html, CleanTxt,
+ and Detrail to create the HTML documentation, the .txt form of the man
+ pages, and it removes trailing spaces from listed files. It also creates
+ pcre.h.generic and config.h.generic from pcre.h and config.h. In the latter
+ case, it wraps all the #defines with #ifndefs. This script should be run
+ before "make dist".
+
+12. Fixed two fairly obscure bugs concerned with quantified caseless matching
+ with Unicode property support.
+
+ (a) For a maximizing quantifier, if the two different cases of the
+ character were of different lengths in their UTF-8 codings (there are
+ some cases like this - I found 11), and the matching function had to
+ back up over a mixture of the two cases, it incorrectly assumed they
+ were both the same length.
+
+ (b) When PCRE was configured to use the heap rather than the stack for
+ recursion during matching, it was not correctly preserving the data for
+ the other case of a UTF-8 character when checking ahead for a match
+ while processing a minimizing repeat. If the check also involved
+ matching a wide character, but failed, corruption could cause an
+ erroneous result when trying to check for a repeat of the original
+ character.
+
+13. Some tidying changes to the testing mechanism:
+
+ (a) The RunTest script now detects the internal link size and whether there
+ is UTF-8 and UCP support by running ./pcretest -C instead of relying on
+ values substituted by "configure". (The RunGrepTest script already did
+ this for UTF-8.) The configure.ac script no longer substitutes the
+ relevant variables.
+
+ (b) The debugging options /B and /D in pcretest show the compiled bytecode
+ with length and offset values. This means that the output is different
+ for different internal link sizes. Test 2 is skipped for link sizes
+ other than 2 because of this, bypassing the problem. Unfortunately,
+ there was also a test in test 3 (the locale tests) that used /B and
+ failed for link sizes other than 2. Rather than cut the whole test out,
+ I have added a new /Z option to pcretest that replaces the length and
+ offset values with spaces. This is now used to make test 3 independent
+ of link size. (Test 2 will be tidied up later.)
+
+14. If erroroffset was passed as NULL to pcre_compile, it provoked a
+ segmentation fault instead of returning the appropriate error message.
+
+15. In multiline mode when the newline sequence was set to "any", the pattern
+ ^$ would give a match between the \r and \n of a subject such as "A\r\nB".
+ This doesn't seem right; it now treats the CRLF combination as the line
+ ending, and so does not match in that case. It's only a pattern such as ^$
+ that would hit this one: something like ^ABC$ would have failed after \r
+ and then tried again after \r\n.
+
+16. Changed the comparison command for RunGrepTest from "diff -u" to "diff -ub"
+ in an attempt to make files that differ only in their line terminators
+ compare equal. This works on Linux.
+
+17. Under certain error circumstances pcregrep might try to free random memory
+ as it exited. This is now fixed, thanks to valgrind.
+
+19. In pcretest, if the pattern /(?m)^$/g<any> was matched against the string
+ "abc\r\n\r\n", it found an unwanted second match after the second \r. This
+ was because its rules for how to advance for /g after matching an empty
+ string at the end of a line did not allow for this case. They now check for
+ it specially.
+
+20. pcretest is supposed to handle patterns and data of any length, by
+ extending its buffers when necessary. It was getting this wrong when the
+ buffer for a data line had to be extended.
+
+21. Added PCRE_NEWLINE_ANYCRLF which is like ANY, but matches only CR, LF, or
+ CRLF as a newline sequence.
+
+22. Code for handling Unicode properties in pcre_dfa_exec() wasn't being cut
+ out by #ifdef SUPPORT_UCP. This did no harm, as it could never be used, but
+ I have nevertheless tidied it up.
+
+23. Added some casts to kill warnings from HP-UX ia64 compiler.
+
+24. Added a man page for pcre-config.
+
+
Version 7.0 19-Dec-06
---------------------
diff --git a/ext/pcre/pcrelib/doc/Tech.Notes b/ext/pcre/pcrelib/HACKING
index c75b3e8a5d..1f30d4c487 100644
--- a/ext/pcre/pcrelib/doc/Tech.Notes
+++ b/ext/pcre/pcrelib/HACKING
@@ -109,15 +109,15 @@ variable length. The first byte in an item is an opcode, and the length of the
item is either implicit in the opcode or contained in the data bytes that
follow it.
-In many cases below "two-byte" data values are specified. This is in fact just
-a default when the number is an offset within the compiled pattern. PCRE can be
+In many cases below LINK_SIZE data values are specified for offsets within the
+compiled pattern. The default value for LINK_SIZE is 2, but PCRE can be
compiled to use 3-byte or 4-byte values for these offsets (impairing the
performance). This is necessary only when patterns whose compiled length is
greater than 64K are going to be processed. In this description, we assume the
-"normal" compilation options. "Two-byte" data values that are counts (e.g. for
-quantifiers) are always just two bytes.
+"normal" compilation options. Data values that are counts (e.g. for
+quantifiers) are always just two bytes long.
-A list of all the opcodes follows:
+A list of the opcodes follows:
Opcodes with no following data
------------------------------
@@ -125,17 +125,23 @@ Opcodes with no following data
These items are all just one byte long
OP_END end of pattern
- OP_ANY match any character
+ OP_ANY match any one character other than newline
+ OP_ALLANY match any one character, including newline
OP_ANYBYTE match any single byte, even in UTF-8 mode
OP_SOD match start of data: \A
OP_SOM, start of match (subject + offset): \G
+ OP_SET_SOM, set start of match (\K)
OP_CIRC ^ (start of data, or after \n in multiline)
OP_NOT_WORD_BOUNDARY \W
OP_WORD_BOUNDARY \w
OP_NOT_DIGIT \D
OP_DIGIT \d
+ OP_NOT_HSPACE \H
+ OP_HSPACE \h
OP_NOT_WHITESPACE \S
OP_WHITESPACE \s
+ OP_NOT_VSPACE \V
+ OP_VSPACE \v
OP_NOT_WORDCHAR \W
OP_WORDCHAR \w
OP_EODN match end of data or \n at end: \Z
@@ -144,6 +150,13 @@ These items are all just one byte long
OP_EXTUNI match an extended Unicode character
OP_ANYNL match any Unicode newline sequence
+ OP_ACCEPT )
+ OP_COMMIT )
+ OP_FAIL ) These are Perl 5.10's "backtracking
+ OP_PRUNE ) control verbs".
+ OP_SKIP )
+ OP_THEN )
+
Repeating single characters
---------------------------
@@ -306,9 +319,12 @@ maximally respectively. All three are followed by LINK_SIZE bytes giving (as a
positive number) the offset back to the matching bracket opcode.
If a subpattern is quantified such that it is permitted to match zero times, it
-is preceded by one of OP_BRAZERO or OP_BRAMINZERO. These are single-byte
-opcodes which tell the matcher that skipping this subpattern entirely is a
-valid branch.
+is preceded by one of OP_BRAZERO, OP_BRAMINZERO, or OP_SKIPZERO. These are
+single-byte opcodes that tell the matcher that skipping the following
+subpattern entirely is a valid branch. In the case of the first two, not
+skipping the pattern is also valid (greedy and non-greedy). The third is used
+when a pattern has the quantifier {0,0}. It cannot be entirely discarded,
+because it may be called as a subroutine from elsewhere in the regex.
A subpattern with an indefinite maximum repetition is replicated in the
compiled data its minimum number of times (or once with OP_BRAZERO if the
@@ -399,4 +415,4 @@ at compile time, and so does not cause anything to be put into the compiled
data.
Philip Hazel
-November 2006
+April 2008
diff --git a/ext/pcre/pcrelib/LICENCE b/ext/pcre/pcrelib/LICENCE
index 58241b2bda..03fabc6aef 100644
--- a/ext/pcre/pcrelib/LICENCE
+++ b/ext/pcre/pcrelib/LICENCE
@@ -20,9 +20,9 @@ Email local part: ph10
Email domain: cam.ac.uk
University of Cambridge Computing Service,
-Cambridge, England. Phone: +44 1223 334714.
+Cambridge, England.
-Copyright (c) 1997-2006 University of Cambridge
+Copyright (c) 1997-2008 University of Cambridge
All rights reserved.
@@ -31,7 +31,7 @@ THE C++ WRAPPER FUNCTIONS
Contributed by: Google Inc.
-Copyright (c) 2006, Google Inc.
+Copyright (c) 2007-2008, Google Inc.
All rights reserved.
diff --git a/ext/pcre/pcrelib/NEWS b/ext/pcre/pcrelib/NEWS
index 92768eaa8c..affe6ea99f 100644
--- a/ext/pcre/pcrelib/NEWS
+++ b/ext/pcre/pcrelib/NEWS
@@ -1,7 +1,127 @@
News about PCRE releases
------------------------
-Release 7.0 23-Nov-06
+
+Release 7.7 07-May-08
+---------------------
+
+This is once again mainly a bug-fix release, but there are a couple of new
+features.
+
+
+Release 7.6 28-Jan-08
+---------------------
+
+The main reason for having this release so soon after 7.5 is because it fixes a
+potential buffer overflow problem in pcre_compile() when run in UTF-8 mode. In
+addition, the CMake configuration files have been brought up to date.
+
+
+Release 7.5 10-Jan-08
+---------------------
+
+This is mainly a bug-fix release. However the ability to link pcregrep with
+libz or libbz2 and the ability to link pcretest with libreadline have been
+added. Also the --line-offsets and --file-offsets options were added to
+pcregrep.
+
+
+Release 7.4 21-Sep-07
+---------------------
+
+The only change of specification is the addition of options to control whether
+\R matches any Unicode line ending (the default) or just CR, LF, and CRLF.
+Otherwise, the changes are bug fixes and a refactoring to reduce the number of
+relocations needed in a shared library. There have also been some documentation
+updates, in particular, some more information about using CMake to build PCRE
+has been added to the NON-UNIX-USE file.
+
+
+Release 7.3 28-Aug-07
+---------------------
+
+Most changes are bug fixes. Some that are not:
+
+1. There is some support for Perl 5.10's experimental "backtracking control
+ verbs" such as (*PRUNE).
+
+2. UTF-8 checking is now as per RFC 3629 instead of RFC 2279; this is more
+ restrictive in the strings it accepts.
+
+3. Checking for potential integer overflow has been made more dynamic, and as a
+ consequence there is no longer a hard limit on the size of a subpattern that
+ has a limited repeat count.
+
+4. When CRLF is a valid line-ending sequence, pcre_exec() and pcre_dfa_exec()
+ no longer advance by two characters instead of one when an unanchored match
+ fails at CRLF if there are explicit CR or LF matches within the pattern.
+ This gets rid of some anomalous effects that previously occurred.
+
+5. Some PCRE-specific settings for varying the newline options at the start of
+ a pattern have been added.
+
+
+Release 7.2 19-Jun-07
+---------------------
+
+WARNING: saved patterns that were compiled by earlier versions of PCRE must be
+recompiled for use with 7.2 (necessitated by the addition of \K, \h, \H, \v,
+and \V).
+
+Correction to the notes for 7.1: the note about shared libraries for Windows is
+wrong. Previously, three libraries were built, but each could function
+independently. For example, the pcreposix library also included all the
+functions from the basic pcre library. The change is that the three libraries
+are no longer independent. They are like the Unix libraries. To use the
+pcreposix functions, for example, you need to link with both the pcreposix and
+the basic pcre library.
+
+Some more features from Perl 5.10 have been added:
+
+ (?-n) and (?+n) relative references for recursion and subroutines.
+
+ (?(-n) and (?(+n) relative references as conditions.
+
+ \k{name} and \g{name} are synonyms for \k<name>.
+
+ \K to reset the start of the matched string; for example, (foo)\Kbar
+ matches bar preceded by foo, but only sets bar as the matched string.
+
+ (?| introduces a group where the capturing parentheses in each alternative
+ start from the same number; for example, (?|(abc)|(xyz)) sets capturing
+ parentheses number 1 in both cases.
+
+ \h, \H, \v, \V match horizontal and vertical whitespace, respectively.
+
+
+Release 7.1 24-Apr-07
+---------------------
+
+There is only one new feature in this release: a linebreak setting of
+PCRE_NEWLINE_ANYCRLF. It is a cut-down version of PCRE_NEWLINE_ANY, which
+recognizes only CRLF, CR, and LF as linebreaks.
+
+A few bugs are fixed (see ChangeLog for details), but the major change is a
+complete re-implementation of the build system. This now has full Autotools
+support and so is now "standard" in some sense. It should help with compiling
+PCRE in a wide variety of environments.
+
+NOTE: when building shared libraries for Windows, three dlls are now built,
+called libpcre, libpcreposix, and libpcrecpp. Previously, everything was
+included in a single dll.
+
+Another important change is that the dftables auxiliary program is no longer
+compiled and run at "make" time by default. Instead, a default set of character
+tables (assuming ASCII coding) is used. If you want to use dftables to generate
+the character tables as previously, add --enable-rebuild-chartables to the
+"configure" command. You must do this if you are compiling PCRE to run on a
+system that uses EBCDIC code.
+
+There is a discussion about character tables in the README file. The default is
+not to use dftables so that that there is no problem when cross-compiling.
+
+
+Release 7.0 19-Dec-06
---------------------
This release has a new major number because there have been some internal
diff --git a/ext/pcre/pcrelib/NON-UNIX-USE b/ext/pcre/pcrelib/NON-UNIX-USE
index bcc0dc9af2..e6726faaad 100644
--- a/ext/pcre/pcrelib/NON-UNIX-USE
+++ b/ext/pcre/pcrelib/NON-UNIX-USE
@@ -1,128 +1,156 @@
Compiling PCRE on non-Unix systems
----------------------------------
-See below for comments on Cygwin or MinGW and OpenVMS usage. I (Philip Hazel)
-have no knowledge of Windows or VMS sytems and how their libraries work. The
-items in the PCRE Makefile that relate to anything other than Unix-like systems
-have been contributed by PCRE users. There are some other comments and files in
-the Contrib directory on the ftp site that you may find useful. See
+This document contains the following sections:
+
+ General
+ Generic instructions for the PCRE C library
+ The C++ wrapper functions
+ Building for virtual Pascal
+ Stack size in Windows environments
+ Linking programs in Windows environments
+ Comments about Win32 builds
+ Building PCRE on Windows with CMake
+ Use of relative paths with CMake on Windows
+ Testing with runtest.bat
+ Building under Windows with BCC5.5
+ Building PCRE on OpenVMS
+
+
+GENERAL
+
+I (Philip Hazel) have no experience of Windows or VMS sytems and how their
+libraries work. The items in the PCRE distribution and Makefile that relate to
+anything other than Unix-like systems are untested by me.
+
+There are some other comments and files in the Contrib directory on the ftp
+site that you may find useful. See
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib
-If you want to compile PCRE for a non-Unix system (or perhaps, more strictly,
-for a system that does not support "configure" and "make" files), note that
-the basic PCRE library consists entirely of code written in Standard C, and so
-should compile successfully on any system that has a Standard C compiler and
-library. The C++ wrapper functions are a separate issue (see below).
-
-
-GENERIC INSTRUCTIONS FOR THE C LIBRARY
-
-The following are generic comments about building PCRE. The interspersed
-indented commands are suggestions from Mark Tetrode as to which commands you
-might use on a Windows system to build a static library.
-
-(1) Copy or rename the file config.h.in as config.h, and change the macros that
-define HAVE_STRERROR and HAVE_MEMMOVE to define them as 1 rather than 0.
-Unfortunately, because of the way Unix autoconf works, the default setting has
-to be 0. You may also want to make changes to other macros in config.h. In
-particular, if you want to force a specific value for newline, you can define
-the NEWLINE macro. The default is to use '\n', thereby using whatever value
-your compiler gives to '\n'.
-
- rem Mark Tetrode's commands
- copy config.h.in config.h
- rem Use write, because notepad cannot handle UNIX files. Change values.
- write config.h
-
-(2) Compile dftables.c as a stand-alone program, and then run it with
-the single argument "pcre_chartables.c". This generates a set of standard
-character tables and writes them to that file.
-
- rem Mark Tetrode's commands
- rem Compile & run
- cl -DSUPPORT_UTF8 -DSUPPORT_UCP dftables.c
- dftables.exe pcre_chartables.c
-
-(3) Compile the following source files:
-
- pcre_chartables.c
- pcre_compile.c
- pcre_config.c
- pcre_dfa_exec.c
- pcre_exec.c
- pcre_fullinfo.c
- pcre_get.c
- pcre_globals.c
- pcre_info.c
- pcre_maketables.c
- pcre_newline.c
- pcre_ord2utf8.c
- pcre_refcount.c
- pcre_study.c
- pcre_tables.c
- pcre_try_flipped.c
- pcre_ucp_searchfuncs.c
- pcre_valid_utf8.c
- pcre_version.c
- pcre_xclass.c
-
-and link them all together into an object library in whichever form your system
-keeps such libraries. This is the pcre C library. If your system has static and
-shared libraries, you may have to do this once for each type.
-
- rem These comments are out-of-date, referring to a previous release which
- rem had fewer source files. Replace with the file names from above.
- rem Mark Tetrode's commands, for a static library
- rem Compile & lib
- cl -DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 /c maketables.c get.c study.c pcre.c
- lib /OUT:pcre.lib maketables.obj get.obj study.obj pcre.obj
-
-(4) Similarly, compile pcreposix.c and link it (on its own) as the pcreposix
-library.
-
- rem Mark Tetrode's commands, for a static library
- rem Compile & lib
- cl -DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 /c pcreposix.c
- lib /OUT:pcreposix.lib pcreposix.obj
-
-(5) Compile the test program pcretest.c. This needs the functions in the
-pcre and pcreposix libraries when linking.
-
- rem Mark Tetrode's commands
- rem compile & link
- cl /F0x400000 pcretest.c pcre.lib pcreposix.lib
-
-(6) Run pcretest on the testinput files in the testdata directory, and check
-that the output matches the corresponding testoutput files. Note that the
-supplied files are in Unix format, with just LF characters as line terminators.
-You may need to edit them to change this if your system uses a different
-convention.
-
- rem Mark Tetrode's commands
- pcretest testdata\testinput1 testdata\myoutput1
- windiff testdata\testoutput1 testdata\myoutput1
- pcretest -i testdata\testinput2 testdata\myoutput2
- windiff testdata\testoutput2 testdata\myoutput2
- pcretest testdata\testinput3 testdata\myoutput3
- windiff testdata\testoutput3 testdata\myoutput3
- pcretest testdata\testinput4 testdata\myoutput4
- windiff testdata\testoutput4 testdata\myoutput4
- pcretest testdata\testinput5 testdata\myoutput5
- windiff testdata\testoutput5 testdata\myoutput5
- pcretest testdata\testinput6 testdata\myoutput6
- windiff testdata\testoutput6 testdata\myoutput6
-
-Note that there are now three more tests (7, 8, 9) that did not exist when Mark
-wrote those comments. The test the new pcre_dfa_exec() function.
-
-(7) If you want to use the pcregrep command, compile and link pcregrep.c; it
-uses only the basic PCRE library.
+If you want to compile PCRE for a non-Unix system (especially for a system that
+does not support "configure" and "make" files), note that the basic PCRE
+library consists entirely of code written in Standard C, and so should compile
+successfully on any system that has a Standard C compiler and library. The C++
+wrapper functions are a separate issue (see below).
+
+The PCRE distribution includes a "configure" file for use by the Configure/Make
+build system, as found in many Unix-like environments. There is also support
+support for CMake, which some users prefer, in particular in Windows
+environments. There are some instructions for CMake under Windows in the
+section entitled "Building PCRE with CMake" below. CMake can also be used to
+build PCRE in Unix-like systems.
+
+
+GENERIC INSTRUCTIONS FOR THE PCRE C LIBRARY
+
+The following are generic comments about building the PCRE C library "by hand".
+
+ (1) Copy or rename the file config.h.generic as config.h, and edit the macro
+ settings that it contains to whatever is appropriate for your environment.
+ In particular, if you want to force a specific value for newline, you can
+ define the NEWLINE macro. When you compile any of the PCRE modules, you
+ must specify -DHAVE_CONFIG_H to your compiler so that config.h is included
+ in the sources.
+
+ An alternative approach is not to edit config.h, but to use -D on the
+ compiler command line to make any changes that you need to the
+ configuration options. In this case -DHAVE_CONFIG_H must not be set.
+
+ NOTE: There have been occasions when the way in which certain parameters
+ in config.h are used has changed between releases. (In the configure/make
+ world, this is handled automatically.) When upgrading to a new release,
+ you are strongly advised to review config.h.generic before re-using what
+ you had previously.
+
+ (2) Copy or rename the file pcre.h.generic as pcre.h.
+
+ (3) EITHER:
+ Copy or rename file pcre_chartables.c.dist as pcre_chartables.c.
+
+ OR:
+ Compile dftables.c as a stand-alone program (using -DHAVE_CONFIG_H if
+ you have set up config.h), and then run it with the single argument
+ "pcre_chartables.c". This generates a set of standard character tables
+ and writes them to that file. The tables are generated using the default
+ C locale for your system. If you want to use a locale that is specified
+ by LC_xxx environment variables, add the -L option to the dftables
+ command. You must use this method if you are building on a system that
+ uses EBCDIC code.
+
+ The tables in pcre_chartables.c are defaults. The caller of PCRE can
+ specify alternative tables at run time.
+
+ (4) Ensure that you have the following header files:
+
+ pcre_internal.h
+ ucp.h
+ ucpinternal.h
+ ucptable.h
+
+ (5) Also ensure that you have the following file, which is #included as source
+ when building a debugging version of PCRE, and is also used by pcretest.
+
+ pcre_printint.src
+
+ (6) Compile the following source files, setting -DHAVE_CONFIG_H as a compiler
+ option if you have set up config.h with your configuration, or else use
+ other -D settings to change the configuration as required.
+
+ pcre_chartables.c
+ pcre_compile.c
+ pcre_config.c
+ pcre_dfa_exec.c
+ pcre_exec.c
+ pcre_fullinfo.c
+ pcre_get.c
+ pcre_globals.c
+ pcre_info.c
+ pcre_maketables.c
+ pcre_newline.c
+ pcre_ord2utf8.c
+ pcre_refcount.c
+ pcre_study.c
+ pcre_tables.c
+ pcre_try_flipped.c
+ pcre_ucp_searchfuncs.c
+ pcre_valid_utf8.c
+ pcre_version.c
+ pcre_xclass.c
+
+ Make sure that you include -I. in the compiler command (or equivalent for
+ an unusual compiler) so that all included PCRE header files are first
+ sought in the current directory. Otherwise you run the risk of picking up
+ a previously-installed file from somewhere else.
+
+ (7) Now link all the compiled code into an object library in whichever form
+ your system keeps such libraries. This is the basic PCRE C library. If
+ your system has static and shared libraries, you may have to do this once
+ for each type.
+
+ (8) Similarly, compile pcreposix.c (remembering -DHAVE_CONFIG_H if necessary)
+ and link the result (on its own) as the pcreposix library.
+
+ (9) Compile the test program pcretest.c (again, don't forget -DHAVE_CONFIG_H).
+ This needs the functions in the pcre and pcreposix libraries when linking.
+ It also needs the pcre_printint.src source file, which it #includes.
+
+(10) Run pcretest on the testinput files in the testdata directory, and check
+ that the output matches the corresponding testoutput files. Note that the
+ supplied files are in Unix format, with just LF characters as line
+ terminators. You may need to edit them to change this if your system uses
+ a different convention. If you are using Windows, you probably should use
+ the wintestinput3 file instead of testinput3 (and the corresponding output
+ file). This is a locale test; wintestinput3 sets the locale to "french"
+ rather than "fr_FR", and there some minor output differences.
+
+(11) If you want to use the pcregrep command, compile and link pcregrep.c; it
+ uses only the basic PCRE library (it does not need the pcreposix library).
THE C++ WRAPPER FUNCTIONS
-The PCRE distribution now contains some C++ wrapper functions and tests,
+The PCRE distribution also contains some C++ wrapper functions and tests,
contributed by Google Inc. On a system that can use "configure" and "make",
the functions are automatically built into a library called pcrecpp. It should
be straightforward to compile the .cc files manually on other systems. The
@@ -130,88 +158,210 @@ files called xxx_unittest.cc are test programs for each of the corresponding
xxx.cc files.
-FURTHER REMARKS
+BUILDING FOR VIRTUAL PASCAL
-If you have a system without "configure" but where you can use a Makefile, edit
-Makefile.in to create Makefile, substituting suitable values for the variables
-at the head of the file.
+A script for building PCRE using Borland's C++ compiler for use with VPASCAL
+was contributed by Alexander Tokarev. Stefan Weber updated the script and added
+additional files. The following files in the distribution are for building PCRE
+for use with VP/Borland: makevp_c.txt, makevp_l.txt, makevp.bat, pcregexp.pas.
-Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
- Some of the core BCC libraries have a version of PCRE from 1998 built in,
- which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
- version mismatch. I'm including an easy workaround below, if you'd like to
- include it in the non-unix instructions:
+STACK SIZE IN WINDOWS ENVIRONMENTS
- When linking a project with BCC5.5, pcre.lib must be included before any of
- the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
- line.
+The default processor stack size of 1Mb in some Windows environments is too
+small for matching patterns that need much recursion. In particular, test 2 may
+fail because of this. Normally, running out of stack causes a crash, but there
+have been cases where the test program has just died silently. See your linker
+documentation for how to increase stack size if you experience problems. The
+Linux default of 8Mb is a reasonable choice for the stack, though even that can
+be too small for some pattern/subject combinations.
-Some help in building a Win32 DLL of PCRE in GnuWin32 environments was
-contributed by Paul Sokolovsky. These environments are Mingw32
-(http://www.xraylith.wisc.edu/~khan/software/gnu-win32/) and CygWin
-(http://sourceware.cygnus.com/cygwin/). Paul comments:
+PCRE has a compile configuration option to disable the use of stack for
+recursion so that heap is used instead. However, pattern matching is
+significantly slower when this is done. There is more about stack usage in the
+"pcrestack" documentation.
- For CygWin, set CFLAGS=-mno-cygwin, and do 'make dll'. You'll get
- pcre.dll (containing pcreposix also), libpcre.dll.a, and dynamically
- linked pgrep and pcretest. If you have /bin/sh, run RunTest (three
- main test go ok, locale not supported).
-Changes to do MinGW with autoconf 2.50 were supplied by Fred Cox
-<sailorFred@yahoo.com>, who comments as follows:
+LINKING PROGRAMS IN WINDOWS ENVIRONMENTS
- If you are using the PCRE DLL, the normal Unix style configure && make &&
- make check && make install should just work[*]. If you want to statically
- link against the .a file, you must define PCRE_STATIC before including
- pcre.h, otherwise the pcre_malloc and pcre_free exported functions will be
- declared __declspec(dllimport), with hilarious results. See the configure.in
- and pcretest.c for how it is done for the static test.
+If you want to statically link a program against a PCRE library in the form of
+a non-dll .a file, you must define PCRE_STATIC before including pcre.h,
+otherwise the pcre_malloc() and pcre_free() exported functions will be declared
+__declspec(dllimport), with unwanted results.
- Also, there will only be a libpcre.la, not a libpcreposix.la, as you
- would expect from the Unix version. The single DLL includes the pcreposix
- interface.
-[*] But note that the supplied test files are in Unix format, with just LF
-characters as line terminators. You will have to edit them to change to CR LF
-terminators.
+COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE WITH CMAKE" below)
-A script for building PCRE using Borland's C++ compiler for use with VPASCAL
-was contributed by Alexander Tokarev. It is called makevp.bat.
+There are two ways of building PCRE using the "configure, make, make install"
+paradigm on Windows systems: using MinGW or using Cygwin. These are not at all
+the same thing; they are completely different from each other. There is also
+support for building using CMake, which some users find a more straightforward
+way of building PCRE under Windows. However, the tests are not run
+automatically when CMake is used.
-These are some further comments about Win32 builds from Mark Evans. They
-were contributed before Fred Cox's changes were made, so it is possible that
-they may no longer be relevant.
+The MinGW home page (http://www.mingw.org/) says this:
-"The documentation for Win32 builds is a bit shy. Under MSVC6 I
-followed their instructions to the letter, but there were still
-some things missing.
+ MinGW: A collection of freely available and freely distributable Windows
+ specific header files and import libraries combined with GNU toolsets that
+ allow one to produce native Windows programs that do not rely on any
+ 3rd-party C runtime DLLs.
-(1) Must #define STATIC for entire project if linking statically.
- (I see no reason to use DLLs for code this compact.) This of
- course is a project setting in MSVC under Preprocessor.
+The Cygwin home page (http://www.cygwin.com/) says this:
-(2) Missing some #ifdefs relating to the function pointers
- pcre_malloc and pcre_free. See my solution below. (The stubs
- may not be mandatory but they made me feel better.)"
+ Cygwin is a Linux-like environment for Windows. It consists of two parts:
-=========================
-#ifdef _WIN32
-#include <malloc.h>
+ . A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing
+ substantial Linux API functionality
-void* malloc_stub(size_t N)
-{ return malloc(N); }
-void free_stub(void* p)
-{ free(p); }
-void *(*pcre_malloc)(size_t) = &malloc_stub;
-void (*pcre_free)(void *) = &free_stub;
+ . A collection of tools which provide Linux look and feel.
-#else
+ The Cygwin DLL currently works with all recent, commercially released x86 32
+ bit and 64 bit versions of Windows, with the exception of Windows CE.
-void *(*pcre_malloc)(size_t) = malloc;
-void (*pcre_free)(void *) = free;
+On both MinGW and Cygwin, PCRE should build correctly using:
-#endif
-=========================
+ ./configure && make && make install
+
+This should create two libraries called libpcre and libpcreposix, and, if you
+have enabled building the C++ wrapper, a third one called libpcrecpp. These are
+independent libraries: when you like with libpcreposix or libpcrecpp you must
+also link with libpcre, which contains the basic functions. (Some earlier
+releases of PCRE included the basic libpcre functions in libpcreposix. This no
+longer happens.)
+
+A user submitted a special-purpose patch that makes it easy to create
+"pcre.dll" under mingw32 using the "msys" environment. It provides "pcre.dll"
+as a special target. If you use this target, no other files are built, and in
+particular, the pcretest and pcregrep programs are not built. An example of how
+this might be used is:
+
+ ./configure --enable-utf --disable-cpp CFLAGS="-03 -s"; make pcre.dll
+
+Using Cygwin's compiler generates libraries and executables that depend on
+cygwin1.dll. If a library that is generated this way is distributed,
+cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL
+licence, this forces not only PCRE to be under the GPL, but also the entire
+application. A distributor who wants to keep their own code proprietary must
+purchase an appropriate Cygwin licence.
+
+MinGW has no such restrictions. The MinGW compiler generates a library or
+executable that can run standalone on Windows without any third party dll or
+licensing issues.
+
+But there is more complication:
+
+If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is
+to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a
+front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's
+gcc and MinGW's gcc). So, a user can:
+
+. Build native binaries by using MinGW or by getting Cygwin and using
+ -mno-cygwin.
+
+. Build binaries that depend on cygwin1.dll by using Cygwin with the normal
+ compiler flags.
+
+The test files that are supplied with PCRE are in Unix format, with LF
+characters as line terminators. It may be necessary to change the line
+terminators in order to get some of the tests to work. We hope to improve
+things in this area in future.
+
+
+BUILDING PCRE ON WINDOWS WITH CMAKE
+
+CMake is an alternative build facility that can be used instead of the
+traditional Unix "configure". CMake version 2.4.7 supports Borland makefiles,
+MinGW makefiles, MSYS makefiles, NMake makefiles, UNIX makefiles, Visual Studio
+6, Visual Studio 7, Visual Studio 8, and Watcom W8. The following instructions
+were contributed by a PCRE user.
+
+1. Download CMake 2.4.7 or above from http://www.cmake.org/, install and ensure
+ that cmake\bin is on your path.
+
+2. Unzip (retaining folder structure) the PCRE source tree into a source
+ directory such as C:\pcre.
+
+3. Create a new, empty build directory: C:\pcre\build\
+
+4. Run CMakeSetup from the Shell envirornment of your build tool, e.g., Msys
+ for Msys/MinGW or Visual Studio Command Prompt for VC/VC++
+
+5. Enter C:\pcre\pcre-xx and C:\pcre\build for the source and build
+ directories, respectively
+
+6. Hit the "Configure" button.
+
+7. Select the particular IDE / build tool that you are using (Visual Studio,
+ MSYS makefiles, MinGW makefiles, etc.)
+
+8. The GUI will then list several configuration options. This is where you can
+ enable UTF-8 support, etc.
+
+9. Hit "Configure" again. The adjacent "OK" button should now be active.
+
+10. Hit "OK".
+
+11. The build directory should now contain a usable build system, be it a
+ solution file for Visual Studio, makefiles for MinGW, etc.
+
+
+USE OF RELATIVE PATHS WITH CMAKE ON WINDOWS
+
+A PCRE user comments as follows:
+
+I thought that others may want to know the current state of
+CMAKE_USE_RELATIVE_PATHS support on Windows.
+
+Here it is:
+-- AdditionalIncludeDirectories is only partially modified (only the
+first path - see below)
+-- Only some of the contained file paths are modified - shown below for
+pcre.vcproj
+-- It properly modifies
+
+I am sure CMake people can fix that if they want to. Until then one will
+need to replace existing absolute paths in project files with relative
+paths manually (e.g. from VS) - relative to project file location. I did
+just that before being told to try CMAKE_USE_RELATIVE_PATHS. Not a big
+deal.
+
+AdditionalIncludeDirectories="E:\builds\pcre\build;E:\builds\pcre\pcre-7.5;"
+AdditionalIncludeDirectories=".;E:\builds\pcre\pcre-7.5;"
+
+RelativePath="pcre.h">
+RelativePath="pcre_chartables.c">
+RelativePath="pcre_chartables.c.rule">
+
+
+TESTING WITH RUNTEST.BAT
+
+1. Copy RunTest.bat into the directory where pcretest.exe has been created.
+
+2. Edit RunTest.bat and insert a line that indentifies the relative location of
+ the pcre source, e.g.:
+
+ set srcdir=..\pcre-7.4-RC3
+
+3. Run RunTest.bat from a command shell environment. Test outputs will
+ automatically be compared to expected results, and discrepancies will
+ identified in the console output.
+
+4. To test pcrecpp, run pcrecpp_unittest.exe, pcre_stringpiece_unittest.exe and
+ pcre_scanner_unittest.exe.
+
+
+BUILDING UNDER WINDOWS WITH BCC5.5
+
+Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
+
+ Some of the core BCC libraries have a version of PCRE from 1998 built in,
+ which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
+ version mismatch. I'm including an easy workaround below, if you'd like to
+ include it in the non-unix instructions:
+
+ When linking a project with BCC5.5, pcre.lib must be included before any of
+ the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
+ line.
BUILDING PCRE ON OPENVMS
@@ -278,4 +428,5 @@ $! Locale could not be set to fr
$!
=========================
+Last Updated: 25 January 2008
****
diff --git a/ext/pcre/pcrelib/README b/ext/pcre/pcrelib/README
index 55e8fd0940..8b48940ace 100644
--- a/ext/pcre/pcrelib/README
+++ b/ext/pcre/pcrelib/README
@@ -5,51 +5,82 @@ The latest release of PCRE is always available from
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-xxx.tar.gz
+There is a mailing list for discussion about the development of PCRE at
+
+ pcre-dev@exim.org
+
Please read the NEWS file if you are upgrading from a previous release.
+The contents of this README file are:
+
+ The PCRE APIs
+ Documentation for PCRE
+ Contributions by users of PCRE
+ Building PCRE on non-Unix systems
+ Building PCRE on Unix-like systems
+ Retrieving configuration information on Unix-like systems
+ Shared libraries on Unix-like systems
+ Cross-compiling on Unix-like systems
+ Using HP's ANSI C++ compiler (aCC)
+ Making new tarballs
+ Testing PCRE
+ Character tables
+ File manifest
The PCRE APIs
-------------
-PCRE is written in C, and it has its own API. The distribution now includes a
-set of C++ wrapper functions, courtesy of Google Inc. (see the pcrecpp man page
-for details).
+PCRE is written in C, and it has its own API. The distribution also includes a
+set of C++ wrapper functions (see the pcrecpp man page for details), courtesy
+of Google Inc.
+
+In addition, there is a set of C wrapper functions that are based on the POSIX
+regular expression API (see the pcreposix man page). These end up in the
+library called libpcreposix. Note that this just provides a POSIX calling
+interface to PCRE; the regular expressions themselves still follow Perl syntax
+and semantics. The POSIX API is restricted, and does not give full access to
+all of PCRE's facilities.
-Also included are a set of C wrapper functions that are based on the POSIX
-API. These end up in the library called libpcreposix. Note that this just
-provides a POSIX calling interface to PCRE: the regular expressions themselves
-still follow Perl syntax and semantics. The header file for the POSIX-style
-functions is called pcreposix.h. The official POSIX name is regex.h, but I
-didn't want to risk possible problems with existing files of that name by
-distributing it that way. To use it with an existing program that uses the
-POSIX API, it will have to be renamed or pointed at by a link.
+The header file for the POSIX-style functions is called pcreposix.h. The
+official POSIX name is regex.h, but I did not want to risk possible problems
+with existing files of that name by distributing it that way. To use PCRE with
+an existing program that uses the POSIX API, pcreposix.h will have to be
+renamed or pointed at by a link.
If you are using the POSIX interface to PCRE and there is already a POSIX regex
-library installed on your system, you must take care when linking programs to
+library installed on your system, as well as worrying about the regex.h header
+file (as mentioned above), you must also take care when linking programs to
ensure that they link with PCRE's libpcreposix library. Otherwise they may pick
-up the "real" POSIX functions of the same name.
+up the POSIX functions of the same name from the other library.
+
+One way of avoiding this confusion is to compile PCRE with the addition of
+-Dregcomp=PCREregcomp (and similarly for the other POSIX functions) to the
+compiler flags (CFLAGS if you are using "configure" -- see below). This has the
+effect of renaming the functions so that the names no longer clash. Of course,
+you have to do the same thing for your applications, or write them using the
+new names.
Documentation for PCRE
----------------------
-If you install PCRE in the normal way, you will end up with an installed set of
-man pages whose names all start with "pcre". The one that is just called "pcre"
-lists all the others. In addition to these man pages, the PCRE documentation is
-supplied in two other forms; however, as there is no standard place to install
-them, they are left in the doc directory of the unpacked source distribution.
-These forms are:
+If you install PCRE in the normal way on a Unix-like system, you will end up
+with a set of man pages whose names all start with "pcre". The one that is just
+called "pcre" lists all the others. In addition to these man pages, the PCRE
+documentation is supplied in two other forms:
- 1. Files called doc/pcre.txt, doc/pcregrep.txt, and doc/pcretest.txt. The
- first of these is a concatenation of the text forms of all the section 3
- man pages except those that summarize individual functions. The other two
- are the text forms of the section 1 man pages for the pcregrep and
- pcretest commands. Text forms are provided for ease of scanning with text
- editors or similar tools.
+ 1. There are files called doc/pcre.txt, doc/pcregrep.txt, and
+ doc/pcretest.txt in the source distribution. The first of these is a
+ concatenation of the text forms of all the section 3 man pages except
+ those that summarize individual functions. The other two are the text
+ forms of the section 1 man pages for the pcregrep and pcretest commands.
+ These text forms are provided for ease of scanning with text editors or
+ similar tools. They are installed in <prefix>/share/doc/pcre, where
+ <prefix> is the installation prefix (defaulting to /usr/local).
- 2. A subdirectory called doc/html contains all the documentation in HTML
- form, hyperlinked in various ways, and rooted in a file called
- doc/index.html.
+ 2. A set of files containing all the documentation in HTML form, hyperlinked
+ in various ways, and rooted in a file called index.html, is distributed in
+ doc/html and installed in <prefix>/share/doc/pcre/html.
Contributions by users of PCRE
@@ -59,27 +90,48 @@ You can find contributions from PCRE users in the directory
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib
-where there is also a README file giving brief descriptions of what they are.
-Several of them provide support for compiling PCRE on various flavours of
-Windows systems (I myself do not use Windows). Some are complete in themselves;
-others are pointers to URLs containing relevant files.
+There is a README file giving brief descriptions of what they are. Some are
+complete in themselves; others are pointers to URLs containing relevant files.
+Some of this material is likely to be well out-of-date. Several of the earlier
+contributions provided support for compiling PCRE on various flavours of
+Windows (I myself do not use Windows). Nowadays there is more Windows support
+in the standard distribution, so these contibutions have been archived.
+
+Building PCRE on non-Unix systems
+---------------------------------
-Building PCRE on a Unix-like system
------------------------------------
+For a non-Unix system, please read the comments in the file NON-UNIX-USE,
+though if your system supports the use of "configure" and "make" you may be
+able to build PCRE in the same way as for Unix-like systems. PCRE can also be
+configured in many platform environments using the GUI facility of CMake's
+CMakeSetup. It creates Makefiles, solution files, etc.
+
+PCRE has been compiled on many different operating systems. It should be
+straightforward to build PCRE on any system that has a Standard C compiler and
+library, because it uses only Standard C functions.
+
+
+Building PCRE on Unix-like systems
+----------------------------------
If you are using HP's ANSI C++ compiler (aCC), please see the special note
in the section entitled "Using HP's ANSI C++ compiler (aCC)" below.
+The following instructions assume the use of the widely used "configure, make,
+make install" process. There is also support for CMake in the PCRE
+distribution; there are some comments about using CMake in the NON-UNIX-USE
+file, though it can also be used in Unix-like systems.
+
To build PCRE on a Unix-like system, first run the "configure" command from the
PCRE distribution directory, with your current directory set to the directory
where you want the files to be created. This command is a standard GNU
"autoconf" configuration script, for which generic instructions are supplied in
-INSTALL.
+the file INSTALL.
Most commonly, people build PCRE within its own distribution directory, and in
-this case, on many systems, just running "./configure" is sufficient, but the
-usual methods of changing standard defaults are available. For example:
+this case, on many systems, just running "./configure" is sufficient. However,
+the usual methods of changing standard defaults are available. For example:
CFLAGS='-O2 -Wall' ./configure --prefix=/opt/local
@@ -103,8 +155,8 @@ library. You can read more about them in the pcrebuild man page.
. If you want to suppress the building of the C++ wrapper library, you can add
--disable-cpp to the "configure" command. Otherwise, when "configure" is run,
- will try to find a C++ compiler and C++ header files, and if it succeeds, it
- will try to build the C++ wrapper.
+ it will try to find a C++ compiler and C++ header files, and if it succeeds,
+ it will try to build the C++ wrapper.
. If you want to make use of the support for UTF-8 character strings in PCRE,
you must add --enable-utf8 to the "configure" command. Without it, the code
@@ -119,16 +171,30 @@ library. You can read more about them in the pcrebuild man page.
supported.
. You can build PCRE to recognize either CR or LF or the sequence CRLF or any
- of the Unicode newline sequences as indicating the end of a line. Whatever
- you specify at build time is the default; the caller of PCRE can change the
- selection at run time. The default newline indicator is a single LF character
- (the Unix standard). You can specify the default newline indicator by adding
- --newline-is-cr or --newline-is-lf or --newline-is-crlf or --newline-is-any
- to the "configure" command, respectively.
+ of the preceding, or any of the Unicode newline sequences as indicating the
+ end of a line. Whatever you specify at build time is the default; the caller
+ of PCRE can change the selection at run time. The default newline indicator
+ is a single LF character (the Unix standard). You can specify the default
+ newline indicator by adding --enable-newline-is-cr or --enable-newline-is-lf
+ or --enable-newline-is-crlf or --enable-newline-is-anycrlf or
+ --enable-newline-is-any to the "configure" command, respectively.
+
+ If you specify --enable-newline-is-cr or --enable-newline-is-crlf, some of
+ the standard tests will fail, because the lines in the test files end with
+ LF. Even if the files are edited to change the line endings, there are likely
+ to be some failures. With --enable-newline-is-anycrlf or
+ --enable-newline-is-any, many tests should succeed, but there may be some
+ failures.
+
+. By default, the sequence \R in a pattern matches any Unicode line ending
+ sequence. This is independent of the option specifying what PCRE considers to
+ be the end of a line (see above). However, the caller of PCRE can restrict \R
+ to match only CR, LF, or CRLF. You can make this the default by adding
+ --enable-bsr-anycrlf to the "configure" command (bsr = "backslash R").
. When called via the POSIX interface, PCRE uses malloc() to get additional
storage for processing capturing parentheses if there are more than 10 of
- them. You can increase this threshold by setting, for example,
+ them in a pattern. You can increase this threshold by setting, for example,
--with-posix-malloc-threshold=20
@@ -141,8 +207,8 @@ library. You can read more about them in the pcrebuild man page.
--with-match-limit=500000
on the "configure" command. This is just the default; individual calls to
- pcre_exec() can supply their own value. There is discussion on the pcreapi
- man page.
+ pcre_exec() can supply their own value. There is more discussion on the
+ pcreapi man page.
. There is a separate counter that limits the depth of recursive function calls
during a matching process. This also has a default of ten million, which is
@@ -157,37 +223,88 @@ library. You can read more about them in the pcrebuild man page.
. The default maximum compiled pattern size is around 64K. You can increase
this by adding --with-link-size=3 to the "configure" command. You can
increase it even more by setting --with-link-size=4, but this is unlikely
- ever to be necessary. If you build PCRE with an increased link size, test 2
- (and 5 if you are using UTF-8) will fail. Part of the output of these tests
- is a representation of the compiled pattern, and this changes with the link
- size.
+ ever to be necessary. Increasing the internal link size will reduce
+ performance.
. You can build PCRE so that its internal match() function that is called from
- pcre_exec() does not call itself recursively. Instead, it uses blocks of data
- from the heap via special functions pcre_stack_malloc() and pcre_stack_free()
- to save data that would otherwise be saved on the stack. To build PCRE like
- this, use
+ pcre_exec() does not call itself recursively. Instead, it uses memory blocks
+ obtained from the heap via the special functions pcre_stack_malloc() and
+ pcre_stack_free() to save data that would otherwise be saved on the stack. To
+ build PCRE like this, use
--disable-stack-for-recursion
on the "configure" command. PCRE runs more slowly in this mode, but it may be
necessary in environments with limited stack sizes. This applies only to the
pcre_exec() function; it does not apply to pcre_dfa_exec(), which does not
- use deeply nested recursion.
+ use deeply nested recursion. There is a discussion about stack sizes in the
+ pcrestack man page.
+
+. For speed, PCRE uses four tables for manipulating and identifying characters
+ whose code point values are less than 256. By default, it uses a set of
+ tables for ASCII encoding that is part of the distribution. If you specify
+
+ --enable-rebuild-chartables
+
+ a program called dftables is compiled and run in the default C locale when
+ you obey "make". It builds a source file called pcre_chartables.c. If you do
+ not specify this option, pcre_chartables.c is created as a copy of
+ pcre_chartables.c.dist. See "Character tables" below for further information.
+
+. It is possible to compile PCRE for use on systems that use EBCDIC as their
+ default character code (as opposed to ASCII) by specifying
+
+ --enable-ebcdic
+
+ This automatically implies --enable-rebuild-chartables (see above).
+
+. It is possible to compile pcregrep to use libz and/or libbz2, in order to
+ read .gz and .bz2 files (respectively), by specifying one or both of
+
+ --enable-pcregrep-libz
+ --enable-pcregrep-libbz2
-The "configure" script builds eight files for the basic C library:
+ Of course, the relevant libraries must be installed on your system.
+
+. It is possible to compile pcretest so that it links with the libreadline
+ library, by specifying
+
+ --enable-pcretest-libreadline
+
+ If this is done, when pcretest's input is from a terminal, it reads it using
+ the readline() function. This provides line-editing and history facilities.
+ Note that libreadline is GPL-licenced, so if you distribute a binary of
+ pcretest linked in this way, there may be licensing issues.
+
+ Setting this option causes the -lreadline option to be added to the pcretest
+ build. In many operating environments with a sytem-installed readline
+ library this is sufficient. However, in some environments (e.g. if an
+ unmodified distribution version of readline is in use), it may be necessary
+ to specify something like LIBS="-lncurses" as well. This is because, to quote
+ the readline INSTALL, "Readline uses the termcap functions, but does not link
+ with the termcap or curses library itself, allowing applications which link
+ with readline the to choose an appropriate library."
+
+The "configure" script builds the following files for the basic C library:
. Makefile is the makefile that builds the library
. config.h contains build-time configuration options for the library
+. pcre.h is the public PCRE header file
. pcre-config is a script that shows the settings of "configure" options
. libpcre.pc is data for the pkg-config command
. libtool is a script that builds shared and/or static libraries
-. RunTest is a script for running tests on the library
+. RunTest is a script for running tests on the basic C library
. RunGrepTest is a script for running tests on the pcregrep command
-In addition, if a C++ compiler is found, the following are also built:
+Versions of config.h and pcre.h are distributed in the PCRE tarballs under
+the names config.h.generic and pcre.h.generic. These are provided for the
+benefit of those who have to built PCRE without the benefit of "configure". If
+you use "configure", the .generic versions are not used.
-. pcrecpp.h is the header file for programs that call PCRE via the C++ wrapper
+If a C++ compiler is found, the following files are also built:
+
+. libpcrecpp.pc is data for the pkg-config command
+. pcrecpparg.h is a header file for programs that call PCRE via the C++ wrapper
. pcre_stringpiece.h is the header for the C++ "stringpiece" functions
The "configure" script also creates config.status, which is an executable
@@ -196,17 +313,61 @@ contains compiler output from tests that "configure" runs.
Once "configure" has run, you can run "make". It builds two libraries, called
libpcre and libpcreposix, a test program called pcretest, and the pcregrep
-command. If a C++ compiler was found on your system, it also builds the C++
+command. If a C++ compiler was found on your system, "make" also builds the C++
wrapper library, which is called libpcrecpp, and some test programs called
pcrecpp_unittest, pcre_scanner_unittest, and pcre_stringpiece_unittest.
-
-The command "make test" runs all the appropriate tests. Details of the PCRE
-tests are given in a separate section of this document, below.
-
-You can use "make install" to copy the libraries, the public header files
-pcre.h, pcreposix.h, pcrecpp.h, and pcre_stringpiece.h (the last two only if
-the C++ wrapper was built), and the man pages to appropriate live directories
-on your system, in the normal way.
+Building the C++ wrapper can be disabled by adding --disable-cpp to the
+"configure" command.
+
+The command "make check" runs all the appropriate tests. Details of the PCRE
+tests are given below in a separate section of this document.
+
+You can use "make install" to install PCRE into live directories on your
+system. The following are installed (file names are all relative to the
+<prefix> that is set when "configure" is run):
+
+ Commands (bin):
+ pcretest
+ pcregrep
+ pcre-config
+
+ Libraries (lib):
+ libpcre
+ libpcreposix
+ libpcrecpp (if C++ support is enabled)
+
+ Configuration information (lib/pkgconfig):
+ libpcre.pc
+ libpcrecpp.pc (if C++ support is enabled)
+
+ Header files (include):
+ pcre.h
+ pcreposix.h
+ pcre_scanner.h )
+ pcre_stringpiece.h ) if C++ support is enabled
+ pcrecpp.h )
+ pcrecpparg.h )
+
+ Man pages (share/man/man{1,3}):
+ pcregrep.1
+ pcretest.1
+ pcre.3
+ pcre*.3 (lots more pages, all starting "pcre")
+
+ HTML documentation (share/doc/pcre/html):
+ index.html
+ *.html (lots more pages, hyperlinked from index.html)
+
+ Text file documentation (share/doc/pcre):
+ AUTHORS
+ COPYING
+ ChangeLog
+ LICENCE
+ NEWS
+ README
+ pcre.txt (a concatenation of the man(3) pages)
+ pcretest.txt the pcretest man page
+ pcregrep.txt the pcregrep man page
If you want to remove PCRE from your system, you can run "make uninstall".
This removes all the files that "make install" installed. However, it does not
@@ -216,9 +377,8 @@ remove any directories, because these are often shared with other programs.
Retrieving configuration information on Unix-like systems
---------------------------------------------------------
-Running "make install" also installs the command pcre-config, which can be used
-to recall information about the PCRE configuration and installation. For
-example:
+Running "make install" installs the command pcre-config, which can be used to
+recall information about the PCRE configuration and installation. For example:
pcre-config --version
@@ -237,7 +397,7 @@ single command is used. For example:
pkg-config --cflags pcre
The data is held in *.pc files that are installed in a directory called
-pkgconfig.
+<prefix>/lib/pkgconfig.
Shared libraries on Unix-like systems
@@ -254,7 +414,7 @@ built. The programs pcretest and pcregrep are built to use these uninstalled
libraries (by means of wrapper scripts in the case of shared libraries). When
you use "make install" to install shared libraries, pcregrep and pcretest are
automatically re-built to use the newly installed shared libraries before being
-installed themselves. However, the versions left in the source directory still
+installed themselves. However, the versions left in the build directory still
use the uninstalled libraries.
To build PCRE using static libraries only you must use --disable-shared when
@@ -266,25 +426,33 @@ Then run "make" in the usual way. Similarly, you can use --disable-static to
build only shared libraries.
-Cross-compiling on a Unix-like system
--------------------------------------
+Cross-compiling on Unix-like systems
+------------------------------------
You can specify CC and CFLAGS in the normal way to the "configure" command, in
-order to cross-compile PCRE for some other host. However, during the building
-process, the dftables.c source file is compiled *and run* on the local host, in
-order to generate the default character tables (the chartables.c file). It
-therefore needs to be compiled with the local compiler, not the cross compiler.
-You can do this by specifying CC_FOR_BUILD (and if necessary CFLAGS_FOR_BUILD;
-there are also CXX_FOR_BUILD and CXXFLAGS_FOR_BUILD for the C++ wrapper)
-when calling the "configure" command. If they are not specified, they default
-to the values of CC and CFLAGS.
+order to cross-compile PCRE for some other host. However, you should NOT
+specify --enable-rebuild-chartables, because if you do, the dftables.c source
+file is compiled and run on the local host, in order to generate the inbuilt
+character tables (the pcre_chartables.c file). This will probably not work,
+because dftables.c needs to be compiled with the local compiler, not the cross
+compiler.
+
+When --enable-rebuild-chartables is not specified, pcre_chartables.c is created
+by making a copy of pcre_chartables.c.dist, which is a default set of tables
+that assumes ASCII code. Cross-compiling with the default tables should not be
+a problem.
+
+If you need to modify the character tables when cross-compiling, you should
+move pcre_chartables.c.dist out of the way, then compile dftables.c by hand and
+run it on the local host to make a new version of pcre_chartables.c.dist.
+Then when you cross-compile PCRE this new version of the tables will be used.
Using HP's ANSI C++ compiler (aCC)
----------------------------------
Unless C++ support is disabled by specifying the "--disable-cpp" option of the
-"configure" script, you *must* include the "-AA" option in the CXXFLAGS
+"configure" script, you must include the "-AA" option in the CXXFLAGS
environment variable in order for the C++ components to compile correctly.
Also, note that the aCC compiler on PA-RISC platforms may have a defect whereby
@@ -296,34 +464,32 @@ running the "configure" script:
CXXLDFLAGS="-lstd_v2 -lCsup_v2"
-Building on non-Unix systems
-----------------------------
+Making new tarballs
+-------------------
-For a non-Unix system, read the comments in the file NON-UNIX-USE, though if
-the system supports the use of "configure" and "make" you may be able to build
-PCRE in the same way as for Unix systems.
+The command "make dist" creates three PCRE tarballs, in tar.gz, tar.bz2, and
+zip formats. The command "make distcheck" does the same, but then does a trial
+build of the new distribution to ensure that it works.
-PCRE has been compiled on Windows systems and on Macintoshes, but I don't know
-the details because I don't use those systems. It should be straightforward to
-build PCRE on any system that has a Standard C compiler and library, because it
-uses only Standard C functions.
+If you have modified any of the man page sources in the doc directory, you
+should first run the PrepareRelease script before making a distribution. This
+script creates the .txt and HTML forms of the documentation from the man pages.
Testing PCRE
------------
-To test PCRE on a Unix system, run the RunTest script that is created by the
-configuring process. There is also a script called RunGrepTest that tests the
-options of the pcregrep command. If the C++ wrapper library is build, three
-test programs called pcrecpp_unittest, pcre_scanner_unittest, and
-pcre_stringpiece_unittest are provided.
+To test the basic PCRE library on a Unix system, run the RunTest script that is
+created by the configuring process. There is also a script called RunGrepTest
+that tests the options of the pcregrep command. If the C++ wrapper library is
+built, three test programs called pcrecpp_unittest, pcre_scanner_unittest, and
+pcre_stringpiece_unittest are also built.
-Both the scripts and all the program tests are run if you obey "make runtest",
-"make check", or "make test". For other systems, see the instructions in
-NON-UNIX-USE.
+Both the scripts and all the program tests are run if you obey "make check" or
+"make test". For other systems, see the instructions in NON-UNIX-USE.
The RunTest script runs the pcretest test program (which is documented in its
-own man page) on each of the testinput files (in the testdata directory) in
+own man page) on each of the testinput files in the testdata directory in
turn, and compares the output with the contents of the corresponding testoutput
files. A file called testtry is used to hold the main output from pcretest
(testsavedregex is also used as a working file). To run pcretest on just one of
@@ -331,14 +497,15 @@ the test files, give its number as an argument to RunTest, for example:
RunTest 2
-The first test file can also be fed directly into the perltest script to check
-that Perl gives the same results. The only difference you should see is in the
-first few lines, where the Perl version is given instead of the PCRE version.
+The first test file can also be fed directly into the perltest.pl script to
+check that Perl gives the same results. The only difference you should see is
+in the first few lines, where the Perl version is given instead of the PCRE
+version.
The second set of tests check pcre_fullinfo(), pcre_info(), pcre_study(),
pcre_copy_substring(), pcre_get_substring(), pcre_get_substring_list(), error
detection, and run-time flags that are specific to PCRE, as well as the POSIX
-wrapper API. It also uses the debugging flag to check some of the internals of
+wrapper API. It also uses the debugging flags to check some of the internals of
pcre_compile().
If you build PCRE with a locale setting that is not the standard C locale, the
@@ -364,6 +531,12 @@ is output to say why. If running this test produces instances of the error
in the comparison output, it means that locale is not available on your system,
despite being listed by "locale". This does not mean that PCRE is broken.
+[If you are trying to run this test on Windows, you may be able to get it to
+work by changing "fr_FR" to "french" everywhere it occurs. Alternatively, use
+RunTest.bat. The version of RunTest.bat included with PCRE 7.4 and above uses
+Windows versions of test 2. More info on using RunTest.bat is included in the
+document entitled NON-UNIX-USE.]
+
The fourth test checks the UTF-8 support. It is not run automatically unless
PCRE is built with UTF-8 support. To do this you must set --enable-utf8 when
running "configure". This file can be also fed directly to the perltest script,
@@ -373,8 +546,8 @@ commented in the script, can be be used.)
The fifth test checks error handling with UTF-8 encoding, and internal UTF-8
features of PCRE that are not relevant to Perl.
-The sixth and test checks the support for Unicode character properties. It it
-not run automatically unless PCRE is built with Unicode property support. To to
+The sixth test checks the support for Unicode character properties. It it not
+run automatically unless PCRE is built with Unicode property support. To to
this you must set --enable-unicode-properties when running "configure".
The seventh, eighth, and ninth tests check the pcre_dfa_exec() alternative
@@ -386,27 +559,42 @@ automatically unless PCRE is build with the relevant support.
Character tables
----------------
-PCRE uses four tables for manipulating and identifying characters whose values
-are less than 256. The final argument of the pcre_compile() function is a
-pointer to a block of memory containing the concatenated tables. A call to
-pcre_maketables() can be used to generate a set of tables in the current
-locale. If the final argument for pcre_compile() is passed as NULL, a set of
-default tables that is built into the binary is used.
-
-The source file called chartables.c contains the default set of tables. This is
-not supplied in the distribution, but is built by the program dftables
-(compiled from dftables.c), which uses the ANSI C character handling functions
-such as isalnum(), isalpha(), isupper(), islower(), etc. to build the table
-sources. This means that the default C locale which is set for your system will
-control the contents of these default tables. You can change the default tables
-by editing chartables.c and then re-building PCRE. If you do this, you should
-probably also edit Makefile to ensure that the file doesn't ever get
-re-generated.
+For speed, PCRE uses four tables for manipulating and identifying characters
+whose code point values are less than 256. The final argument of the
+pcre_compile() function is a pointer to a block of memory containing the
+concatenated tables. A call to pcre_maketables() can be used to generate a set
+of tables in the current locale. If the final argument for pcre_compile() is
+passed as NULL, a set of default tables that is built into the binary is used.
+
+The source file called pcre_chartables.c contains the default set of tables. By
+default, this is created as a copy of pcre_chartables.c.dist, which contains
+tables for ASCII coding. However, if --enable-rebuild-chartables is specified
+for ./configure, a different version of pcre_chartables.c is built by the
+program dftables (compiled from dftables.c), which uses the ANSI C character
+handling functions such as isalnum(), isalpha(), isupper(), islower(), etc. to
+build the table sources. This means that the default C locale which is set for
+your system will control the contents of these default tables. You can change
+the default tables by editing pcre_chartables.c and then re-building PCRE. If
+you do this, you should take care to ensure that the file does not get
+automatically re-generated. The best way to do this is to move
+pcre_chartables.c.dist out of the way and replace it with your customized
+tables.
+
+When the dftables program is run as a result of --enable-rebuild-chartables,
+it uses the default C locale that is set on your system. It does not pay
+attention to the LC_xxx environment variables. In other words, it uses the
+system's default locale rather than whatever the compiling user happens to have
+set. If you really do want to build a source set of character tables in a
+locale that is specified by the LC_xxx variables, you can run the dftables
+program by hand with the -L option. For example:
+
+ ./dftables -L pcre_chartables.c.special
The first two 256-byte tables provide lower casing and case flipping functions,
respectively. The next table consists of three 32-byte bit maps which identify
digits, "word" characters, and white space, respectively. These are used when
-building 32-byte bit maps that represent character classes.
+building 32-byte bit maps that represent character classes for code points less
+than 256.
The final 256-byte table has bits indicating various character types, as
follows:
@@ -422,108 +610,143 @@ You should not alter the set of characters that contain the 128 bit, as that
will cause PCRE to malfunction.
-Manifest
---------
+File manifest
+-------------
The distribution should contain the following files:
-(A) The actual source files of the PCRE library functions and their
- headers:
-
- dftables.c auxiliary program for building chartables.c
-
- pcreposix.c )
- pcre_compile.c )
- pcre_config.c )
- pcre_dfa_exec.c )
- pcre_exec.c )
- pcre_fullinfo.c )
- pcre_get.c ) sources for the functions in the library,
- pcre_globals.c ) and some internal functions that they use
- pcre_info.c )
- pcre_maketables.c )
- pcre_newline.c )
- pcre_ord2utf8.c )
- pcre_refcount.c )
- pcre_study.c )
- pcre_tables.c )
- pcre_try_flipped.c )
- pcre_ucp_searchfuncs.c)
- pcre_valid_utf8.c )
- pcre_version.c )
- pcre_xclass.c )
- ucptable.c )
-
- pcre_printint.src ) debugging function that is #included in pcretest, and
- ) can also be #included in pcre_compile()
-
- pcre.h the public PCRE header file
- pcreposix.h header for the external POSIX wrapper API
- pcre_internal.h header for internal use
- ucp.h ) headers concerned with
- ucpinternal.h ) Unicode property handling
- config.in template for config.h, which is built by configure
-
- pcrecpp.h the header file for the C++ wrapper
- pcrecpparg.h.in "source" for another C++ header file
- pcrecpp.cc )
- pcre_scanner.cc ) source for the C++ wrapper library
-
- pcre_stringpiece.h.in "source" for pcre_stringpiece.h, the header for the
- C++ stringpiece functions
- pcre_stringpiece.cc source for the C++ stringpiece functions
-
-(B) Auxiliary files:
-
- AUTHORS information about the author of PCRE
- ChangeLog log of changes to the code
- INSTALL generic installation instructions
- LICENCE conditions for the use of PCRE
- COPYING the same, using GNU's standard name
- Makefile.in template for Unix Makefile, which is built by configure
- NEWS important changes in this release
- NON-UNIX-USE notes on building PCRE on non-Unix systems
- README this file
- RunTest.in template for a Unix shell script for running tests
- RunGrepTest.in template for a Unix shell script for pcregrep tests
- config.guess ) files used by libtool,
- config.sub ) used only when building a shared library
- config.h.in "source" for the config.h header file
- configure a configuring shell script (built by autoconf)
- configure.ac the autoconf input used to build configure
- doc/Tech.Notes notes on the encoding
- doc/*.3 man page sources for the PCRE functions
- doc/*.1 man page sources for pcregrep and pcretest
- doc/html/* HTML documentation
- doc/pcre.txt plain text version of the man pages
- doc/pcretest.txt plain text documentation of test program
- doc/perltest.txt plain text documentation of Perl test program
- install-sh a shell script for installing files
- libpcre.pc.in "source" for libpcre.pc for pkg-config
- ltmain.sh file used to build a libtool script
- mkinstalldirs script for making install directories
- pcretest.c comprehensive test program
- pcredemo.c simple demonstration of coding calls to PCRE
- perltest Perl test program
- pcregrep.c source of a grep utility that uses PCRE
- pcre-config.in source of script which retains PCRE information
- pcrecpp_unittest.c )
- pcre_scanner_unittest.c ) test programs for the C++ wrapper
- pcre_stringpiece_unittest.c )
- testdata/testinput* test data for main library tests
- testdata/testoutput* expected test results
- testdata/grep* input and output for pcregrep tests
-
-(C) Auxiliary files for Win32 DLL
-
- libpcre.def
- libpcreposix.def
-
-(D) Auxiliary file for VPASCAL
+(A) Source files of the PCRE library functions and their headers:
+
+ dftables.c auxiliary program for building pcre_chartables.c
+ when --enable-rebuild-chartables is specified
+
+ pcre_chartables.c.dist a default set of character tables that assume ASCII
+ coding; used, unless --enable-rebuild-chartables is
+ specified, by copying to pcre_chartables.c
+
+ pcreposix.c )
+ pcre_compile.c )
+ pcre_config.c )
+ pcre_dfa_exec.c )
+ pcre_exec.c )
+ pcre_fullinfo.c )
+ pcre_get.c ) sources for the functions in the library,
+ pcre_globals.c ) and some internal functions that they use
+ pcre_info.c )
+ pcre_maketables.c )
+ pcre_newline.c )
+ pcre_ord2utf8.c )
+ pcre_refcount.c )
+ pcre_study.c )
+ pcre_tables.c )
+ pcre_try_flipped.c )
+ pcre_ucp_searchfuncs.c )
+ pcre_valid_utf8.c )
+ pcre_version.c )
+ pcre_xclass.c )
+ pcre_printint.src ) debugging function that is #included in pcretest,
+ ) and can also be #included in pcre_compile()
+ pcre.h.in template for pcre.h when built by "configure"
+ pcreposix.h header for the external POSIX wrapper API
+ pcre_internal.h header for internal use
+ ucp.h ) headers concerned with
+ ucpinternal.h ) Unicode property handling
+ ucptable.h ) (this one is the data table)
+
+ config.h.in template for config.h, which is built by "configure"
+
+ pcrecpp.h public header file for the C++ wrapper
+ pcrecpparg.h.in template for another C++ header file
+ pcre_scanner.h public header file for C++ scanner functions
+ pcrecpp.cc )
+ pcre_scanner.cc ) source for the C++ wrapper library
+
+ pcre_stringpiece.h.in template for pcre_stringpiece.h, the header for the
+ C++ stringpiece functions
+ pcre_stringpiece.cc source for the C++ stringpiece functions
+
+(B) Source files for programs that use PCRE:
+
+ pcredemo.c simple demonstration of coding calls to PCRE
+ pcregrep.c source of a grep utility that uses PCRE
+ pcretest.c comprehensive test program
+
+(C) Auxiliary files:
+
+ 132html script to turn "man" pages into HTML
+ AUTHORS information about the author of PCRE
+ ChangeLog log of changes to the code
+ CleanTxt script to clean nroff output for txt man pages
+ Detrail script to remove trailing spaces
+ HACKING some notes about the internals of PCRE
+ INSTALL generic installation instructions
+ LICENCE conditions for the use of PCRE
+ COPYING the same, using GNU's standard name
+ Makefile.in ) template for Unix Makefile, which is built by
+ ) "configure"
+ Makefile.am ) the automake input that was used to create
+ ) Makefile.in
+ NEWS important changes in this release
+ NON-UNIX-USE notes on building PCRE on non-Unix systems
+ PrepareRelease script to make preparations for "make dist"
+ README this file
+ RunTest a Unix shell script for running tests
+ RunGrepTest a Unix shell script for pcregrep tests
+ aclocal.m4 m4 macros (generated by "aclocal")
+ config.guess ) files used by libtool,
+ config.sub ) used only when building a shared library
+ configure a configuring shell script (built by autoconf)
+ configure.ac ) the autoconf input that was used to build
+ ) "configure" and config.h
+ depcomp ) script to find program dependencies, generated by
+ ) automake
+ doc/*.3 man page sources for the PCRE functions
+ doc/*.1 man page sources for pcregrep and pcretest
+ doc/index.html.src the base HTML page
+ doc/html/* HTML documentation
+ doc/pcre.txt plain text version of the man pages
+ doc/pcretest.txt plain text documentation of test program
+ doc/perltest.txt plain text documentation of Perl test program
+ install-sh a shell script for installing files
+ libpcre.pc.in template for libpcre.pc for pkg-config
+ libpcrecpp.pc.in template for libpcrecpp.pc for pkg-config
+ ltmain.sh file used to build a libtool script
+ missing ) common stub for a few missing GNU programs while
+ ) installing, generated by automake
+ mkinstalldirs script for making install directories
+ perltest.pl Perl test program
+ pcre-config.in source of script which retains PCRE information
+ pcrecpp_unittest.cc )
+ pcre_scanner_unittest.cc ) test programs for the C++ wrapper
+ pcre_stringpiece_unittest.cc )
+ testdata/testinput* test data for main library tests
+ testdata/testoutput* expected test results
+ testdata/grep* input and output for pcregrep tests
+
+(D) Auxiliary files for cmake support
+
+ CMakeLists.txt
+ config-cmake.h.in
+
+(E) Auxiliary files for VPASCAL
makevp.bat
+ makevp_c.txt
+ makevp_l.txt
+ pcregexp.pas
+
+(F) Auxiliary files for building PCRE "by hand"
+
+ pcre.h.generic ) a version of the public PCRE header file
+ ) for use in non-"configure" environments
+ config.h.generic ) a version of config.h for use in non-"configure"
+ ) environments
+
+(F) Miscellaneous
+
+ RunTest.bat a script for running tests under Windows
Philip Hazel
Email local part: ph10
Email domain: cam.ac.uk
-November 2006
+Last updated: 13 April 2008
diff --git a/ext/pcre/pcrelib/config.h b/ext/pcre/pcrelib/config.h
new file mode 100644
index 0000000000..2b1afc27b4
--- /dev/null
+++ b/ext/pcre/pcrelib/config.h
@@ -0,0 +1,318 @@
+
+#include <php_compat.h>
+#undef PACKAGE_NAME
+#undef PACKAGE_VERSION
+#undef PACKAGE_TARNAME
+#undef PACKAGE_STRING
+
+#define SUPPORT_UCP
+#define SUPPORT_UTF8
+
+
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+
+/* On Unix-like systems config.h.in is converted by "configure" into config.h.
+Some other environments also support the use of "configure". PCRE is written in
+Standard C, but there are a few non-standard things it can cope with, allowing
+it to run on SunOS4 and other "close to standard" systems.
+
+If you are going to build PCRE "by hand" on a system without "configure" you
+should copy the distributed config.h.generic to config.h, and then set up the
+macro definitions the way you need them. You must then add -DHAVE_CONFIG_H to
+all of your compile commands, so that config.h is included at the start of
+every source.
+
+Alternatively, you can avoid editing by using -D on the compiler command line
+to set the macro values. In this case, you do not have to set -DHAVE_CONFIG_H.
+
+PCRE uses memmove() if HAVE_MEMMOVE is set to 1; otherwise it uses bcopy() if
+HAVE_BCOPY is set to 1. If your system has neither bcopy() nor memmove(), set
+them both to 0; an emulation function will be used. */
+
+/* By default, the \R escape sequence matches any Unicode line ending
+ character or sequence of characters. If BSR_ANYCRLF is defined, this is
+ changed so that backslash-R matches only CR, LF, or CRLF. The build- time
+ default can be overridden by the user of PCRE at runtime. On systems that
+ support it, "configure" can be used to override the default. */
+/* #undef BSR_ANYCRLF */
+
+/* If you are compiling for a system that uses EBCDIC instead of ASCII
+ character codes, define this macro as 1. On systems that can use
+ "configure", this can be done via --enable-ebcdic. */
+/* #undef EBCDIC */
+
+/* Define to 1 if you have the `bcopy' function. */
+#ifndef HAVE_BCOPY
+#define HAVE_BCOPY 1
+#endif
+
+/* Define to 1 if you have the <bits/type_traits.h> header file. */
+/* #undef HAVE_BITS_TYPE_TRAITS_H */
+
+/* Define to 1 if you have the <bzlib.h> header file. */
+#ifndef HAVE_BZLIB_H
+#define HAVE_BZLIB_H 1
+#endif
+
+/* Define to 1 if you have the <dirent.h> header file. */
+#ifndef HAVE_DIRENT_H
+#define HAVE_DIRENT_H 1
+#endif
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#ifndef HAVE_DLFCN_H
+#define HAVE_DLFCN_H 1
+#endif
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#ifndef HAVE_INTTYPES_H
+#define HAVE_INTTYPES_H 1
+#endif
+
+/* Define to 1 if you have the <limits.h> header file. */
+#ifndef HAVE_LIMITS_H
+#define HAVE_LIMITS_H 1
+#endif
+
+/* Define to 1 if the system has the type `long long'. */
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG 1
+#endif
+
+/* Define to 1 if you have the `memmove' function. */
+#ifndef HAVE_MEMMOVE
+#define HAVE_MEMMOVE 1
+#endif
+
+/* Define to 1 if you have the <memory.h> header file. */
+#ifndef HAVE_MEMORY_H
+#define HAVE_MEMORY_H 1
+#endif
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#ifndef HAVE_READLINE_HISTORY_H
+#define HAVE_READLINE_HISTORY_H 1
+#endif
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#ifndef HAVE_READLINE_READLINE_H
+#define HAVE_READLINE_READLINE_H 1
+#endif
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#ifndef HAVE_STDINT_H
+#define HAVE_STDINT_H 1
+#endif
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#ifndef HAVE_STDLIB_H
+#define HAVE_STDLIB_H 1
+#endif
+
+/* Define to 1 if you have the `strerror' function. */
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR 1
+#endif
+
+/* Define to 1 if you have the <string> header file. */
+#ifndef HAVE_STRING
+#define HAVE_STRING 1
+#endif
+
+/* Define to 1 if you have the <strings.h> header file. */
+#ifndef HAVE_STRINGS_H
+#define HAVE_STRINGS_H 1
+#endif
+
+/* Define to 1 if you have the <string.h> header file. */
+#ifndef HAVE_STRING_H
+#define HAVE_STRING_H 1
+#endif
+
+/* Define to 1 if you have the `strtoll' function. */
+/* #undef HAVE_STRTOLL */
+
+/* Define to 1 if you have the `strtoq' function. */
+#ifndef HAVE_STRTOQ
+#define HAVE_STRTOQ 1
+#endif
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#ifndef HAVE_SYS_STAT_H
+#define HAVE_SYS_STAT_H 1
+#endif
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#ifndef HAVE_SYS_TYPES_H
+#define HAVE_SYS_TYPES_H 1
+#endif
+
+/* Define to 1 if you have the <type_traits.h> header file. */
+/* #undef HAVE_TYPE_TRAITS_H */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#ifndef HAVE_UNISTD_H
+#define HAVE_UNISTD_H 1
+#endif
+
+/* Define to 1 if the system has the type `unsigned long long'. */
+#ifndef HAVE_UNSIGNED_LONG_LONG
+#define HAVE_UNSIGNED_LONG_LONG 1
+#endif
+
+/* Define to 1 if you have the <windows.h> header file. */
+/* #undef HAVE_WINDOWS_H */
+
+/* Define to 1 if you have the <zlib.h> header file. */
+#ifndef HAVE_ZLIB_H
+#define HAVE_ZLIB_H 1
+#endif
+
+/* Define to 1 if you have the `_strtoi64' function. */
+/* #undef HAVE__STRTOI64 */
+
+/* The value of LINK_SIZE determines the number of bytes used to store links
+ as offsets within the compiled regex. The default is 2, which allows for
+ compiled patterns up to 64K long. This covers the vast majority of cases.
+ However, PCRE can also be compiled to use 3 or 4 bytes instead. This allows
+ for longer patterns in extreme cases. On systems that support it,
+ "configure" can be used to override this default. */
+#ifndef LINK_SIZE
+#define LINK_SIZE 2
+#endif
+
+/* The value of MATCH_LIMIT determines the default number of times the
+ internal match() function can be called during a single execution of
+ pcre_exec(). There is a runtime interface for setting a different limit.
+ The limit exists in order to catch runaway regular expressions that take
+ for ever to determine that they do not match. The default is set very large
+ so that it does not accidentally catch legitimate cases. On systems that
+ support it, "configure" can be used to override this default default. */
+#ifndef MATCH_LIMIT
+#define MATCH_LIMIT 10000000
+#endif
+
+/* The above limit applies to all calls of match(), whether or not they
+ increase the recursion depth. In some environments it is desirable to limit
+ the depth of recursive calls of match() more strictly, in order to restrict
+ the maximum amount of stack (or heap, if NO_RECURSE is defined) that is
+ used. The value of MATCH_LIMIT_RECURSION applies only to recursive calls of
+ match(). To have any useful effect, it must be less than the value of
+ MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT. There is
+ a runtime method for setting a different limit. On systems that support it,
+ "configure" can be used to override the default. */
+#ifndef MATCH_LIMIT_RECURSION
+#define MATCH_LIMIT_RECURSION MATCH_LIMIT
+#endif
+
+/* This limit is parameterized just in case anybody ever wants to change it.
+ Care must be taken if it is increased, because it guards against integer
+ overflow caused by enormously large patterns. */
+#ifndef MAX_NAME_COUNT
+#define MAX_NAME_COUNT 10000
+#endif
+
+/* This limit is parameterized just in case anybody ever wants to change it.
+ Care must be taken if it is increased, because it guards against integer
+ overflow caused by enormously large patterns. */
+#ifndef MAX_NAME_SIZE
+#define MAX_NAME_SIZE 32
+#endif
+
+/* The value of NEWLINE determines the newline character sequence. On systems
+ that support it, "configure" can be used to override the default, which is
+ 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or -2
+ (ANYCRLF). */
+#ifndef NEWLINE
+#define NEWLINE 10
+#endif
+
+/* PCRE uses recursive function calls to handle backtracking while matching.
+ This can sometimes be a problem on systems that have stacks of limited
+ size. Define NO_RECURSE to get a version that doesn't use recursion in the
+ match() function; instead it creates its own stack by steam using
+ pcre_recurse_malloc() to obtain memory from the heap. For more detail, see
+ the comments and other stuff just above the match() function. On systems
+ that support it, "configure" can be used to set this in the Makefile (use
+ --disable-stack-for-recursion). */
+/* #undef NO_RECURSE */
+
+/* Name of package */
+#define PACKAGE "pcre"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "PCRE"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "PCRE 7.7"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "pcre"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "7.7"
+
+
+/* If you are compiling for a system other than a Unix-like system or
+ Win32, and it needs some magic to be inserted before the definition
+ of a function that is exported by the library, define this macro to
+ contain the relevant magic. If you do not define this macro, it
+ defaults to "extern" for a C compiler and "extern C" for a C++
+ compiler on non-Win32 systems. This macro apears at the start of
+ every exported function that is part of the external API. It does
+ not appear on functions that are "external" in the C sense, but
+ which are internal to the library. */
+/* #undef PCRE_EXP_DEFN */
+
+/* Define if linking statically (TODO: make nice with Libtool) */
+/* #undef PCRE_STATIC */
+
+/* When calling PCRE via the POSIX interface, additional working storage is
+ required for holding the pointers to capturing substrings because PCRE
+ requires three integers per substring, whereas the POSIX interface provides
+ only two. If the number of expected substrings is small, the wrapper
+ function uses space on the stack, because this is faster than using
+ malloc() for each call. The threshold above which the stack is no longer
+ used is defined by POSIX_MALLOC_THRESHOLD. On systems that support it,
+ "configure" can be used to override this default. */
+#ifndef POSIX_MALLOC_THRESHOLD
+#define POSIX_MALLOC_THRESHOLD 10
+#endif
+
+/* Define to 1 if you have the ANSI C header files. */
+#ifndef STDC_HEADERS
+#define STDC_HEADERS 1
+#endif
+
+/* Define to allow pcregrep to be linked with libbz2, so that it is able to
+ handle .bz2 files. */
+/* #undef SUPPORT_LIBBZ2 */
+
+/* Define to allow pcretest to be linked with libreadline. */
+/* #undef SUPPORT_LIBREADLINE */
+
+/* Define to allow pcregrep to be linked with libz, so that it is able to
+ handle .gz files. */
+/* #undef SUPPORT_LIBZ */
+
+/* Define to enable support for Unicode properties */
+/* #undef SUPPORT_UCP */
+
+/* Define to enable support for the UTF-8 Unicode encoding. */
+/* #undef SUPPORT_UTF8 */
+
+/* Version number of package */
+#ifndef VERSION
+#define VERSION "7.7"
+#endif
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
diff --git a/ext/pcre/pcrelib/dftables.c b/ext/pcre/pcrelib/dftables.c
index a94b7a61d5..63fc7074ec 100644
--- a/ext/pcre/pcrelib/dftables.c
+++ b/ext/pcre/pcrelib/dftables.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -38,14 +38,17 @@ POSSIBILITY OF SUCH DAMAGE.
*/
-/* This is a freestanding support program to generate a file containing default
-character tables for PCRE. The tables are built according to the default C
+/* This is a freestanding support program to generate a file containing
+character tables for PCRE. The tables are built according to the current
locale. Now that pcre_maketables is a function visible to the outside world, we
make use of its code from here in order to be consistent. */
+#include "config.h"
+
#include <ctype.h>
#include <stdio.h>
#include <string.h>
+#include <locale.h>
#include "pcre_internal.h"
@@ -55,45 +58,58 @@ make use of its code from here in order to be consistent. */
int main(int argc, char **argv)
{
-int i;
FILE *f;
-const unsigned char *tables = pcre_maketables();
-const unsigned char *base_of_tables = tables;
+int i = 1;
+const unsigned char *tables;
+const unsigned char *base_of_tables;
+
+/* By default, the default C locale is used rather than what the building user
+happens to have set. However, if the -L option is given, set the locale from
+the LC_xxx environment variables. */
-if (argc != 2)
+if (argc > 1 && strcmp(argv[1], "-L") == 0)
+ {
+ setlocale(LC_ALL, ""); /* Set from environment variables */
+ i++;
+ }
+
+if (argc < i + 1)
{
fprintf(stderr, "dftables: one filename argument is required\n");
return 1;
}
-f = fopen(argv[1], "wb");
+tables = pcre_maketables();
+base_of_tables = tables;
+
+f = fopen(argv[i], "wb");
if (f == NULL)
{
fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
return 1;
}
-/* There are two fprintf() calls here, because gcc in pedantic mode complains
-about the very long string otherwise. */
+/* There are several fprintf() calls here, because gcc in pedantic mode
+complains about the very long string otherwise. */
fprintf(f,
"/*************************************************\n"
"* Perl-Compatible Regular Expressions *\n"
"*************************************************/\n\n"
- "/* This file is automatically written by the dftables auxiliary \n"
- "program. If you edit it by hand, you might like to edit the Makefile to \n"
- "prevent its ever being regenerated.\n\n");
-fprintf(f,
- "This file contains the default tables for characters with codes less than\n"
- "128 (ASCII characters). These tables are used when no external tables are\n"
- "passed to PCRE.\n\n");
+ "/* This file was automatically written by the dftables auxiliary\n"
+ "program. It contains character tables that are used when no external\n"
+ "tables are passed to PCRE by the application that calls it. The tables\n"
+ "are used only for characters whose code values are less than 256.\n\n");
fprintf(f,
- "The following #include is present because without it gcc 4.x may remove\n"
+ "The following #includes are present because without them gcc 4.x may remove\n"
"the array definition from the final binary if PCRE is built into a static\n"
"library and dead code stripping is activated. This leads to link errors.\n"
"Pulling in the header ensures that the array gets flagged as \"someone\n"
"outside this compilation unit might reference this\" and so it will always\n"
"be supplied to the linker. */\n\n"
+ "#ifdef HAVE_CONFIG_H\n"
+ "#include \"config.h\"\n"
+ "#endif\n\n"
"#include \"pcre_internal.h\"\n\n");
fprintf(f,
"const unsigned char _pcre_default_tables[] = {\n\n"
@@ -171,7 +187,7 @@ if (isprint(i-8)) fprintf(f, " %c -", i-8);
else fprintf(f, "%3d-", i-8);
if (isprint(i-1)) fprintf(f, " %c ", i-1);
else fprintf(f, "%3d", i-1);
-fprintf(f, " */\n\n/* End of chartables.c */\n");
+fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
fclose(f);
free((void *)base_of_tables);
diff --git a/ext/pcre/pcrelib/doc/pcre.txt b/ext/pcre/pcrelib/doc/pcre.txt
index 9c7884998c..1a328ce200 100644
--- a/ext/pcre/pcrelib/doc/pcre.txt
+++ b/ext/pcre/pcrelib/doc/pcre.txt
@@ -18,9 +18,11 @@ INTRODUCTION
The PCRE library is a set of functions that implement regular expres-
sion pattern matching using the same syntax and semantics as Perl, with
- just a few differences. (Certain features that appeared in Python and
+ just a few differences. Certain features that appeared in Python and
PCRE before they appeared in Perl are also available using the Python
- syntax.)
+ syntax. There is also some support for certain .NET and Oniguruma syn-
+ tax items, and there is an option for requesting some minor changes
+ that give better JavaScript compatibility.
The current implementation of PCRE (release 7.x) corresponds approxi-
mately with Perl 5.10, including support for UTF-8 encoded strings and
@@ -45,33 +47,35 @@ INTRODUCTION
Details of exactly which Perl regular expression features are and are
not supported by PCRE are given in separate documents. See the pcrepat-
- tern and pcrecompat pages.
+ tern and pcrecompat pages. There is a syntax summary in the pcresyntax
+ page.
- Some features of PCRE can be included, excluded, or changed when the
- library is built. The pcre_config() function makes it possible for a
- client to discover which features are available. The features them-
- selves are described in the pcrebuild page. Documentation about build-
- ing PCRE for various operating systems can be found in the README file
+ Some features of PCRE can be included, excluded, or changed when the
+ library is built. The pcre_config() function makes it possible for a
+ client to discover which features are available. The features them-
+ selves are described in the pcrebuild page. Documentation about build-
+ ing PCRE for various operating systems can be found in the README file
in the source distribution.
- The library contains a number of undocumented internal functions and
- data tables that are used by more than one of the exported external
- functions, but which are not intended for use by external callers.
- Their names all begin with "_pcre_", which hopefully will not provoke
+ The library contains a number of undocumented internal functions and
+ data tables that are used by more than one of the exported external
+ functions, but which are not intended for use by external callers.
+ Their names all begin with "_pcre_", which hopefully will not provoke
any name clashes. In some environments, it is possible to control which
- external symbols are exported when a shared library is built, and in
+ external symbols are exported when a shared library is built, and in
these cases the undocumented symbols are not exported.
USER DOCUMENTATION
- The user documentation for PCRE comprises a number of different sec-
- tions. In the "man" format, each of these is a separate "man page". In
- the HTML format, each is a separate page, linked from the index page.
- In the plain text format, all the sections are concatenated, for ease
+ The user documentation for PCRE comprises a number of different sec-
+ tions. In the "man" format, each of these is a separate "man page". In
+ the HTML format, each is a separate page, linked from the index page.
+ In the plain text format, all the sections are concatenated, for ease
of searching. The sections are as follows:
pcre this document
+ pcre-config show PCRE installation configuration information
pcreapi details of PCRE's native C API
pcrebuild options for building PCRE
pcrecallout details of the callout feature
@@ -82,6 +86,7 @@ USER DOCUMENTATION
pcrepartial details of the partial matching facility
pcrepattern syntax and semantics of supported
regular expressions
+ pcresyntax quick syntax reference
pcreperform discussion of performance issues
pcreposix the POSIX-compatible C API
pcreprecompile details of saving and re-using precompiled patterns
@@ -89,26 +94,24 @@ USER DOCUMENTATION
pcrestack discussion of stack usage
pcretest description of the pcretest testing command
- In addition, in the "man" and HTML formats, there is a short page for
+ In addition, in the "man" and HTML formats, there is a short page for
each C library function, listing its arguments and results.
LIMITATIONS
- There are some size limitations in PCRE but it is hoped that they will
+ There are some size limitations in PCRE but it is hoped that they will
never in practice be relevant.
- The maximum length of a compiled pattern is 65539 (sic) bytes if PCRE
+ The maximum length of a compiled pattern is 65539 (sic) bytes if PCRE
is compiled with the default internal linkage size of 2. If you want to
- process regular expressions that are truly enormous, you can compile
- PCRE with an internal linkage size of 3 or 4 (see the README file in
- the source distribution and the pcrebuild documentation for details).
- In these cases the limit is substantially larger. However, the speed
+ process regular expressions that are truly enormous, you can compile
+ PCRE with an internal linkage size of 3 or 4 (see the README file in
+ the source distribution and the pcrebuild documentation for details).
+ In these cases the limit is substantially larger. However, the speed
of execution is slower.
- All values in repeating quantifiers must be less than 65536. The maxi-
- mum compiled length of subpattern with an explicit repeat count is
- 30000 bytes. The maximum number of capturing subpatterns is 65535.
+ All values in repeating quantifiers must be less than 65536.
There is no limit to the number of parenthesized subpatterns, but there
can be no more than 65535 capturing subpatterns.
@@ -116,110 +119,147 @@ LIMITATIONS
The maximum length of name for a named subpattern is 32 characters, and
the maximum number of named subpatterns is 10000.
- The maximum length of a subject string is the largest positive number
- that an integer variable can hold. However, when using the traditional
+ The maximum length of a subject string is the largest positive number
+ that an integer variable can hold. However, when using the traditional
matching function, PCRE uses recursion to handle subpatterns and indef-
- inite repetition. This means that the available stack space may limit
+ inite repetition. This means that the available stack space may limit
the size of a subject string that can be processed by certain patterns.
For a discussion of stack issues, see the pcrestack documentation.
UTF-8 AND UNICODE PROPERTY SUPPORT
- From release 3.3, PCRE has had some support for character strings
- encoded in the UTF-8 format. For release 4.0 this was greatly extended
- to cover most common requirements, and in release 5.0 additional sup-
+ From release 3.3, PCRE has had some support for character strings
+ encoded in the UTF-8 format. For release 4.0 this was greatly extended
+ to cover most common requirements, and in release 5.0 additional sup-
port for Unicode general category properties was added.
- In order process UTF-8 strings, you must build PCRE to include UTF-8
- support in the code, and, in addition, you must call pcre_compile()
- with the PCRE_UTF8 option flag. When you do this, both the pattern and
- any subject strings that are matched against it are treated as UTF-8
+ In order process UTF-8 strings, you must build PCRE to include UTF-8
+ support in the code, and, in addition, you must call pcre_compile()
+ with the PCRE_UTF8 option flag. When you do this, both the pattern and
+ any subject strings that are matched against it are treated as UTF-8
strings instead of just strings of bytes.
- If you compile PCRE with UTF-8 support, but do not use it at run time,
- the library will be a bit bigger, but the additional run time overhead
+ If you compile PCRE with UTF-8 support, but do not use it at run time,
+ the library will be a bit bigger, but the additional run time overhead
is limited to testing the PCRE_UTF8 flag occasionally, so should not be
very big.
If PCRE is built with Unicode character property support (which implies
- UTF-8 support), the escape sequences \p{..}, \P{..}, and \X are sup-
+ UTF-8 support), the escape sequences \p{..}, \P{..}, and \X are sup-
ported. The available properties that can be tested are limited to the
- general category properties such as Lu for an upper case letter or Nd
- for a decimal number, the Unicode script names such as Arabic or Han,
- and the derived properties Any and L&. A full list is given in the
+ general category properties such as Lu for an upper case letter or Nd
+ for a decimal number, the Unicode script names such as Arabic or Han,
+ and the derived properties Any and L&. A full list is given in the
pcrepattern documentation. Only the short names for properties are sup-
- ported. For example, \p{L} matches a letter. Its Perl synonym, \p{Let-
- ter}, is not supported. Furthermore, in Perl, many properties may
- optionally be prefixed by "Is", for compatibility with Perl 5.6. PCRE
+ ported. For example, \p{L} matches a letter. Its Perl synonym, \p{Let-
+ ter}, is not supported. Furthermore, in Perl, many properties may
+ optionally be prefixed by "Is", for compatibility with Perl 5.6. PCRE
does not support this.
- The following comments apply when PCRE is running in UTF-8 mode:
-
- 1. When you set the PCRE_UTF8 flag, the strings passed as patterns and
- subjects are checked for validity on entry to the relevant functions.
- If an invalid UTF-8 string is passed, an error return is given. In some
- situations, you may already know that your strings are valid, and
- therefore want to skip these checks in order to improve performance. If
- you set the PCRE_NO_UTF8_CHECK flag at compile time or at run time,
- PCRE assumes that the pattern or subject it is given (respectively)
- contains only valid UTF-8 codes. In this case, it does not diagnose an
- invalid UTF-8 string. If you pass an invalid UTF-8 string to PCRE when
- PCRE_NO_UTF8_CHECK is set, the results are undefined. Your program may
- crash.
-
- 2. An unbraced hexadecimal escape sequence (such as \xb3) matches a
+ Validity of UTF-8 strings
+
+ When you set the PCRE_UTF8 flag, the strings passed as patterns and
+ subjects are (by default) checked for validity on entry to the relevant
+ functions. From release 7.3 of PCRE, the check is according the rules
+ of RFC 3629, which are themselves derived from the Unicode specifica-
+ tion. Earlier releases of PCRE followed the rules of RFC 2279, which
+ allows the full range of 31-bit values (0 to 0x7FFFFFFF). The current
+ check allows only values in the range U+0 to U+10FFFF, excluding U+D800
+ to U+DFFF.
+
+ The excluded code points are the "Low Surrogate Area" of Unicode, of
+ which the Unicode Standard says this: "The Low Surrogate Area does not
+ contain any character assignments, consequently no character code
+ charts or namelists are provided for this area. Surrogates are reserved
+ for use with UTF-16 and then must be used in pairs." The code points
+ that are encoded by UTF-16 pairs are available as independent code
+ points in the UTF-8 encoding. (In other words, the whole surrogate
+ thing is a fudge for UTF-16 which unfortunately messes up UTF-8.)
+
+ If an invalid UTF-8 string is passed to PCRE, an error return
+ (PCRE_ERROR_BADUTF8) is given. In some situations, you may already know
+ that your strings are valid, and therefore want to skip these checks in
+ order to improve performance. If you set the PCRE_NO_UTF8_CHECK flag at
+ compile time or at run time, PCRE assumes that the pattern or subject
+ it is given (respectively) contains only valid UTF-8 codes. In this
+ case, it does not diagnose an invalid UTF-8 string.
+
+ If you pass an invalid UTF-8 string when PCRE_NO_UTF8_CHECK is set,
+ what happens depends on why the string is invalid. If the string con-
+ forms to the "old" definition of UTF-8 (RFC 2279), it is processed as a
+ string of characters in the range 0 to 0x7FFFFFFF. In other words,
+ apart from the initial validity test, PCRE (when in UTF-8 mode) handles
+ strings according to the more liberal rules of RFC 2279. However, if
+ the string does not even conform to RFC 2279, the result is undefined.
+ Your program may crash.
+
+ If you want to process strings of values in the full range 0 to
+ 0x7FFFFFFF, encoded in a UTF-8-like manner as per the old RFC, you can
+ set PCRE_NO_UTF8_CHECK to bypass the more restrictive test. However, in
+ this situation, you will have to apply your own validity check.
+
+ General comments about UTF-8 mode
+
+ 1. An unbraced hexadecimal escape sequence (such as \xb3) matches a
two-byte UTF-8 character if the value is greater than 127.
- 3. Octal numbers up to \777 are recognized, and match two-byte UTF-8
+ 2. Octal numbers up to \777 are recognized, and match two-byte UTF-8
characters for values greater than \177.
- 4. Repeat quantifiers apply to complete UTF-8 characters, not to indi-
+ 3. Repeat quantifiers apply to complete UTF-8 characters, not to indi-
vidual bytes, for example: \x{100}{3}.
- 5. The dot metacharacter matches one UTF-8 character instead of a sin-
+ 4. The dot metacharacter matches one UTF-8 character instead of a sin-
gle byte.
- 6. The escape sequence \C can be used to match a single byte in UTF-8
- mode, but its use can lead to some strange effects. This facility is
+ 5. The escape sequence \C can be used to match a single byte in UTF-8
+ mode, but its use can lead to some strange effects. This facility is
not available in the alternative matching function, pcre_dfa_exec().
- 7. The character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
- test characters of any code value, but the characters that PCRE recog-
- nizes as digits, spaces, or word characters remain the same set as
+ 6. The character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
+ test characters of any code value, but the characters that PCRE recog-
+ nizes as digits, spaces, or word characters remain the same set as
before, all with values less than 256. This remains true even when PCRE
- includes Unicode property support, because to do otherwise would slow
- down PCRE in many common cases. If you really want to test for a wider
- sense of, say, "digit", you must use Unicode property tests such as
+ includes Unicode property support, because to do otherwise would slow
+ down PCRE in many common cases. If you really want to test for a wider
+ sense of, say, "digit", you must use Unicode property tests such as
\p{Nd}.
- 8. Similarly, characters that match the POSIX named character classes
+ 7. Similarly, characters that match the POSIX named character classes
are all low-valued characters.
- 9. Case-insensitive matching applies only to characters whose values
- are less than 128, unless PCRE is built with Unicode property support.
- Even when Unicode property support is available, PCRE still uses its
- own character tables when checking the case of low-valued characters,
- so as not to degrade performance. The Unicode property information is
+ 8. However, the Perl 5.10 horizontal and vertical whitespace matching
+ escapes (\h, \H, \v, and \V) do match all the appropriate Unicode char-
+ acters.
+
+ 9. Case-insensitive matching applies only to characters whose values
+ are less than 128, unless PCRE is built with Unicode property support.
+ Even when Unicode property support is available, PCRE still uses its
+ own character tables when checking the case of low-valued characters,
+ so as not to degrade performance. The Unicode property information is
used only for characters with higher values. Even when Unicode property
support is available, PCRE supports case-insensitive matching only when
- there is a one-to-one mapping between a letter's cases. There are a
- small number of many-to-one mappings in Unicode; these are not sup-
+ there is a one-to-one mapping between a letter's cases. There are a
+ small number of many-to-one mappings in Unicode; these are not sup-
ported by PCRE.
AUTHOR
Philip Hazel
- University Computing Service,
+ University Computing Service
Cambridge CB2 3QH, England.
- Putting an actual email address here seems to have been a spam magnet,
- so I've taken it away. If you want to email me, use my initial and sur-
- name, separated by a dot, at the domain ucs.cam.ac.uk.
+ Putting an actual email address here seems to have been a spam magnet,
+ so I've taken it away. If you want to email me, use my two initials,
+ followed by the two digits 10, at the domain cam.ac.uk.
+
-Last updated: 23 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+REVISION
+
+ Last updated: 12 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -233,20 +273,25 @@ NAME
PCRE BUILD-TIME OPTIONS
This document describes the optional features of PCRE that can be
- selected when the library is compiled. They are all selected, or dese-
- lected, by providing options to the configure script that is run before
- the make command. The complete list of options for configure (which
- includes the standard ones such as the selection of the installation
- directory) can be obtained by running
+ selected when the library is compiled. It assumes use of the configure
+ script, where the optional features are selected or deselected by pro-
+ viding options to configure before running the make command. However,
+ the same options can be selected in both Unix-like and non-Unix-like
+ environments using the GUI facility of CMakeSetup if you are using
+ CMake instead of configure to build PCRE.
+
+ The complete list of options for configure (which includes the standard
+ ones such as the selection of the installation directory) can be
+ obtained by running
./configure --help
- The following sections describe certain options whose names begin with
- --enable or --disable. These settings specify changes to the defaults
- for the configure command. Because of the way that configure works,
- --enable and --disable always come in pairs, so the complementary
- option always exists as well, but as it specifies the default, it is
- not described.
+ The following sections include descriptions of options whose names
+ begin with --enable or --disable. These settings specify changes to the
+ defaults for the configure command. Because of the way that configure
+ works, --enable and --disable always come in pairs, so the complemen-
+ tary option always exists as well, but as it specifies the default, it
+ is not described.
C++ SUPPORT
@@ -266,29 +311,28 @@ UTF-8 SUPPORT
--enable-utf8
- to the configure command. Of itself, this does not make PCRE treat
- strings as UTF-8. As well as compiling PCRE with this option, you also
- have have to set the PCRE_UTF8 option when you call the pcre_compile()
+ to the configure command. Of itself, this does not make PCRE treat
+ strings as UTF-8. As well as compiling PCRE with this option, you also
+ have have to set the PCRE_UTF8 option when you call the pcre_compile()
function.
UNICODE CHARACTER PROPERTY SUPPORT
- UTF-8 support allows PCRE to process character values greater than 255
- in the strings that it handles. On its own, however, it does not pro-
+ UTF-8 support allows PCRE to process character values greater than 255
+ in the strings that it handles. On its own, however, it does not pro-
vide any facilities for accessing the properties of such characters. If
- you want to be able to use the pattern escapes \P, \p, and \X, which
+ you want to be able to use the pattern escapes \P, \p, and \X, which
refer to Unicode character properties, you must add
--enable-unicode-properties
- to the configure command. This implies UTF-8 support, even if you have
+ to the configure command. This implies UTF-8 support, even if you have
not explicitly requested it.
- Including Unicode property support adds around 90K of tables to the
- PCRE library, approximately doubling its size. Only the general cate-
- gory properties such as Lu and Nd are supported. Details are given in
- the pcrepattern documentation.
+ Including Unicode property support adds around 30K of tables to the
+ PCRE library. Only the general category properties such as Lu and Nd
+ are supported. Details are given in the pcrepattern documentation.
CODE VALUE OF NEWLINE
@@ -310,15 +354,33 @@ CODE VALUE OF NEWLINE
to the configure command. There is a fourth option, specified by
+ --enable-newline-is-anycrlf
+
+ which causes PCRE to recognize any of the three sequences CR, LF, or
+ CRLF as indicating a line ending. Finally, a fifth option, specified by
+
--enable-newline-is-any
- which causes PCRE to recognize any Unicode newline sequence.
+ causes PCRE to recognize any Unicode newline sequence.
Whatever line ending convention is selected when PCRE is built can be
overridden when the library functions are called. At build time it is
conventional to use the standard for your operating system.
+WHAT \R MATCHES
+
+ By default, the sequence \R in a pattern matches any Unicode newline
+ sequence, whatever has been selected as the line ending sequence. If
+ you specify
+
+ --enable-bsr-anycrlf
+
+ the default is changed so that \R matches only CR, LF, or CRLF. What-
+ ever is selected when PCRE is built can be overridden when the library
+ functions are called.
+
+
BUILDING SHARED AND STATIC LIBRARIES
The PCRE building process uses libtool to build both shared and static
@@ -364,86 +426,160 @@ HANDLING VERY LARGE PATTERNS
longer offsets slows down the operation of PCRE because it has to load
additional bytes when handling them.
- If you build PCRE with an increased link size, test 2 (and test 5 if
- you are using UTF-8) will fail. Part of the output of these tests is a
- representation of the compiled pattern, and this changes with the link
- size.
-
AVOIDING EXCESSIVE STACK USAGE
When matching with the pcre_exec() function, PCRE implements backtrack-
- ing by making recursive calls to an internal function called match().
- In environments where the size of the stack is limited, this can se-
- verely limit PCRE's operation. (The Unix environment does not usually
+ ing by making recursive calls to an internal function called match().
+ In environments where the size of the stack is limited, this can se-
+ verely limit PCRE's operation. (The Unix environment does not usually
suffer from this problem, but it may sometimes be necessary to increase
- the maximum stack size. There is a discussion in the pcrestack docu-
- mentation.) An alternative approach to recursion that uses memory from
- the heap to remember data, instead of using recursive function calls,
- has been implemented to work round the problem of limited stack size.
+ the maximum stack size. There is a discussion in the pcrestack docu-
+ mentation.) An alternative approach to recursion that uses memory from
+ the heap to remember data, instead of using recursive function calls,
+ has been implemented to work round the problem of limited stack size.
If you want to build a version of PCRE that works this way, add
--disable-stack-for-recursion
- to the configure command. With this configuration, PCRE will use the
- pcre_stack_malloc and pcre_stack_free variables to call memory manage-
- ment functions. Separate functions are provided because the usage is
- very predictable: the block sizes requested are always the same, and
- the blocks are always freed in reverse order. A calling program might
- be able to implement optimized functions that perform better than the
- standard malloc() and free() functions. PCRE runs noticeably more
- slowly when built in this way. This option affects only the pcre_exec()
- function; it is not relevant for the the pcre_dfa_exec() function.
+ to the configure command. With this configuration, PCRE will use the
+ pcre_stack_malloc and pcre_stack_free variables to call memory manage-
+ ment functions. By default these point to malloc() and free(), but you
+ can replace the pointers so that your own functions are used.
+
+ Separate functions are provided rather than using pcre_malloc and
+ pcre_free because the usage is very predictable: the block sizes
+ requested are always the same, and the blocks are always freed in
+ reverse order. A calling program might be able to implement optimized
+ functions that perform better than malloc() and free(). PCRE runs
+ noticeably more slowly when built in this way. This option affects only
+ the pcre_exec() function; it is not relevant for the the
+ pcre_dfa_exec() function.
LIMITING PCRE RESOURCE USAGE
- Internally, PCRE has a function called match(), which it calls repeat-
- edly (sometimes recursively) when matching a pattern with the
- pcre_exec() function. By controlling the maximum number of times this
- function may be called during a single matching operation, a limit can
- be placed on the resources used by a single call to pcre_exec(). The
- limit can be changed at run time, as described in the pcreapi documen-
- tation. The default is 10 million, but this can be changed by adding a
+ Internally, PCRE has a function called match(), which it calls repeat-
+ edly (sometimes recursively) when matching a pattern with the
+ pcre_exec() function. By controlling the maximum number of times this
+ function may be called during a single matching operation, a limit can
+ be placed on the resources used by a single call to pcre_exec(). The
+ limit can be changed at run time, as described in the pcreapi documen-
+ tation. The default is 10 million, but this can be changed by adding a
setting such as
--with-match-limit=500000
- to the configure command. This setting has no effect on the
+ to the configure command. This setting has no effect on the
pcre_dfa_exec() matching function.
- In some environments it is desirable to limit the depth of recursive
+ In some environments it is desirable to limit the depth of recursive
calls of match() more strictly than the total number of calls, in order
- to restrict the maximum amount of stack (or heap, if --disable-stack-
+ to restrict the maximum amount of stack (or heap, if --disable-stack-
for-recursion is specified) that is used. A second limit controls this;
- it defaults to the value that is set for --with-match-limit, which
- imposes no additional constraints. However, you can set a lower limit
+ it defaults to the value that is set for --with-match-limit, which
+ imposes no additional constraints. However, you can set a lower limit
by adding, for example,
--with-match-limit-recursion=10000
- to the configure command. This value can also be overridden at run
+ to the configure command. This value can also be overridden at run
time.
+CREATING CHARACTER TABLES AT BUILD TIME
+
+ PCRE uses fixed tables for processing characters whose code values are
+ less than 256. By default, PCRE is built with a set of tables that are
+ distributed in the file pcre_chartables.c.dist. These tables are for
+ ASCII codes only. If you add
+
+ --enable-rebuild-chartables
+
+ to the configure command, the distributed tables are no longer used.
+ Instead, a program called dftables is compiled and run. This outputs
+ the source for new set of tables, created in the default locale of your
+ C runtime system. (This method of replacing the tables does not work if
+ you are cross compiling, because dftables is run on the local host. If
+ you need to create alternative tables when cross compiling, you will
+ have to do so "by hand".)
+
+
USING EBCDIC CODE
PCRE assumes by default that it will run in an environment where the
character code is ASCII (or Unicode, which is a superset of ASCII).
- PCRE can, however, be compiled to run in an EBCDIC environment by
- adding
+ This is the case for most computer operating systems. PCRE can, how-
+ ever, be compiled to run in an EBCDIC environment by adding
--enable-ebcdic
- to the configure command.
+ to the configure command. This setting implies --enable-rebuild-charta-
+ bles. You should only use it if you know that you are in an EBCDIC
+ environment (for example, an IBM mainframe operating system).
+
+
+PCREGREP OPTIONS FOR COMPRESSED FILE SUPPORT
+
+ By default, pcregrep reads all files as plain text. You can build it so
+ that it recognizes files whose names end in .gz or .bz2, and reads them
+ with libz or libbz2, respectively, by adding one or both of
+
+ --enable-pcregrep-libz
+ --enable-pcregrep-libbz2
+
+ to the configure command. These options naturally require that the rel-
+ evant libraries are installed on your system. Configuration will fail
+ if they are not.
+
+
+PCRETEST OPTION FOR LIBREADLINE SUPPORT
+
+ If you add
+
+ --enable-pcretest-libreadline
+
+ to the configure command, pcretest is linked with the libreadline
+ library, and when its input is from a terminal, it reads it using the
+ readline() function. This provides line-editing and history facilities.
+ Note that libreadline is GPL-licenced, so if you distribute a binary of
+ pcretest linked in this way, there may be licensing issues.
+
+ Setting this option causes the -lreadline option to be added to the
+ pcretest build. In many operating environments with a sytem-installed
+ libreadline this is sufficient. However, in some environments (e.g. if
+ an unmodified distribution version of readline is in use), some extra
+ configuration may be necessary. The INSTALL file for libreadline says
+ this:
+
+ "Readline uses the termcap functions, but does not link with the
+ termcap or curses library itself, allowing applications which link
+ with readline the to choose an appropriate library."
+
+ If your environment has not been set up so that an appropriate library
+ is automatically included, you may need to add something like
+
+ LIBS="-ncurses"
+
+ immediately before the configure command.
SEE ALSO
pcreapi(3), pcre_config(3).
-Last updated: 30 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 13 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -495,8 +631,8 @@ REGULAR EXPRESSIONS AS TREES
THE STANDARD MATCHING ALGORITHM
- In the terminology of Jeffrey Friedl's book Mastering Regular Expres-
- sions, the standard algorithm is an "NFA algorithm". It conducts a
+ In the terminology of Jeffrey Friedl's book "Mastering Regular Expres-
+ sions", the standard algorithm is an "NFA algorithm". It conducts a
depth-first search of the pattern tree. That is, it proceeds along a
single path through the tree, checking that the subject matches what is
required. When there is a mismatch, the algorithm tries any alterna-
@@ -578,34 +714,43 @@ THE ALTERNATIVE MATCHING ALGORITHM
ence as the condition or test for a specific group recursion are not
supported.
- 5. Callouts are supported, but the value of the capture_top field is
+ 5. Because many paths through the tree may be active, the \K escape
+ sequence, which resets the start of the match when encountered (but may
+ be on some paths and not on others), is not supported. It causes an
+ error if encountered.
+
+ 6. Callouts are supported, but the value of the capture_top field is
always 1, and the value of the capture_last field is always -1.
- 6. The \C escape sequence, which (in the standard algorithm) matches a
- single byte, even in UTF-8 mode, is not supported because the alterna-
- tive algorithm moves through the subject string one character at a
+ 7. The \C escape sequence, which (in the standard algorithm) matches a
+ single byte, even in UTF-8 mode, is not supported because the alterna-
+ tive algorithm moves through the subject string one character at a
time, for all active paths through the tree.
+ 8. Except for (*FAIL), the backtracking control verbs such as (*PRUNE)
+ are not supported. (*FAIL) is supported, and behaves like a failing
+ negative assertion.
+
ADVANTAGES OF THE ALTERNATIVE ALGORITHM
- Using the alternative matching algorithm provides the following advan-
+ Using the alternative matching algorithm provides the following advan-
tages:
1. All possible matches (at a single point in the subject) are automat-
- ically found, and in particular, the longest match is found. To find
+ ically found, and in particular, the longest match is found. To find
more than one match using the standard algorithm, you have to do kludgy
things with callouts.
- 2. There is much better support for partial matching. The restrictions
- on the content of the pattern that apply when using the standard algo-
- rithm for partial matching do not apply to the alternative algorithm.
- For non-anchored patterns, the starting position of a partial match is
+ 2. There is much better support for partial matching. The restrictions
+ on the content of the pattern that apply when using the standard algo-
+ rithm for partial matching do not apply to the alternative algorithm.
+ For non-anchored patterns, the starting position of a partial match is
available.
- 3. Because the alternative algorithm scans the subject string just
- once, and never needs to backtrack, it is possible to pass very long
- subject strings to the matching function in several pieces, checking
+ 3. Because the alternative algorithm scans the subject string just
+ once, and never needs to backtrack, it is possible to pass very long
+ subject strings to the matching function in several pieces, checking
for partial matching each time.
@@ -613,8 +758,8 @@ DISADVANTAGES OF THE ALTERNATIVE ALGORITHM
The alternative algorithm suffers from a number of disadvantages:
- 1. It is substantially slower than the standard algorithm. This is
- partly because it has to search for all possible matches, but is also
+ 1. It is substantially slower than the standard algorithm. This is
+ partly because it has to search for all possible matches, but is also
because it is less susceptible to optimization.
2. Capturing parentheses and back references are not supported.
@@ -622,8 +767,18 @@ DISADVANTAGES OF THE ALTERNATIVE ALGORITHM
3. Although atomic groups are supported, their use does not provide the
performance advantage that it does for the standard algorithm.
-Last updated: 24 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 19 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -735,7 +890,7 @@ PCRE API OVERVIEW
a Perl-compatible manner. A sample program that demonstrates the sim-
plest way of using them is provided in the file called pcredemo.c in
the source distribution. The pcresample documentation describes how to
- run it.
+ compile and run it.
A second matching function, pcre_dfa_exec(), which is not Perl-compati-
ble, is also provided. This uses a different algorithm for the match-
@@ -805,13 +960,13 @@ PCRE API OVERVIEW
NEWLINES
- PCRE supports four different conventions for indicating line breaks in
+ PCRE supports five different conventions for indicating line breaks in
strings: a single CR (carriage return) character, a single LF (line-
- feed) character, the two-character sequence CRLF, or any Unicode new-
- line sequence. The Unicode newline sequences are the three just men-
- tioned, plus the single characters VT (vertical tab, U+000B), FF (form-
- feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028),
- and PS (paragraph separator, U+2029).
+ feed) character, the two-character sequence CRLF, any of the three pre-
+ ceding, or any Unicode newline sequence. The Unicode newline sequences
+ are the three just mentioned, plus the single characters VT (vertical
+ tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085), LS (line
+ separator, U+2028), and PS (paragraph separator, U+2029).
Each of the first three conventions is used by at least one operating
system as its standard newline sequence. When PCRE is built, a default
@@ -819,23 +974,32 @@ NEWLINES
dard. When PCRE is run, the default can be overridden, either when a
pattern is compiled, or when it is matched.
+ At compile time, the newline convention can be specified by the options
+ argument of pcre_compile(), or it can be specified by special text at
+ the start of the pattern itself; this overrides any other settings. See
+ the pcrepattern page for details of the special character sequences.
+
In the PCRE documentation the word "newline" is used to mean "the char-
- acter or pair of characters that indicate a line break". The choice of
- newline convention affects the handling of the dot, circumflex, and
+ acter or pair of characters that indicate a line break". The choice of
+ newline convention affects the handling of the dot, circumflex, and
dollar metacharacters, the handling of #-comments in /x mode, and, when
- CRLF is a recognized line ending sequence, the match position advance-
- ment for a non-anchored pattern. The choice of newline convention does
- not affect the interpretation of the \n or \r escape sequences.
+ CRLF is a recognized line ending sequence, the match position advance-
+ ment for a non-anchored pattern. There is more detail about this in the
+ section on pcre_exec() options below.
+
+ The choice of newline convention does not affect the interpretation of
+ the \n or \r escape sequences, nor does it affect what \R matches,
+ which is controlled in a similar way, but by separate options.
MULTITHREADING
- The PCRE functions can be used in multi-threading applications, with
+ The PCRE functions can be used in multi-threading applications, with
the proviso that the memory management functions pointed to by
pcre_malloc, pcre_free, pcre_stack_malloc, and pcre_stack_free, and the
callout function pointed to by pcre_callout, are shared by all threads.
- The compiled form of a regular expression is not altered during match-
+ The compiled form of a regular expression is not altered during match-
ing, so the same compiled pattern can safely be used by several threads
at once.
@@ -843,78 +1007,88 @@ MULTITHREADING
SAVING PRECOMPILED PATTERNS FOR LATER USE
The compiled form of a regular expression can be saved and re-used at a
- later time, possibly by a different program, and even on a host other
- than the one on which it was compiled. Details are given in the
- pcreprecompile documentation.
+ later time, possibly by a different program, and even on a host other
+ than the one on which it was compiled. Details are given in the
+ pcreprecompile documentation. However, compiling a regular expression
+ with one version of PCRE for use with a different version is not guar-
+ anteed to work and may cause crashes.
CHECKING BUILD-TIME OPTIONS
int pcre_config(int what, void *where);
- The function pcre_config() makes it possible for a PCRE client to dis-
+ The function pcre_config() makes it possible for a PCRE client to dis-
cover which optional features have been compiled into the PCRE library.
- The pcrebuild documentation has more details about these optional fea-
+ The pcrebuild documentation has more details about these optional fea-
tures.
- The first argument for pcre_config() is an integer, specifying which
+ The first argument for pcre_config() is an integer, specifying which
information is required; the second argument is a pointer to a variable
- into which the information is placed. The following information is
+ into which the information is placed. The following information is
available:
PCRE_CONFIG_UTF8
- The output is an integer that is set to one if UTF-8 support is avail-
+ The output is an integer that is set to one if UTF-8 support is avail-
able; otherwise it is set to zero.
PCRE_CONFIG_UNICODE_PROPERTIES
- The output is an integer that is set to one if support for Unicode
+ The output is an integer that is set to one if support for Unicode
character properties is available; otherwise it is set to zero.
PCRE_CONFIG_NEWLINE
- The output is an integer whose value specifies the default character
- sequence that is recognized as meaning "newline". The four values that
- are supported are: 10 for LF, 13 for CR, 3338 for CRLF, and -1 for ANY.
- The default should normally be the standard sequence for your operating
- system.
+ The output is an integer whose value specifies the default character
+ sequence that is recognized as meaning "newline". The four values that
+ are supported are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF,
+ and -1 for ANY. The default should normally be the standard sequence
+ for your operating system.
+
+ PCRE_CONFIG_BSR
+
+ The output is an integer whose value indicates what character sequences
+ the \R escape sequence matches by default. A value of 0 means that \R
+ matches any Unicode line ending sequence; a value of 1 means that \R
+ matches only CR, LF, or CRLF. The default can be overridden when a pat-
+ tern is compiled or matched.
PCRE_CONFIG_LINK_SIZE
- The output is an integer that contains the number of bytes used for
+ The output is an integer that contains the number of bytes used for
internal linkage in compiled regular expressions. The value is 2, 3, or
- 4. Larger values allow larger regular expressions to be compiled, at
- the expense of slower matching. The default value of 2 is sufficient
- for all but the most massive patterns, since it allows the compiled
+ 4. Larger values allow larger regular expressions to be compiled, at
+ the expense of slower matching. The default value of 2 is sufficient
+ for all but the most massive patterns, since it allows the compiled
pattern to be up to 64K in size.
PCRE_CONFIG_POSIX_MALLOC_THRESHOLD
- The output is an integer that contains the threshold above which the
- POSIX interface uses malloc() for output vectors. Further details are
+ The output is an integer that contains the threshold above which the
+ POSIX interface uses malloc() for output vectors. Further details are
given in the pcreposix documentation.
PCRE_CONFIG_MATCH_LIMIT
The output is an integer that gives the default limit for the number of
- internal matching function calls in a pcre_exec() execution. Further
+ internal matching function calls in a pcre_exec() execution. Further
details are given with pcre_exec() below.
PCRE_CONFIG_MATCH_LIMIT_RECURSION
- The output is an integer that gives the default limit for the depth of
- recursion when calling the internal matching function in a pcre_exec()
+ The output is an integer that gives the default limit for the depth of
+ recursion when calling the internal matching function in a pcre_exec()
execution. Further details are given with pcre_exec() below.
PCRE_CONFIG_STACKRECURSE
- The output is an integer that is set to one if internal recursion when
+ The output is an integer that is set to one if internal recursion when
running pcre_exec() is implemented by recursive function calls that use
- the stack to remember their state. This is the usual way that PCRE is
+ the stack to remember their state. This is the usual way that PCRE is
compiled. The output is zero if PCRE was compiled to use blocks of data
- on the heap instead of recursive function calls. In this case,
- pcre_stack_malloc and pcre_stack_free are called to manage memory
+ on the heap instead of recursive function calls. In this case,
+ pcre_stack_malloc and pcre_stack_free are called to manage memory
blocks on the heap, thus avoiding the use of the stack.
@@ -931,55 +1105,55 @@ COMPILING A PATTERN
Either of the functions pcre_compile() or pcre_compile2() can be called
to compile a pattern into an internal form. The only difference between
- the two interfaces is that pcre_compile2() has an additional argument,
+ the two interfaces is that pcre_compile2() has an additional argument,
errorcodeptr, via which a numerical error code can be returned.
The pattern is a C string terminated by a binary zero, and is passed in
- the pattern argument. A pointer to a single block of memory that is
- obtained via pcre_malloc is returned. This contains the compiled code
+ the pattern argument. A pointer to a single block of memory that is
+ obtained via pcre_malloc is returned. This contains the compiled code
and related data. The pcre type is defined for the returned block; this
is a typedef for a structure whose contents are not externally defined.
It is up to the caller to free the memory (via pcre_free) when it is no
longer required.
- Although the compiled code of a PCRE regex is relocatable, that is, it
+ Although the compiled code of a PCRE regex is relocatable, that is, it
does not depend on memory location, the complete pcre data block is not
- fully relocatable, because it may contain a copy of the tableptr argu-
+ fully relocatable, because it may contain a copy of the tableptr argu-
ment, which is an address (see below).
The options argument contains various bit settings that affect the com-
- pilation. It should be zero if no options are required. The available
- options are described below. Some of them, in particular, those that
- are compatible with Perl, can also be set and unset from within the
- pattern (see the detailed description in the pcrepattern documenta-
- tion). For these options, the contents of the options argument speci-
- fies their initial settings at the start of compilation and execution.
- The PCRE_ANCHORED and PCRE_NEWLINE_xxx options can be set at the time
+ pilation. It should be zero if no options are required. The available
+ options are described below. Some of them, in particular, those that
+ are compatible with Perl, can also be set and unset from within the
+ pattern (see the detailed description in the pcrepattern documenta-
+ tion). For these options, the contents of the options argument speci-
+ fies their initial settings at the start of compilation and execution.
+ The PCRE_ANCHORED and PCRE_NEWLINE_xxx options can be set at the time
of matching as well as at compile time.
If errptr is NULL, pcre_compile() returns NULL immediately. Otherwise,
- if compilation of a pattern fails, pcre_compile() returns NULL, and
+ if compilation of a pattern fails, pcre_compile() returns NULL, and
sets the variable pointed to by errptr to point to a textual error mes-
sage. This is a static string that is part of the library. You must not
try to free it. The offset from the start of the pattern to the charac-
ter where the error was discovered is placed in the variable pointed to
- by erroffset, which must not be NULL. If it is, an immediate error is
+ by erroffset, which must not be NULL. If it is, an immediate error is
given.
- If pcre_compile2() is used instead of pcre_compile(), and the error-
- codeptr argument is not NULL, a non-zero error code number is returned
- via this argument in the event of an error. This is in addition to the
+ If pcre_compile2() is used instead of pcre_compile(), and the error-
+ codeptr argument is not NULL, a non-zero error code number is returned
+ via this argument in the event of an error. This is in addition to the
textual error message. Error codes and messages are listed below.
- If the final argument, tableptr, is NULL, PCRE uses a default set of
- character tables that are built when PCRE is compiled, using the
- default C locale. Otherwise, tableptr must be an address that is the
- result of a call to pcre_maketables(). This value is stored with the
- compiled pattern, and used again by pcre_exec(), unless another table
+ If the final argument, tableptr, is NULL, PCRE uses a default set of
+ character tables that are built when PCRE is compiled, using the
+ default C locale. Otherwise, tableptr must be an address that is the
+ result of a call to pcre_maketables(). This value is stored with the
+ compiled pattern, and used again by pcre_exec(), unless another table
pointer is passed to it. For more discussion, see the section on locale
support below.
- This code fragment shows a typical straightforward call to pcre_com-
+ This code fragment shows a typical straightforward call to pcre_com-
pile():
pcre *re;
@@ -992,96 +1166,122 @@ COMPILING A PATTERN
&erroffset, /* for error offset */
NULL); /* use default character tables */
- The following names for option bits are defined in the pcre.h header
+ The following names for option bits are defined in the pcre.h header
file:
PCRE_ANCHORED
If this bit is set, the pattern is forced to be "anchored", that is, it
- is constrained to match only at the first matching point in the string
- that is being searched (the "subject string"). This effect can also be
- achieved by appropriate constructs in the pattern itself, which is the
+ is constrained to match only at the first matching point in the string
+ that is being searched (the "subject string"). This effect can also be
+ achieved by appropriate constructs in the pattern itself, which is the
only way to do it in Perl.
PCRE_AUTO_CALLOUT
If this bit is set, pcre_compile() automatically inserts callout items,
- all with number 255, before each pattern item. For discussion of the
+ all with number 255, before each pattern item. For discussion of the
callout facility, see the pcrecallout documentation.
+ PCRE_BSR_ANYCRLF
+ PCRE_BSR_UNICODE
+
+ These options (which are mutually exclusive) control what the \R escape
+ sequence matches. The choice is either to match only CR, LF, or CRLF,
+ or to match any Unicode newline sequence. The default is specified when
+ PCRE is built. It can be overridden from within the pattern, or by set-
+ ting an option when a compiled pattern is matched.
+
PCRE_CASELESS
- If this bit is set, letters in the pattern match both upper and lower
- case letters. It is equivalent to Perl's /i option, and it can be
- changed within a pattern by a (?i) option setting. In UTF-8 mode, PCRE
- always understands the concept of case for characters whose values are
- less than 128, so caseless matching is always possible. For characters
- with higher values, the concept of case is supported if PCRE is com-
- piled with Unicode property support, but not otherwise. If you want to
- use caseless matching for characters 128 and above, you must ensure
- that PCRE is compiled with Unicode property support as well as with
+ If this bit is set, letters in the pattern match both upper and lower
+ case letters. It is equivalent to Perl's /i option, and it can be
+ changed within a pattern by a (?i) option setting. In UTF-8 mode, PCRE
+ always understands the concept of case for characters whose values are
+ less than 128, so caseless matching is always possible. For characters
+ with higher values, the concept of case is supported if PCRE is com-
+ piled with Unicode property support, but not otherwise. If you want to
+ use caseless matching for characters 128 and above, you must ensure
+ that PCRE is compiled with Unicode property support as well as with
UTF-8 support.
PCRE_DOLLAR_ENDONLY
- If this bit is set, a dollar metacharacter in the pattern matches only
- at the end of the subject string. Without this option, a dollar also
- matches immediately before a newline at the end of the string (but not
- before any other newlines). The PCRE_DOLLAR_ENDONLY option is ignored
- if PCRE_MULTILINE is set. There is no equivalent to this option in
+ If this bit is set, a dollar metacharacter in the pattern matches only
+ at the end of the subject string. Without this option, a dollar also
+ matches immediately before a newline at the end of the string (but not
+ before any other newlines). The PCRE_DOLLAR_ENDONLY option is ignored
+ if PCRE_MULTILINE is set. There is no equivalent to this option in
Perl, and no way to set it within a pattern.
PCRE_DOTALL
If this bit is set, a dot metacharater in the pattern matches all char-
- acters, including those that indicate newline. Without it, a dot does
- not match when the current position is at a newline. This option is
- equivalent to Perl's /s option, and it can be changed within a pattern
- by a (?s) option setting. A negative class such as [^a] always matches
+ acters, including those that indicate newline. Without it, a dot does
+ not match when the current position is at a newline. This option is
+ equivalent to Perl's /s option, and it can be changed within a pattern
+ by a (?s) option setting. A negative class such as [^a] always matches
newline characters, independent of the setting of this option.
PCRE_DUPNAMES
- If this bit is set, names used to identify capturing subpatterns need
+ If this bit is set, names used to identify capturing subpatterns need
not be unique. This can be helpful for certain types of pattern when it
- is known that only one instance of the named subpattern can ever be
- matched. There are more details of named subpatterns below; see also
+ is known that only one instance of the named subpattern can ever be
+ matched. There are more details of named subpatterns below; see also
the pcrepattern documentation.
PCRE_EXTENDED
- If this bit is set, whitespace data characters in the pattern are
+ If this bit is set, whitespace data characters in the pattern are
totally ignored except when escaped or inside a character class. White-
space does not include the VT character (code 11). In addition, charac-
ters between an unescaped # outside a character class and the next new-
- line, inclusive, are also ignored. This is equivalent to Perl's /x
- option, and it can be changed within a pattern by a (?x) option set-
+ line, inclusive, are also ignored. This is equivalent to Perl's /x
+ option, and it can be changed within a pattern by a (?x) option set-
ting.
- This option makes it possible to include comments inside complicated
- patterns. Note, however, that this applies only to data characters.
- Whitespace characters may never appear within special character
- sequences in a pattern, for example within the sequence (?( which
+ This option makes it possible to include comments inside complicated
+ patterns. Note, however, that this applies only to data characters.
+ Whitespace characters may never appear within special character
+ sequences in a pattern, for example within the sequence (?( which
introduces a conditional subpattern.
PCRE_EXTRA
- This option was invented in order to turn on additional functionality
- of PCRE that is incompatible with Perl, but it is currently of very
- little use. When set, any backslash in a pattern that is followed by a
- letter that has no special meaning causes an error, thus reserving
- these combinations for future expansion. By default, as in Perl, a
- backslash followed by a letter with no special meaning is treated as a
- literal. (Perl can, however, be persuaded to give a warning for this.)
- There are at present no other features controlled by this option. It
+ This option was invented in order to turn on additional functionality
+ of PCRE that is incompatible with Perl, but it is currently of very
+ little use. When set, any backslash in a pattern that is followed by a
+ letter that has no special meaning causes an error, thus reserving
+ these combinations for future expansion. By default, as in Perl, a
+ backslash followed by a letter with no special meaning is treated as a
+ literal. (Perl can, however, be persuaded to give a warning for this.)
+ There are at present no other features controlled by this option. It
can also be set by a (?X) option setting within a pattern.
PCRE_FIRSTLINE
- If this option is set, an unanchored pattern is required to match
- before or at the first newline in the subject string, though the
+ If this option is set, an unanchored pattern is required to match
+ before or at the first newline in the subject string, though the
matched text may continue over the newline.
+ PCRE_JAVASCRIPT_COMPAT
+
+ If this option is set, PCRE's behaviour is changed in some ways so that
+ it is compatible with JavaScript rather than Perl. The changes are as
+ follows:
+
+ (1) A lone closing square bracket in a pattern causes a compile-time
+ error, because this is illegal in JavaScript (by default it is treated
+ as a data character). Thus, the pattern AB]CD becomes illegal when this
+ option is set.
+
+ (2) At run time, a back reference to an unset subpattern group matches
+ an empty string (by default this causes the current matching alterna-
+ tive to fail). A pattern such as (\1)(a) succeeds when this option is
+ set (assuming it can find an "a" in the subject), whereas it fails by
+ default, for Perl compatibility.
+
PCRE_MULTILINE
By default, PCRE treats the subject string as consisting of a single
@@ -1102,26 +1302,29 @@ COMPILING A PATTERN
PCRE_NEWLINE_CR
PCRE_NEWLINE_LF
PCRE_NEWLINE_CRLF
+ PCRE_NEWLINE_ANYCRLF
PCRE_NEWLINE_ANY
These options override the default newline definition that was chosen
when PCRE was built. Setting the first or the second specifies that a
newline is indicated by a single character (CR or LF, respectively).
Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by the
- two-character CRLF sequence. Setting PCRE_NEWLINE_ANY specifies that
- any Unicode newline sequence should be recognized. The Unicode newline
- sequences are the three just mentioned, plus the single characters VT
- (vertical tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085),
- LS (line separator, U+2028), and PS (paragraph separator, U+2029). The
- last two are recognized only in UTF-8 mode.
+ two-character CRLF sequence. Setting PCRE_NEWLINE_ANYCRLF specifies
+ that any of the three preceding sequences should be recognized. Setting
+ PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should be
+ recognized. The Unicode newline sequences are the three just mentioned,
+ plus the single characters VT (vertical tab, U+000B), FF (formfeed,
+ U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
+ (paragraph separator, U+2029). The last two are recognized only in
+ UTF-8 mode.
The newline setting in the options word uses three bits that are
- treated as a number, giving eight possibilities. Currently only five
- are used (default plus the four values above). This means that if you
- set more than one newline option, the combination may or may not be
- sensible. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equiva-
- lent to PCRE_NEWLINE_CRLF, but other combinations yield unused numbers
- and cause an error.
+ treated as a number, giving eight possibilities. Currently only six are
+ used (default plus the five values above). This means that if you set
+ more than one newline option, the combination may or may not be sensi-
+ ble. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to
+ PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers and
+ cause an error.
The only time that a line break is specially recognized when compiling
a pattern is if PCRE_EXTENDED is set, and an unescaped # outside a
@@ -1161,21 +1364,22 @@ COMPILING A PATTERN
PCRE_NO_UTF8_CHECK
When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is
- automatically checked. If an invalid UTF-8 sequence of bytes is found,
- pcre_compile() returns an error. If you already know that your pattern
- is valid, and you want to skip this check for performance reasons, you
- can set the PCRE_NO_UTF8_CHECK option. When it is set, the effect of
- passing an invalid UTF-8 string as a pattern is undefined. It may cause
- your program to crash. Note that this option can also be passed to
- pcre_exec() and pcre_dfa_exec(), to suppress the UTF-8 validity check-
- ing of subject strings.
+ automatically checked. There is a discussion about the validity of
+ UTF-8 strings in the main pcre page. If an invalid UTF-8 sequence of
+ bytes is found, pcre_compile() returns an error. If you already know
+ that your pattern is valid, and you want to skip this check for perfor-
+ mance reasons, you can set the PCRE_NO_UTF8_CHECK option. When it is
+ set, the effect of passing an invalid UTF-8 string as a pattern is
+ undefined. It may cause your program to crash. Note that this option
+ can also be passed to pcre_exec() and pcre_dfa_exec(), to suppress the
+ UTF-8 validity checking of subject strings.
COMPILATION ERROR CODES
- The following table lists the error codes than may be returned by
- pcre_compile2(), along with the error messages that may be returned by
- both compiling functions. As PCRE has developed, some error codes have
+ The following table lists the error codes than may be returned by
+ pcre_compile2(), along with the error messages that may be returned by
+ both compiling functions. As PCRE has developed, some error codes have
fallen out of use. To avoid confusion, they have not been re-used.
0 no error
@@ -1190,7 +1394,7 @@ COMPILATION ERROR CODES
9 nothing to repeat
10 [this code is not in use]
11 internal error: unexpected repeat
- 12 unrecognized character after (?
+ 12 unrecognized character after (? or (?-
13 POSIX named classes are supported only within a class
14 missing )
15 reference to non-existent subpattern
@@ -1198,7 +1402,7 @@ COMPILATION ERROR CODES
17 unknown option bit(s) set
18 missing ) after comment
19 [this code is not in use]
- 20 regular expression too large
+ 20 regular expression is too large
21 failed to get memory
22 unmatched parentheses
23 internal error: code overflow
@@ -1207,7 +1411,7 @@ COMPILATION ERROR CODES
26 malformed number or name after (?(
27 conditional group contains more than two branches
28 assertion expected after (?(
- 29 (?R or (?digits must be followed by )
+ 29 (?R or (?[+-]digits must be followed by )
30 unknown POSIX class name
31 POSIX collating elements are not supported
32 this version of PCRE is not compiled with PCRE_UTF8 support
@@ -1227,15 +1431,27 @@ COMPILATION ERROR CODES
46 malformed \P or \p sequence
47 unknown property name after \P or \p
48 subpattern name is too long (maximum 32 characters)
- 49 too many named subpatterns (maximum 10,000)
- 50 repeated subpattern is too long
+ 49 too many named subpatterns (maximum 10000)
+ 50 [this code is not in use]
51 octal value is greater than \377 (not in UTF-8 mode)
52 internal error: overran compiling workspace
- 53 internal error: previously-checked referenced subpattern not
+ 53 internal error: previously-checked referenced subpattern not
found
54 DEFINE group contains more than one branch
55 repeating a DEFINE group is not allowed
- 56 inconsistent NEWLINE options"
+ 56 inconsistent NEWLINE options
+ 57 \g is not followed by a braced, angle-bracketed, or quoted
+ name/number or by a plain number
+ 58 a numbered reference must not be zero
+ 59 (*VERB) with an argument is not supported
+ 60 (*VERB) not recognized
+ 61 number is too big
+ 62 subpattern name expected
+ 63 digit expected after (?+
+ 64 ] is an invalid data character in JavaScript compatibility mode
+
+ The numbers 32 and 10000 in errors 48 and 49 are defaults; different
+ values may be used if the limits were changed when PCRE was built.
STUDYING A PATTERN
@@ -1287,31 +1503,41 @@ STUDYING A PATTERN
LOCALE SUPPORT
PCRE handles caseless matching, and determines whether characters are
- letters digits, or whatever, by reference to a set of tables, indexed
+ letters, digits, or whatever, by reference to a set of tables, indexed
by character value. When running in UTF-8 mode, this applies only to
characters with codes less than 128. Higher-valued codes never match
escapes such as \w or \d, but can be tested with \p if PCRE is built
with Unicode character property support. The use of locales with Uni-
- code is discouraged.
-
- An internal set of tables is created in the default C locale when PCRE
- is built. This is used when the final argument of pcre_compile() is
- NULL, and is sufficient for many applications. An alternative set of
- tables can, however, be supplied. These may be created in a different
- locale from the default. As more and more applications change to using
- Unicode, the need for this locale support is expected to die away.
-
- External tables are built by calling the pcre_maketables() function,
- which has no arguments, in the relevant locale. The result can then be
- passed to pcre_compile() or pcre_exec() as often as necessary. For
- example, to build and use tables that are appropriate for the French
- locale (where accented characters with values greater than 128 are
+ code is discouraged. If you are handling characters with codes greater
+ than 128, you should either use UTF-8 and Unicode, or use locales, but
+ not try to mix the two.
+
+ PCRE contains an internal set of tables that are used when the final
+ argument of pcre_compile() is NULL. These are sufficient for many
+ applications. Normally, the internal tables recognize only ASCII char-
+ acters. However, when PCRE is built, it is possible to cause the inter-
+ nal tables to be rebuilt in the default "C" locale of the local system,
+ which may cause them to be different.
+
+ The internal tables can always be overridden by tables supplied by the
+ application that calls PCRE. These may be created in a different locale
+ from the default. As more and more applications change to using Uni-
+ code, the need for this locale support is expected to die away.
+
+ External tables are built by calling the pcre_maketables() function,
+ which has no arguments, in the relevant locale. The result can then be
+ passed to pcre_compile() or pcre_exec() as often as necessary. For
+ example, to build and use tables that are appropriate for the French
+ locale (where accented characters with values greater than 128 are
treated as letters), the following code could be used:
setlocale(LC_CTYPE, "fr_FR");
tables = pcre_maketables();
re = pcre_compile(..., tables);
+ The locale name "fr_FR" is used on Linux and other Unix-like systems;
+ if you are using Windows, the name for the French locale is "french".
+
When pcre_maketables() runs, the tables are built in memory that is
obtained via pcre_malloc. It is the caller's responsibility to ensure
that the memory containing the tables remains available for as long as
@@ -1414,13 +1640,26 @@ INFORMATION ABOUT A PATTERN
returned. The fourth argument should point to an unsigned char * vari-
able.
+ PCRE_INFO_HASCRORLF
+
+ Return 1 if the pattern contains any explicit matches for CR or LF
+ characters, otherwise 0. The fourth argument should point to an int
+ variable. An explicit match is either a literal CR or LF character, or
+ \r or \n.
+
+ PCRE_INFO_JCHANGED
+
+ Return 1 if the (?J) or (?-J) option setting is used in the pattern,
+ otherwise 0. The fourth argument should point to an int variable. (?J)
+ and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
+
PCRE_INFO_LASTLITERAL
- Return the value of the rightmost literal byte that must exist in any
- matched string, other than at its start, if such a byte has been
+ Return the value of the rightmost literal byte that must exist in any
+ matched string, other than at its start, if such a byte has been
recorded. The fourth argument should point to an int variable. If there
- is no such byte, -1 is returned. For anchored patterns, a last literal
- byte is recorded only if it follows something of variable length. For
+ is no such byte, -1 is returned. For anchored patterns, a last literal
+ byte is recorded only if it follows something of variable length. For
example, for the pattern /^a\d+z\d+/ the returned value is "z", but for
/^a\dz\d/ the returned value is -1.
@@ -1428,34 +1667,34 @@ INFORMATION ABOUT A PATTERN
PCRE_INFO_NAMEENTRYSIZE
PCRE_INFO_NAMETABLE
- PCRE supports the use of named as well as numbered capturing parenthe-
- ses. The names are just an additional way of identifying the parenthe-
+ PCRE supports the use of named as well as numbered capturing parenthe-
+ ses. The names are just an additional way of identifying the parenthe-
ses, which still acquire numbers. Several convenience functions such as
- pcre_get_named_substring() are provided for extracting captured sub-
- strings by name. It is also possible to extract the data directly, by
- first converting the name to a number in order to access the correct
+ pcre_get_named_substring() are provided for extracting captured sub-
+ strings by name. It is also possible to extract the data directly, by
+ first converting the name to a number in order to access the correct
pointers in the output vector (described with pcre_exec() below). To do
- the conversion, you need to use the name-to-number map, which is
+ the conversion, you need to use the name-to-number map, which is
described by these three values.
The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT
gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size
- of each entry; both of these return an int value. The entry size
- depends on the length of the longest name. PCRE_INFO_NAMETABLE returns
- a pointer to the first entry of the table (a pointer to char). The
+ of each entry; both of these return an int value. The entry size
+ depends on the length of the longest name. PCRE_INFO_NAMETABLE returns
+ a pointer to the first entry of the table (a pointer to char). The
first two bytes of each entry are the number of the capturing parenthe-
- sis, most significant byte first. The rest of the entry is the corre-
- sponding name, zero terminated. The names are in alphabetical order.
+ sis, most significant byte first. The rest of the entry is the corre-
+ sponding name, zero terminated. The names are in alphabetical order.
When PCRE_DUPNAMES is set, duplicate names are in order of their paren-
- theses numbers. For example, consider the following pattern (assume
- PCRE_EXTENDED is set, so white space - including newlines - is
+ theses numbers. For example, consider the following pattern (assume
+ PCRE_EXTENDED is set, so white space - including newlines - is
ignored):
(?<date> (?<year>(\d\d)?\d\d) -
(?<month>\d\d) - (?<day>\d\d) )
- There are four named subpatterns, so the table has four entries, and
- each entry in the table is eight bytes long. The table is as follows,
+ There are four named subpatterns, so the table has four entries, and
+ each entry in the table is eight bytes long. The table is as follows,
with non-printing bytes shows in hexadecimal, and undefined bytes shown
as ??:
@@ -1464,16 +1703,27 @@ INFORMATION ABOUT A PATTERN
00 04 m o n t h 00
00 02 y e a r 00 ??
- When writing code to extract data from named subpatterns using the
- name-to-number map, remember that the length of the entries is likely
+ When writing code to extract data from named subpatterns using the
+ name-to-number map, remember that the length of the entries is likely
to be different for each compiled pattern.
+ PCRE_INFO_OKPARTIAL
+
+ Return 1 if the pattern can be used for partial matching, otherwise 0.
+ The fourth argument should point to an int variable. The pcrepartial
+ documentation lists the restrictions that apply to patterns when par-
+ tial matching is used.
+
PCRE_INFO_OPTIONS
Return a copy of the options with which the pattern was compiled. The
fourth argument should point to an unsigned long int variable. These
option bits are those specified in the call to pcre_compile(), modified
- by any top-level option settings within the pattern itself.
+ by any top-level option settings at the start of the pattern itself. In
+ other words, they are the options that will be in force when matching
+ starts. For example, if the pattern /(?im)abc(?-i)d/ is compiled with
+ the PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE,
+ and PCRE_EXTENDED.
A pattern is automatically anchored by PCRE if all of its top-level
alternatives begin with one of the following:
@@ -1676,20 +1926,50 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
turned out to be anchored by virtue of its contents, it cannot be made
unachored at matching time.
+ PCRE_BSR_ANYCRLF
+ PCRE_BSR_UNICODE
+
+ These options (which are mutually exclusive) control what the \R escape
+ sequence matches. The choice is either to match only CR, LF, or CRLF,
+ or to match any Unicode newline sequence. These options override the
+ choice that was made or defaulted when the pattern was compiled.
+
PCRE_NEWLINE_CR
PCRE_NEWLINE_LF
PCRE_NEWLINE_CRLF
+ PCRE_NEWLINE_ANYCRLF
PCRE_NEWLINE_ANY
- These options override the newline definition that was chosen or
- defaulted when the pattern was compiled. For details, see the descrip-
- tion of pcre_compile() above. During matching, the newline choice
- affects the behaviour of the dot, circumflex, and dollar metacharac-
- ters. It may also alter the way the match position is advanced after a
- match failure for an unanchored pattern. When PCRE_NEWLINE_CRLF or
- PCRE_NEWLINE_ANY is set, and a match attempt fails when the current
- position is at a CRLF sequence, the match position is advanced by two
- characters instead of one, in other words, to after the CRLF.
+ These options override the newline definition that was chosen or
+ defaulted when the pattern was compiled. For details, see the descrip-
+ tion of pcre_compile() above. During matching, the newline choice
+ affects the behaviour of the dot, circumflex, and dollar metacharac-
+ ters. It may also alter the way the match position is advanced after a
+ match failure for an unanchored pattern.
+
+ When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is
+ set, and a match attempt for an unanchored pattern fails when the cur-
+ rent position is at a CRLF sequence, and the pattern contains no
+ explicit matches for CR or LF characters, the match position is
+ advanced by two characters instead of one, in other words, to after the
+ CRLF.
+
+ The above rule is a compromise that makes the most common cases work as
+ expected. For example, if the pattern is .+A (and the PCRE_DOTALL
+ option is not set), it does not match the string "\r\nA" because, after
+ failing at the start, it skips both the CR and the LF before retrying.
+ However, the pattern [\r\n]A does match that string, because it con-
+ tains an explicit CR or LF reference, and so advances only by one char-
+ acter after the first failure.
+
+ An explicit match for CR of LF is either a literal appearance of one of
+ those characters, or one of the \r or \n escape sequences. Implicit
+ matches such as [^X] do not count, nor does \s (which includes CR and
+ LF in the characters that it matches).
+
+ Notwithstanding the above, anomalous effects may still occur when CRLF
+ is a valid newline sequence and explicit \r or \n escapes appear in the
+ pattern.
PCRE_NOTBOL
@@ -1736,140 +2016,141 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
When PCRE_UTF8 is set at compile time, the validity of the subject as a
UTF-8 string is automatically checked when pcre_exec() is subsequently
called. The value of startoffset is also checked to ensure that it
- points to the start of a UTF-8 character. If an invalid UTF-8 sequence
- of bytes is found, pcre_exec() returns the error PCRE_ERROR_BADUTF8. If
- startoffset contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is
- returned.
-
- If you already know that your subject is valid, and you want to skip
- these checks for performance reasons, you can set the
- PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to
- do this for the second and subsequent calls to pcre_exec() if you are
- making repeated calls to find all the matches in a single subject
- string. However, you should be sure that the value of startoffset
- points to the start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is
- set, the effect of passing an invalid UTF-8 string as a subject, or a
- value of startoffset that does not point to the start of a UTF-8 char-
+ points to the start of a UTF-8 character. There is a discussion about
+ the validity of UTF-8 strings in the section on UTF-8 support in the
+ main pcre page. If an invalid UTF-8 sequence of bytes is found,
+ pcre_exec() returns the error PCRE_ERROR_BADUTF8. If startoffset con-
+ tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.
+
+ If you already know that your subject is valid, and you want to skip
+ these checks for performance reasons, you can set the
+ PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to
+ do this for the second and subsequent calls to pcre_exec() if you are
+ making repeated calls to find all the matches in a single subject
+ string. However, you should be sure that the value of startoffset
+ points to the start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is
+ set, the effect of passing an invalid UTF-8 string as a subject, or a
+ value of startoffset that does not point to the start of a UTF-8 char-
acter, is undefined. Your program may crash.
PCRE_PARTIAL
- This option turns on the partial matching feature. If the subject
- string fails to match the pattern, but at some point during the match-
- ing process the end of the subject was reached (that is, the subject
- partially matches the pattern and the failure to match occurred only
- because there were not enough subject characters), pcre_exec() returns
- PCRE_ERROR_PARTIAL instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is
- used, there are restrictions on what may appear in the pattern. These
+ This option turns on the partial matching feature. If the subject
+ string fails to match the pattern, but at some point during the match-
+ ing process the end of the subject was reached (that is, the subject
+ partially matches the pattern and the failure to match occurred only
+ because there were not enough subject characters), pcre_exec() returns
+ PCRE_ERROR_PARTIAL instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is
+ used, there are restrictions on what may appear in the pattern. These
are discussed in the pcrepartial documentation.
The string to be matched by pcre_exec()
- The subject string is passed to pcre_exec() as a pointer in subject, a
- length in length, and a starting byte offset in startoffset. In UTF-8
- mode, the byte offset must point to the start of a UTF-8 character.
- Unlike the pattern string, the subject may contain binary zero bytes.
- When the starting offset is zero, the search for a match starts at the
+ The subject string is passed to pcre_exec() as a pointer in subject, a
+ length in length, and a starting byte offset in startoffset. In UTF-8
+ mode, the byte offset must point to the start of a UTF-8 character.
+ Unlike the pattern string, the subject may contain binary zero bytes.
+ When the starting offset is zero, the search for a match starts at the
beginning of the subject, and this is by far the most common case.
- A non-zero starting offset is useful when searching for another match
- in the same subject by calling pcre_exec() again after a previous suc-
- cess. Setting startoffset differs from just passing over a shortened
- string and setting PCRE_NOTBOL in the case of a pattern that begins
+ A non-zero starting offset is useful when searching for another match
+ in the same subject by calling pcre_exec() again after a previous suc-
+ cess. Setting startoffset differs from just passing over a shortened
+ string and setting PCRE_NOTBOL in the case of a pattern that begins
with any kind of lookbehind. For example, consider the pattern
\Biss\B
- which finds occurrences of "iss" in the middle of words. (\B matches
- only if the current position in the subject is not a word boundary.)
- When applied to the string "Mississipi" the first call to pcre_exec()
- finds the first occurrence. If pcre_exec() is called again with just
- the remainder of the subject, namely "issipi", it does not match,
+ which finds occurrences of "iss" in the middle of words. (\B matches
+ only if the current position in the subject is not a word boundary.)
+ When applied to the string "Mississipi" the first call to pcre_exec()
+ finds the first occurrence. If pcre_exec() is called again with just
+ the remainder of the subject, namely "issipi", it does not match,
because \B is always false at the start of the subject, which is deemed
- to be a word boundary. However, if pcre_exec() is passed the entire
+ to be a word boundary. However, if pcre_exec() is passed the entire
string again, but with startoffset set to 4, it finds the second occur-
- rence of "iss" because it is able to look behind the starting point to
+ rence of "iss" because it is able to look behind the starting point to
discover that it is preceded by a letter.
- If a non-zero starting offset is passed when the pattern is anchored,
+ If a non-zero starting offset is passed when the pattern is anchored,
one attempt to match at the given offset is made. This can only succeed
- if the pattern does not require the match to be at the start of the
+ if the pattern does not require the match to be at the start of the
subject.
How pcre_exec() returns captured substrings
- In general, a pattern matches a certain portion of the subject, and in
- addition, further substrings from the subject may be picked out by
- parts of the pattern. Following the usage in Jeffrey Friedl's book,
- this is called "capturing" in what follows, and the phrase "capturing
- subpattern" is used for a fragment of a pattern that picks out a sub-
- string. PCRE supports several other kinds of parenthesized subpattern
+ In general, a pattern matches a certain portion of the subject, and in
+ addition, further substrings from the subject may be picked out by
+ parts of the pattern. Following the usage in Jeffrey Friedl's book,
+ this is called "capturing" in what follows, and the phrase "capturing
+ subpattern" is used for a fragment of a pattern that picks out a sub-
+ string. PCRE supports several other kinds of parenthesized subpattern
that do not cause substrings to be captured.
- Captured substrings are returned to the caller via a vector of integer
- offsets whose address is passed in ovector. The number of elements in
- the vector is passed in ovecsize, which must be a non-negative number.
+ Captured substrings are returned to the caller via a vector of integer
+ offsets whose address is passed in ovector. The number of elements in
+ the vector is passed in ovecsize, which must be a non-negative number.
Note: this argument is NOT the size of ovector in bytes.
- The first two-thirds of the vector is used to pass back captured sub-
- strings, each substring using a pair of integers. The remaining third
- of the vector is used as workspace by pcre_exec() while matching cap-
- turing subpatterns, and is not available for passing back information.
- The length passed in ovecsize should always be a multiple of three. If
+ The first two-thirds of the vector is used to pass back captured sub-
+ strings, each substring using a pair of integers. The remaining third
+ of the vector is used as workspace by pcre_exec() while matching cap-
+ turing subpatterns, and is not available for passing back information.
+ The length passed in ovecsize should always be a multiple of three. If
it is not, it is rounded down.
- When a match is successful, information about captured substrings is
- returned in pairs of integers, starting at the beginning of ovector,
- and continuing up to two-thirds of its length at the most. The first
+ When a match is successful, information about captured substrings is
+ returned in pairs of integers, starting at the beginning of ovector,
+ and continuing up to two-thirds of its length at the most. The first
element of a pair is set to the offset of the first character in a sub-
- string, and the second is set to the offset of the first character
- after the end of a substring. The first pair, ovector[0] and ovec-
- tor[1], identify the portion of the subject string matched by the
- entire pattern. The next pair is used for the first capturing subpat-
+ string, and the second is set to the offset of the first character
+ after the end of a substring. The first pair, ovector[0] and ovec-
+ tor[1], identify the portion of the subject string matched by the
+ entire pattern. The next pair is used for the first capturing subpat-
tern, and so on. The value returned by pcre_exec() is one more than the
highest numbered pair that has been set. For example, if two substrings
- have been captured, the returned value is 3. If there are no capturing
- subpatterns, the return value from a successful match is 1, indicating
+ have been captured, the returned value is 3. If there are no capturing
+ subpatterns, the return value from a successful match is 1, indicating
that just the first pair of offsets has been set.
If a capturing subpattern is matched repeatedly, it is the last portion
of the string that it matched that is returned.
- If the vector is too small to hold all the captured substring offsets,
+ If the vector is too small to hold all the captured substring offsets,
it is used as far as possible (up to two-thirds of its length), and the
- function returns a value of zero. In particular, if the substring off-
+ function returns a value of zero. In particular, if the substring off-
sets are not of interest, pcre_exec() may be called with ovector passed
- as NULL and ovecsize as zero. However, if the pattern contains back
- references and the ovector is not big enough to remember the related
- substrings, PCRE has to get additional memory for use during matching.
+ as NULL and ovecsize as zero. However, if the pattern contains back
+ references and the ovector is not big enough to remember the related
+ substrings, PCRE has to get additional memory for use during matching.
Thus it is usually advisable to supply an ovector.
- The pcre_info() function can be used to find out how many capturing
- subpatterns there are in a compiled pattern. The smallest size for
- ovector that will allow for n captured substrings, in addition to the
+ The pcre_info() function can be used to find out how many capturing
+ subpatterns there are in a compiled pattern. The smallest size for
+ ovector that will allow for n captured substrings, in addition to the
offsets of the substring matched by the whole pattern, is (n+1)*3.
- It is possible for capturing subpattern number n+1 to match some part
+ It is possible for capturing subpattern number n+1 to match some part
of the subject when subpattern n has not been used at all. For example,
- if the string "abc" is matched against the pattern (a|(z))(bc) the
+ if the string "abc" is matched against the pattern (a|(z))(bc) the
return from the function is 4, and subpatterns 1 and 3 are matched, but
- 2 is not. When this happens, both values in the offset pairs corre-
+ 2 is not. When this happens, both values in the offset pairs corre-
sponding to unused subpatterns are set to -1.
- Offset values that correspond to unused subpatterns at the end of the
- expression are also set to -1. For example, if the string "abc" is
- matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not
- matched. The return from the function is 2, because the highest used
+ Offset values that correspond to unused subpatterns at the end of the
+ expression are also set to -1. For example, if the string "abc" is
+ matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not
+ matched. The return from the function is 2, because the highest used
capturing subpattern number is 1. However, you can refer to the offsets
- for the second and third capturing subpatterns if you wish (assuming
+ for the second and third capturing subpatterns if you wish (assuming
the vector is large enough, of course).
- Some convenience functions are provided for extracting the captured
+ Some convenience functions are provided for extracting the captured
substrings as separate strings. These are described below.
Error return values from pcre_exec()
- If pcre_exec() fails, it returns a negative number. The following are
+ If pcre_exec() fails, it returns a negative number. The following are
defined in the header file:
PCRE_ERROR_NOMATCH (-1)
@@ -1878,7 +2159,7 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
PCRE_ERROR_NULL (-2)
- Either code or subject was passed as NULL, or ovector was NULL and
+ Either code or subject was passed as NULL, or ovector was NULL and
ovecsize was not zero.
PCRE_ERROR_BADOPTION (-3)
@@ -1887,94 +2168,86 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
PCRE_ERROR_BADMAGIC (-4)
- PCRE stores a 4-byte "magic number" at the start of the compiled code,
+ PCRE stores a 4-byte "magic number" at the start of the compiled code,
to catch the case when it is passed a junk pointer and to detect when a
pattern that was compiled in an environment of one endianness is run in
- an environment with the other endianness. This is the error that PCRE
+ an environment with the other endianness. This is the error that PCRE
gives when the magic number is not present.
PCRE_ERROR_UNKNOWN_OPCODE (-5)
While running the pattern match, an unknown item was encountered in the
- compiled pattern. This error could be caused by a bug in PCRE or by
+ compiled pattern. This error could be caused by a bug in PCRE or by
overwriting of the compiled pattern.
PCRE_ERROR_NOMEMORY (-6)
- If a pattern contains back references, but the ovector that is passed
+ If a pattern contains back references, but the ovector that is passed
to pcre_exec() is not big enough to remember the referenced substrings,
- PCRE gets a block of memory at the start of matching to use for this
- purpose. If the call via pcre_malloc() fails, this error is given. The
+ PCRE gets a block of memory at the start of matching to use for this
+ purpose. If the call via pcre_malloc() fails, this error is given. The
memory is automatically freed at the end of matching.
PCRE_ERROR_NOSUBSTRING (-7)
- This error is used by the pcre_copy_substring(), pcre_get_substring(),
+ This error is used by the pcre_copy_substring(), pcre_get_substring(),
and pcre_get_substring_list() functions (see below). It is never
returned by pcre_exec().
PCRE_ERROR_MATCHLIMIT (-8)
- The backtracking limit, as specified by the match_limit field in a
- pcre_extra structure (or defaulted) was reached. See the description
+ The backtracking limit, as specified by the match_limit field in a
+ pcre_extra structure (or defaulted) was reached. See the description
above.
PCRE_ERROR_CALLOUT (-9)
This error is never generated by pcre_exec() itself. It is provided for
- use by callout functions that want to yield a distinctive error code.
+ use by callout functions that want to yield a distinctive error code.
See the pcrecallout documentation for details.
PCRE_ERROR_BADUTF8 (-10)
- A string that contains an invalid UTF-8 byte sequence was passed as a
+ A string that contains an invalid UTF-8 byte sequence was passed as a
subject.
PCRE_ERROR_BADUTF8_OFFSET (-11)
The UTF-8 byte sequence that was passed as a subject was valid, but the
- value of startoffset did not point to the beginning of a UTF-8 charac-
+ value of startoffset did not point to the beginning of a UTF-8 charac-
ter.
PCRE_ERROR_PARTIAL (-12)
- The subject string did not match, but it did match partially. See the
+ The subject string did not match, but it did match partially. See the
pcrepartial documentation for details of partial matching.
PCRE_ERROR_BADPARTIAL (-13)
- The PCRE_PARTIAL option was used with a compiled pattern containing
- items that are not supported for partial matching. See the pcrepartial
+ The PCRE_PARTIAL option was used with a compiled pattern containing
+ items that are not supported for partial matching. See the pcrepartial
documentation for details of partial matching.
PCRE_ERROR_INTERNAL (-14)
- An unexpected internal error has occurred. This error could be caused
+ An unexpected internal error has occurred. This error could be caused
by a bug in PCRE or by overwriting of the compiled pattern.
PCRE_ERROR_BADCOUNT (-15)
- This error is given if the value of the ovecsize argument is negative.
+ This error is given if the value of the ovecsize argument is negative.
PCRE_ERROR_RECURSIONLIMIT (-21)
The internal recursion limit, as specified by the match_limit_recursion
- field in a pcre_extra structure (or defaulted) was reached. See the
+ field in a pcre_extra structure (or defaulted) was reached. See the
description above.
- PCRE_ERROR_NULLWSLIMIT (-22)
-
- When a group that can match an empty substring is repeated with an
- unbounded upper limit, the subject position at the start of the group
- must be remembered, so that a test for an empty string can be made when
- the end of the group is reached. Some workspace is required for this;
- if it runs out, this error is given.
-
PCRE_ERROR_BADNEWLINE (-23)
An invalid combination of PCRE_NEWLINE_xxx options was given.
- Error numbers -16 to -20 are not used by pcre_exec().
+ Error numbers -16 to -20 and -22 are not used by pcre_exec().
EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
@@ -1990,78 +2263,78 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
int pcre_get_substring_list(const char *subject,
int *ovector, int stringcount, const char ***listptr);
- Captured substrings can be accessed directly by using the offsets
- returned by pcre_exec() in ovector. For convenience, the functions
+ Captured substrings can be accessed directly by using the offsets
+ returned by pcre_exec() in ovector. For convenience, the functions
pcre_copy_substring(), pcre_get_substring(), and pcre_get_sub-
- string_list() are provided for extracting captured substrings as new,
- separate, zero-terminated strings. These functions identify substrings
- by number. The next section describes functions for extracting named
+ string_list() are provided for extracting captured substrings as new,
+ separate, zero-terminated strings. These functions identify substrings
+ by number. The next section describes functions for extracting named
substrings.
- A substring that contains a binary zero is correctly extracted and has
- a further zero added on the end, but the result is not, of course, a C
- string. However, you can process such a string by referring to the
- length that is returned by pcre_copy_substring() and pcre_get_sub-
+ A substring that contains a binary zero is correctly extracted and has
+ a further zero added on the end, but the result is not, of course, a C
+ string. However, you can process such a string by referring to the
+ length that is returned by pcre_copy_substring() and pcre_get_sub-
string(). Unfortunately, the interface to pcre_get_substring_list() is
- not adequate for handling strings containing binary zeros, because the
+ not adequate for handling strings containing binary zeros, because the
end of the final string is not independently indicated.
- The first three arguments are the same for all three of these func-
- tions: subject is the subject string that has just been successfully
+ The first three arguments are the same for all three of these func-
+ tions: subject is the subject string that has just been successfully
matched, ovector is a pointer to the vector of integer offsets that was
passed to pcre_exec(), and stringcount is the number of substrings that
- were captured by the match, including the substring that matched the
+ were captured by the match, including the substring that matched the
entire regular expression. This is the value returned by pcre_exec() if
- it is greater than zero. If pcre_exec() returned zero, indicating that
- it ran out of space in ovector, the value passed as stringcount should
+ it is greater than zero. If pcre_exec() returned zero, indicating that
+ it ran out of space in ovector, the value passed as stringcount should
be the number of elements in the vector divided by three.
- The functions pcre_copy_substring() and pcre_get_substring() extract a
- single substring, whose number is given as stringnumber. A value of
- zero extracts the substring that matched the entire pattern, whereas
- higher values extract the captured substrings. For pcre_copy_sub-
- string(), the string is placed in buffer, whose length is given by
- buffersize, while for pcre_get_substring() a new block of memory is
- obtained via pcre_malloc, and its address is returned via stringptr.
- The yield of the function is the length of the string, not including
+ The functions pcre_copy_substring() and pcre_get_substring() extract a
+ single substring, whose number is given as stringnumber. A value of
+ zero extracts the substring that matched the entire pattern, whereas
+ higher values extract the captured substrings. For pcre_copy_sub-
+ string(), the string is placed in buffer, whose length is given by
+ buffersize, while for pcre_get_substring() a new block of memory is
+ obtained via pcre_malloc, and its address is returned via stringptr.
+ The yield of the function is the length of the string, not including
the terminating zero, or one of these error codes:
PCRE_ERROR_NOMEMORY (-6)
- The buffer was too small for pcre_copy_substring(), or the attempt to
+ The buffer was too small for pcre_copy_substring(), or the attempt to
get memory failed for pcre_get_substring().
PCRE_ERROR_NOSUBSTRING (-7)
There is no substring whose number is stringnumber.
- The pcre_get_substring_list() function extracts all available sub-
- strings and builds a list of pointers to them. All this is done in a
+ The pcre_get_substring_list() function extracts all available sub-
+ strings and builds a list of pointers to them. All this is done in a
single block of memory that is obtained via pcre_malloc. The address of
- the memory block is returned via listptr, which is also the start of
- the list of string pointers. The end of the list is marked by a NULL
- pointer. The yield of the function is zero if all went well, or the
+ the memory block is returned via listptr, which is also the start of
+ the list of string pointers. The end of the list is marked by a NULL
+ pointer. The yield of the function is zero if all went well, or the
error code
PCRE_ERROR_NOMEMORY (-6)
if the attempt to get the memory block failed.
- When any of these functions encounter a substring that is unset, which
- can happen when capturing subpattern number n+1 matches some part of
- the subject, but subpattern n has not been used at all, they return an
+ When any of these functions encounter a substring that is unset, which
+ can happen when capturing subpattern number n+1 matches some part of
+ the subject, but subpattern n has not been used at all, they return an
empty string. This can be distinguished from a genuine zero-length sub-
- string by inspecting the appropriate offset in ovector, which is nega-
+ string by inspecting the appropriate offset in ovector, which is nega-
tive for unset substrings.
- The two convenience functions pcre_free_substring() and pcre_free_sub-
- string_list() can be used to free the memory returned by a previous
+ The two convenience functions pcre_free_substring() and pcre_free_sub-
+ string_list() can be used to free the memory returned by a previous
call of pcre_get_substring() or pcre_get_substring_list(), respec-
- tively. They do nothing more than call the function pointed to by
- pcre_free, which of course could be called directly from a C program.
- However, PCRE is used in some situations where it is linked via a spe-
- cial interface to another programming language that cannot use
- pcre_free directly; it is for these cases that the functions are pro-
+ tively. They do nothing more than call the function pointed to by
+ pcre_free, which of course could be called directly from a C program.
+ However, PCRE is used in some situations where it is linked via a spe-
+ cial interface to another programming language that cannot use
+ pcre_free directly; it is for these cases that the functions are pro-
vided.
@@ -2080,7 +2353,7 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME
int stringcount, const char *stringname,
const char **stringptr);
- To extract a substring by name, you first have to find associated num-
+ To extract a substring by name, you first have to find associated num-
ber. For example, for this pattern
(a+)b(?<xxx>\d+)...
@@ -2089,27 +2362,28 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME
be unique (PCRE_DUPNAMES was not set), you can find the number from the
name by calling pcre_get_stringnumber(). The first argument is the com-
piled pattern, and the second is the name. The yield of the function is
- the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no
+ the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no
subpattern of that name.
Given the number, you can extract the substring directly, or use one of
the functions described in the previous section. For convenience, there
are also two functions that do the whole job.
- Most of the arguments of pcre_copy_named_substring() and
- pcre_get_named_substring() are the same as those for the similarly
- named functions that extract by number. As these are described in the
- previous section, they are not re-described here. There are just two
+ Most of the arguments of pcre_copy_named_substring() and
+ pcre_get_named_substring() are the same as those for the similarly
+ named functions that extract by number. As these are described in the
+ previous section, they are not re-described here. There are just two
differences:
- First, instead of a substring number, a substring name is given. Sec-
+ First, instead of a substring number, a substring name is given. Sec-
ond, there is an extra argument, given at the start, which is a pointer
- to the compiled pattern. This is needed in order to gain access to the
+ to the compiled pattern. This is needed in order to gain access to the
name-to-number translation table.
- These functions call pcre_get_stringnumber(), and if it succeeds, they
- then call pcre_copy_substring() or pcre_get_substring(), as appropri-
- ate.
+ These functions call pcre_get_stringnumber(), and if it succeeds, they
+ then call pcre_copy_substring() or pcre_get_substring(), as appropri-
+ ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate names, the
+ behaviour may not be what you want (see the next section).
DUPLICATE SUBPATTERN NAMES
@@ -2121,12 +2395,14 @@ DUPLICATE SUBPATTERN NAMES
subpatterns are not required to be unique. Normally, patterns with
duplicate names are such that in any one match, only one of the named
subpatterns participates. An example is shown in the pcrepattern docu-
- mentation. When duplicates are present, pcre_copy_named_substring() and
+ mentation.
+
+ When duplicates are present, pcre_copy_named_substring() and
pcre_get_named_substring() return the first substring corresponding to
- the given name that is set. If none are set, an empty string is
- returned. The pcre_get_stringnumber() function returns one of the num-
- bers that are associated with the name, but it is not defined which it
- is.
+ the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING
+ (-7) is returned; no data is returned. The pcre_get_stringnumber()
+ function returns one of the numbers that are associated with the name,
+ but it is not defined which it is.
If you want to get full details of all captured substrings for a given
name, you must use the pcre_get_stringtable_entries() function. The
@@ -2318,8 +2594,18 @@ SEE ALSO
pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar-
tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).
-Last updated: 30 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 12 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -2346,7 +2632,7 @@ PCRE CALLOUTS
default value is zero. For example, this pattern has two callout
points:
- (?C1)eabc(?C2)def
+ (?C1)abc(?C2)def
If the PCRE_AUTO_CALLOUT option bit is set when pcre_compile() is
called, PCRE automatically inserts callouts, all with number 255,
@@ -2421,10 +2707,12 @@ THE CALLOUT INTERFACE
The subject and subject_length fields contain copies of the values that
were passed to pcre_exec().
- The start_match field contains the offset within the subject at which
- the current match attempt started. If the pattern is not anchored, the
- callout function may be called several times from the same point in the
- pattern for different starting points in the subject.
+ The start_match field normally contains the offset within the subject
+ at which the current match attempt started. However, if the escape
+ sequence \K has been encountered, this value is changed to reflect the
+ modified starting point. If the pattern is not anchored, the callout
+ function may be called several times from the same point in the pattern
+ for different starting points in the subject.
The current_position field contains the offset within the subject of
the current match pointer.
@@ -2477,8 +2765,18 @@ RETURN VALUES
reserved for use by callout functions; it will never be used by PCRE
itself.
-Last updated: 28 February 2005
-Copyright (c) 1997-2005 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 29 May 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
@@ -2493,8 +2791,8 @@ DIFFERENCES BETWEEN PCRE AND PERL
This document describes the differences in the ways that PCRE and Perl
handle regular expressions. The differences described here are mainly
- with respect to Perl 5.8, though PCRE version 7.0 contains some fea-
- tures that are expected to be in the forthcoming Perl 5.10.
+ with respect to Perl 5.8, though PCRE versions 7.0 and later contain
+ some features that are expected to be in the forthcoming Perl 5.10.
1. PCRE has only a subset of Perl's UTF-8 and Unicode support. Details
of what it does have are given in the section on UTF-8 support in the
@@ -2559,7 +2857,13 @@ DIFFERENCES BETWEEN PCRE AND PERL
matching "aba" against the pattern /^(a(b)?)+$/ in Perl leaves $2
unset, but in PCRE it is set to "b".
- 11. PCRE provides some extensions to the Perl regular expression facil-
+ 11. PCRE does support Perl 5.10's backtracking verbs (*ACCEPT),
+ (*FAIL), (*F), (*COMMIT), (*PRUNE), (*SKIP), and (*THEN), but only in
+ the forms without an argument. PCRE does not support (*MARK). If
+ (*ACCEPT) is within capturing parentheses, PCRE does not set that cap-
+ ture group; this is different to Perl.
+
+ 12. PCRE provides some extensions to the Perl regular expression facil-
ities. Perl 5.10 will include new features that are not in earlier
versions, some of which (such as named parentheses) have been in PCRE
for some time. This list is with respect to Perl 5.10:
@@ -2572,8 +2876,8 @@ DIFFERENCES BETWEEN PCRE AND PERL
meta-character matches only at the very end of the string.
(c) If PCRE_EXTRA is set, a backslash followed by a letter with no spe-
- cial meaning is faulted. Otherwise, like Perl, the backslash is
- ignored. (Perl can be made to issue a warning.)
+ cial meaning is faulted. Otherwise, like Perl, the backslash is quietly
+ ignored. (Perl can be made to issue a warning.)
(d) If PCRE_UNGREEDY is set, the greediness of the repetition quanti-
fiers is inverted, that is, by default they are not greedy, but if fol-
@@ -2585,18 +2889,35 @@ DIFFERENCES BETWEEN PCRE AND PERL
(f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAP-
TURE options for pcre_exec() have no Perl equivalents.
- (g) The callout facility is PCRE-specific.
+ (g) The \R escape sequence can be restricted to match only CR, LF, or
+ CRLF by the PCRE_BSR_ANYCRLF option.
+
+ (h) The callout facility is PCRE-specific.
- (h) The partial matching facility is PCRE-specific.
+ (i) The partial matching facility is PCRE-specific.
- (i) Patterns compiled by PCRE can be saved and re-used at a later time,
+ (j) Patterns compiled by PCRE can be saved and re-used at a later time,
even on different hosts that have the other endianness.
- (j) The alternative matching function (pcre_dfa_exec()) matches in a
+ (k) The alternative matching function (pcre_dfa_exec()) matches in a
different way and is not Perl-compatible.
-Last updated: 28 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+ (l) PCRE recognizes some special sequences such as (*CR) at the start
+ of a pattern that set overall options that cannot be changed within the
+ pattern.
+
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 11 September 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
@@ -2609,12 +2930,20 @@ NAME
PCRE REGULAR EXPRESSION DETAILS
- The syntax and semantics of the regular expressions supported by PCRE
- are described below. Regular expressions are also described in the Perl
- documentation and in a number of books, some of which have copious
- examples. Jeffrey Friedl's "Mastering Regular Expressions", published
- by O'Reilly, covers regular expressions in great detail. This descrip-
- tion of PCRE's regular expressions is intended as reference material.
+ The syntax and semantics of the regular expressions that are supported
+ by PCRE are described in detail below. There is a quick-reference syn-
+ tax summary in the pcresyntax page. PCRE tries to match Perl syntax and
+ semantics as closely as it can. PCRE also supports some alternative
+ regular expression syntax (which does not conflict with the Perl syn-
+ tax) in order to provide some compatibility with regular expressions in
+ Python, .NET, and Oniguruma.
+
+ Perl's regular expressions are described in its own documentation, and
+ regular expressions in general are covered in a number of books, some
+ of which have copious examples. Jeffrey Friedl's "Mastering Regular
+ Expressions", published by O'Reilly, covers regular expressions in
+ great detail. This description of PCRE's regular expressions is
+ intended as reference material.
The original operation of PCRE was on strings of one-byte characters.
However, there is now also support for UTF-8 character strings. To use
@@ -2628,38 +2957,76 @@ PCRE REGULAR EXPRESSION DETAILS
ported by PCRE when its main matching function, pcre_exec(), is used.
From release 6.0, PCRE offers a second matching function,
pcre_dfa_exec(), which matches using a different algorithm that is not
- Perl-compatible. The advantages and disadvantages of the alternative
- function, and how it differs from the normal function, are discussed in
- the pcrematching page.
+ Perl-compatible. Some of the features discussed below are not available
+ when pcre_dfa_exec() is used. The advantages and disadvantages of the
+ alternative function, and how it differs from the normal function, are
+ discussed in the pcrematching page.
+
+
+NEWLINE CONVENTIONS
+
+ PCRE supports five different conventions for indicating line breaks in
+ strings: a single CR (carriage return) character, a single LF (line-
+ feed) character, the two-character sequence CRLF, any of the three pre-
+ ceding, or any Unicode newline sequence. The pcreapi page has further
+ discussion about newlines, and shows how to set the newline convention
+ in the options arguments for the compiling and matching functions.
+
+ It is also possible to specify a newline convention by starting a pat-
+ tern string with one of the following five sequences:
+
+ (*CR) carriage return
+ (*LF) linefeed
+ (*CRLF) carriage return, followed by linefeed
+ (*ANYCRLF) any of the three above
+ (*ANY) all Unicode newline sequences
+
+ These override the default and the options given to pcre_compile(). For
+ example, on a Unix system where LF is the default newline sequence, the
+ pattern
+
+ (*CR)a.b
+
+ changes the convention to CR. That pattern matches "a\nb" because LF is
+ no longer a newline. Note that these special settings, which are not
+ Perl-compatible, are recognized only at the very start of a pattern,
+ and that they must be in upper case. If more than one of them is
+ present, the last one is used.
+
+ The newline convention does not affect what the \R escape sequence
+ matches. By default, this is any Unicode newline sequence, for Perl
+ compatibility. However, this can be changed; see the description of \R
+ in the section entitled "Newline sequences" below. A change of \R set-
+ ting can be combined with a change of newline convention.
CHARACTERS AND METACHARACTERS
- A regular expression is a pattern that is matched against a subject
- string from left to right. Most characters stand for themselves in a
- pattern, and match the corresponding characters in the subject. As a
+ A regular expression is a pattern that is matched against a subject
+ string from left to right. Most characters stand for themselves in a
+ pattern, and match the corresponding characters in the subject. As a
trivial example, the pattern
The quick brown fox
matches a portion of a subject string that is identical to itself. When
- caseless matching is specified (the PCRE_CASELESS option), letters are
- matched independently of case. In UTF-8 mode, PCRE always understands
- the concept of case for characters whose values are less than 128, so
- caseless matching is always possible. For characters with higher val-
- ues, the concept of case is supported if PCRE is compiled with Unicode
- property support, but not otherwise. If you want to use caseless
- matching for characters 128 and above, you must ensure that PCRE is
+ caseless matching is specified (the PCRE_CASELESS option), letters are
+ matched independently of case. In UTF-8 mode, PCRE always understands
+ the concept of case for characters whose values are less than 128, so
+ caseless matching is always possible. For characters with higher val-
+ ues, the concept of case is supported if PCRE is compiled with Unicode
+ property support, but not otherwise. If you want to use caseless
+ matching for characters 128 and above, you must ensure that PCRE is
compiled with Unicode property support as well as with UTF-8 support.
- The power of regular expressions comes from the ability to include
- alternatives and repetitions in the pattern. These are encoded in the
+ The power of regular expressions comes from the ability to include
+ alternatives and repetitions in the pattern. These are encoded in the
pattern by the use of metacharacters, which do not stand for themselves
but instead are interpreted in some special way.
- There are two different sets of metacharacters: those that are recog-
- nized anywhere in the pattern except within square brackets, and those
- that are recognized within square brackets. Outside square brackets,
+ There are two different sets of metacharacters: those that are recog-
+ nized anywhere in the pattern except within square brackets, and those
+ that are recognized within square brackets. Outside square brackets,
the metacharacters are as follows:
\ general escape character with several uses
@@ -2678,7 +3045,7 @@ CHARACTERS AND METACHARACTERS
also "possessive quantifier"
{ start min/max quantifier
- Part of a pattern that is in square brackets is called a "character
+ Part of a pattern that is in square brackets is called a "character
class". In a character class the only metacharacters are:
\ general escape character
@@ -2688,33 +3055,33 @@ CHARACTERS AND METACHARACTERS
syntax)
] terminates the character class
- The following sections describe the use of each of the metacharacters.
+ The following sections describe the use of each of the metacharacters.
BACKSLASH
The backslash character has several uses. Firstly, if it is followed by
- a non-alphanumeric character, it takes away any special meaning that
- character may have. This use of backslash as an escape character
+ a non-alphanumeric character, it takes away any special meaning that
+ character may have. This use of backslash as an escape character
applies both inside and outside character classes.
- For example, if you want to match a * character, you write \* in the
- pattern. This escaping action applies whether or not the following
- character would otherwise be interpreted as a metacharacter, so it is
- always safe to precede a non-alphanumeric with backslash to specify
- that it stands for itself. In particular, if you want to match a back-
+ For example, if you want to match a * character, you write \* in the
+ pattern. This escaping action applies whether or not the following
+ character would otherwise be interpreted as a metacharacter, so it is
+ always safe to precede a non-alphanumeric with backslash to specify
+ that it stands for itself. In particular, if you want to match a back-
slash, you write \\.
- If a pattern is compiled with the PCRE_EXTENDED option, whitespace in
- the pattern (other than in a character class) and characters between a
+ If a pattern is compiled with the PCRE_EXTENDED option, whitespace in
+ the pattern (other than in a character class) and characters between a
# outside a character class and the next newline are ignored. An escap-
- ing backslash can be used to include a whitespace or # character as
+ ing backslash can be used to include a whitespace or # character as
part of the pattern.
- If you want to remove the special meaning from a sequence of charac-
- ters, you can do so by putting them between \Q and \E. This is differ-
- ent from Perl in that $ and @ are handled as literals in \Q...\E
- sequences in PCRE, whereas in Perl, $ and @ cause variable interpola-
+ If you want to remove the special meaning from a sequence of charac-
+ ters, you can do so by putting them between \Q and \E. This is differ-
+ ent from Perl in that $ and @ are handled as literals in \Q...\E
+ sequences in PCRE, whereas in Perl, $ and @ cause variable interpola-
tion. Note the following examples:
Pattern PCRE matches Perl matches
@@ -2724,43 +3091,46 @@ BACKSLASH
\Qabc\$xyz\E abc\$xyz abc\$xyz
\Qabc\E\$\Qxyz\E abc$xyz abc$xyz
- The \Q...\E sequence is recognized both inside and outside character
+ The \Q...\E sequence is recognized both inside and outside character
classes.
Non-printing characters
A second use of backslash provides a way of encoding non-printing char-
- acters in patterns in a visible manner. There is no restriction on the
- appearance of non-printing characters, apart from the binary zero that
- terminates a pattern, but when a pattern is being prepared by text
- editing, it is usually easier to use one of the following escape
+ acters in patterns in a visible manner. There is no restriction on the
+ appearance of non-printing characters, apart from the binary zero that
+ terminates a pattern, but when a pattern is being prepared by text
+ editing, it is usually easier to use one of the following escape
sequences than the binary character it represents:
\a alarm, that is, the BEL character (hex 07)
\cx "control-x", where x is any character
\e escape (hex 1B)
\f formfeed (hex 0C)
- \n newline (hex 0A)
+ \n linefeed (hex 0A)
\r carriage return (hex 0D)
\t tab (hex 09)
\ddd character with octal code ddd, or backreference
\xhh character with hex code hh
\x{hhh..} character with hex code hhh..
- The precise effect of \cx is as follows: if x is a lower case letter,
- it is converted to upper case. Then bit 6 of the character (hex 40) is
- inverted. Thus \cz becomes hex 1A, but \c{ becomes hex 3B, while \c;
+ The precise effect of \cx is as follows: if x is a lower case letter,
+ it is converted to upper case. Then bit 6 of the character (hex 40) is
+ inverted. Thus \cz becomes hex 1A, but \c{ becomes hex 3B, while \c;
becomes hex 7B.
- After \x, from zero to two hexadecimal digits are read (letters can be
- in upper or lower case). Any number of hexadecimal digits may appear
- between \x{ and }, but the value of the character code must be less
- than 256 in non-UTF-8 mode, and less than 2**31 in UTF-8 mode (that is,
- the maximum hexadecimal value is 7FFFFFFF). If characters other than
- hexadecimal digits appear between \x{ and }, or if there is no termi-
- nating }, this form of escape is not recognized. Instead, the initial
- \x will be interpreted as a basic hexadecimal escape, with no following
- digits, giving a character whose value is zero.
+ After \x, from zero to two hexadecimal digits are read (letters can be
+ in upper or lower case). Any number of hexadecimal digits may appear
+ between \x{ and }, but the value of the character code must be less
+ than 256 in non-UTF-8 mode, and less than 2**31 in UTF-8 mode. That is,
+ the maximum value in hexadecimal is 7FFFFFFF. Note that this is bigger
+ than the largest Unicode code point, which is 10FFFF.
+
+ If characters other than hexadecimal digits appear between \x{ and },
+ or if there is no terminating }, this form of escape is not recognized.
+ Instead, the initial \x will be interpreted as a basic hexadecimal
+ escape, with no following digits, giving a character whose value is
+ zero.
Characters whose value is less than 256 can be defined by either of the
two syntaxes for \x. There is no difference in the way they are han-
@@ -2815,10 +3185,19 @@ BACKSLASH
Absolute and relative back references
- The sequence \g followed by a positive or negative number, optionally
- enclosed in braces, is an absolute or relative back reference. Back
- references are discussed later, following the discussion of parenthe-
- sized subpatterns.
+ The sequence \g followed by an unsigned or a negative number, option-
+ ally enclosed in braces, is an absolute or relative back reference. A
+ named back reference can be coded as \g{name}. Back references are dis-
+ cussed later, following the discussion of parenthesized subpatterns.
+
+ Absolute and relative subroutine calls
+
+ For compatibility with Oniguruma, the non-Perl syntax \g followed by a
+ name or a number enclosed either in angle brackets or single quotes, is
+ an alternative syntax for referencing a subpattern as a "subroutine".
+ Details are discussed later. Note that \g{...} (Perl syntax) and
+ \g<...> (Oniguruma syntax) are not synonymous. The former is a back
+ reference; the latter is a subroutine call.
Generic character types
@@ -2827,66 +3206,130 @@ BACKSLASH
\d any decimal digit
\D any character that is not a decimal digit
+ \h any horizontal whitespace character
+ \H any character that is not a horizontal whitespace character
\s any whitespace character
\S any character that is not a whitespace character
+ \v any vertical whitespace character
+ \V any character that is not a vertical whitespace character
\w any "word" character
\W any "non-word" character
Each pair of escape sequences partitions the complete set of characters
- into two disjoint sets. Any given character matches one, and only one,
+ into two disjoint sets. Any given character matches one, and only one,
of each pair.
These character type sequences can appear both inside and outside char-
- acter classes. They each match one character of the appropriate type.
- If the current matching point is at the end of the subject string, all
+ acter classes. They each match one character of the appropriate type.
+ If the current matching point is at the end of the subject string, all
of them fail, since there is no character to match.
- For compatibility with Perl, \s does not match the VT character (code
- 11). This makes it different from the the POSIX "space" class. The \s
- characters are HT (9), LF (10), FF (12), CR (13), and space (32). (If
+ For compatibility with Perl, \s does not match the VT character (code
+ 11). This makes it different from the the POSIX "space" class. The \s
+ characters are HT (9), LF (10), FF (12), CR (13), and space (32). If
"use locale;" is included in a Perl script, \s may match the VT charac-
- ter. In PCRE, it never does.)
+ ter. In PCRE, it never does.
- A "word" character is an underscore or any character less than 256 that
- is a letter or digit. The definition of letters and digits is con-
- trolled by PCRE's low-valued character tables, and may vary if locale-
- specific matching is taking place (see "Locale support" in the pcreapi
- page). For example, in the "fr_FR" (French) locale, some character
- codes greater than 128 are used for accented letters, and these are
- matched by \w.
-
- In UTF-8 mode, characters with values greater than 128 never match \d,
+ In UTF-8 mode, characters with values greater than 128 never match \d,
\s, or \w, and always match \D, \S, and \W. This is true even when Uni-
- code character property support is available. The use of locales with
- Unicode is discouraged.
+ code character property support is available. These sequences retain
+ their original meanings from before UTF-8 support was available, mainly
+ for efficiency reasons.
+
+ The sequences \h, \H, \v, and \V are Perl 5.10 features. In contrast to
+ the other sequences, these do match certain high-valued codepoints in
+ UTF-8 mode. The horizontal space characters are:
+
+ U+0009 Horizontal tab
+ U+0020 Space
+ U+00A0 Non-break space
+ U+1680 Ogham space mark
+ U+180E Mongolian vowel separator
+ U+2000 En quad
+ U+2001 Em quad
+ U+2002 En space
+ U+2003 Em space
+ U+2004 Three-per-em space
+ U+2005 Four-per-em space
+ U+2006 Six-per-em space
+ U+2007 Figure space
+ U+2008 Punctuation space
+ U+2009 Thin space
+ U+200A Hair space
+ U+202F Narrow no-break space
+ U+205F Medium mathematical space
+ U+3000 Ideographic space
+
+ The vertical space characters are:
+
+ U+000A Linefeed
+ U+000B Vertical tab
+ U+000C Formfeed
+ U+000D Carriage return
+ U+0085 Next line
+ U+2028 Line separator
+ U+2029 Paragraph separator
+
+ A "word" character is an underscore or any character less than 256 that
+ is a letter or digit. The definition of letters and digits is con-
+ trolled by PCRE's low-valued character tables, and may vary if locale-
+ specific matching is taking place (see "Locale support" in the pcreapi
+ page). For example, in a French locale such as "fr_FR" in Unix-like
+ systems, or "french" in Windows, some character codes greater than 128
+ are used for accented letters, and these are matched by \w. The use of
+ locales with Unicode is discouraged.
Newline sequences
- Outside a character class, the escape sequence \R matches any Unicode
- newline sequence. This is an extension to Perl. In non-UTF-8 mode \R is
- equivalent to the following:
+ Outside a character class, by default, the escape sequence \R matches
+ any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8
+ mode \R is equivalent to the following:
(?>\r\n|\n|\x0b|\f|\r|\x85)
- This is an example of an "atomic group", details of which are given
+ This is an example of an "atomic group", details of which are given
below. This particular group matches either the two-character sequence
- CR followed by LF, or one of the single characters LF (linefeed,
+ CR followed by LF, or one of the single characters LF (linefeed,
U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage
return, U+000D), or NEL (next line, U+0085). The two-character sequence
is treated as a single unit that cannot be split.
- In UTF-8 mode, two additional characters whose codepoints are greater
+ In UTF-8 mode, two additional characters whose codepoints are greater
than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-
- rator, U+2029). Unicode character property support is not needed for
+ rator, U+2029). Unicode character property support is not needed for
these characters to be recognized.
+ It is possible to restrict \R to match only CR, LF, or CRLF (instead of
+ the complete set of Unicode line endings) by setting the option
+ PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
+ (BSR is an abbrevation for "backslash R".) This can be made the default
+ when PCRE is built; if this is the case, the other behaviour can be
+ requested via the PCRE_BSR_UNICODE option. It is also possible to
+ specify these settings by starting a pattern string with one of the
+ following sequences:
+
+ (*BSR_ANYCRLF) CR, LF, or CRLF only
+ (*BSR_UNICODE) any Unicode newline sequence
+
+ These override the default and the options given to pcre_compile(), but
+ they can be overridden by options given to pcre_exec(). Note that these
+ special settings, which are not Perl-compatible, are recognized only at
+ the very start of a pattern, and that they must be in upper case. If
+ more than one of them is present, the last one is used. They can be
+ combined with a change of newline convention, for example, a pattern
+ can start with:
+
+ (*ANY)(*BSR_ANYCRLF)
+
Inside a character class, \R matches the letter "R".
Unicode character properties
When PCRE is built with Unicode character property support, three addi-
- tional escape sequences to match character properties are available
- when UTF-8 mode is selected. They are:
+ tional escape sequences that match characters with specific properties
+ are available. When not in UTF-8 mode, these sequences are of course
+ limited to testing characters whose codepoints are less than 256, but
+ they do work in this mode. The extra escape sequences are:
\p{xx} a character with the xx property
\P{xx} a character without the xx property
@@ -2981,6 +3424,12 @@ BACKSLASH
has the Lu, Ll, or Lt property, in other words, a letter that is not
classified as a modifier or "other".
+ The Cs (Surrogate) property applies only to characters in the range
+ U+D800 to U+DFFF. Such characters are not valid in UTF-8 strings (see
+ RFC 3629) and so cannot be tested by PCRE, unless UTF-8 validity check-
+ ing has been turned off (see the discussion of PCRE_NO_UTF8_CHECK in
+ the pcreapi page).
+
The long synonyms for these properties that Perl supports (such as
\p{Letter}) are not supported by PCRE, nor is it permitted to prefix
any of these properties with "Is".
@@ -3000,19 +3449,40 @@ BACKSLASH
That is, it matches a character without the "mark" property, followed
by zero or more characters with the "mark" property, and treats the
sequence as an atomic group (see below). Characters with the "mark"
- property are typically accents that affect the preceding character.
+ property are typically accents that affect the preceding character.
+ None of them have codepoints less than 256, so in non-UTF-8 mode \X
+ matches any one character.
Matching characters by Unicode property is not fast, because PCRE has
to search a structure that contains data for over fifteen thousand
characters. That is why the traditional escape sequences such as \d and
\w do not use Unicode properties in PCRE.
+ Resetting the match start
+
+ The escape sequence \K, which is a Perl 5.10 feature, causes any previ-
+ ously matched characters not to be included in the final matched
+ sequence. For example, the pattern:
+
+ foo\Kbar
+
+ matches "foobar", but reports that it has matched "bar". This feature
+ is similar to a lookbehind assertion (described below). However, in
+ this case, the part of the subject before the real match does not have
+ to be of fixed length, as lookbehind assertions do. The use of \K does
+ not interfere with the setting of captured substrings. For example,
+ when the pattern
+
+ (foo)\Kbar
+
+ matches "foobar", the first substring is still set to "foo".
+
Simple assertions
- The final use of backslash is for certain simple assertions. An asser-
- tion specifies a condition that has to be met at a particular point in
- a match, without consuming any characters from the subject string. The
- use of subpatterns for more complicated assertions is described below.
+ The final use of backslash is for certain simple assertions. An asser-
+ tion specifies a condition that has to be met at a particular point in
+ a match, without consuming any characters from the subject string. The
+ use of subpatterns for more complicated assertions is described below.
The backslashed assertions are:
\b matches at a word boundary
@@ -3023,41 +3493,41 @@ BACKSLASH
\z matches only at the end of the subject
\G matches at the first matching position in the subject
- These assertions may not appear in character classes (but note that \b
+ These assertions may not appear in character classes (but note that \b
has a different meaning, namely the backspace character, inside a char-
acter class).
- A word boundary is a position in the subject string where the current
- character and the previous character do not both match \w or \W (i.e.
- one matches \w and the other matches \W), or the start or end of the
+ A word boundary is a position in the subject string where the current
+ character and the previous character do not both match \w or \W (i.e.
+ one matches \w and the other matches \W), or the start or end of the
string if the first or last character matches \w, respectively.
- The \A, \Z, and \z assertions differ from the traditional circumflex
+ The \A, \Z, and \z assertions differ from the traditional circumflex
and dollar (described in the next section) in that they only ever match
- at the very start and end of the subject string, whatever options are
- set. Thus, they are independent of multiline mode. These three asser-
+ at the very start and end of the subject string, whatever options are
+ set. Thus, they are independent of multiline mode. These three asser-
tions are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options, which
- affect only the behaviour of the circumflex and dollar metacharacters.
- However, if the startoffset argument of pcre_exec() is non-zero, indi-
+ affect only the behaviour of the circumflex and dollar metacharacters.
+ However, if the startoffset argument of pcre_exec() is non-zero, indi-
cating that matching is to start at a point other than the beginning of
- the subject, \A can never match. The difference between \Z and \z is
+ the subject, \A can never match. The difference between \Z and \z is
that \Z matches before a newline at the end of the string as well as at
the very end, whereas \z matches only at the end.
- The \G assertion is true only when the current matching position is at
- the start point of the match, as specified by the startoffset argument
- of pcre_exec(). It differs from \A when the value of startoffset is
- non-zero. By calling pcre_exec() multiple times with appropriate argu-
+ The \G assertion is true only when the current matching position is at
+ the start point of the match, as specified by the startoffset argument
+ of pcre_exec(). It differs from \A when the value of startoffset is
+ non-zero. By calling pcre_exec() multiple times with appropriate argu-
ments, you can mimic Perl's /g option, and it is in this kind of imple-
mentation where \G can be useful.
- Note, however, that PCRE's interpretation of \G, as the start of the
+ Note, however, that PCRE's interpretation of \G, as the start of the
current match, is subtly different from Perl's, which defines it as the
- end of the previous match. In Perl, these can be different when the
- previously matched string was empty. Because PCRE does just one match
+ end of the previous match. In Perl, these can be different when the
+ previously matched string was empty. Because PCRE does just one match
at a time, it cannot reproduce this behaviour.
- If all the alternatives of a pattern begin with \G, the expression is
+ If all the alternatives of a pattern begin with \G, the expression is
anchored to the starting match position, and the "anchored" flag is set
in the compiled regular expression.
@@ -3065,90 +3535,90 @@ BACKSLASH
CIRCUMFLEX AND DOLLAR
Outside a character class, in the default matching mode, the circumflex
- character is an assertion that is true only if the current matching
- point is at the start of the subject string. If the startoffset argu-
- ment of pcre_exec() is non-zero, circumflex can never match if the
- PCRE_MULTILINE option is unset. Inside a character class, circumflex
+ character is an assertion that is true only if the current matching
+ point is at the start of the subject string. If the startoffset argu-
+ ment of pcre_exec() is non-zero, circumflex can never match if the
+ PCRE_MULTILINE option is unset. Inside a character class, circumflex
has an entirely different meaning (see below).
- Circumflex need not be the first character of the pattern if a number
- of alternatives are involved, but it should be the first thing in each
- alternative in which it appears if the pattern is ever to match that
- branch. If all possible alternatives start with a circumflex, that is,
- if the pattern is constrained to match only at the start of the sub-
- ject, it is said to be an "anchored" pattern. (There are also other
+ Circumflex need not be the first character of the pattern if a number
+ of alternatives are involved, but it should be the first thing in each
+ alternative in which it appears if the pattern is ever to match that
+ branch. If all possible alternatives start with a circumflex, that is,
+ if the pattern is constrained to match only at the start of the sub-
+ ject, it is said to be an "anchored" pattern. (There are also other
constructs that can cause a pattern to be anchored.)
- A dollar character is an assertion that is true only if the current
- matching point is at the end of the subject string, or immediately
+ A dollar character is an assertion that is true only if the current
+ matching point is at the end of the subject string, or immediately
before a newline at the end of the string (by default). Dollar need not
- be the last character of the pattern if a number of alternatives are
- involved, but it should be the last item in any branch in which it
+ be the last character of the pattern if a number of alternatives are
+ involved, but it should be the last item in any branch in which it
appears. Dollar has no special meaning in a character class.
- The meaning of dollar can be changed so that it matches only at the
- very end of the string, by setting the PCRE_DOLLAR_ENDONLY option at
+ The meaning of dollar can be changed so that it matches only at the
+ very end of the string, by setting the PCRE_DOLLAR_ENDONLY option at
compile time. This does not affect the \Z assertion.
The meanings of the circumflex and dollar characters are changed if the
- PCRE_MULTILINE option is set. When this is the case, a circumflex
- matches immediately after internal newlines as well as at the start of
- the subject string. It does not match after a newline that ends the
- string. A dollar matches before any newlines in the string, as well as
- at the very end, when PCRE_MULTILINE is set. When newline is specified
- as the two-character sequence CRLF, isolated CR and LF characters do
+ PCRE_MULTILINE option is set. When this is the case, a circumflex
+ matches immediately after internal newlines as well as at the start of
+ the subject string. It does not match after a newline that ends the
+ string. A dollar matches before any newlines in the string, as well as
+ at the very end, when PCRE_MULTILINE is set. When newline is specified
+ as the two-character sequence CRLF, isolated CR and LF characters do
not indicate newlines.
- For example, the pattern /^abc$/ matches the subject string "def\nabc"
- (where \n represents a newline) in multiline mode, but not otherwise.
- Consequently, patterns that are anchored in single line mode because
- all branches start with ^ are not anchored in multiline mode, and a
- match for circumflex is possible when the startoffset argument of
- pcre_exec() is non-zero. The PCRE_DOLLAR_ENDONLY option is ignored if
+ For example, the pattern /^abc$/ matches the subject string "def\nabc"
+ (where \n represents a newline) in multiline mode, but not otherwise.
+ Consequently, patterns that are anchored in single line mode because
+ all branches start with ^ are not anchored in multiline mode, and a
+ match for circumflex is possible when the startoffset argument of
+ pcre_exec() is non-zero. The PCRE_DOLLAR_ENDONLY option is ignored if
PCRE_MULTILINE is set.
- Note that the sequences \A, \Z, and \z can be used to match the start
- and end of the subject in both modes, and if all branches of a pattern
- start with \A it is always anchored, whether or not PCRE_MULTILINE is
+ Note that the sequences \A, \Z, and \z can be used to match the start
+ and end of the subject in both modes, and if all branches of a pattern
+ start with \A it is always anchored, whether or not PCRE_MULTILINE is
set.
FULL STOP (PERIOD, DOT)
Outside a character class, a dot in the pattern matches any one charac-
- ter in the subject string except (by default) a character that signi-
- fies the end of a line. In UTF-8 mode, the matched character may be
+ ter in the subject string except (by default) a character that signi-
+ fies the end of a line. In UTF-8 mode, the matched character may be
more than one byte long.
- When a line ending is defined as a single character, dot never matches
- that character; when the two-character sequence CRLF is used, dot does
- not match CR if it is immediately followed by LF, but otherwise it
- matches all characters (including isolated CRs and LFs). When any Uni-
- code line endings are being recognized, dot does not match CR or LF or
+ When a line ending is defined as a single character, dot never matches
+ that character; when the two-character sequence CRLF is used, dot does
+ not match CR if it is immediately followed by LF, but otherwise it
+ matches all characters (including isolated CRs and LFs). When any Uni-
+ code line endings are being recognized, dot does not match CR or LF or
any of the other line ending characters.
- The behaviour of dot with regard to newlines can be changed. If the
- PCRE_DOTALL option is set, a dot matches any one character, without
+ The behaviour of dot with regard to newlines can be changed. If the
+ PCRE_DOTALL option is set, a dot matches any one character, without
exception. If the two-character sequence CRLF is present in the subject
string, it takes two dots to match it.
- The handling of dot is entirely independent of the handling of circum-
- flex and dollar, the only relationship being that they both involve
+ The handling of dot is entirely independent of the handling of circum-
+ flex and dollar, the only relationship being that they both involve
newlines. Dot has no special meaning in a character class.
MATCHING A SINGLE BYTE
Outside a character class, the escape sequence \C matches any one byte,
- both in and out of UTF-8 mode. Unlike a dot, it always matches any
- line-ending characters. The feature is provided in Perl in order to
- match individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-
- acters into individual bytes, what remains in the string may be a mal-
- formed UTF-8 string. For this reason, the \C escape sequence is best
+ both in and out of UTF-8 mode. Unlike a dot, it always matches any
+ line-ending characters. The feature is provided in Perl in order to
+ match individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-
+ acters into individual bytes, what remains in the string may be a mal-
+ formed UTF-8 string. For this reason, the \C escape sequence is best
avoided.
- PCRE does not allow \C to appear in lookbehind assertions (described
- below), because in UTF-8 mode this would make it impossible to calcu-
+ PCRE does not allow \C to appear in lookbehind assertions (described
+ below), because in UTF-8 mode this would make it impossible to calcu-
late the length of the lookbehind.
@@ -3157,96 +3627,96 @@ SQUARE BRACKETS AND CHARACTER CLASSES
An opening square bracket introduces a character class, terminated by a
closing square bracket. A closing square bracket on its own is not spe-
cial. If a closing square bracket is required as a member of the class,
- it should be the first data character in the class (after an initial
+ it should be the first data character in the class (after an initial
circumflex, if present) or escaped with a backslash.
- A character class matches a single character in the subject. In UTF-8
- mode, the character may occupy more than one byte. A matched character
+ A character class matches a single character in the subject. In UTF-8
+ mode, the character may occupy more than one byte. A matched character
must be in the set of characters defined by the class, unless the first
- character in the class definition is a circumflex, in which case the
- subject character must not be in the set defined by the class. If a
- circumflex is actually required as a member of the class, ensure it is
+ character in the class definition is a circumflex, in which case the
+ subject character must not be in the set defined by the class. If a
+ circumflex is actually required as a member of the class, ensure it is
not the first character, or escape it with a backslash.
- For example, the character class [aeiou] matches any lower case vowel,
- while [^aeiou] matches any character that is not a lower case vowel.
+ For example, the character class [aeiou] matches any lower case vowel,
+ while [^aeiou] matches any character that is not a lower case vowel.
Note that a circumflex is just a convenient notation for specifying the
- characters that are in the class by enumerating those that are not. A
- class that starts with a circumflex is not an assertion: it still con-
- sumes a character from the subject string, and therefore it fails if
+ characters that are in the class by enumerating those that are not. A
+ class that starts with a circumflex is not an assertion: it still con-
+ sumes a character from the subject string, and therefore it fails if
the current pointer is at the end of the string.
- In UTF-8 mode, characters with values greater than 255 can be included
- in a class as a literal string of bytes, or by using the \x{ escaping
+ In UTF-8 mode, characters with values greater than 255 can be included
+ in a class as a literal string of bytes, or by using the \x{ escaping
mechanism.
- When caseless matching is set, any letters in a class represent both
- their upper case and lower case versions, so for example, a caseless
- [aeiou] matches "A" as well as "a", and a caseless [^aeiou] does not
- match "A", whereas a caseful version would. In UTF-8 mode, PCRE always
- understands the concept of case for characters whose values are less
- than 128, so caseless matching is always possible. For characters with
- higher values, the concept of case is supported if PCRE is compiled
- with Unicode property support, but not otherwise. If you want to use
- caseless matching for characters 128 and above, you must ensure that
- PCRE is compiled with Unicode property support as well as with UTF-8
+ When caseless matching is set, any letters in a class represent both
+ their upper case and lower case versions, so for example, a caseless
+ [aeiou] matches "A" as well as "a", and a caseless [^aeiou] does not
+ match "A", whereas a caseful version would. In UTF-8 mode, PCRE always
+ understands the concept of case for characters whose values are less
+ than 128, so caseless matching is always possible. For characters with
+ higher values, the concept of case is supported if PCRE is compiled
+ with Unicode property support, but not otherwise. If you want to use
+ caseless matching for characters 128 and above, you must ensure that
+ PCRE is compiled with Unicode property support as well as with UTF-8
support.
- Characters that might indicate line breaks are never treated in any
- special way when matching character classes, whatever line-ending
- sequence is in use, and whatever setting of the PCRE_DOTALL and
+ Characters that might indicate line breaks are never treated in any
+ special way when matching character classes, whatever line-ending
+ sequence is in use, and whatever setting of the PCRE_DOTALL and
PCRE_MULTILINE options is used. A class such as [^a] always matches one
of these characters.
- The minus (hyphen) character can be used to specify a range of charac-
- ters in a character class. For example, [d-m] matches any letter
- between d and m, inclusive. If a minus character is required in a
- class, it must be escaped with a backslash or appear in a position
- where it cannot be interpreted as indicating a range, typically as the
+ The minus (hyphen) character can be used to specify a range of charac-
+ ters in a character class. For example, [d-m] matches any letter
+ between d and m, inclusive. If a minus character is required in a
+ class, it must be escaped with a backslash or appear in a position
+ where it cannot be interpreted as indicating a range, typically as the
first or last character in the class.
It is not possible to have the literal character "]" as the end charac-
- ter of a range. A pattern such as [W-]46] is interpreted as a class of
- two characters ("W" and "-") followed by a literal string "46]", so it
- would match "W46]" or "-46]". However, if the "]" is escaped with a
- backslash it is interpreted as the end of range, so [W-\]46] is inter-
- preted as a class containing a range followed by two other characters.
- The octal or hexadecimal representation of "]" can also be used to end
+ ter of a range. A pattern such as [W-]46] is interpreted as a class of
+ two characters ("W" and "-") followed by a literal string "46]", so it
+ would match "W46]" or "-46]". However, if the "]" is escaped with a
+ backslash it is interpreted as the end of range, so [W-\]46] is inter-
+ preted as a class containing a range followed by two other characters.
+ The octal or hexadecimal representation of "]" can also be used to end
a range.
- Ranges operate in the collating sequence of character values. They can
- also be used for characters specified numerically, for example
- [\000-\037]. In UTF-8 mode, ranges can include characters whose values
+ Ranges operate in the collating sequence of character values. They can
+ also be used for characters specified numerically, for example
+ [\000-\037]. In UTF-8 mode, ranges can include characters whose values
are greater than 255, for example [\x{100}-\x{2ff}].
If a range that includes letters is used when caseless matching is set,
it matches the letters in either case. For example, [W-c] is equivalent
- to [][\\^_`wxyzabc], matched caselessly, and in non-UTF-8 mode, if
- character tables for the "fr_FR" locale are in use, [\xc8-\xcb] matches
- accented E characters in both cases. In UTF-8 mode, PCRE supports the
- concept of case for characters with values greater than 128 only when
+ to [][\\^_`wxyzabc], matched caselessly, and in non-UTF-8 mode, if
+ character tables for a French locale are in use, [\xc8-\xcb] matches
+ accented E characters in both cases. In UTF-8 mode, PCRE supports the
+ concept of case for characters with values greater than 128 only when
it is compiled with Unicode property support.
- The character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear
- in a character class, and add the characters that they match to the
+ The character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear
+ in a character class, and add the characters that they match to the
class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
- flex can conveniently be used with the upper case character types to
- specify a more restricted set of characters than the matching lower
- case type. For example, the class [^\W_] matches any letter or digit,
+ flex can conveniently be used with the upper case character types to
+ specify a more restricted set of characters than the matching lower
+ case type. For example, the class [^\W_] matches any letter or digit,
but not underscore.
- The only metacharacters that are recognized in character classes are
- backslash, hyphen (only where it can be interpreted as specifying a
- range), circumflex (only at the start), opening square bracket (only
- when it can be interpreted as introducing a POSIX class name - see the
- next section), and the terminating closing square bracket. However,
+ The only metacharacters that are recognized in character classes are
+ backslash, hyphen (only where it can be interpreted as specifying a
+ range), circumflex (only at the start), opening square bracket (only
+ when it can be interpreted as introducing a POSIX class name - see the
+ next section), and the terminating closing square bracket. However,
escaping other non-alphanumeric characters does no harm.
POSIX CHARACTER CLASSES
Perl supports the POSIX notation for character classes. This uses names
- enclosed by [: and :] within the enclosing square brackets. PCRE also
+ enclosed by [: and :] within the enclosing square brackets. PCRE also
supports this notation. For example,
[01[:alpha:]%]
@@ -3269,18 +3739,18 @@ POSIX CHARACTER CLASSES
word "word" characters (same as \w)
xdigit hexadecimal digits
- The "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13),
- and space (32). Notice that this list includes the VT character (code
+ The "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13),
+ and space (32). Notice that this list includes the VT character (code
11). This makes "space" different to \s, which does not include VT (for
Perl compatibility).
- The name "word" is a Perl extension, and "blank" is a GNU extension
- from Perl 5.8. Another Perl extension is negation, which is indicated
+ The name "word" is a Perl extension, and "blank" is a GNU extension
+ from Perl 5.8. Another Perl extension is negation, which is indicated
by a ^ character after the colon. For example,
[12[:^digit:]]
- matches "1", "2", or any non-digit. PCRE (and Perl) also recognize the
+ matches "1", "2", or any non-digit. PCRE (and Perl) also recognize the
POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
these are not supported, and an error is given if they are encountered.
@@ -3290,25 +3760,25 @@ POSIX CHARACTER CLASSES
VERTICAL BAR
- Vertical bar characters are used to separate alternative patterns. For
+ Vertical bar characters are used to separate alternative patterns. For
example, the pattern
gilbert|sullivan
- matches either "gilbert" or "sullivan". Any number of alternatives may
- appear, and an empty alternative is permitted (matching the empty
+ matches either "gilbert" or "sullivan". Any number of alternatives may
+ appear, and an empty alternative is permitted (matching the empty
string). The matching process tries each alternative in turn, from left
- to right, and the first one that succeeds is used. If the alternatives
- are within a subpattern (defined below), "succeeds" means matching the
- rest of the main pattern as well as the alternative in the subpattern.
+ to right, and the first one that succeeds is used. If the alternatives
+ are within a subpattern (defined below), "succeeds" means matching the
+ rest of the main pattern as well as the alternative in the subpattern.
INTERNAL OPTION SETTING
- The settings of the PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
- PCRE_EXTENDED options can be changed from within the pattern by a
- sequence of Perl option letters enclosed between "(?" and ")". The
- option letters are
+ The settings of the PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
+ PCRE_EXTENDED options (which are Perl-compatible) can be changed from
+ within the pattern by a sequence of Perl option letters enclosed
+ between "(?" and ")". The option letters are
i for PCRE_CASELESS
m for PCRE_MULTILINE
@@ -3317,39 +3787,45 @@ INTERNAL OPTION SETTING
For example, (?im) sets caseless, multiline matching. It is also possi-
ble to unset these options by preceding the letter with a hyphen, and a
- combined setting and unsetting such as (?im-sx), which sets PCRE_CASE-
- LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
- is also permitted. If a letter appears both before and after the
+ combined setting and unsetting such as (?im-sx), which sets PCRE_CASE-
+ LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
+ is also permitted. If a letter appears both before and after the
hyphen, the option is unset.
- When an option change occurs at top level (that is, not inside subpat-
- tern parentheses), the change applies to the remainder of the pattern
+ The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
+ can be changed in the same way as the Perl-compatible options by using
+ the characters J, U and X respectively.
+
+ When an option change occurs at top level (that is, not inside subpat-
+ tern parentheses), the change applies to the remainder of the pattern
that follows. If the change is placed right at the start of a pattern,
PCRE extracts it into the global options (and it will therefore show up
in data extracted by the pcre_fullinfo() function).
- An option change within a subpattern (see below for a description of
+ An option change within a subpattern (see below for a description of
subpatterns) affects only that part of the current pattern that follows
it, so
(a(?i)b)c
matches abc and aBc and no other strings (assuming PCRE_CASELESS is not
- used). By this means, options can be made to have different settings
- in different parts of the pattern. Any changes made in one alternative
- do carry on into subsequent branches within the same subpattern. For
+ used). By this means, options can be made to have different settings
+ in different parts of the pattern. Any changes made in one alternative
+ do carry on into subsequent branches within the same subpattern. For
example,
(a(?i)b|c)
- matches "ab", "aB", "c", and "C", even though when matching "C" the
- first branch is abandoned before the option setting. This is because
- the effects of option settings happen at compile time. There would be
+ matches "ab", "aB", "c", and "C", even though when matching "C" the
+ first branch is abandoned before the option setting. This is because
+ the effects of option settings happen at compile time. There would be
some very weird behaviour otherwise.
- The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
- can be changed in the same way as the Perl-compatible options by using
- the characters J, U and X respectively.
+ Note: There are other PCRE-specific options that can be set by the
+ application when the compile or match functions are called. In some
+ cases the pattern can contain special leading sequences to override
+ what the application has set or what has been defaulted. Details are
+ given in the section entitled "Newline sequences" above.
SUBPATTERNS
@@ -3361,18 +3837,18 @@ SUBPATTERNS
cat(aract|erpillar|)
- matches one of the words "cat", "cataract", or "caterpillar". Without
- the parentheses, it would match "cataract", "erpillar" or an empty
+ matches one of the words "cat", "cataract", or "caterpillar". Without
+ the parentheses, it would match "cataract", "erpillar" or an empty
string.
- 2. It sets up the subpattern as a capturing subpattern. This means
- that, when the whole pattern matches, that portion of the subject
+ 2. It sets up the subpattern as a capturing subpattern. This means
+ that, when the whole pattern matches, that portion of the subject
string that matched the subpattern is passed back to the caller via the
- ovector argument of pcre_exec(). Opening parentheses are counted from
- left to right (starting from 1) to obtain numbers for the capturing
+ ovector argument of pcre_exec(). Opening parentheses are counted from
+ left to right (starting from 1) to obtain numbers for the capturing
subpatterns.
- For example, if the string "the red king" is matched against the pat-
+ For example, if the string "the red king" is matched against the pat-
tern
the ((red|white) (king|queen))
@@ -3380,12 +3856,12 @@ SUBPATTERNS
the captured substrings are "red king", "red", and "king", and are num-
bered 1, 2, and 3, respectively.
- The fact that plain parentheses fulfil two functions is not always
- helpful. There are often times when a grouping subpattern is required
- without a capturing requirement. If an opening parenthesis is followed
- by a question mark and a colon, the subpattern does not do any captur-
- ing, and is not counted when computing the number of any subsequent
- capturing subpatterns. For example, if the string "the white queen" is
+ The fact that plain parentheses fulfil two functions is not always
+ helpful. There are often times when a grouping subpattern is required
+ without a capturing requirement. If an opening parenthesis is followed
+ by a question mark and a colon, the subpattern does not do any captur-
+ ing, and is not counted when computing the number of any subsequent
+ capturing subpatterns. For example, if the string "the white queen" is
matched against the pattern
the ((?:red|white) (king|queen))
@@ -3393,49 +3869,80 @@ SUBPATTERNS
the captured substrings are "white queen" and "queen", and are numbered
1 and 2. The maximum number of capturing subpatterns is 65535.
- As a convenient shorthand, if any option settings are required at the
- start of a non-capturing subpattern, the option letters may appear
+ As a convenient shorthand, if any option settings are required at the
+ start of a non-capturing subpattern, the option letters may appear
between the "?" and the ":". Thus the two patterns
(?i:saturday|sunday)
(?:(?i)saturday|sunday)
match exactly the same set of strings. Because alternative branches are
- tried from left to right, and options are not reset until the end of
- the subpattern is reached, an option setting in one branch does affect
- subsequent branches, so the above patterns match "SUNDAY" as well as
+ tried from left to right, and options are not reset until the end of
+ the subpattern is reached, an option setting in one branch does affect
+ subsequent branches, so the above patterns match "SUNDAY" as well as
"Saturday".
+DUPLICATE SUBPATTERN NUMBERS
+
+ Perl 5.10 introduced a feature whereby each alternative in a subpattern
+ uses the same numbers for its capturing parentheses. Such a subpattern
+ starts with (?| and is itself a non-capturing subpattern. For example,
+ consider this pattern:
+
+ (?|(Sat)ur|(Sun))day
+
+ Because the two alternatives are inside a (?| group, both sets of cap-
+ turing parentheses are numbered one. Thus, when the pattern matches,
+ you can look at captured substring number one, whichever alternative
+ matched. This construct is useful when you want to capture part, but
+ not all, of one of a number of alternatives. Inside a (?| group, paren-
+ theses are numbered as usual, but the number is reset at the start of
+ each branch. The numbers of any capturing buffers that follow the sub-
+ pattern start after the highest number used in any branch. The follow-
+ ing example is taken from the Perl documentation. The numbers under-
+ neath show in which buffer the captured content will be stored.
+
+ # before ---------------branch-reset----------- after
+ / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
+ # 1 2 2 3 2 3 4
+
+ A backreference or a recursive call to a numbered subpattern always
+ refers to the first one in the pattern with the given number.
+
+ An alternative approach to using this "branch reset" feature is to use
+ duplicate named subpatterns, as described in the next section.
+
+
NAMED SUBPATTERNS
- Identifying capturing parentheses by number is simple, but it can be
- very hard to keep track of the numbers in complicated regular expres-
- sions. Furthermore, if an expression is modified, the numbers may
- change. To help with this difficulty, PCRE supports the naming of sub-
+ Identifying capturing parentheses by number is simple, but it can be
+ very hard to keep track of the numbers in complicated regular expres-
+ sions. Furthermore, if an expression is modified, the numbers may
+ change. To help with this difficulty, PCRE supports the naming of sub-
patterns. This feature was not added to Perl until release 5.10. Python
- had the feature earlier, and PCRE introduced it at release 4.0, using
- the Python syntax. PCRE now supports both the Perl and the Python syn-
+ had the feature earlier, and PCRE introduced it at release 4.0, using
+ the Python syntax. PCRE now supports both the Perl and the Python syn-
tax.
- In PCRE, a subpattern can be named in one of three ways: (?<name>...)
- or (?'name'...) as in Perl, or (?P<name>...) as in Python. References
+ In PCRE, a subpattern can be named in one of three ways: (?<name>...)
+ or (?'name'...) as in Perl, or (?P<name>...) as in Python. References
to capturing parentheses from other parts of the pattern, such as back-
- references, recursion, and conditions, can be made by name as well as
+ references, recursion, and conditions, can be made by name as well as
by number.
- Names consist of up to 32 alphanumeric characters and underscores.
- Named capturing parentheses are still allocated numbers as well as
- names, exactly as if the names were not present. The PCRE API provides
+ Names consist of up to 32 alphanumeric characters and underscores.
+ Named capturing parentheses are still allocated numbers as well as
+ names, exactly as if the names were not present. The PCRE API provides
function calls for extracting the name-to-number translation table from
a compiled pattern. There is also a convenience function for extracting
a captured substring by name.
- By default, a name must be unique within a pattern, but it is possible
+ By default, a name must be unique within a pattern, but it is possible
to relax this constraint by setting the PCRE_DUPNAMES option at compile
- time. This can be useful for patterns where only one instance of the
- named parentheses can match. Suppose you want to match the name of a
- weekday, either as a 3-letter abbreviation or as the full name, and in
+ time. This can be useful for patterns where only one instance of the
+ named parentheses can match. Suppose you want to match the name of a
+ weekday, either as a 3-letter abbreviation or as the full name, and in
both cases you want to extract the abbreviation. This pattern (ignoring
the line breaks) does the job:
@@ -3445,20 +3952,22 @@ NAMED SUBPATTERNS
(?<DN>Thu)(?:rsday)?|
(?<DN>Sat)(?:urday)?
- There are five capturing substrings, but only one is ever set after a
- match. The convenience function for extracting the data by name
- returns the substring for the first (and in this example, the only)
- subpattern of that name that matched. This saves searching to find
- which numbered subpattern it was. If you make a reference to a non-
- unique named subpattern from elsewhere in the pattern, the one that
- corresponds to the lowest number is used. For further details of the
- interfaces for handling named subpatterns, see the pcreapi documenta-
- tion.
+ There are five capturing substrings, but only one is ever set after a
+ match. (An alternative way of solving this problem is to use a "branch
+ reset" subpattern, as described in the previous section.)
+
+ The convenience function for extracting the data by name returns the
+ substring for the first (and in this example, the only) subpattern of
+ that name that matched. This saves searching to find which numbered
+ subpattern it was. If you make a reference to a non-unique named sub-
+ pattern from elsewhere in the pattern, the one that corresponds to the
+ lowest number is used. For further details of the interfaces for han-
+ dling named subpatterns, see the pcreapi documentation.
REPETITION
- Repetition is specified by quantifiers, which can follow any of the
+ Repetition is specified by quantifiers, which can follow any of the
following items:
a literal data character
@@ -3471,17 +3980,17 @@ REPETITION
a back reference (see next section)
a parenthesized subpattern (unless it is an assertion)
- The general repetition quantifier specifies a minimum and maximum num-
- ber of permitted matches, by giving the two numbers in curly brackets
- (braces), separated by a comma. The numbers must be less than 65536,
+ The general repetition quantifier specifies a minimum and maximum num-
+ ber of permitted matches, by giving the two numbers in curly brackets
+ (braces), separated by a comma. The numbers must be less than 65536,
and the first must be less than or equal to the second. For example:
z{2,4}
- matches "zz", "zzz", or "zzzz". A closing brace on its own is not a
- special character. If the second number is omitted, but the comma is
- present, there is no upper limit; if the second number and the comma
- are both omitted, the quantifier specifies an exact number of required
+ matches "zz", "zzz", or "zzzz". A closing brace on its own is not a
+ special character. If the second number is omitted, but the comma is
+ present, there is no upper limit; if the second number and the comma
+ are both omitted, the quantifier specifies an exact number of required
matches. Thus
[aeiou]{3,}
@@ -3490,20 +3999,23 @@ REPETITION
\d{8}
- matches exactly 8 digits. An opening curly bracket that appears in a
- position where a quantifier is not allowed, or one that does not match
- the syntax of a quantifier, is taken as a literal character. For exam-
+ matches exactly 8 digits. An opening curly bracket that appears in a
+ position where a quantifier is not allowed, or one that does not match
+ the syntax of a quantifier, is taken as a literal character. For exam-
ple, {,6} is not a quantifier, but a literal string of four characters.
- In UTF-8 mode, quantifiers apply to UTF-8 characters rather than to
+ In UTF-8 mode, quantifiers apply to UTF-8 characters rather than to
individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-
acters, each of which is represented by a two-byte sequence. Similarly,
when Unicode property support is available, \X{3} matches three Unicode
- extended sequences, each of which may be several bytes long (and they
+ extended sequences, each of which may be several bytes long (and they
may be of different lengths).
The quantifier {0} is permitted, causing the expression to behave as if
- the previous item and the quantifier were not present.
+ the previous item and the quantifier were not present. This may be use-
+ ful for subpatterns that are referenced as subroutines from elsewhere
+ in the pattern. Items other than subpatterns that have a {0} quantifier
+ are omitted from the compiled pattern.
For convenience, the three most common quantifiers have single-charac-
ter abbreviations:
@@ -3658,122 +4170,132 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
\d++foo
- Possessive quantifiers are always greedy; the setting of the
+ Note that a possessive quantifier can be used with an entire group, for
+ example:
+
+ (abc|xyz){2,3}+
+
+ Possessive quantifiers are always greedy; the setting of the
PCRE_UNGREEDY option is ignored. They are a convenient notation for the
- simpler forms of atomic group. However, there is no difference in the
- meaning of a possessive quantifier and the equivalent atomic group,
- though there may be a performance difference; possessive quantifiers
+ simpler forms of atomic group. However, there is no difference in the
+ meaning of a possessive quantifier and the equivalent atomic group,
+ though there may be a performance difference; possessive quantifiers
should be slightly faster.
- The possessive quantifier syntax is an extension to the Perl 5.8 syn-
- tax. Jeffrey Friedl originated the idea (and the name) in the first
+ The possessive quantifier syntax is an extension to the Perl 5.8 syn-
+ tax. Jeffrey Friedl originated the idea (and the name) in the first
edition of his book. Mike McCloskey liked it, so implemented it when he
- built Sun's Java package, and PCRE copied it from there. It ultimately
+ built Sun's Java package, and PCRE copied it from there. It ultimately
found its way into Perl at release 5.10.
PCRE has an optimization that automatically "possessifies" certain sim-
- ple pattern constructs. For example, the sequence A+B is treated as
- A++B because there is no point in backtracking into a sequence of A's
+ ple pattern constructs. For example, the sequence A+B is treated as
+ A++B because there is no point in backtracking into a sequence of A's
when B must follow.
- When a pattern contains an unlimited repeat inside a subpattern that
- can itself be repeated an unlimited number of times, the use of an
- atomic group is the only way to avoid some failing matches taking a
+ When a pattern contains an unlimited repeat inside a subpattern that
+ can itself be repeated an unlimited number of times, the use of an
+ atomic group is the only way to avoid some failing matches taking a
very long time indeed. The pattern
(\D+|<\d+>)*[!?]
- matches an unlimited number of substrings that either consist of non-
- digits, or digits enclosed in <>, followed by either ! or ?. When it
+ matches an unlimited number of substrings that either consist of non-
+ digits, or digits enclosed in <>, followed by either ! or ?. When it
matches, it runs quickly. However, if it is applied to
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- it takes a long time before reporting failure. This is because the
- string can be divided between the internal \D+ repeat and the external
- * repeat in a large number of ways, and all have to be tried. (The
- example uses [!?] rather than a single character at the end, because
- both PCRE and Perl have an optimization that allows for fast failure
- when a single character is used. They remember the last single charac-
- ter that is required for a match, and fail early if it is not present
- in the string.) If the pattern is changed so that it uses an atomic
+ it takes a long time before reporting failure. This is because the
+ string can be divided between the internal \D+ repeat and the external
+ * repeat in a large number of ways, and all have to be tried. (The
+ example uses [!?] rather than a single character at the end, because
+ both PCRE and Perl have an optimization that allows for fast failure
+ when a single character is used. They remember the last single charac-
+ ter that is required for a match, and fail early if it is not present
+ in the string.) If the pattern is changed so that it uses an atomic
group, like this:
((?>\D+)|<\d+>)*[!?]
- sequences of non-digits cannot be broken, and failure happens quickly.
+ sequences of non-digits cannot be broken, and failure happens quickly.
BACK REFERENCES
Outside a character class, a backslash followed by a digit greater than
0 (and possibly further digits) is a back reference to a capturing sub-
- pattern earlier (that is, to its left) in the pattern, provided there
+ pattern earlier (that is, to its left) in the pattern, provided there
have been that many previous capturing left parentheses.
However, if the decimal number following the backslash is less than 10,
- it is always taken as a back reference, and causes an error only if
- there are not that many capturing left parentheses in the entire pat-
- tern. In other words, the parentheses that are referenced need not be
- to the left of the reference for numbers less than 10. A "forward back
- reference" of this type can make sense when a repetition is involved
- and the subpattern to the right has participated in an earlier itera-
+ it is always taken as a back reference, and causes an error only if
+ there are not that many capturing left parentheses in the entire pat-
+ tern. In other words, the parentheses that are referenced need not be
+ to the left of the reference for numbers less than 10. A "forward back
+ reference" of this type can make sense when a repetition is involved
+ and the subpattern to the right has participated in an earlier itera-
tion.
- It is not possible to have a numerical "forward back reference" to a
- subpattern whose number is 10 or more using this syntax because a
- sequence such as \50 is interpreted as a character defined in octal.
+ It is not possible to have a numerical "forward back reference" to a
+ subpattern whose number is 10 or more using this syntax because a
+ sequence such as \50 is interpreted as a character defined in octal.
See the subsection entitled "Non-printing characters" above for further
- details of the handling of digits following a backslash. There is no
- such problem when named parentheses are used. A back reference to any
+ details of the handling of digits following a backslash. There is no
+ such problem when named parentheses are used. A back reference to any
subpattern is possible using named parentheses (see below).
- Another way of avoiding the ambiguity inherent in the use of digits
+ Another way of avoiding the ambiguity inherent in the use of digits
following a backslash is to use the \g escape sequence, which is a fea-
- ture introduced in Perl 5.10. This escape must be followed by a posi-
- tive or a negative number, optionally enclosed in braces. These exam-
- ples are all identical:
+ ture introduced in Perl 5.10. This escape must be followed by an
+ unsigned number or a negative number, optionally enclosed in braces.
+ These examples are all identical:
(ring), \1
(ring), \g1
(ring), \g{1}
- A positive number specifies an absolute reference without the ambiguity
- that is present in the older syntax. It is also useful when literal
+ An unsigned number specifies an absolute reference without the ambigu-
+ ity that is present in the older syntax. It is also useful when literal
digits follow the reference. A negative number is a relative reference.
Consider this example:
(abc(def)ghi)\g{-1}
The sequence \g{-1} is a reference to the most recently started captur-
- ing subpattern before \g, that is, is it equivalent to \2. Similarly,
+ ing subpattern before \g, that is, is it equivalent to \2. Similarly,
\g{-2} would be equivalent to \1. The use of relative references can be
- helpful in long patterns, and also in patterns that are created by
+ helpful in long patterns, and also in patterns that are created by
joining together fragments that contain references within themselves.
- A back reference matches whatever actually matched the capturing sub-
- pattern in the current subject string, rather than anything matching
+ A back reference matches whatever actually matched the capturing sub-
+ pattern in the current subject string, rather than anything matching
the subpattern itself (see "Subpatterns as subroutines" below for a way
of doing that). So the pattern
(sens|respons)e and \1ibility
- matches "sense and sensibility" and "response and responsibility", but
- not "sense and responsibility". If caseful matching is in force at the
- time of the back reference, the case of letters is relevant. For exam-
+ matches "sense and sensibility" and "response and responsibility", but
+ not "sense and responsibility". If caseful matching is in force at the
+ time of the back reference, the case of letters is relevant. For exam-
ple,
((?i)rah)\s+\1
- matches "rah rah" and "RAH RAH", but not "RAH rah", even though the
+ matches "rah rah" and "RAH RAH", but not "RAH rah", even though the
original capturing subpattern is matched caselessly.
- Back references to named subpatterns use the Perl syntax \k<name> or
- \k'name' or the Python syntax (?P=name). We could rewrite the above
- example in either of the following ways:
+ There are several different ways of writing back references to named
+ subpatterns. The .NET syntax \k{name} and the Perl syntax \k<name> or
+ \k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's
+ unified back reference syntax, in which \g can be used for both numeric
+ and named references, is also supported. We could rewrite the above
+ example in any of the following ways:
(?<p1>(?i)rah)\s+\k<p1>
+ (?'p1'(?i)rah)\s+\k{p1}
(?P<p1>(?i)rah)\s+(?P=p1)
+ (?<p1>(?i)rah)\s+\g{p1}
A subpattern that is referenced by name may appear in the pattern
before or after the reference.
@@ -3888,6 +4410,10 @@ ASSERTIONS
(?<=abc|abde)
+ In some cases, the Perl 5.10 escape sequence \K (see above) can be used
+ instead of a lookbehind assertion; this is not restricted to a fixed-
+ length.
+
The implementation of lookbehind assertions is, for each alternative,
to temporarily move the current position back by the fixed length and
then try to match. If there are insufficient characters before the cur-
@@ -3981,35 +4507,48 @@ CONDITIONAL SUBPATTERNS
If the text between the parentheses consists of a sequence of digits,
the condition is true if the capturing subpattern of that number has
- previously matched.
-
- Consider the following pattern, which contains non-significant white
+ previously matched. An alternative notation is to precede the digits
+ with a plus or minus sign. In this case, the subpattern number is rela-
+ tive rather than absolute. The most recently opened parentheses can be
+ referenced by (?(-1), the next most recent by (?(-2), and so on. In
+ looping constructs it can also make sense to refer to subsequent groups
+ with constructs such as (?(+2).
+
+ Consider the following pattern, which contains non-significant white
space to make it more readable (assume the PCRE_EXTENDED option) and to
divide it into three parts for ease of discussion:
( \( )? [^()]+ (?(1) \) )
- The first part matches an optional opening parenthesis, and if that
+ The first part matches an optional opening parenthesis, and if that
character is present, sets it as the first captured substring. The sec-
- ond part matches one or more characters that are not parentheses. The
+ ond part matches one or more characters that are not parentheses. The
third part is a conditional subpattern that tests whether the first set
of parentheses matched or not. If they did, that is, if subject started
with an opening parenthesis, the condition is true, and so the yes-pat-
- tern is executed and a closing parenthesis is required. Otherwise,
- since no-pattern is not present, the subpattern matches nothing. In
- other words, this pattern matches a sequence of non-parentheses,
+ tern is executed and a closing parenthesis is required. Otherwise,
+ since no-pattern is not present, the subpattern matches nothing. In
+ other words, this pattern matches a sequence of non-parentheses,
optionally enclosed in parentheses.
+ If you were embedding this pattern in a larger one, you could use a
+ relative reference:
+
+ ...other stuff... ( \( )? [^()]+ (?(-1) \) ) ...
+
+ This makes the fragment independent of the parentheses in the larger
+ pattern.
+
Checking for a used subpattern by name
- Perl uses the syntax (?(<name>)...) or (?('name')...) to test for a
- used subpattern by name. For compatibility with earlier versions of
- PCRE, which had this facility before Perl, the syntax (?(name)...) is
- also recognized. However, there is a possible ambiguity with this syn-
- tax, because subpattern names may consist entirely of digits. PCRE
- looks first for a named subpattern; if it cannot find one and the name
- consists entirely of digits, PCRE looks for a subpattern of that num-
- ber, which must be greater than zero. Using subpattern names that con-
+ Perl uses the syntax (?(<name>)...) or (?('name')...) to test for a
+ used subpattern by name. For compatibility with earlier versions of
+ PCRE, which had this facility before Perl, the syntax (?(name)...) is
+ also recognized. However, there is a possible ambiguity with this syn-
+ tax, because subpattern names may consist entirely of digits. PCRE
+ looks first for a named subpattern; if it cannot find one and the name
+ consists entirely of digits, PCRE looks for a subpattern of that num-
+ ber, which must be greater than zero. Using subpattern names that con-
sist entirely of digits is not recommended.
Rewriting the above example to use a named subpattern gives this:
@@ -4020,85 +4559,85 @@ CONDITIONAL SUBPATTERNS
Checking for pattern recursion
If the condition is the string (R), and there is no subpattern with the
- name R, the condition is true if a recursive call to the whole pattern
+ name R, the condition is true if a recursive call to the whole pattern
or any subpattern has been made. If digits or a name preceded by amper-
sand follow the letter R, for example:
(?(R3)...) or (?(R&name)...)
- the condition is true if the most recent recursion is into the subpat-
- tern whose number or name is given. This condition does not check the
+ the condition is true if the most recent recursion is into the subpat-
+ tern whose number or name is given. This condition does not check the
entire recursion stack.
- At "top level", all these recursion test conditions are false. Recur-
+ At "top level", all these recursion test conditions are false. Recur-
sive patterns are described below.
Defining subpatterns for use by reference only
- If the condition is the string (DEFINE), and there is no subpattern
- with the name DEFINE, the condition is always false. In this case,
- there may be only one alternative in the subpattern. It is always
- skipped if control reaches this point in the pattern; the idea of
- DEFINE is that it can be used to define "subroutines" that can be ref-
- erenced from elsewhere. (The use of "subroutines" is described below.)
- For example, a pattern to match an IPv4 address could be written like
+ If the condition is the string (DEFINE), and there is no subpattern
+ with the name DEFINE, the condition is always false. In this case,
+ there may be only one alternative in the subpattern. It is always
+ skipped if control reaches this point in the pattern; the idea of
+ DEFINE is that it can be used to define "subroutines" that can be ref-
+ erenced from elsewhere. (The use of "subroutines" is described below.)
+ For example, a pattern to match an IPv4 address could be written like
this (ignore whitespace and line breaks):
(?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )
\b (?&byte) (\.(?&byte)){3} \b
- The first part of the pattern is a DEFINE group inside which a another
- group named "byte" is defined. This matches an individual component of
- an IPv4 address (a number less than 256). When matching takes place,
- this part of the pattern is skipped because DEFINE acts like a false
+ The first part of the pattern is a DEFINE group inside which a another
+ group named "byte" is defined. This matches an individual component of
+ an IPv4 address (a number less than 256). When matching takes place,
+ this part of the pattern is skipped because DEFINE acts like a false
condition.
The rest of the pattern uses references to the named group to match the
- four dot-separated components of an IPv4 address, insisting on a word
+ four dot-separated components of an IPv4 address, insisting on a word
boundary at each end.
Assertion conditions
- If the condition is not in any of the above formats, it must be an
- assertion. This may be a positive or negative lookahead or lookbehind
- assertion. Consider this pattern, again containing non-significant
+ If the condition is not in any of the above formats, it must be an
+ assertion. This may be a positive or negative lookahead or lookbehind
+ assertion. Consider this pattern, again containing non-significant
white space, and with the two alternatives on the second line:
(?(?=[^a-z]*[a-z])
\d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} )
- The condition is a positive lookahead assertion that matches an
- optional sequence of non-letters followed by a letter. In other words,
- it tests for the presence of at least one letter in the subject. If a
- letter is found, the subject is matched against the first alternative;
- otherwise it is matched against the second. This pattern matches
- strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are
+ The condition is a positive lookahead assertion that matches an
+ optional sequence of non-letters followed by a letter. In other words,
+ it tests for the presence of at least one letter in the subject. If a
+ letter is found, the subject is matched against the first alternative;
+ otherwise it is matched against the second. This pattern matches
+ strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are
letters and dd are digits.
COMMENTS
- The sequence (?# marks the start of a comment that continues up to the
- next closing parenthesis. Nested parentheses are not permitted. The
- characters that make up a comment play no part in the pattern matching
+ The sequence (?# marks the start of a comment that continues up to the
+ next closing parenthesis. Nested parentheses are not permitted. The
+ characters that make up a comment play no part in the pattern matching
at all.
- If the PCRE_EXTENDED option is set, an unescaped # character outside a
- character class introduces a comment that continues to immediately
+ If the PCRE_EXTENDED option is set, an unescaped # character outside a
+ character class introduces a comment that continues to immediately
after the next newline in the pattern.
RECURSIVE PATTERNS
- Consider the problem of matching a string in parentheses, allowing for
- unlimited nested parentheses. Without the use of recursion, the best
- that can be done is to use a pattern that matches up to some fixed
- depth of nesting. It is not possible to handle an arbitrary nesting
+ Consider the problem of matching a string in parentheses, allowing for
+ unlimited nested parentheses. Without the use of recursion, the best
+ that can be done is to use a pattern that matches up to some fixed
+ depth of nesting. It is not possible to handle an arbitrary nesting
depth.
For some time, Perl has provided a facility that allows regular expres-
- sions to recurse (amongst other things). It does this by interpolating
- Perl code in the expression at run time, and the code can refer to the
+ sions to recurse (amongst other things). It does this by interpolating
+ Perl code in the expression at run time, and the code can refer to the
expression itself. A Perl pattern using code interpolation to solve the
parentheses problem can be created like this:
@@ -4108,130 +4647,173 @@ RECURSIVE PATTERNS
refers recursively to the pattern in which it appears.
Obviously, PCRE cannot support the interpolation of Perl code. Instead,
- it supports special syntax for recursion of the entire pattern, and
- also for individual subpattern recursion. After its introduction in
- PCRE and Python, this kind of recursion was introduced into Perl at
+ it supports special syntax for recursion of the entire pattern, and
+ also for individual subpattern recursion. After its introduction in
+ PCRE and Python, this kind of recursion was introduced into Perl at
release 5.10.
- A special item that consists of (? followed by a number greater than
+ A special item that consists of (? followed by a number greater than
zero and a closing parenthesis is a recursive call of the subpattern of
- the given number, provided that it occurs inside that subpattern. (If
- not, it is a "subroutine" call, which is described in the next sec-
- tion.) The special item (?R) or (?0) is a recursive call of the entire
+ the given number, provided that it occurs inside that subpattern. (If
+ not, it is a "subroutine" call, which is described in the next sec-
+ tion.) The special item (?R) or (?0) is a recursive call of the entire
regular expression.
- In PCRE (like Python, but unlike Perl), a recursive subpattern call is
+ In PCRE (like Python, but unlike Perl), a recursive subpattern call is
always treated as an atomic group. That is, once it has matched some of
the subject string, it is never re-entered, even if it contains untried
alternatives and there is a subsequent matching failure.
- This PCRE pattern solves the nested parentheses problem (assume the
+ This PCRE pattern solves the nested parentheses problem (assume the
PCRE_EXTENDED option is set so that white space is ignored):
\( ( (?>[^()]+) | (?R) )* \)
- First it matches an opening parenthesis. Then it matches any number of
- substrings which can either be a sequence of non-parentheses, or a
- recursive match of the pattern itself (that is, a correctly parenthe-
+ First it matches an opening parenthesis. Then it matches any number of
+ substrings which can either be a sequence of non-parentheses, or a
+ recursive match of the pattern itself (that is, a correctly parenthe-
sized substring). Finally there is a closing parenthesis.
- If this were part of a larger pattern, you would not want to recurse
+ If this were part of a larger pattern, you would not want to recurse
the entire pattern, so instead you could use this:
( \( ( (?>[^()]+) | (?1) )* \) )
- We have put the pattern into parentheses, and caused the recursion to
- refer to them instead of the whole pattern. In a larger pattern, keep-
- ing track of parenthesis numbers can be tricky. It may be more conve-
- nient to use named parentheses instead. The Perl syntax for this is
- (?&name); PCRE's earlier syntax (?P>name) is also supported. We could
- rewrite the above example as follows:
+ We have put the pattern into parentheses, and caused the recursion to
+ refer to them instead of the whole pattern.
+
+ In a larger pattern, keeping track of parenthesis numbers can be
+ tricky. This is made easier by the use of relative references. (A Perl
+ 5.10 feature.) Instead of (?1) in the pattern above you can write
+ (?-2) to refer to the second most recently opened parentheses preceding
+ the recursion. In other words, a negative number counts capturing
+ parentheses leftwards from the point at which it is encountered.
+
+ It is also possible to refer to subsequently opened parentheses, by
+ writing references such as (?+2). However, these cannot be recursive
+ because the reference is not inside the parentheses that are refer-
+ enced. They are always "subroutine" calls, as described in the next
+ section.
+
+ An alternative approach is to use named parentheses instead. The Perl
+ syntax for this is (?&name); PCRE's earlier syntax (?P>name) is also
+ supported. We could rewrite the above example as follows:
(?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )
If there is more than one subpattern with the same name, the earliest
- one is used. This particular example pattern contains nested unlimited
- repeats, and so the use of atomic grouping for matching strings of non-
- parentheses is important when applying the pattern to strings that do
- not match. For example, when this pattern is applied to
+ one is used.
+
+ This particular example pattern that we have been looking at contains
+ nested unlimited repeats, and so the use of atomic grouping for match-
+ ing strings of non-parentheses is important when applying the pattern
+ to strings that do not match. For example, when this pattern is applied
+ to
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
- it yields "no match" quickly. However, if atomic grouping is not used,
- the match runs for a very long time indeed because there are so many
- different ways the + and * repeats can carve up the subject, and all
+ it yields "no match" quickly. However, if atomic grouping is not used,
+ the match runs for a very long time indeed because there are so many
+ different ways the + and * repeats can carve up the subject, and all
have to be tested before failure can be reported.
At the end of a match, the values set for any capturing subpatterns are
those from the outermost level of the recursion at which the subpattern
- value is set. If you want to obtain intermediate values, a callout
- function can be used (see below and the pcrecallout documentation). If
+ value is set. If you want to obtain intermediate values, a callout
+ function can be used (see below and the pcrecallout documentation). If
the pattern above is matched against
(ab(cd)ef)
- the value for the capturing parentheses is "ef", which is the last
- value taken on at the top level. If additional parentheses are added,
+ the value for the capturing parentheses is "ef", which is the last
+ value taken on at the top level. If additional parentheses are added,
giving
\( ( ( (?>[^()]+) | (?R) )* ) \)
^ ^
^ ^
- the string they capture is "ab(cd)ef", the contents of the top level
- parentheses. If there are more than 15 capturing parentheses in a pat-
+ the string they capture is "ab(cd)ef", the contents of the top level
+ parentheses. If there are more than 15 capturing parentheses in a pat-
tern, PCRE has to obtain extra memory to store data during a recursion,
- which it does by using pcre_malloc, freeing it via pcre_free after-
- wards. If no memory can be obtained, the match fails with the
+ which it does by using pcre_malloc, freeing it via pcre_free after-
+ wards. If no memory can be obtained, the match fails with the
PCRE_ERROR_NOMEMORY error.
- Do not confuse the (?R) item with the condition (R), which tests for
- recursion. Consider this pattern, which matches text in angle brack-
- ets, allowing for arbitrary nesting. Only digits are allowed in nested
- brackets (that is, when recursing), whereas any characters are permit-
+ Do not confuse the (?R) item with the condition (R), which tests for
+ recursion. Consider this pattern, which matches text in angle brack-
+ ets, allowing for arbitrary nesting. Only digits are allowed in nested
+ brackets (that is, when recursing), whereas any characters are permit-
ted at the outer level.
< (?: (?(R) \d++ | [^<>]*+) | (?R)) * >
- In this pattern, (?(R) is the start of a conditional subpattern, with
- two different alternatives for the recursive and non-recursive cases.
+ In this pattern, (?(R) is the start of a conditional subpattern, with
+ two different alternatives for the recursive and non-recursive cases.
The (?R) item is the actual recursive call.
SUBPATTERNS AS SUBROUTINES
If the syntax for a recursive subpattern reference (either by number or
- by name) is used outside the parentheses to which it refers, it oper-
- ates like a subroutine in a programming language. The "called" subpat-
- tern may be defined before or after the reference. An earlier example
- pointed out that the pattern
+ by name) is used outside the parentheses to which it refers, it oper-
+ ates like a subroutine in a programming language. The "called" subpat-
+ tern may be defined before or after the reference. A numbered reference
+ can be absolute or relative, as in these examples:
+
+ (...(absolute)...)...(?2)...
+ (...(relative)...)...(?-1)...
+ (...(?+1)...(relative)...
+
+ An earlier example pointed out that the pattern
(sens|respons)e and \1ibility
- matches "sense and sensibility" and "response and responsibility", but
+ matches "sense and sensibility" and "response and responsibility", but
not "sense and responsibility". If instead the pattern
(sens|respons)e and (?1)ibility
- is used, it does match "sense and responsibility" as well as the other
- two strings. Another example is given in the discussion of DEFINE
+ is used, it does match "sense and responsibility" as well as the other
+ two strings. Another example is given in the discussion of DEFINE
above.
Like recursive subpatterns, a "subroutine" call is always treated as an
- atomic group. That is, once it has matched some of the subject string,
- it is never re-entered, even if it contains untried alternatives and
+ atomic group. That is, once it has matched some of the subject string,
+ it is never re-entered, even if it contains untried alternatives and
there is a subsequent matching failure.
- When a subpattern is used as a subroutine, processing options such as
+ When a subpattern is used as a subroutine, processing options such as
case-independence are fixed when the subpattern is defined. They cannot
be changed for different calls. For example, consider this pattern:
- (abc)(?i:(?1))
+ (abc)(?i:(?-1))
- It matches "abcabc". It does not match "abcABC" because the change of
+ It matches "abcabc". It does not match "abcABC" because the change of
processing option does not affect the called subpattern.
+ONIGURUMA SUBROUTINE SYNTAX
+
+ For compatibility with Oniguruma, the non-Perl syntax \g followed by a
+ name or a number enclosed either in angle brackets or single quotes, is
+ an alternative syntax for referencing a subpattern as a subroutine,
+ possibly recursively. Here are two of the examples used above, rewrit-
+ ten using this syntax:
+
+ (?<pn> \( ( (?>[^()]+) | \g<pn> )* \) )
+ (sens|respons)e and \g'1'ibility
+
+ PCRE supports an extension to Oniguruma: if a number is preceded by a
+ plus or a minus sign it is taken as a relative reference. For example:
+
+ (abc)(?i:\g<-1>)
+
+ Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not
+ synonymous. The former is a back reference; the latter is a subroutine
+ call.
+
+
CALLOUTS
Perl has a feature whereby using the sequence (?{...}) causes arbitrary
@@ -4267,12 +4849,486 @@ CALLOUTS
is given in the pcrecallout documentation.
+BACKTRACKING CONTROL
+
+ Perl 5.10 introduced a number of "Special Backtracking Control Verbs",
+ which are described in the Perl documentation as "experimental and sub-
+ ject to change or removal in a future version of Perl". It goes on to
+ say: "Their usage in production code should be noted to avoid problems
+ during upgrades." The same remarks apply to the PCRE features described
+ in this section.
+
+ Since these verbs are specifically related to backtracking, most of
+ them can be used only when the pattern is to be matched using
+ pcre_exec(), which uses a backtracking algorithm. With the exception of
+ (*FAIL), which behaves like a failing negative assertion, they cause an
+ error if encountered by pcre_dfa_exec().
+
+ The new verbs make use of what was previously invalid syntax: an open-
+ ing parenthesis followed by an asterisk. In Perl, they are generally of
+ the form (*VERB:ARG) but PCRE does not support the use of arguments, so
+ its general form is just (*VERB). Any number of these verbs may occur
+ in a pattern. There are two kinds:
+
+ Verbs that act immediately
+
+ The following verbs act as soon as they are encountered:
+
+ (*ACCEPT)
+
+ This verb causes the match to end successfully, skipping the remainder
+ of the pattern. When inside a recursion, only the innermost pattern is
+ ended immediately. PCRE differs from Perl in what happens if the
+ (*ACCEPT) is inside capturing parentheses. In Perl, the data so far is
+ captured: in PCRE no data is captured. For example:
+
+ A(A|B(*ACCEPT)|C)D
+
+ This matches "AB", "AAD", or "ACD", but when it matches "AB", no data
+ is captured.
+
+ (*FAIL) or (*F)
+
+ This verb causes the match to fail, forcing backtracking to occur. It
+ is equivalent to (?!) but easier to read. The Perl documentation notes
+ that it is probably useful only when combined with (?{}) or (??{}).
+ Those are, of course, Perl features that are not present in PCRE. The
+ nearest equivalent is the callout feature, as for example in this pat-
+ tern:
+
+ a+(?C)(*FAIL)
+
+ A match with the string "aaaa" always fails, but the callout is taken
+ before each backtrack happens (in this example, 10 times).
+
+ Verbs that act after backtracking
+
+ The following verbs do nothing when they are encountered. Matching con-
+ tinues with what follows, but if there is no subsequent match, a fail-
+ ure is forced. The verbs differ in exactly what kind of failure
+ occurs.
+
+ (*COMMIT)
+
+ This verb causes the whole match to fail outright if the rest of the
+ pattern does not match. Even if the pattern is unanchored, no further
+ attempts to find a match by advancing the start point take place. Once
+ (*COMMIT) has been passed, pcre_exec() is committed to finding a match
+ at the current starting point, or not at all. For example:
+
+ a+(*COMMIT)b
+
+ This matches "xxaab" but not "aacaab". It can be thought of as a kind
+ of dynamic anchor, or "I've started, so I must finish."
+
+ (*PRUNE)
+
+ This verb causes the match to fail at the current position if the rest
+ of the pattern does not match. If the pattern is unanchored, the normal
+ "bumpalong" advance to the next starting character then happens. Back-
+ tracking can occur as usual to the left of (*PRUNE), or when matching
+ to the right of (*PRUNE), but if there is no match to the right, back-
+ tracking cannot cross (*PRUNE). In simple cases, the use of (*PRUNE)
+ is just an alternative to an atomic group or possessive quantifier, but
+ there are some uses of (*PRUNE) that cannot be expressed in any other
+ way.
+
+ (*SKIP)
+
+ This verb is like (*PRUNE), except that if the pattern is unanchored,
+ the "bumpalong" advance is not to the next character, but to the posi-
+ tion in the subject where (*SKIP) was encountered. (*SKIP) signifies
+ that whatever text was matched leading up to it cannot be part of a
+ successful match. Consider:
+
+ a+(*SKIP)b
+
+ If the subject is "aaaac...", after the first match attempt fails
+ (starting at the first character in the string), the starting point
+ skips on to start the next attempt at "c". Note that a possessive quan-
+ tifer does not have the same effect in this example; although it would
+ suppress backtracking during the first match attempt, the second
+ attempt would start at the second character instead of skipping on to
+ "c".
+
+ (*THEN)
+
+ This verb causes a skip to the next alternation if the rest of the pat-
+ tern does not match. That is, it cancels pending backtracking, but only
+ within the current alternation. Its name comes from the observation
+ that it can be used for a pattern-based if-then-else block:
+
+ ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ...
+
+ If the COND1 pattern matches, FOO is tried (and possibly further items
+ after the end of the group if FOO succeeds); on failure the matcher
+ skips to the second alternative and tries COND2, without backtracking
+ into COND1. If (*THEN) is used outside of any alternation, it acts
+ exactly like (*PRUNE).
+
+
SEE ALSO
pcreapi(3), pcrecallout(3), pcrematching(3), pcre(3).
-Last updated: 06 December 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 19 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
+------------------------------------------------------------------------------
+
+
+PCRESYNTAX(3) PCRESYNTAX(3)
+
+
+NAME
+ PCRE - Perl-compatible regular expressions
+
+
+PCRE REGULAR EXPRESSION SYNTAX SUMMARY
+
+ The full syntax and semantics of the regular expressions that are sup-
+ ported by PCRE are described in the pcrepattern documentation. This
+ document contains just a quick-reference summary of the syntax.
+
+
+QUOTING
+
+ \x where x is non-alphanumeric is a literal x
+ \Q...\E treat enclosed characters as literal
+
+
+CHARACTERS
+
+ \a alarm, that is, the BEL character (hex 07)
+ \cx "control-x", where x is any character
+ \e escape (hex 1B)
+ \f formfeed (hex 0C)
+ \n newline (hex 0A)
+ \r carriage return (hex 0D)
+ \t tab (hex 09)
+ \ddd character with octal code ddd, or backreference
+ \xhh character with hex code hh
+ \x{hhh..} character with hex code hhh..
+
+
+CHARACTER TYPES
+
+ . any character except newline;
+ in dotall mode, any character whatsoever
+ \C one byte, even in UTF-8 mode (best avoided)
+ \d a decimal digit
+ \D a character that is not a decimal digit
+ \h a horizontal whitespace character
+ \H a character that is not a horizontal whitespace character
+ \p{xx} a character with the xx property
+ \P{xx} a character without the xx property
+ \R a newline sequence
+ \s a whitespace character
+ \S a character that is not a whitespace character
+ \v a vertical whitespace character
+ \V a character that is not a vertical whitespace character
+ \w a "word" character
+ \W a "non-word" character
+ \X an extended Unicode sequence
+
+ In PCRE, \d, \D, \s, \S, \w, and \W recognize only ASCII characters.
+
+
+GENERAL CATEGORY PROPERTY CODES FOR \p and \P
+
+ C Other
+ Cc Control
+ Cf Format
+ Cn Unassigned
+ Co Private use
+ Cs Surrogate
+
+ L Letter
+ Ll Lower case letter
+ Lm Modifier letter
+ Lo Other letter
+ Lt Title case letter
+ Lu Upper case letter
+ L& Ll, Lu, or Lt
+
+ M Mark
+ Mc Spacing mark
+ Me Enclosing mark
+ Mn Non-spacing mark
+
+ N Number
+ Nd Decimal number
+ Nl Letter number
+ No Other number
+
+ P Punctuation
+ Pc Connector punctuation
+ Pd Dash punctuation
+ Pe Close punctuation
+ Pf Final punctuation
+ Pi Initial punctuation
+ Po Other punctuation
+ Ps Open punctuation
+
+ S Symbol
+ Sc Currency symbol
+ Sk Modifier symbol
+ Sm Mathematical symbol
+ So Other symbol
+
+ Z Separator
+ Zl Line separator
+ Zp Paragraph separator
+ Zs Space separator
+
+
+SCRIPT NAMES FOR \p AND \P
+
+ Arabic, Armenian, Balinese, Bengali, Bopomofo, Braille, Buginese,
+ Buhid, Canadian_Aboriginal, Cherokee, Common, Coptic, Cuneiform,
+ Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
+ Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-
+ gana, Inherited, Kannada, Katakana, Kharoshthi, Khmer, Lao, Latin,
+ Limbu, Linear_B, Malayalam, Mongolian, Myanmar, New_Tai_Lue, Nko,
+ Ogham, Old_Italic, Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,
+ Runic, Shavian, Sinhala, Syloti_Nagri, Syriac, Tagalog, Tagbanwa,
+ Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
+
+
+CHARACTER CLASSES
+
+ [...] positive character class
+ [^...] negative character class
+ [x-y] range (can be used for hex characters)
+ [[:xxx:]] positive POSIX named set
+ [[:^xxx:]] negative POSIX named set
+
+ alnum alphanumeric
+ alpha alphabetic
+ ascii 0-127
+ blank space or tab
+ cntrl control character
+ digit decimal digit
+ graph printing, excluding space
+ lower lower case letter
+ print printing, including space
+ punct printing, excluding alphanumeric
+ space whitespace
+ upper upper case letter
+ word same as \w
+ xdigit hexadecimal digit
+
+ In PCRE, POSIX character set names recognize only ASCII characters. You
+ can use \Q...\E inside a character class.
+
+
+QUANTIFIERS
+
+ ? 0 or 1, greedy
+ ?+ 0 or 1, possessive
+ ?? 0 or 1, lazy
+ * 0 or more, greedy
+ *+ 0 or more, possessive
+ *? 0 or more, lazy
+ + 1 or more, greedy
+ ++ 1 or more, possessive
+ +? 1 or more, lazy
+ {n} exactly n
+ {n,m} at least n, no more than m, greedy
+ {n,m}+ at least n, no more than m, possessive
+ {n,m}? at least n, no more than m, lazy
+ {n,} n or more, greedy
+ {n,}+ n or more, possessive
+ {n,}? n or more, lazy
+
+
+ANCHORS AND SIMPLE ASSERTIONS
+
+ \b word boundary
+ \B not a word boundary
+ ^ start of subject
+ also after internal newline in multiline mode
+ \A start of subject
+ $ end of subject
+ also before newline at end of subject
+ also before internal newline in multiline mode
+ \Z end of subject
+ also before newline at end of subject
+ \z end of subject
+ \G first matching position in subject
+
+
+MATCH POINT RESET
+
+ \K reset start of match
+
+
+ALTERNATION
+
+ expr|expr|expr...
+
+
+CAPTURING
+
+ (...) capturing group
+ (?<name>...) named capturing group (Perl)
+ (?'name'...) named capturing group (Perl)
+ (?P<name>...) named capturing group (Python)
+ (?:...) non-capturing group
+ (?|...) non-capturing group; reset group numbers for
+ capturing groups in each alternative
+
+
+ATOMIC GROUPS
+
+ (?>...) atomic, non-capturing group
+
+
+COMMENT
+
+ (?#....) comment (not nestable)
+
+
+OPTION SETTING
+
+ (?i) caseless
+ (?J) allow duplicate names
+ (?m) multiline
+ (?s) single line (dotall)
+ (?U) default ungreedy (lazy)
+ (?x) extended (ignore white space)
+ (?-...) unset option(s)
+
+
+LOOKAHEAD AND LOOKBEHIND ASSERTIONS
+
+ (?=...) positive look ahead
+ (?!...) negative look ahead
+ (?<=...) positive look behind
+ (?<!...) negative look behind
+
+ Each top-level branch of a look behind must be of a fixed length.
+
+
+BACKREFERENCES
+
+ \n reference by number (can be ambiguous)
+ \gn reference by number
+ \g{n} reference by number
+ \g{-n} relative reference by number
+ \k<name> reference by name (Perl)
+ \k'name' reference by name (Perl)
+ \g{name} reference by name (Perl)
+ \k{name} reference by name (.NET)
+ (?P=name) reference by name (Python)
+
+
+SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)
+
+ (?R) recurse whole pattern
+ (?n) call subpattern by absolute number
+ (?+n) call subpattern by relative number
+ (?-n) call subpattern by relative number
+ (?&name) call subpattern by name (Perl)
+ (?P>name) call subpattern by name (Python)
+ \g<name> call subpattern by name (Oniguruma)
+ \g'name' call subpattern by name (Oniguruma)
+ \g<n> call subpattern by absolute number (Oniguruma)
+ \g'n' call subpattern by absolute number (Oniguruma)
+ \g<+n> call subpattern by relative number (PCRE extension)
+ \g'+n' call subpattern by relative number (PCRE extension)
+ \g<-n> call subpattern by relative number (PCRE extension)
+ \g'-n' call subpattern by relative number (PCRE extension)
+
+
+CONDITIONAL PATTERNS
+
+ (?(condition)yes-pattern)
+ (?(condition)yes-pattern|no-pattern)
+
+ (?(n)... absolute reference condition
+ (?(+n)... relative reference condition
+ (?(-n)... relative reference condition
+ (?(<name>)... named reference condition (Perl)
+ (?('name')... named reference condition (Perl)
+ (?(name)... named reference condition (PCRE)
+ (?(R)... overall recursion condition
+ (?(Rn)... specific group recursion condition
+ (?(R&name)... specific recursion condition
+ (?(DEFINE)... define subpattern for reference
+ (?(assert)... assertion condition
+
+
+BACKTRACKING CONTROL
+
+ The following act immediately they are reached:
+
+ (*ACCEPT) force successful match
+ (*FAIL) force backtrack; synonym (*F)
+
+ The following act only when a subsequent match failure causes a back-
+ track to reach them. They all force a match failure, but they differ in
+ what happens afterwards. Those that advance the start-of-match point do
+ so only if the pattern is not anchored.
+
+ (*COMMIT) overall failure, no advance of starting point
+ (*PRUNE) advance to next starting character
+ (*SKIP) advance start to current matching position
+ (*THEN) local failure, backtrack to next alternation
+
+
+NEWLINE CONVENTIONS
+
+ These are recognized only at the very start of the pattern or after a
+ (*BSR_...) option.
+
+ (*CR)
+ (*LF)
+ (*CRLF)
+ (*ANYCRLF)
+ (*ANY)
+
+
+WHAT \R MATCHES
+
+ These are recognized only at the very start of the pattern or after a
+ (*...) option that sets the newline convention.
+
+ (*BSR_ANYCRLF)
+ (*BSR_UNICODE)
+
+
+CALLOUTS
+
+ (?C) callout
+ (?Cn) callout with data n
+
+
+SEE ALSO
+
+ pcrepattern(3), pcreapi(3), pcrecallout(3), pcrematching(3), pcre(3).
+
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 09 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -4352,12 +5408,13 @@ RESTRICTED PATTERNS FOR PCRE_PARTIAL
If PCRE_PARTIAL is set for a pattern that does not conform to the
restrictions, pcre_exec() returns the error code PCRE_ERROR_BADPARTIAL
- (-13).
+ (-13). You can use the PCRE_INFO_OKPARTIAL call to pcre_fullinfo() to
+ find out if a compiled pattern can be used for partial matching.
EXAMPLE OF PARTIAL MATCHING USING PCRETEST
- If the escape sequence \P is present in a pcretest data line, the
+ If the escape sequence \P is present in a pcretest data line, the
PCRE_PARTIAL flag is used for the match. Here is a run of pcretest that
uses the date example quoted above:
@@ -4374,13 +5431,13 @@ EXAMPLE OF PARTIAL MATCHING USING PCRETEST
data> j\P
No match
- The first data string is matched completely, so pcretest shows the
- matched substrings. The remaining four strings do not match the com-
- plete pattern, but the first two are partial matches. The same test,
- using pcre_dfa_exec() matching (by means of the \D escape sequence),
+ The first data string is matched completely, so pcretest shows the
+ matched substrings. The remaining four strings do not match the com-
+ plete pattern, but the first two are partial matches. The same test,
+ using pcre_dfa_exec() matching (by means of the \D escape sequence),
produces the following output:
- re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/
+ re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
data> 25jun04\P\D
0: 25jun04
data> 23dec3\P\D
@@ -4392,58 +5449,57 @@ EXAMPLE OF PARTIAL MATCHING USING PCRETEST
data> j\P\D
No match
- Notice that in this case the portion of the string that was matched is
+ Notice that in this case the portion of the string that was matched is
made available.
MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
When a partial match has been found using pcre_dfa_exec(), it is possi-
- ble to continue the match by providing additional subject data and
- calling pcre_dfa_exec() again with the same compiled regular expres-
+ ble to continue the match by providing additional subject data and
+ calling pcre_dfa_exec() again with the same compiled regular expres-
sion, this time setting the PCRE_DFA_RESTART option. You must also pass
- the same working space as before, because this is where details of the
- previous partial match are stored. Here is an example using pcretest,
+ the same working space as before, because this is where details of the
+ previous partial match are stored. Here is an example using pcretest,
using the \R escape sequence to set the PCRE_DFA_RESTART option (\P and
\D are as above):
- re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/
+ re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
data> 23ja\P\D
Partial match: 23ja
data> n05\R\D
0: n05
- The first call has "23ja" as the subject, and requests partial match-
- ing; the second call has "n05" as the subject for the continued
- (restarted) match. Notice that when the match is complete, only the
- last part is shown; PCRE does not retain the previously partially-
- matched string. It is up to the calling program to do that if it needs
+ The first call has "23ja" as the subject, and requests partial match-
+ ing; the second call has "n05" as the subject for the continued
+ (restarted) match. Notice that when the match is complete, only the
+ last part is shown; PCRE does not retain the previously partially-
+ matched string. It is up to the calling program to do that if it needs
to.
- You can set PCRE_PARTIAL with PCRE_DFA_RESTART to continue partial
+ You can set PCRE_PARTIAL with PCRE_DFA_RESTART to continue partial
matching over multiple segments. This facility can be used to pass very
- long subject strings to pcre_dfa_exec(). However, some care is needed
+ long subject strings to pcre_dfa_exec(). However, some care is needed
for certain types of pattern.
- 1. If the pattern contains tests for the beginning or end of a line,
- you need to pass the PCRE_NOTBOL or PCRE_NOTEOL options, as appropri-
- ate, when the subject string for any call does not contain the begin-
+ 1. If the pattern contains tests for the beginning or end of a line,
+ you need to pass the PCRE_NOTBOL or PCRE_NOTEOL options, as appropri-
+ ate, when the subject string for any call does not contain the begin-
ning or end of a line.
- 2. If the pattern contains backward assertions (including \b or \B),
- you need to arrange for some overlap in the subject strings to allow
- for this. For example, you could pass the subject in chunks that are
- 500 bytes long, but in a buffer of 700 bytes, with the starting offset
+ 2. If the pattern contains backward assertions (including \b or \B),
+ you need to arrange for some overlap in the subject strings to allow
+ for this. For example, you could pass the subject in chunks that are
+ 500 bytes long, but in a buffer of 700 bytes, with the starting offset
set to 200 and the previous 200 bytes at the start of the buffer.
- 3. Matching a subject string that is split into multiple segments does
- not always produce exactly the same result as matching over one single
- long string. The difference arises when there are multiple matching
- possibilities, because a partial match result is given only when there
- are no completed matches in a call to fBpcre_dfa_exec(). This means
- that as soon as the shortest match has been found, continuation to a
- new subject segment is no longer possible. Consider this pcretest
- example:
+ 3. Matching a subject string that is split into multiple segments does
+ not always produce exactly the same result as matching over one single
+ long string. The difference arises when there are multiple matching
+ possibilities, because a partial match result is given only when there
+ are no completed matches in a call to pcre_dfa_exec(). This means that
+ as soon as the shortest match has been found, continuation to a new
+ subject segment is no longer possible. Consider this pcretest example:
re> /dog(sbody)?/
data> do\P\D
@@ -4454,13 +5510,13 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
0: dogsbody
1: dog
- The pattern matches the words "dog" or "dogsbody". When the subject is
- presented in several parts ("do" and "gsb" being the first two) the
- match stops when "dog" has been found, and it is not possible to con-
- tinue. On the other hand, if "dogsbody" is presented as a single
+ The pattern matches the words "dog" or "dogsbody". When the subject is
+ presented in several parts ("do" and "gsb" being the first two) the
+ match stops when "dog" has been found, and it is not possible to con-
+ tinue. On the other hand, if "dogsbody" is presented as a single
string, both matches are found.
- Because of this phenomenon, it does not usually make sense to end a
+ Because of this phenomenon, it does not usually make sense to end a
pattern that is going to be matched in this way with a variable repeat.
4. Patterns that contain alternatives at the top level which do not all
@@ -4469,21 +5525,31 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
1234|3789
- If the first part of the subject is "ABC123", a partial match of the
- first alternative is found at offset 3. There is no partial match for
+ If the first part of the subject is "ABC123", a partial match of the
+ first alternative is found at offset 3. There is no partial match for
the second alternative, because such a match does not start at the same
- point in the subject string. Attempting to continue with the string
+ point in the subject string. Attempting to continue with the string
"789" does not yield a match because only those alternatives that match
- at one point in the subject are remembered. The problem arises because
- the start of the second alternative matches within the first alterna-
+ at one point in the subject are remembered. The problem arises because
+ the start of the second alternative matches within the first alterna-
tive. There is no problem with anchored patterns or patterns such as:
1234|ABCD
where no string can be a partial match for both alternatives.
-Last updated: 30 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 04 June 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
@@ -4507,7 +5573,9 @@ SAVING AND RE-USING PRECOMPILED PCRE PATTERNS
ent host and run them there. This works even if the new host has the
opposite endianness to the one on which the patterns were compiled.
There may be a small performance penalty, but it should be insignifi-
- cant.
+ cant. However, compiling regular expressions with one version of PCRE
+ for use with a different version is not guaranteed to work and may
+ cause crashes.
SAVING A COMPILED PATTERN
@@ -4590,22 +5658,22 @@ RE-USING A PRECOMPILED PATTERN
COMPATIBILITY WITH DIFFERENT PCRE RELEASES
- The layout of the control block that is at the start of the data that
- makes up a compiled pattern was changed for release 5.0. If you have
- any saved patterns that were compiled with previous releases (not a
- facility that was previously advertised), you will have to recompile
- them for release 5.0 and above.
+ In general, it is safest to recompile all saved patterns when you
+ update to a new PCRE release, though not all updates actually require
+ this. Recompiling is definitely needed for release 7.2.
+
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
- If you have any saved patterns in UTF-8 mode that use \p or \P that
- were compiled with any release up to and including 6.4, you will have
- to recompile them for release 6.5 and above.
- All saved patterns from earlier releases must be recompiled for release
- 7.0 or higher, because there was an internal reorganization at that
- release.
+REVISION
-Last updated: 28 November 2006
-Copyright (c) 1997-2006 University of Cambridge.
+ Last updated: 13 June 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
@@ -4744,8 +5812,18 @@ PROCESSING TIME
In many cases, the solution to this kind of performance issue is to use
an atomic group or a possessive quantifier.
-Last updated: 20 September 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 06 March 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
@@ -4905,8 +5983,9 @@ MATCHING NEWLINE CHARACTERS
MATCHING A PATTERN
The function regexec() is called to match a compiled pattern preg
- against a given string, which is terminated by a zero byte, subject to
- the options in eflags. These can be:
+ against a given string, which is by default terminated by a zero byte
+ (but see REG_STARTEND below), subject to the options in eflags. These
+ can be:
REG_NOTBOL
@@ -4918,6 +5997,17 @@ MATCHING A PATTERN
The PCRE_NOTEOL option is set when calling the underlying PCRE matching
function.
+ REG_STARTEND
+
+ The string is considered to start at string + pmatch[0].rm_so and to
+ have a terminating NUL located at string + pmatch[0].rm_eo (there need
+ not actually be a NUL at that location), regardless of the value of
+ nmatch. This is a BSD extension, compatible with but not specified by
+ IEEE Standard 1003.2 (POSIX.2), and should be used with caution in
+ software intended to be portable to other systems. Note that a non-zero
+ rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location
+ of the string, not how it is matched.
+
If the pattern was compiled with the REG_NOSUB flag, no data about any
matched strings is returned. The nmatch and pmatch arguments of
regexec() are ignored.
@@ -4958,11 +6048,14 @@ MEMORY USAGE
AUTHOR
Philip Hazel
- University Computing Service,
+ University Computing Service
Cambridge CB2 3QH, England.
-Last updated: 16 January 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+REVISION
+
+ Last updated: 05 April 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
@@ -5050,7 +6143,8 @@ MATCHING INTERFACE
c. The "i"th argument has a suitable type for holding the
string captured as the "i"th sub-pattern. If you pass in
- NULL for the "i"th argument, or pass fewer arguments than
+ void * NULL for the "i"th argument, or a non-void * NULL
+ of the correct type, or pass fewer arguments than the
number of sub-patterns, "i"th captured sub-pattern is
ignored.
@@ -5059,7 +6153,7 @@ MATCHING INTERFACE
return false (because the empty string is not a valid number):
int number;
- pcrecpp::RE::FullMatch("abc", "[a-z]+(\d+)?", &number);
+ pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number);
The matching interface supports at most 16 arguments per call. If you
need more, consider using the more general interface
@@ -5293,7 +6387,12 @@ REPLACING PARTS OF STRINGS
AUTHOR
The C++ wrapper was contributed by Google Inc.
- Copyright (c) 2006 Google Inc.
+ Copyright (c) 2007 Google Inc.
+
+
+REVISION
+
+ Last updated: 12 November 2007
------------------------------------------------------------------------------
@@ -5360,8 +6459,18 @@ PCRE SAMPLE PROGRAM
(for example) to the compile command to get round this problem.
-Last updated: 09 September 2004
-Copyright (c) 1997-2004 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 23 January 2008
+ Copyright (c) 1997-2008 University of Cambridge.
------------------------------------------------------------------------------
PCRESTACK(3) PCRESTACK(3)
@@ -5414,7 +6523,7 @@ PCRE DISCUSSION OF STACK USAGE
ter. For a long string, a lot of stack is required. Consider now this
rewritten pattern, which matches exactly the same strings:
- ([^<]++|<(?!inet))
+ ([^<]++|<(?!inet))+
This uses very much less stack, because runs of characters that do not
contain "<" are "swallowed" in one item inside the parentheses. Recur-
@@ -5430,17 +6539,24 @@ PCRE DISCUSSION OF STACK USAGE
In environments where stack memory is constrained, you might want to
compile PCRE to use heap memory instead of stack for remembering back-
up points. This makes it run a lot more slowly, however. Details of how
- to do this are given in the pcrebuild documentation.
-
- In Unix-like environments, there is not often a problem with the stack
- unless very long strings are involved, though the default limit on
- stack size varies from system to system. Values from 8Mb to 64Mb are
+ to do this are given in the pcrebuild documentation. When built in this
+ way, instead of using the stack, PCRE obtains and frees memory by call-
+ ing the functions that are pointed to by the pcre_stack_malloc and
+ pcre_stack_free variables. By default, these point to malloc() and
+ free(), but you can replace the pointers to cause PCRE to use your own
+ functions. Since the block sizes are always the same, and are always
+ freed in reverse order, it may be possible to implement customized mem-
+ ory handlers that are more efficient than the standard functions.
+
+ In Unix-like environments, there is not often a problem with the stack
+ unless very long strings are involved, though the default limit on
+ stack size varies from system to system. Values from 8Mb to 64Mb are
common. You can find your default limit by running the command:
ulimit -s
- Unfortunately, the effect of running out of stack is often SIGSEGV,
- though sometimes a more explicit error message is given. You can nor-
+ Unfortunately, the effect of running out of stack is often SIGSEGV,
+ though sometimes a more explicit error message is given. You can nor-
mally increase the limit on stack size by code such as this:
struct rlimit rlim;
@@ -5448,26 +6564,36 @@ PCRE DISCUSSION OF STACK USAGE
rlim.rlim_cur = 100*1024*1024;
setrlimit(RLIMIT_STACK, &rlim);
- This reads the current limits (soft and hard) using getrlimit(), then
- attempts to increase the soft limit to 100Mb using setrlimit(). You
+ This reads the current limits (soft and hard) using getrlimit(), then
+ attempts to increase the soft limit to 100Mb using setrlimit(). You
must do this before calling pcre_exec().
- PCRE has an internal counter that can be used to limit the depth of
- recursion, and thus cause pcre_exec() to give an error code before it
- runs out of stack. By default, the limit is very large, and unlikely
- ever to operate. It can be changed when PCRE is built, and it can also
+ PCRE has an internal counter that can be used to limit the depth of
+ recursion, and thus cause pcre_exec() to give an error code before it
+ runs out of stack. By default, the limit is very large, and unlikely
+ ever to operate. It can be changed when PCRE is built, and it can also
be set when pcre_exec() is called. For details of these interfaces, see
the pcrebuild and pcreapi documentation.
As a very rough rule of thumb, you should reckon on about 500 bytes per
- recursion. Thus, if you want to limit your stack usage to 8Mb, you
- should set the limit at 16000 recursions. A 64Mb stack, on the other
- hand, can support around 128000 recursions. The pcretest test program
+ recursion. Thus, if you want to limit your stack usage to 8Mb, you
+ should set the limit at 16000 recursions. A 64Mb stack, on the other
+ hand, can support around 128000 recursions. The pcretest test program
has a command line option (-S) that can be used to increase the size of
its stack.
-Last updated: 14 September 2006
-Copyright (c) 1997-2006 University of Cambridge.
+
+AUTHOR
+
+ Philip Hazel
+ University Computing Service
+ Cambridge CB2 3QH, England.
+
+
+REVISION
+
+ Last updated: 05 June 2007
+ Copyright (c) 1997-2007 University of Cambridge.
------------------------------------------------------------------------------
diff --git a/ext/pcre/pcrelib/libpcre.def b/ext/pcre/pcrelib/libpcre.def
deleted file mode 100644
index 01db4bd22c..0000000000
--- a/ext/pcre/pcrelib/libpcre.def
+++ /dev/null
@@ -1,20 +0,0 @@
-LIBRARY libpcre
-EXPORTS
-pcre_malloc
-pcre_free
-pcre_config
-pcre_callout
-pcre_compile
-pcre_copy_substring
-pcre_dfa_exec
-pcre_exec
-pcre_get_substring
-pcre_get_stringnumber
-pcre_get_substring_list
-pcre_free_substring
-pcre_free_substring_list
-pcre_info
-pcre_fullinfo
-pcre_maketables
-pcre_study
-pcre_version
diff --git a/ext/pcre/pcrelib/libpcreposix.def b/ext/pcre/pcrelib/libpcreposix.def
deleted file mode 100644
index 5f30247969..0000000000
--- a/ext/pcre/pcrelib/libpcreposix.def
+++ /dev/null
@@ -1,25 +0,0 @@
-LIBRARY libpcreposix
-EXPORTS
-pcre_malloc
-pcre_free
-pcre_config
-pcre_callout
-pcre_compile
-pcre_copy_substring
-pcre_dfa_exec
-pcre_exec
-pcre_get_substring
-pcre_get_stringnumber
-pcre_get_substring_list
-pcre_free_substring
-pcre_free_substring_list
-pcre_info
-pcre_fullinfo
-pcre_maketables
-pcre_study
-pcre_version
-
-regcomp
-regexec
-regerror
-regfree
diff --git a/ext/pcre/pcrelib/pcre.def b/ext/pcre/pcrelib/pcre.def
deleted file mode 100644
index ec2c7b395b..0000000000
--- a/ext/pcre/pcrelib/pcre.def
+++ /dev/null
@@ -1,29 +0,0 @@
-EXPORTS
-
-pcre_malloc DATA
-pcre_free DATA
-
-pcre_compile
-pcre_compile2
-pcre_config
-pcre_copy_named_substring
-pcre_copy_substring
-pcre_dfa_exec
-pcre_exec
-pcre_free_substring
-pcre_free_substring_list
-pcre_fullinfo
-pcre_get_named_substring
-pcre_get_stringnumber
-pcre_get_substring
-pcre_get_substring_list
-pcre_info
-pcre_maketables
-pcre_refcount
-pcre_study
-pcre_version
-
-regcomp
-regexec
-regerror
-regfree
diff --git a/ext/pcre/pcrelib/pcre.h b/ext/pcre/pcrelib/pcre.h
index c1961e597c..6f6a3328e5 100644
--- a/ext/pcre/pcrelib/pcre.h
+++ b/ext/pcre/pcrelib/pcre.h
@@ -5,7 +5,7 @@
/* This is the public header file for the PCRE library, to be #included by
applications that call the PCRE functions.
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -39,48 +39,48 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef _PCRE_H
#define _PCRE_H
-#include "php_compat.h"
-
/* The current PCRE version information. */
-/* NOTES FOR FUTURE MAINTAINERS: Do not use numbers with leading zeros, because
-they may be treated as octal constants. The PCRE_PRERELEASE feature is for
-identifying release candidates. It might be defined as -RC2, for example. In
-real releases, it should be defined empty. Do not change the alignment of these
-statments. The code in ./configure greps out the version numbers by using "cut"
-to get values from column 29 onwards. These are substituted into pcre-config
-and libpcre.pc. The values are not put into configure.ac and substituted here
-(which would simplify this issue) because that makes life harder for those who
-cannot run ./configure. As it now stands, this file need not be edited in that
-circumstance. */
-
#define PCRE_MAJOR 7
-#define PCRE_MINOR 0
-#define PCRE_PRERELEASE
-#define PCRE_DATE 18-Dec-2006
-
-/* Win32 uses DLL by default; it needs special stuff for exported functions
-when building PCRE. */
-
-#ifdef _WIN32
-# ifdef PCRE_DEFINITION
-# ifdef DLL_EXPORT
-# define PCRE_DATA_SCOPE __declspec(dllexport)
+#define PCRE_MINOR 7
+#define PCRE_PRERELEASE
+#define PCRE_DATE 2008-05-07
+
+/* When an application links to a PCRE DLL in Windows, the symbols that are
+imported have to be identified as such. When building PCRE, the appropriate
+export setting is defined in pcre_internal.h, which includes this file. So we
+don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */
+
+#if defined(_WIN32) && !defined(PCRE_STATIC)
+# ifndef PCRE_EXP_DECL
+# define PCRE_EXP_DECL extern __declspec(dllimport)
+# endif
+# ifdef __cplusplus
+# ifndef PCRECPP_EXP_DECL
+# define PCRECPP_EXP_DECL extern __declspec(dllimport)
# endif
-# else
-# ifndef PCRE_STATIC
-# define PCRE_DATA_SCOPE extern __declspec(dllimport)
+# ifndef PCRECPP_EXP_DEFN
+# define PCRECPP_EXP_DEFN __declspec(dllimport)
# endif
# endif
#endif
-/* Otherwise, we use the standard "extern". */
+/* By default, we use the standard "extern" declarations. */
-#ifndef PCRE_DATA_SCOPE
+#ifndef PCRE_EXP_DECL
# ifdef __cplusplus
-# define PCRE_DATA_SCOPE extern "C"
+# define PCRE_EXP_DECL extern "C"
# else
-# define PCRE_DATA_SCOPE extern
+# define PCRE_EXP_DECL extern
+# endif
+#endif
+
+#ifdef __cplusplus
+# ifndef PCRECPP_EXP_DECL
+# define PCRECPP_EXP_DECL extern
+# endif
+# ifndef PCRECPP_EXP_DEFN
+# define PCRECPP_EXP_DEFN
# endif
#endif
@@ -121,6 +121,10 @@ extern "C" {
#define PCRE_NEWLINE_LF 0x00200000
#define PCRE_NEWLINE_CRLF 0x00300000
#define PCRE_NEWLINE_ANY 0x00400000
+#define PCRE_NEWLINE_ANYCRLF 0x00500000
+#define PCRE_BSR_ANYCRLF 0x00800000
+#define PCRE_BSR_UNICODE 0x01000000
+#define PCRE_JAVASCRIPT_COMPAT 0x02000000
/* Exec-time and get/set-time error codes */
@@ -146,7 +150,7 @@ extern "C" {
#define PCRE_ERROR_DFA_WSSIZE (-19)
#define PCRE_ERROR_DFA_RECURSE (-20)
#define PCRE_ERROR_RECURSIONLIMIT (-21)
-#define PCRE_ERROR_NULLWSLIMIT (-22)
+#define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */
#define PCRE_ERROR_BADNEWLINE (-23)
/* Request types for pcre_fullinfo() */
@@ -164,6 +168,9 @@ extern "C" {
#define PCRE_INFO_NAMETABLE 9
#define PCRE_INFO_STUDYSIZE 10
#define PCRE_INFO_DEFAULT_TABLES 11
+#define PCRE_INFO_OKPARTIAL 12
+#define PCRE_INFO_JCHANGED 13
+#define PCRE_INFO_HASCRORLF 14
/* Request types for pcre_config(). Do not re-arrange, in order to remain
compatible. */
@@ -176,6 +183,7 @@ compatible. */
#define PCRE_CONFIG_STACKRECURSE 5
#define PCRE_CONFIG_UNICODE_PROPERTIES 6
#define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7
+#define PCRE_CONFIG_BSR 8
/* Bit flags for the pcre_extra structure. Do not re-arrange or redefine
these bits, just add new ones on the end, in order to remain compatible. */
@@ -242,52 +250,52 @@ that is triggered by the (?) regex item. For Virtual Pascal, these definitions
have to take another form. */
#ifndef VPCOMPAT
-PCRE_DATA_SCOPE void *(*pcre_malloc)(size_t);
-PCRE_DATA_SCOPE void (*pcre_free)(void *);
-PCRE_DATA_SCOPE void *(*pcre_stack_malloc)(size_t);
-PCRE_DATA_SCOPE void (*pcre_stack_free)(void *);
-PCRE_DATA_SCOPE int (*pcre_callout)(pcre_callout_block *);
+PCRE_EXP_DECL void *(*pcre_malloc)(size_t);
+PCRE_EXP_DECL void (*pcre_free)(void *);
+PCRE_EXP_DECL void *(*pcre_stack_malloc)(size_t);
+PCRE_EXP_DECL void (*pcre_stack_free)(void *);
+PCRE_EXP_DECL int (*pcre_callout)(pcre_callout_block *);
#else /* VPCOMPAT */
-PCRE_DATA_SCOPE void *pcre_malloc(size_t);
-PCRE_DATA_SCOPE void pcre_free(void *);
-PCRE_DATA_SCOPE void *pcre_stack_malloc(size_t);
-PCRE_DATA_SCOPE void pcre_stack_free(void *);
-PCRE_DATA_SCOPE int pcre_callout(pcre_callout_block *);
+PCRE_EXP_DECL void *pcre_malloc(size_t);
+PCRE_EXP_DECL void pcre_free(void *);
+PCRE_EXP_DECL void *pcre_stack_malloc(size_t);
+PCRE_EXP_DECL void pcre_stack_free(void *);
+PCRE_EXP_DECL int pcre_callout(pcre_callout_block *);
#endif /* VPCOMPAT */
/* Exported PCRE functions */
-PCRE_DATA_SCOPE pcre *pcre_compile(const char *, int, const char **, int *,
+PCRE_EXP_DECL pcre *pcre_compile(const char *, int, const char **, int *,
const unsigned char *);
-PCRE_DATA_SCOPE pcre *pcre_compile2(const char *, int, int *, const char **,
+PCRE_EXP_DECL pcre *pcre_compile2(const char *, int, int *, const char **,
int *, const unsigned char *);
-PCRE_DATA_SCOPE int pcre_config(int, void *);
-PCRE_DATA_SCOPE int pcre_copy_named_substring(const pcre *, const char *,
+PCRE_EXP_DECL int pcre_config(int, void *);
+PCRE_EXP_DECL int pcre_copy_named_substring(const pcre *, const char *,
int *, int, const char *, char *, int);
-PCRE_DATA_SCOPE int pcre_copy_substring(const char *, int *, int, int, char *,
+PCRE_EXP_DECL int pcre_copy_substring(const char *, int *, int, int, char *,
int);
-PCRE_DATA_SCOPE int pcre_dfa_exec(const pcre *, const pcre_extra *,
+PCRE_EXP_DECL int pcre_dfa_exec(const pcre *, const pcre_extra *,
const char *, int, int, int, int *, int , int *, int);
-PCRE_DATA_SCOPE int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR,
+PCRE_EXP_DECL int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR,
int, int, int, int *, int);
-PCRE_DATA_SCOPE void pcre_free_substring(const char *);
-PCRE_DATA_SCOPE void pcre_free_substring_list(const char **);
-PCRE_DATA_SCOPE int pcre_fullinfo(const pcre *, const pcre_extra *, int,
+PCRE_EXP_DECL void pcre_free_substring(const char *);
+PCRE_EXP_DECL void pcre_free_substring_list(const char **);
+PCRE_EXP_DECL int pcre_fullinfo(const pcre *, const pcre_extra *, int,
void *);
-PCRE_DATA_SCOPE int pcre_get_named_substring(const pcre *, const char *,
+PCRE_EXP_DECL int pcre_get_named_substring(const pcre *, const char *,
int *, int, const char *, const char **);
-PCRE_DATA_SCOPE int pcre_get_stringnumber(const pcre *, const char *);
-PCRE_DATA_SCOPE int pcre_get_stringtable_entries(const pcre *, const char *,
+PCRE_EXP_DECL int pcre_get_stringnumber(const pcre *, const char *);
+PCRE_EXP_DECL int pcre_get_stringtable_entries(const pcre *, const char *,
char **, char **);
-PCRE_DATA_SCOPE int pcre_get_substring(const char *, int *, int, int,
+PCRE_EXP_DECL int pcre_get_substring(const char *, int *, int, int,
const char **);
-PCRE_DATA_SCOPE int pcre_get_substring_list(const char *, int *, int,
+PCRE_EXP_DECL int pcre_get_substring_list(const char *, int *, int,
const char ***);
-PCRE_DATA_SCOPE int pcre_info(const pcre *, int *, int *);
-PCRE_DATA_SCOPE const unsigned char *pcre_maketables(void);
-PCRE_DATA_SCOPE int pcre_refcount(pcre *, int);
-PCRE_DATA_SCOPE pcre_extra *pcre_study(const pcre *, int, const char **);
-PCRE_DATA_SCOPE const char *pcre_version(void);
+PCRE_EXP_DECL int pcre_info(const pcre *, int *, int *);
+PCRE_EXP_DECL const unsigned char *pcre_maketables(void);
+PCRE_EXP_DECL int pcre_refcount(pcre *, int);
+PCRE_EXP_DECL pcre_extra *pcre_study(const pcre *, int, const char **);
+PCRE_EXP_DECL const char *pcre_version(void);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/ext/pcre/pcrelib/pcre_chartables.c b/ext/pcre/pcrelib/pcre_chartables.c
index d491433e25..f1dbaaedf2 100644
--- a/ext/pcre/pcrelib/pcre_chartables.c
+++ b/ext/pcre/pcrelib/pcre_chartables.c
@@ -2,13 +2,27 @@
* Perl-Compatible Regular Expressions *
*************************************************/
-/* This file is automatically written by the dftables auxiliary
-program. If you edit it by hand, you might like to edit the Makefile to
-prevent its ever being regenerated.
+/* This file contains character tables that are used when no external tables
+are passed to PCRE by the application that calls it. The tables are used only
+for characters whose code values are less than 256.
-This file contains the default tables for characters with codes less than
-128 (ASCII characters). These tables are used when no external tables are
-passed to PCRE. */
+This is a default version of the tables that assumes ASCII encoding. A program
+called dftables (which is distributed with PCRE) can be used to build
+alternative versions of this file. This is necessary if you are running in an
+EBCDIC environment, or if you want to default to a different encoding, for
+example ISO-8859-1. When dftables is run, it creates these tables in the
+current locale. If PCRE is configured with --enable-rebuild-chartables, this
+happens automatically.
+
+The following #includes are present because without the gcc 4.x may remove the
+array definition from the final binary if PCRE is built into a static library
+and dead code stripping is activated. This leads to link errors. Pulling in the
+header ensures that the array gets flagged as "someone outside this compilation
+unit might reference this" and so it will always be supplied to the linker. */
+
+#include "config.h"
+
+#include "pcre_internal.h"
const unsigned char _pcre_default_tables[] = {
@@ -82,11 +96,10 @@ const unsigned char _pcre_default_tables[] = {
240,241,242,243,244,245,246,247,
248,249,250,251,252,253,254,255,
-/* This table contains bit maps for various character classes.
-Each map is 32 bytes long and the bits run from the least
-significant end of each byte. The classes that have their own
-maps are: space, xdigit, digit, upper, lower, word, graph
-print, punct, and cntrl. Other classes are built from combinations. */
+/* This table contains bit maps for various character classes. Each map is 32
+bytes long and the bits run from the least significant end of each byte. The
+classes that have their own maps are: space, xdigit, digit, upper, lower, word,
+graph, print, punct, and cntrl. Other classes are built from combinations. */
0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -158,7 +171,7 @@ print, punct, and cntrl. Other classes are built from combinations. */
0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */
- 0x12,0x12,0x12,0x80,0x00,0x00,0x80,0x10, /* X - _ */
+ 0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /* X - _ */
0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */
0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */
@@ -180,4 +193,4 @@ print, punct, and cntrl. Other classes are built from combinations. */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
-/* End of chartables.c */
+/* End of pcre_chartables.c */
diff --git a/ext/pcre/pcrelib/pcre_compile.c b/ext/pcre/pcrelib/pcre_compile.c
index 34721c8863..0f3ebf93fd 100644
--- a/ext/pcre/pcrelib/pcre_compile.c
+++ b/ext/pcre/pcrelib/pcre_compile.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,11 +42,12 @@ POSSIBILITY OF SUCH DAMAGE.
supporting internal functions that are not used by other modules. */
+#include "config.h"
+
#define NLBLOCK cd /* Block containing newline information */
#define PSSTART start_pattern /* Field containing processed string start */
#define PSEND end_pattern /* Field containing processed string end */
-
#include "pcre_internal.h"
@@ -58,6 +59,18 @@ used by pcretest. DEBUG is not defined when building a production library. */
#endif
+/* Macro for setting individual bits in class bitmaps. */
+
+#define SETBIT(a,b) a[b/8] |= (1 << (b%8))
+
+/* Maximum length value to check against when making sure that the integer that
+holds the compiled pattern length does not overflow. We make it a bit less than
+INT_MAX to allow for adding in group terminating bytes, so that we don't have
+to check them every time. */
+
+#define OFLOW_MAX (INT_MAX - 20)
+
+
/*************************************************
* Code parameters and static tables *
*************************************************/
@@ -82,21 +95,21 @@ are simple data values; negative values are for special things like \d and so
on. Zero means further processing is needed (for things like \x), or the escape
is invalid. */
-#if !EBCDIC /* This is the "normal" table for ASCII systems */
+#ifndef EBCDIC /* This is the "normal" table for ASCII systems */
static const short int escapes[] = {
0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 7 */
0, 0, ':', ';', '<', '=', '>', '?', /* 8 - ? */
'@', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E, 0, -ESC_G, /* @ - G */
- 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
--ESC_P, -ESC_Q, -ESC_R, -ESC_S, 0, 0, 0, -ESC_W, /* P - W */
+-ESC_H, 0, 0, -ESC_K, 0, 0, 0, 0, /* H - O */
+-ESC_P, -ESC_Q, -ESC_R, -ESC_S, 0, 0, -ESC_V, -ESC_W, /* P - W */
-ESC_X, 0, -ESC_Z, '[', '\\', ']', '^', '_', /* X - _ */
'`', 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0, /* ` - g */
- 0, 0, 0, -ESC_k, 0, 0, ESC_n, 0, /* h - o */
--ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, 0, -ESC_w, /* p - w */
+-ESC_h, 0, 0, -ESC_k, 0, 0, ESC_n, 0, /* h - o */
+-ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, -ESC_v, -ESC_w, /* p - w */
0, 0, -ESC_z /* x - z */
};
-#else /* This is the "abnormal" table for EBCDIC systems */
+#else /* This is the "abnormal" table for EBCDIC systems */
static const short int escapes[] = {
/* 48 */ 0, 0, 0, '.', '<', '(', '+', '|',
/* 50 */ '&', 0, 0, 0, 0, 0, 0, 0,
@@ -106,18 +119,18 @@ static const short int escapes[] = {
/* 70 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 78 */ 0, '`', ':', '#', '@', '\'', '=', '"',
/* 80 */ 0, 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0,
-/* 88 */ 0, 0, 0, '{', 0, 0, 0, 0,
+/* 88 */-ESC_h, 0, 0, '{', 0, 0, 0, 0,
/* 90 */ 0, 0, -ESC_k, 'l', 0, ESC_n, 0, -ESC_p,
/* 98 */ 0, ESC_r, 0, '}', 0, 0, 0, 0,
-/* A0 */ 0, '~', -ESC_s, ESC_tee, 0, 0, -ESC_w, 0,
+/* A0 */ 0, '~', -ESC_s, ESC_tee, 0,-ESC_v, -ESC_w, 0,
/* A8 */ 0,-ESC_z, 0, 0, 0, '[', 0, 0,
/* B0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* B8 */ 0, 0, 0, 0, 0, ']', '=', '-',
/* C0 */ '{',-ESC_A, -ESC_B, -ESC_C, -ESC_D,-ESC_E, 0, -ESC_G,
-/* C8 */ 0, 0, 0, 0, 0, 0, 0, 0,
-/* D0 */ '}', 0, 0, 0, 0, 0, 0, -ESC_P,
+/* C8 */-ESC_H, 0, 0, 0, 0, 0, 0, 0,
+/* D0 */ '}', 0, -ESC_K, 0, 0, 0, 0, -ESC_P,
/* D8 */-ESC_Q,-ESC_R, 0, 0, 0, 0, 0, 0,
-/* E0 */ '\\', 0, -ESC_S, 0, 0, 0, -ESC_W, -ESC_X,
+/* E0 */ '\\', 0, -ESC_S, 0, 0,-ESC_V, -ESC_W, -ESC_X,
/* E8 */ 0,-ESC_Z, 0, 0, 0, 0, 0, 0,
/* F0 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* F8 */ 0, 0, 0, 0, 0, 0, 0, 0
@@ -125,14 +138,47 @@ static const short int escapes[] = {
#endif
-/* Tables of names of POSIX character classes and their lengths. The list is
-terminated by a zero length entry. The first three must be alpha, lower, upper,
-as this is assumed for handling case independence. */
+/* Table of special "verbs" like (*PRUNE). This is a short table, so it is
+searched linearly. Put all the names into a single string, in order to reduce
+the number of relocations when a shared library is dynamically linked. */
+
+typedef struct verbitem {
+ int len;
+ int op;
+} verbitem;
+
+static const char verbnames[] =
+ "ACCEPT\0"
+ "COMMIT\0"
+ "F\0"
+ "FAIL\0"
+ "PRUNE\0"
+ "SKIP\0"
+ "THEN";
+
+static const verbitem verbs[] = {
+ { 6, OP_ACCEPT },
+ { 6, OP_COMMIT },
+ { 1, OP_FAIL },
+ { 4, OP_FAIL },
+ { 5, OP_PRUNE },
+ { 4, OP_SKIP },
+ { 4, OP_THEN }
+};
+
+static const int verbcount = sizeof(verbs)/sizeof(verbitem);
+
-static const char *const posix_names[] = {
- "alpha", "lower", "upper",
- "alnum", "ascii", "blank", "cntrl", "digit", "graph",
- "print", "punct", "space", "word", "xdigit" };
+/* Tables of names of POSIX character classes and their lengths. The names are
+now all in a single string, to reduce the number of relocations when a shared
+library is dynamically loaded. The list of lengths is terminated by a zero
+length entry. The first three must be alpha, lower, upper, as this is assumed
+for handling case independence. */
+
+static const char posix_names[] =
+ "alpha\0" "lower\0" "upper\0" "alnum\0" "ascii\0" "blank\0"
+ "cntrl\0" "digit\0" "graph\0" "print\0" "punct\0" "space\0"
+ "word\0" "xdigit";
static const uschar posix_name_lengths[] = {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 };
@@ -171,79 +217,91 @@ static const int posix_class_maps[] = {
/* The texts of compile-time error messages. These are "char *" because they
are passed to the outside world. Do not ever re-use any error number, because
they are documented. Always add a new error instead. Messages marked DEAD below
-are no longer used. */
-
-static const char *error_texts[] = {
- "no error",
- "\\ at end of pattern",
- "\\c at end of pattern",
- "unrecognized character follows \\",
- "numbers out of order in {} quantifier",
+are no longer used. This used to be a table of strings, but in order to reduce
+the number of relocations needed when a shared library is loaded dynamically,
+it is now one long string. We cannot use a table of offsets, because the
+lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we
+simply count through to the one we want - this isn't a performance issue
+because these strings are used only when there is a compilation error. */
+
+static const char error_texts[] =
+ "no error\0"
+ "\\ at end of pattern\0"
+ "\\c at end of pattern\0"
+ "unrecognized character follows \\\0"
+ "numbers out of order in {} quantifier\0"
/* 5 */
- "number too big in {} quantifier",
- "missing terminating ] for character class",
- "invalid escape sequence in character class",
- "range out of order in character class",
- "nothing to repeat",
+ "number too big in {} quantifier\0"
+ "missing terminating ] for character class\0"
+ "invalid escape sequence in character class\0"
+ "range out of order in character class\0"
+ "nothing to repeat\0"
/* 10 */
- "operand of unlimited repeat could match the empty string", /** DEAD **/
- "internal error: unexpected repeat",
- "unrecognized character after (?",
- "POSIX named classes are supported only within a class",
- "missing )",
+ "operand of unlimited repeat could match the empty string\0" /** DEAD **/
+ "internal error: unexpected repeat\0"
+ "unrecognized character after (? or (?-\0"
+ "POSIX named classes are supported only within a class\0"
+ "missing )\0"
/* 15 */
- "reference to non-existent subpattern",
- "erroffset passed as NULL",
- "unknown option bit(s) set",
- "missing ) after comment",
- "parentheses nested too deeply", /** DEAD **/
+ "reference to non-existent subpattern\0"
+ "erroffset passed as NULL\0"
+ "unknown option bit(s) set\0"
+ "missing ) after comment\0"
+ "parentheses nested too deeply\0" /** DEAD **/
/* 20 */
- "regular expression too large",
- "failed to get memory",
- "unmatched parentheses",
- "internal error: code overflow",
- "unrecognized character after (?<",
+ "regular expression is too large\0"
+ "failed to get memory\0"
+ "unmatched parentheses\0"
+ "internal error: code overflow\0"
+ "unrecognized character after (?<\0"
/* 25 */
- "lookbehind assertion is not fixed length",
- "malformed number or name after (?(",
- "conditional group contains more than two branches",
- "assertion expected after (?(",
- "(?R or (?digits must be followed by )",
+ "lookbehind assertion is not fixed length\0"
+ "malformed number or name after (?(\0"
+ "conditional group contains more than two branches\0"
+ "assertion expected after (?(\0"
+ "(?R or (?[+-]digits must be followed by )\0"
/* 30 */
- "unknown POSIX class name",
- "POSIX collating elements are not supported",
- "this version of PCRE is not compiled with PCRE_UTF8 support",
- "spare error", /** DEAD **/
- "character value in \\x{...} sequence is too large",
+ "unknown POSIX class name\0"
+ "POSIX collating elements are not supported\0"
+ "this version of PCRE is not compiled with PCRE_UTF8 support\0"
+ "spare error\0" /** DEAD **/
+ "character value in \\x{...} sequence is too large\0"
/* 35 */
- "invalid condition (?(0)",
- "\\C not allowed in lookbehind assertion",
- "PCRE does not support \\L, \\l, \\N, \\U, or \\u",
- "number after (?C is > 255",
- "closing ) for (?C expected",
+ "invalid condition (?(0)\0"
+ "\\C not allowed in lookbehind assertion\0"
+ "PCRE does not support \\L, \\l, \\N, \\U, or \\u\0"
+ "number after (?C is > 255\0"
+ "closing ) for (?C expected\0"
/* 40 */
- "recursive call could loop indefinitely",
- "unrecognized character after (?P",
- "syntax error in subpattern name (missing terminator)",
- "two named subpatterns have the same name",
- "invalid UTF-8 string",
+ "recursive call could loop indefinitely\0"
+ "unrecognized character after (?P\0"
+ "syntax error in subpattern name (missing terminator)\0"
+ "two named subpatterns have the same name\0"
+ "invalid UTF-8 string\0"
/* 45 */
- "support for \\P, \\p, and \\X has not been compiled",
- "malformed \\P or \\p sequence",
- "unknown property name after \\P or \\p",
- "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)",
- "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")",
+ "support for \\P, \\p, and \\X has not been compiled\0"
+ "malformed \\P or \\p sequence\0"
+ "unknown property name after \\P or \\p\0"
+ "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)\0"
+ "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")\0"
/* 50 */
- "repeated subpattern is too long",
- "octal value is greater than \\377 (not in UTF-8 mode)",
- "internal error: overran compiling workspace",
- "internal error: previously-checked referenced subpattern not found",
- "DEFINE group contains more than one branch",
+ "repeated subpattern is too long\0" /** DEAD **/
+ "octal value is greater than \\377 (not in UTF-8 mode)\0"
+ "internal error: overran compiling workspace\0"
+ "internal error: previously-checked referenced subpattern not found\0"
+ "DEFINE group contains more than one branch\0"
/* 55 */
- "repeating a DEFINE group is not allowed",
- "inconsistent NEWLINE options",
- "\\g is not followed by an (optionally braced) non-zero number"
-};
+ "repeating a DEFINE group is not allowed\0"
+ "inconsistent NEWLINE options\0"
+ "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"
+ "a numbered reference must not be zero\0"
+ "(*VERB) with an argument is not supported\0"
+ /* 60 */
+ "(*VERB) not recognized\0"
+ "number is too big\0"
+ "subpattern name expected\0"
+ "digit expected after (?+\0"
+ "] is an invalid data character in JavaScript compatibility mode";
/* Table to identify digits and hex digits. This is used when compiling
@@ -262,7 +320,7 @@ For convenience, we use the same bit definitions as in chartables:
Then we can use ctype_digit and ctype_xdigit in the code. */
-#if !EBCDIC /* This is the "normal" case, for ASCII systems */
+#ifndef EBCDIC /* This is the "normal" case, for ASCII systems */
static const unsigned char digitab[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */
@@ -298,7 +356,7 @@ static const unsigned char digitab[] =
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
-#else /* This is the "abnormal" case, for EBCDIC systems */
+#else /* This is the "abnormal" case, for EBCDIC systems */
static const unsigned char digitab[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 0 */
@@ -312,7 +370,7 @@ static const unsigned char digitab[] =
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - 71 40 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 72- | */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* & - 87 50 */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 88- ¬ */
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 88- 95 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - -103 60 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 104- ? */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 112-119 70 */
@@ -346,7 +404,7 @@ static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - 71 */
0x00,0x00,0x00,0x80,0x00,0x80,0x80,0x80, /* 72- | */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* & - 87 */
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, /* 88- ¬ */
+ 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, /* 88- 95 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - -103 */
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x80, /* 104- ? */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 112-119 */
@@ -373,10 +431,32 @@ static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */
/* Definition to allow mutual recursion */
static BOOL
- compile_regex(int, int, uschar **, const uschar **, int *, BOOL, int, int *,
- int *, branch_chain *, compile_data *, int *);
+ compile_regex(int, int, uschar **, const uschar **, int *, BOOL, BOOL, int,
+ int *, int *, branch_chain *, compile_data *, int *);
+
+/*************************************************
+* Find an error text *
+*************************************************/
+
+/* The error texts are now all in one long string, to save on relocations. As
+some of the text is of unknown length, we can't use a table of offsets.
+Instead, just count through the strings. This is not a performance issue
+because it happens only when there has been a compilation error.
+
+Argument: the error number
+Returns: pointer to the error string
+*/
+
+static const char *
+find_error_text(int n)
+{
+const char *s = error_texts;
+for (; n > 0; n--) while (*s++ != 0);
+return s;
+}
+
/*************************************************
* Handle escapes *
@@ -399,7 +479,7 @@ Arguments:
Returns: zero or positive => a data character
negative => a special escape sequence
- on error, errorptr is set
+ on error, errorcodeptr is set
*/
static int
@@ -417,16 +497,16 @@ ptr--; /* Set pointer back to the last byte */
if (c == 0) *errorcodeptr = ERR1;
-/* Non-alphamerics are literals. For digits or letters, do an initial lookup in
-a table. A non-zero result is something that can be returned immediately.
+/* Non-alphanumerics are literals. For digits or letters, do an initial lookup
+in a table. A non-zero result is something that can be returned immediately.
Otherwise further processing may be required. */
-#if !EBCDIC /* ASCII coding */
-else if (c < '0' || c > 'z') {} /* Not alphameric */
+#ifndef EBCDIC /* ASCII coding */
+else if (c < '0' || c > 'z') {} /* Not alphanumeric */
else if ((i = escapes[c - '0']) != 0) c = i;
-#else /* EBCDIC coding */
-else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {} /* Not alphameric */
+#else /* EBCDIC coding */
+else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {} /* Not alphanumeric */
else if ((i = escapes[c - 0x48]) != 0) c = i;
#endif
@@ -450,13 +530,41 @@ else
*errorcodeptr = ERR37;
break;
- /* \g must be followed by a number, either plain or braced. If positive, it
- is an absolute backreference. If negative, it is a relative backreference.
- This is a Perl 5.10 feature. */
+ /* \g must be followed by one of a number of specific things:
+
+ (1) A number, either plain or braced. If positive, it is an absolute
+ backreference. If negative, it is a relative backreference. This is a Perl
+ 5.10 feature.
+
+ (2) Perl 5.10 also supports \g{name} as a reference to a named group. This
+ is part of Perl's movement towards a unified syntax for back references. As
+ this is synonymous with \k{name}, we fudge it up by pretending it really
+ was \k.
+
+ (3) For Oniguruma compatibility we also support \g followed by a name or a
+ number either in angle brackets or in single quotes. However, these are
+ (possibly recursive) subroutine calls, _not_ backreferences. Just return
+ the -ESC_g code (cf \k). */
case 'g':
+ if (ptr[1] == '<' || ptr[1] == '\'')
+ {
+ c = -ESC_g;
+ break;
+ }
+
+ /* Handle the Perl-compatible cases */
+
if (ptr[1] == '{')
{
+ const uschar *p;
+ for (p = ptr+2; *p != 0 && *p != '}'; p++)
+ if (*p != '-' && (digitab[*p] & ctype_digit) == 0) break;
+ if (*p != 0 && *p != '}')
+ {
+ c = -ESC_k;
+ break;
+ }
braced = TRUE;
ptr++;
}
@@ -473,10 +581,22 @@ else
while ((digitab[ptr[1]] & ctype_digit) != 0)
c = c * 10 + *(++ptr) - '0';
- if (c == 0 || (braced && *(++ptr) != '}'))
+ if (c < 0) /* Integer overflow */
+ {
+ *errorcodeptr = ERR61;
+ break;
+ }
+
+ if (braced && *(++ptr) != '}')
{
*errorcodeptr = ERR57;
- return 0;
+ break;
+ }
+
+ if (c == 0)
+ {
+ *errorcodeptr = ERR58;
+ break;
}
if (negated)
@@ -484,7 +604,7 @@ else
if (c > bracount)
{
*errorcodeptr = ERR15;
- return 0;
+ break;
}
c = bracount - (c - 1);
}
@@ -513,6 +633,11 @@ else
c -= '0';
while ((digitab[ptr[1]] & ctype_digit) != 0)
c = c * 10 + *(++ptr) - '0';
+ if (c < 0) /* Integer overflow */
+ {
+ *errorcodeptr = ERR61;
+ break;
+ }
if (c < 10 || c <= bracount)
{
c = -(ESC_REF + c);
@@ -562,10 +687,10 @@ else
if (c == 0 && cc == '0') continue; /* Leading zeroes */
count++;
-#if !EBCDIC /* ASCII coding */
+#ifndef EBCDIC /* ASCII coding */
if (cc >= 'a') cc -= 32; /* Convert to upper case */
c = (c << 4) + cc - ((cc < 'A')? '0' : ('A' - 10));
-#else /* EBCDIC coding */
+#else /* EBCDIC coding */
if (cc >= 'a' && cc <= 'z') cc += 64; /* Convert to upper case */
c = (c << 4) + cc - ((cc >= '0')? '0' : ('A' - 10));
#endif
@@ -589,10 +714,10 @@ else
{
int cc; /* Some compilers don't like ++ */
cc = *(++ptr); /* in initializers */
-#if !EBCDIC /* ASCII coding */
+#ifndef EBCDIC /* ASCII coding */
if (cc >= 'a') cc -= 32; /* Convert to upper case */
c = c * 16 + cc - ((cc < 'A')? '0' : ('A' - 10));
-#else /* EBCDIC coding */
+#else /* EBCDIC coding */
if (cc <= 'z') cc += 64; /* Convert to upper case */
c = c * 16 + cc - ((cc >= '0')? '0' : ('A' - 10));
#endif
@@ -608,23 +733,23 @@ else
if (c == 0)
{
*errorcodeptr = ERR2;
- return 0;
+ break;
}
-#if !EBCDIC /* ASCII coding */
+#ifndef EBCDIC /* ASCII coding */
if (c >= 'a' && c <= 'z') c -= 32;
c ^= 0x40;
-#else /* EBCDIC coding */
+#else /* EBCDIC coding */
if (c >= 'a' && c <= 'z') c += 64;
c ^= 0xC0;
#endif
break;
/* PCRE_EXTRA enables extensions to Perl in the matter of escapes. Any
- other alphameric following \ is an error if PCRE_EXTRA was set; otherwise,
- for Perl compatibility, it is a literal. This code looks a bit odd, but
- there used to be some cases other than the default, and there may be again
- in future, so I haven't "optimized" it. */
+ other alphanumeric following \ is an error if PCRE_EXTRA was set;
+ otherwise, for Perl compatibility, it is a literal. This code looks a bit
+ odd, but there used to be some cases other than the default, and there may
+ be again in future, so I haven't "optimized" it. */
default:
if ((options & PCRE_EXTRA) != 0) switch(c)
@@ -684,7 +809,7 @@ if (c == '{')
*negptr = TRUE;
ptr++;
}
- for (i = 0; i < sizeof(name) - 1; i++)
+ for (i = 0; i < (int)sizeof(name) - 1; i++)
{
c = *(++ptr);
if (c == 0) goto ERROR_RETURN;
@@ -713,7 +838,7 @@ top = _pcre_utt_size;
while (bot < top)
{
i = (bot + top) >> 1;
- c = strcmp(name, _pcre_utt[i].name);
+ c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset);
if (c == 0)
{
*dptr = _pcre_utt[i].value;
@@ -849,7 +974,7 @@ be terminated by '>' because that is checked in the first pass.
Arguments:
ptr current position in the pattern
- count current count of capturing parens so far encountered
+ cd compile background data
name name to seek, or NULL if seeking a numbered subpattern
lorn name length, or subpattern number if name is NULL
xmode TRUE if we are in /x mode
@@ -858,10 +983,11 @@ Returns: the number of the named subpattern, or -1 if not found
*/
static int
-find_parens(const uschar *ptr, int count, const uschar *name, int lorn,
+find_parens(const uschar *ptr, compile_data *cd, const uschar *name, int lorn,
BOOL xmode)
{
const uschar *thisname;
+int count = cd->bracount;
for (; *ptr != 0; ptr++)
{
@@ -881,12 +1007,37 @@ for (; *ptr != 0; ptr++)
continue;
}
- /* Skip over character classes */
+ /* Skip over character classes; this logic must be similar to the way they
+ are handled for real. If the first character is '^', skip it. Also, if the
+ first few characters (either before or after ^) are \Q\E or \E we skip them
+ too. This makes for compatibility with Perl. */
if (*ptr == '[')
{
+ BOOL negate_class = FALSE;
+ for (;;)
+ {
+ int c = *(++ptr);
+ if (c == '\\')
+ {
+ if (ptr[1] == 'E') ptr++;
+ else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3;
+ else break;
+ }
+ else if (!negate_class && c == '^')
+ negate_class = TRUE;
+ else break;
+ }
+
+ /* If the next character is ']', it is a data character that must be
+ skipped, except in JavaScript compatibility mode. */
+
+ if (ptr[1] == ']' && (cd->external_options & PCRE_JAVASCRIPT_COMPAT) == 0)
+ ptr++;
+
while (*(++ptr) != ']')
{
+ if (*ptr == 0) return -1;
if (*ptr == '\\')
{
if (*(++ptr) == 0) return -1;
@@ -914,7 +1065,7 @@ for (; *ptr != 0; ptr++)
/* An opening parens must now be a real metacharacter */
if (*ptr != '(') continue;
- if (ptr[1] != '?')
+ if (ptr[1] != '?' && ptr[1] != '*')
{
count++;
if (name == NULL && count == lorn) return count;
@@ -1042,7 +1193,6 @@ for (;;)
{
int d;
register int op = *cc;
-
switch (op)
{
case OP_CBRA:
@@ -1131,6 +1281,7 @@ for (;;)
case OP_TYPEEXACT:
branchlength += GET2(cc,1);
+ if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;
cc += 4;
break;
@@ -1148,6 +1299,7 @@ for (;;)
case OP_NOT_WORDCHAR:
case OP_WORDCHAR:
case OP_ANY:
+ case OP_ALLANY:
branchlength++;
cc++;
break;
@@ -1239,13 +1391,43 @@ for (;;)
code += _pcre_OP_lengths[c];
}
- /* In UTF-8 mode, opcodes that are followed by a character may be followed by
- a multi-byte character. The length in the table is a minimum, so we have to
- arrange to skip the extra bytes. */
+ /* Otherwise, we can get the item's length from the table, except that for
+ repeated character types, we have to test for \p and \P, which have an extra
+ two bytes of parameters. */
else
{
+ switch(c)
+ {
+ case OP_TYPESTAR:
+ case OP_TYPEMINSTAR:
+ case OP_TYPEPLUS:
+ case OP_TYPEMINPLUS:
+ case OP_TYPEQUERY:
+ case OP_TYPEMINQUERY:
+ case OP_TYPEPOSSTAR:
+ case OP_TYPEPOSPLUS:
+ case OP_TYPEPOSQUERY:
+ if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
+ break;
+
+ case OP_TYPEUPTO:
+ case OP_TYPEMINUPTO:
+ case OP_TYPEEXACT:
+ case OP_TYPEPOSUPTO:
+ if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
+ break;
+ }
+
+ /* Add in the fixed length from the table */
+
code += _pcre_OP_lengths[c];
+
+ /* In UTF-8 mode, opcodes that are followed by a character may be followed by
+ a multi-byte character. The length in the table is a minimum, so we have to
+ arrange to skip the extra bytes. */
+
+#ifdef SUPPORT_UTF8
if (utf8) switch(c)
{
case OP_CHAR:
@@ -1266,6 +1448,7 @@ for (;;)
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];
break;
}
+#endif
}
}
}
@@ -1301,14 +1484,43 @@ for (;;)
if (c == OP_XCLASS) code += GET(code, 1);
- /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes
- that are followed by a character may be followed by a multi-byte character.
- The length in the table is a minimum, so we have to arrange to skip the extra
- bytes. */
+ /* Otherwise, we can get the item's length from the table, except that for
+ repeated character types, we have to test for \p and \P, which have an extra
+ two bytes of parameters. */
else
{
+ switch(c)
+ {
+ case OP_TYPESTAR:
+ case OP_TYPEMINSTAR:
+ case OP_TYPEPLUS:
+ case OP_TYPEMINPLUS:
+ case OP_TYPEQUERY:
+ case OP_TYPEMINQUERY:
+ case OP_TYPEPOSSTAR:
+ case OP_TYPEPOSPLUS:
+ case OP_TYPEPOSQUERY:
+ if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
+ break;
+
+ case OP_TYPEPOSUPTO:
+ case OP_TYPEUPTO:
+ case OP_TYPEMINUPTO:
+ case OP_TYPEEXACT:
+ if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
+ break;
+ }
+
+ /* Add in the fixed length from the table */
+
code += _pcre_OP_lengths[c];
+
+ /* In UTF-8 mode, opcodes that are followed by a character may be followed
+ by a multi-byte character. The length in the table is a minimum, so we have
+ to arrange to skip the extra bytes. */
+
+#ifdef SUPPORT_UTF8
if (utf8) switch(c)
{
case OP_CHAR:
@@ -1329,6 +1541,7 @@ for (;;)
if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];
break;
}
+#endif
}
}
}
@@ -1343,8 +1556,9 @@ for (;;)
can match the empty string or not. It is called from could_be_empty()
below and from compile_branch() when checking for an unlimited repeat of a
group that can match nothing. Note that first_significant_code() skips over
-assertions. If we hit an unclosed bracket, we return "empty" - this means we've
-struck an inner bracket whose current branch will already have been scanned.
+backward and negative forward assertions when its final argument is TRUE. If we
+hit an unclosed bracket, we return "empty" - this means we've struck an inner
+bracket whose current branch will already have been scanned.
Arguments:
code points to start of search
@@ -1366,7 +1580,29 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
c = *code;
- if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE)
+ /* Skip over forward assertions; the other assertions are skipped by
+ first_significant_code() with a TRUE final argument. */
+
+ if (c == OP_ASSERT)
+ {
+ do code += GET(code, 1); while (*code == OP_ALT);
+ c = *code;
+ continue;
+ }
+
+ /* Groups with zero repeats can of course be empty; skip them. */
+
+ if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO)
+ {
+ code += _pcre_OP_lengths[c];
+ do code += GET(code, 1); while (*code == OP_ALT);
+ c = *code;
+ continue;
+ }
+
+ /* For other groups, scan the branches. */
+
+ if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)
{
BOOL empty_branch;
if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */
@@ -1382,12 +1618,7 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
}
while (*code == OP_ALT);
if (!empty_branch) return FALSE; /* All branches are non-empty */
-
- /* Move past the KET and fudge things so that the increment in the "for"
- above has no effect. */
-
- c = OP_END;
- code += 1 + LINK_SIZE - _pcre_OP_lengths[c];
+ c = *code;
continue;
}
@@ -1395,11 +1626,15 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
switch (c)
{
- /* Check for quantifiers after a class */
+ /* Check for quantifiers after a class. XCLASS is used for classes that
+ cannot be represented just by a bit map. This includes negated single
+ high-valued characters. The length in _pcre_OP_lengths[] is zero; the
+ actual length is stored in the compiled code, so we must update "code"
+ here. */
#ifdef SUPPORT_UTF8
case OP_XCLASS:
- ccode = code + GET(code, 1);
+ ccode = code += GET(code, 1);
goto CHECK_CLASS_REPEAT;
#endif
@@ -1443,6 +1678,7 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
case OP_NOT_WORDCHAR:
case OP_WORDCHAR:
case OP_ANY:
+ case OP_ALLANY:
case OP_ANYBYTE:
case OP_CHAR:
case OP_CHARNC:
@@ -1461,6 +1697,26 @@ for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE
case OP_TYPEEXACT:
return FALSE;
+ /* These are going to continue, as they may be empty, but we have to
+ fudge the length for the \p and \P cases. */
+
+ case OP_TYPESTAR:
+ case OP_TYPEMINSTAR:
+ case OP_TYPEPOSSTAR:
+ case OP_TYPEQUERY:
+ case OP_TYPEMINQUERY:
+ case OP_TYPEPOSQUERY:
+ if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
+ break;
+
+ /* Same for these */
+
+ case OP_TYPEUPTO:
+ case OP_TYPEMINUPTO:
+ case OP_TYPEPOSUPTO:
+ if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
+ break;
+
/* End of branch */
case OP_KET:
@@ -1530,29 +1786,48 @@ return TRUE;
*************************************************/
/* This function is called when the sequence "[:" or "[." or "[=" is
-encountered in a character class. It checks whether this is followed by an
-optional ^ and then a sequence of letters, terminated by a matching ":]" or
-".]" or "=]".
+encountered in a character class. It checks whether this is followed by a
+sequence of characters terminated by a matching ":]" or ".]" or "=]". If we
+reach an unescaped ']' without the special preceding character, return FALSE.
+
+Originally, this function only recognized a sequence of letters between the
+terminators, but it seems that Perl recognizes any sequence of characters,
+though of course unknown POSIX names are subsequently rejected. Perl gives an
+"Unknown POSIX class" error for [:f\oo:] for example, where previously PCRE
+didn't consider this to be a POSIX class. Likewise for [:1234:].
+
+The problem in trying to be exactly like Perl is in the handling of escapes. We
+have to be sure that [abc[:x\]pqr] is *not* treated as containing a POSIX
+class, but [abc[:x\]pqr:]] is (so that an error can be generated). The code
+below handles the special case of \], but does not try to do any other escape
+processing. This makes it different from Perl for cases such as [:l\ower:]
+where Perl recognizes it as the POSIX class "lower" but PCRE does not recognize
+"l\ower". This is a lesser evil that not diagnosing bad classes when Perl does,
+I think.
-Argument:
+Arguments:
ptr pointer to the initial [
endptr where to return the end pointer
- cd pointer to compile data
Returns: TRUE or FALSE
*/
static BOOL
-check_posix_syntax(const uschar *ptr, const uschar **endptr, compile_data *cd)
+check_posix_syntax(const uschar *ptr, const uschar **endptr)
{
int terminator; /* Don't combine these lines; the Solaris cc */
terminator = *(++ptr); /* compiler warns about "non-constant" initializer. */
-if (*(++ptr) == '^') ptr++;
-while ((cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;
-if (*ptr == terminator && ptr[1] == ']')
+for (++ptr; *ptr != 0; ptr++)
{
- *endptr = ptr;
- return TRUE;
+ if (*ptr == '\\' && ptr[1] == ']') ptr++; else
+ {
+ if (*ptr == ']') return FALSE;
+ if (*ptr == terminator && ptr[1] == ']')
+ {
+ *endptr = ptr;
+ return TRUE;
+ }
+ }
}
return FALSE;
}
@@ -1577,11 +1852,13 @@ Returns: a value representing the name, or -1 if unknown
static int
check_posix_name(const uschar *ptr, int len)
{
+const char *pn = posix_names;
register int yield = 0;
while (posix_name_lengths[yield] != 0)
{
if (len == posix_name_lengths[yield] &&
- strncmp((const char *)ptr, posix_names[yield], len) == 0) return yield;
+ strncmp((const char *)ptr, pn, len) == 0) return yield;
+ pn += posix_name_lengths[yield] + 1;
yield++;
}
return -1;
@@ -1596,11 +1873,12 @@ return -1;
that is referenced. This means that groups can be replicated for fixed
repetition simply by copying (because the recursion is allowed to refer to
earlier groups that are outside the current group). However, when a group is
-optional (i.e. the minimum quantifier is zero), OP_BRAZERO is inserted before
-it, after it has been compiled. This means that any OP_RECURSE items within it
-that refer to the group itself or any contained groups have to have their
-offsets adjusted. That one of the jobs of this function. Before it is called,
-the partially compiled regex must be temporarily terminated with OP_END.
+optional (i.e. the minimum quantifier is zero), OP_BRAZERO or OP_SKIPZERO is
+inserted before it, after it has been compiled. This means that any OP_RECURSE
+items within it that refer to the group itself or any contained groups have to
+have their offsets adjusted. That one of the jobs of this function. Before it
+is called, the partially compiled regex must be temporarily terminated with
+OP_END.
This function has been extended with the possibility of forward references for
recursions and subroutine calls. It must also check the list of such references
@@ -1623,6 +1901,7 @@ adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd,
uschar *save_hwm)
{
uschar *ptr = group;
+
while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL)
{
int offset;
@@ -1884,7 +2163,6 @@ if (next >= 0) switch(op_code)
/* For OP_NOT, "item" must be a single-byte character. */
case OP_NOT:
- if (next < 0) return FALSE; /* Not a character */
if (item == next) return TRUE;
if ((options & PCRE_CASELESS) == 0) return FALSE;
#ifdef SUPPORT_UTF8
@@ -1921,6 +2199,50 @@ if (next >= 0) switch(op_code)
case OP_NOT_WORDCHAR:
return next <= 127 && (cd->ctypes[next] & ctype_word) != 0;
+ case OP_HSPACE:
+ case OP_NOT_HSPACE:
+ switch(next)
+ {
+ case 0x09:
+ case 0x20:
+ case 0xa0:
+ case 0x1680:
+ case 0x180e:
+ case 0x2000:
+ case 0x2001:
+ case 0x2002:
+ case 0x2003:
+ case 0x2004:
+ case 0x2005:
+ case 0x2006:
+ case 0x2007:
+ case 0x2008:
+ case 0x2009:
+ case 0x200A:
+ case 0x202f:
+ case 0x205f:
+ case 0x3000:
+ return op_code != OP_HSPACE;
+ default:
+ return op_code == OP_HSPACE;
+ }
+
+ case OP_VSPACE:
+ case OP_NOT_VSPACE:
+ switch(next)
+ {
+ case 0x0a:
+ case 0x0b:
+ case 0x0c:
+ case 0x0d:
+ case 0x85:
+ case 0x2028:
+ case 0x2029:
+ return op_code != OP_VSPACE;
+ default:
+ return op_code == OP_VSPACE;
+ }
+
default:
return FALSE;
}
@@ -1955,12 +2277,57 @@ switch(op_code)
case ESC_W:
return item <= 127 && (cd->ctypes[item] & ctype_word) != 0;
+ case ESC_h:
+ case ESC_H:
+ switch(item)
+ {
+ case 0x09:
+ case 0x20:
+ case 0xa0:
+ case 0x1680:
+ case 0x180e:
+ case 0x2000:
+ case 0x2001:
+ case 0x2002:
+ case 0x2003:
+ case 0x2004:
+ case 0x2005:
+ case 0x2006:
+ case 0x2007:
+ case 0x2008:
+ case 0x2009:
+ case 0x200A:
+ case 0x202f:
+ case 0x205f:
+ case 0x3000:
+ return -next != ESC_h;
+ default:
+ return -next == ESC_h;
+ }
+
+ case ESC_v:
+ case ESC_V:
+ switch(item)
+ {
+ case 0x0a:
+ case 0x0b:
+ case 0x0c:
+ case 0x0d:
+ case 0x85:
+ case 0x2028:
+ case 0x2029:
+ return -next != ESC_v;
+ default:
+ return -next == ESC_v;
+ }
+
default:
return FALSE;
}
case OP_DIGIT:
- return next == -ESC_D || next == -ESC_s || next == -ESC_W;
+ return next == -ESC_D || next == -ESC_s || next == -ESC_W ||
+ next == -ESC_h || next == -ESC_v;
case OP_NOT_DIGIT:
return next == -ESC_d;
@@ -1969,10 +2336,23 @@ switch(op_code)
return next == -ESC_S || next == -ESC_d || next == -ESC_w;
case OP_NOT_WHITESPACE:
- return next == -ESC_s;
+ return next == -ESC_s || next == -ESC_h || next == -ESC_v;
+
+ case OP_HSPACE:
+ return next == -ESC_S || next == -ESC_H || next == -ESC_d || next == -ESC_w;
+
+ case OP_NOT_HSPACE:
+ return next == -ESC_h;
+
+ /* Can't have \S in here because VT matches \S (Perl anomaly) */
+ case OP_VSPACE:
+ return next == -ESC_V || next == -ESC_d || next == -ESC_w;
+
+ case OP_NOT_VSPACE:
+ return next == -ESC_v;
case OP_WORDCHAR:
- return next == -ESC_W || next == -ESC_s;
+ return next == -ESC_W || next == -ESC_s || next == -ESC_h || next == -ESC_v;
case OP_NOT_WORDCHAR:
return next == -ESC_w || next == -ESC_d;
@@ -2045,6 +2425,7 @@ uschar classbits[32];
BOOL class_utf8;
BOOL utf8 = (options & PCRE_UTF8) != 0;
uschar *class_utf8data;
+uschar *class_utf8data_base;
uschar utf8_char[6];
#else
BOOL utf8 = FALSE;
@@ -2084,13 +2465,16 @@ req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;
for (;; ptr++)
{
BOOL negate_class;
+ BOOL should_flip_negation;
BOOL possessive_quantifier;
BOOL is_quantifier;
BOOL is_recurse;
+ BOOL reset_bracount;
int class_charcount;
int class_lastchar;
int newoptions;
int recno;
+ int refsign;
int skipbytes;
int subreqbyte;
int subfirstbyte;
@@ -2123,6 +2507,15 @@ for (;; ptr++)
*/
if (code < last_code) code = last_code;
+
+ /* Paranoid check for integer overflow */
+
+ if (OFLOW_MAX - *lengthptr < code - last_code)
+ {
+ *errorcodeptr = ERR20;
+ goto FAILED;
+ }
+
*lengthptr += code - last_code;
DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));
@@ -2235,6 +2628,11 @@ for (;; ptr++)
*ptrptr = ptr;
if (lengthptr != NULL)
{
+ if (OFLOW_MAX - *lengthptr < code - last_code)
+ {
+ *errorcodeptr = ERR20;
+ goto FAILED;
+ }
*lengthptr += code - last_code; /* To include callout length */
DPRINTF((">> end branch\n"));
}
@@ -2267,7 +2665,7 @@ for (;; ptr++)
zerofirstbyte = firstbyte;
zeroreqbyte = reqbyte;
previous = code;
- *code++ = OP_ANY;
+ *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
break;
@@ -2282,7 +2680,17 @@ for (;; ptr++)
opcode is compiled. It may optionally have a bit map for characters < 256,
but those above are are explicitly listed afterwards. A flag byte tells
whether the bitmap is present, and whether this is a negated class or not.
- */
+
+ In JavaScript compatibility mode, an isolated ']' causes an error. In
+ default (Perl) mode, it is treated as a data character. */
+
+ case ']':
+ if ((cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
+ {
+ *errorcodeptr = ERR64;
+ goto FAILED;
+ }
+ goto NORMAL_CHAR;
case '[':
previous = code;
@@ -2291,24 +2699,50 @@ for (;; ptr++)
they are encountered at the top level, so we'll do that too. */
if ((ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') &&
- check_posix_syntax(ptr, &tempptr, cd))
+ check_posix_syntax(ptr, &tempptr))
{
*errorcodeptr = (ptr[1] == ':')? ERR13 : ERR31;
goto FAILED;
}
- /* If the first character is '^', set the negation flag and skip it. */
+ /* If the first character is '^', set the negation flag and skip it. Also,
+ if the first few characters (either before or after ^) are \Q\E or \E we
+ skip them too. This makes for compatibility with Perl. */
- if ((c = *(++ptr)) == '^')
+ negate_class = FALSE;
+ for (;;)
{
- negate_class = TRUE;
c = *(++ptr);
+ if (c == '\\')
+ {
+ if (ptr[1] == 'E') ptr++;
+ else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3;
+ else break;
+ }
+ else if (!negate_class && c == '^')
+ negate_class = TRUE;
+ else break;
}
- else
+
+ /* Empty classes are allowed in JavaScript compatibility mode. Otherwise,
+ an initial ']' is taken as a data character -- the code below handles
+ that. In JS mode, [] must always fail, so generate OP_FAIL, whereas
+ [^] must match any character, so generate OP_ALLANY. */
+
+ if (c ==']' && (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
{
- negate_class = FALSE;
+ *code++ = negate_class? OP_ALLANY : OP_FAIL;
+ if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
+ zerofirstbyte = firstbyte;
+ break;
}
+ /* If a class contains a negative special such as \S, we need to flip the
+ negation flag at the end, so that support for characters > 255 works
+ correctly (they are all included in the class). */
+
+ should_flip_negation = FALSE;
+
/* Keep a count of chars with values < 256 so that we can optimize the case
of just a single character (as long as it's < 256). However, For higher
valued UTF-8 characters, we don't yet do any optimization. */
@@ -2326,6 +2760,7 @@ for (;; ptr++)
#ifdef SUPPORT_UTF8
class_utf8 = FALSE; /* No chars >= 256 */
class_utf8data = code + LINK_SIZE + 2; /* For UTF-8 items */
+ class_utf8data_base = class_utf8data; /* For resetting in pass 1 */
#endif
/* Process characters until ] is reached. By writing this as a "do" it
@@ -2341,6 +2776,18 @@ for (;; ptr++)
{ /* Braces are required because the */
GETCHARLEN(c, ptr, ptr); /* macro generates multiple statements */
}
+
+ /* In the pre-compile phase, accumulate the length of any UTF-8 extra
+ data and reset the pointer. This is so that very large classes that
+ contain a zillion UTF-8 characters no longer overwrite the work space
+ (which is on the stack). */
+
+ if (lengthptr != NULL)
+ {
+ *lengthptr += class_utf8data - class_utf8data_base;
+ class_utf8data = class_utf8data_base;
+ }
+
#endif
/* Inside \Q...\E everything is literal except \E */
@@ -2364,7 +2811,7 @@ for (;; ptr++)
if (c == '[' &&
(ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') &&
- check_posix_syntax(ptr, &tempptr, cd))
+ check_posix_syntax(ptr, &tempptr))
{
BOOL local_negate = FALSE;
int posix_class, taboffset, tabopt;
@@ -2381,6 +2828,7 @@ for (;; ptr++)
if (*ptr == '^')
{
local_negate = TRUE;
+ should_flip_negation = TRUE; /* Note negative special */
ptr++;
}
@@ -2447,7 +2895,7 @@ for (;; ptr++)
of the specials, which just set a flag. The sequence \b is a special
case. Inside a class (and only there) it is treated as backspace.
Elsewhere it marks a word boundary. Other escapes have preset maps ready
- to or into the one we are building. We assume they have more than one
+ to 'or' into the one we are building. We assume they have more than one
character in them, so set class_charcount bigger than one. */
if (c == '\\')
@@ -2455,7 +2903,7 @@ for (;; ptr++)
c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
if (*errorcodeptr != 0) goto FAILED;
- if (-c == ESC_b) c = '\b'; /* \b is backslash in a class */
+ if (-c == ESC_b) c = '\b'; /* \b is backspace in a class */
else if (-c == ESC_X) c = 'X'; /* \X is literal X in a class */
else if (-c == ESC_R) c = 'R'; /* \R is literal R in a class */
else if (-c == ESC_Q) /* Handle start of quoted string */
@@ -2467,6 +2915,7 @@ for (;; ptr++)
else inescq = TRUE;
continue;
}
+ else if (-c == ESC_E) continue; /* Ignore orphan \E */
if (c < 0)
{
@@ -2482,6 +2931,7 @@ for (;; ptr++)
continue;
case ESC_D:
+ should_flip_negation = TRUE;
for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_digit];
continue;
@@ -2490,6 +2940,7 @@ for (;; ptr++)
continue;
case ESC_W:
+ should_flip_negation = TRUE;
for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_word];
continue;
@@ -2499,13 +2950,11 @@ for (;; ptr++)
continue;
case ESC_S:
+ should_flip_negation = TRUE;
for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */
continue;
- case ESC_E: /* Perl ignores an orphan \E */
- continue;
-
default: /* Not recognized; fall through */
break; /* Need "default" setting to stop compiler warning. */
}
@@ -2515,6 +2964,133 @@ for (;; ptr++)
else if (c == -ESC_d || c == -ESC_D || c == -ESC_w ||
c == -ESC_W || c == -ESC_s || c == -ESC_S) continue;
+ /* We need to deal with \H, \h, \V, and \v in both phases because
+ they use extra memory. */
+
+ if (-c == ESC_h)
+ {
+ SETBIT(classbits, 0x09); /* VT */
+ SETBIT(classbits, 0x20); /* SPACE */
+ SETBIT(classbits, 0xa0); /* NSBP */
+#ifdef SUPPORT_UTF8
+ if (utf8)
+ {
+ class_utf8 = TRUE;
+ *class_utf8data++ = XCL_SINGLE;
+ class_utf8data += _pcre_ord2utf8(0x1680, class_utf8data);
+ *class_utf8data++ = XCL_SINGLE;
+ class_utf8data += _pcre_ord2utf8(0x180e, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x2000, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x200A, class_utf8data);
+ *class_utf8data++ = XCL_SINGLE;
+ class_utf8data += _pcre_ord2utf8(0x202f, class_utf8data);
+ *class_utf8data++ = XCL_SINGLE;
+ class_utf8data += _pcre_ord2utf8(0x205f, class_utf8data);
+ *class_utf8data++ = XCL_SINGLE;
+ class_utf8data += _pcre_ord2utf8(0x3000, class_utf8data);
+ }
+#endif
+ continue;
+ }
+
+ if (-c == ESC_H)
+ {
+ for (c = 0; c < 32; c++)
+ {
+ int x = 0xff;
+ switch (c)
+ {
+ case 0x09/8: x ^= 1 << (0x09%8); break;
+ case 0x20/8: x ^= 1 << (0x20%8); break;
+ case 0xa0/8: x ^= 1 << (0xa0%8); break;
+ default: break;
+ }
+ classbits[c] |= x;
+ }
+
+#ifdef SUPPORT_UTF8
+ if (utf8)
+ {
+ class_utf8 = TRUE;
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x167f, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x1681, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x180d, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x180f, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x1fff, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x200B, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x202e, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x2030, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x205e, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x2060, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x2fff, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x3001, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);
+ }
+#endif
+ continue;
+ }
+
+ if (-c == ESC_v)
+ {
+ SETBIT(classbits, 0x0a); /* LF */
+ SETBIT(classbits, 0x0b); /* VT */
+ SETBIT(classbits, 0x0c); /* FF */
+ SETBIT(classbits, 0x0d); /* CR */
+ SETBIT(classbits, 0x85); /* NEL */
+#ifdef SUPPORT_UTF8
+ if (utf8)
+ {
+ class_utf8 = TRUE;
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x2028, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);
+ }
+#endif
+ continue;
+ }
+
+ if (-c == ESC_V)
+ {
+ for (c = 0; c < 32; c++)
+ {
+ int x = 0xff;
+ switch (c)
+ {
+ case 0x0a/8: x ^= 1 << (0x0a%8);
+ x ^= 1 << (0x0b%8);
+ x ^= 1 << (0x0c%8);
+ x ^= 1 << (0x0d%8);
+ break;
+ case 0x85/8: x ^= 1 << (0x85%8); break;
+ default: break;
+ }
+ classbits[c] |= x;
+ }
+
+#ifdef SUPPORT_UTF8
+ if (utf8)
+ {
+ class_utf8 = TRUE;
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x2027, class_utf8data);
+ *class_utf8data++ = XCL_RANGE;
+ class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);
+ class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);
+ }
+#endif
+ continue;
+ }
+
/* We need to deal with \P and \p in both phases. */
#ifdef SUPPORT_UCP
@@ -2566,6 +3142,12 @@ for (;; ptr++)
oldptr = ptr;
+ /* Remember \r or \n */
+
+ if (c == '\r' || c == '\n') cd->external_flags |= PCRE_HASCRORLF;
+
+ /* Check for range */
+
if (!inescq && ptr[1] == '-')
{
int d;
@@ -2607,7 +3189,7 @@ for (;; ptr++)
d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
if (*errorcodeptr != 0) goto FAILED;
- /* \b is backslash; \X is literal X; \R is literal R; any other
+ /* \b is backspace; \X is literal X; \R is literal R; any other
special means the '-' was literal */
if (d < 0)
@@ -2633,6 +3215,10 @@ for (;; ptr++)
if (d == c) goto LONE_SINGLE_CHARACTER; /* A few lines below */
+ /* Remember \r or \n */
+
+ if (d == '\r' || d == '\n') cd->external_flags |= PCRE_HASCRORLF;
+
/* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless
matching, we have to use an XCLASS with extra data items. Caseless
matching for characters > 127 is available only if UCP support is
@@ -2655,14 +3241,18 @@ for (;; ptr++)
unsigned int origd = d;
while (get_othercase_range(&cc, origd, &occ, &ocd))
{
- if (occ >= c && ocd <= d) continue; /* Skip embedded ranges */
+ if (occ >= (unsigned int)c &&
+ ocd <= (unsigned int)d)
+ continue; /* Skip embedded ranges */
- if (occ < c && ocd >= c - 1) /* Extend the basic range */
+ if (occ < (unsigned int)c &&
+ ocd >= (unsigned int)c - 1) /* Extend the basic range */
{ /* if there is overlap, */
c = occ; /* noting that if occ < c */
continue; /* we can't have ocd > d */
} /* because a subrange is */
- if (ocd > d && occ <= d + 1) /* always shorter than */
+ if (ocd > (unsigned int)d &&
+ occ <= (unsigned int)d + 1) /* always shorter than */
{ /* the basic range. */
d = ocd;
continue;
@@ -2782,12 +3372,34 @@ for (;; ptr++)
goto FAILED;
}
+
+/* This code has been disabled because it would mean that \s counts as
+an explicit \r or \n reference, and that's not really what is wanted. Now
+we set the flag only if there is a literal "\r" or "\n" in the class. */
+
+#if 0
+ /* Remember whether \r or \n are in this class */
+
+ if (negate_class)
+ {
+ if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF;
+ }
+ else
+ {
+ if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF;
+ }
+#endif
+
+
/* If class_charcount is 1, we saw precisely one character whose value is
- less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we
- can optimize the negative case only if there were no characters >= 128
- because OP_NOT and the related opcodes like OP_NOTSTAR operate on
- single-bytes only. This is an historical hangover. Maybe one day we can
- tidy these opcodes to handle multi-byte characters.
+ less than 256. As long as there were no characters >= 128 and there was no
+ use of \p or \P, in other words, no use of any XCLASS features, we can
+ optimize.
+
+ In UTF-8 mode, we can optimize the negative case only if there were no
+ characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR
+ operate on single-bytes only. This is an historical hangover. Maybe one day
+ we can tidy these opcodes to handle multi-byte characters.
The optimization throws away the bit map. We turn the item into a
1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note
@@ -2797,10 +3409,8 @@ for (;; ptr++)
reqbyte, save the previous value for reinstating. */
#ifdef SUPPORT_UTF8
- if (class_charcount == 1 &&
- (!utf8 ||
- (!class_utf8 && (!negate_class || class_lastchar < 128))))
-
+ if (class_charcount == 1 && !class_utf8 &&
+ (!utf8 || !negate_class || class_lastchar < 128))
#else
if (class_charcount == 1)
#endif
@@ -2843,11 +3453,14 @@ for (;; ptr++)
zeroreqbyte = reqbyte;
/* If there are characters with values > 255, we have to compile an
- extended class, with its own opcode. If there are no characters < 256,
- we can omit the bitmap in the actual compiled code. */
+ extended class, with its own opcode, unless there was a negated special
+ such as \S in the class, because in that case all characters > 255 are in
+ the class, so any that were explicitly given as well can be ignored. If
+ (when there are explicit characters > 255 that must be listed) there are no
+ characters < 256, we can omit the bitmap in the actual compiled code. */
#ifdef SUPPORT_UTF8
- if (class_utf8)
+ if (class_utf8 && !should_flip_negation)
{
*class_utf8data++ = XCL_END; /* Marks the end of extra data */
*code++ = OP_XCLASS;
@@ -2873,20 +3486,19 @@ for (;; ptr++)
}
#endif
- /* If there are no characters > 255, negate the 32-byte map if necessary,
- and copy it into the code vector. If this is the first thing in the branch,
- there can be no first char setting, whatever the repeat count. Any reqbyte
- setting must remain unchanged after any kind of repeat. */
+ /* If there are no characters > 255, set the opcode to OP_CLASS or
+ OP_NCLASS, depending on whether the whole class was negated and whether
+ there were negative specials such as \S in the class. Then copy the 32-byte
+ map into the code vector, negating it if necessary. */
+ *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
if (negate_class)
{
- *code++ = OP_NCLASS;
if (lengthptr == NULL) /* Save time in the pre-compile phase */
for (c = 0; c < 32; c++) code[c] = ~classbits[c];
}
else
{
- *code++ = OP_CLASS;
memcpy(code, classbits, 32);
}
code += 32;
@@ -3072,7 +3684,7 @@ for (;; ptr++)
/* All real repeats make it impossible to handle partial matching (maybe
one day we will be able to remove this restriction). */
- if (repeat_max != 1) cd->nopartial = TRUE;
+ if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;
/* Combine the op_type with the repeat_type */
@@ -3222,7 +3834,7 @@ for (;; ptr++)
/* All real repeats make it impossible to handle partial matching (maybe
one day we will be able to remove this restriction). */
- if (repeat_max != 1) cd->nopartial = TRUE;
+ if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;
if (repeat_min == 0 && repeat_max == -1)
*code++ = OP_CRSTAR + repeat_type;
@@ -3258,14 +3870,6 @@ for (;; ptr++)
goto FAILED;
}
- /* This is a paranoid check to stop integer overflow later on */
-
- if (len > MAX_DUPLENGTH)
- {
- *errorcodeptr = ERR50;
- goto FAILED;
- }
-
/* If the maximum repeat count is unlimited, find the end of the bracket
by scanning through from the start, and compute the offset back to it
from the current code pointer. There may be an OP_OPT setting following
@@ -3288,28 +3892,38 @@ for (;; ptr++)
if (repeat_min == 0)
{
- /* If the maximum is also zero, we just omit the group from the output
- altogether. */
-
- if (repeat_max == 0)
- {
- code = previous;
- goto END_REPEAT;
- }
-
- /* If the maximum is 1 or unlimited, we just have to stick in the
- BRAZERO and do no more at this point. However, we do need to adjust
- any OP_RECURSE calls inside the group that refer to the group itself or
- any internal or forward referenced group, because the offset is from
- the start of the whole regex. Temporarily terminate the pattern while
- doing this. */
-
- if (repeat_max <= 1)
+ /* If the maximum is also zero, we used to just omit the group from the
+ output altogether, like this:
+
+ ** if (repeat_max == 0)
+ ** {
+ ** code = previous;
+ ** goto END_REPEAT;
+ ** }
+
+ However, that fails when a group is referenced as a subroutine from
+ elsewhere in the pattern, so now we stick in OP_SKIPZERO in front of it
+ so that it is skipped on execution. As we don't have a list of which
+ groups are referenced, we cannot do this selectively.
+
+ If the maximum is 1 or unlimited, we just have to stick in the BRAZERO
+ and do no more at this point. However, we do need to adjust any
+ OP_RECURSE calls inside the group that refer to the group itself or any
+ internal or forward referenced group, because the offset is from the
+ start of the whole regex. Temporarily terminate the pattern while doing
+ this. */
+
+ if (repeat_max <= 1) /* Covers 0, 1, and unlimited */
{
*code = OP_END;
adjust_recurse(previous, 1, utf8, cd, save_hwm);
memmove(previous+1, previous, len);
code++;
+ if (repeat_max == 0)
+ {
+ *previous++ = OP_SKIPZERO;
+ goto END_REPEAT;
+ }
*previous++ = OP_BRAZERO + repeat_type;
}
@@ -3354,10 +3968,21 @@ for (;; ptr++)
if (repeat_min > 1)
{
/* In the pre-compile phase, we don't actually do the replication. We
- just adjust the length as if we had. */
+ just adjust the length as if we had. Do some paranoid checks for
+ potential integer overflow. */
if (lengthptr != NULL)
- *lengthptr += (repeat_min - 1)*length_prevgroup;
+ {
+ int delta = (repeat_min - 1)*length_prevgroup;
+ if ((double)(repeat_min - 1)*(double)length_prevgroup >
+ (double)INT_MAX ||
+ OFLOW_MAX - *lengthptr < delta)
+ {
+ *errorcodeptr = ERR20;
+ goto FAILED;
+ }
+ *lengthptr += delta;
+ }
/* This is compiling for real */
@@ -3395,11 +4020,23 @@ for (;; ptr++)
/* In the pre-compile phase, we don't actually do the replication. We
just adjust the length as if we had. For each repetition we must add 1
to the length for BRAZERO and for all but the last repetition we must
- add 2 + 2*LINKSIZE to allow for the nesting that occurs. */
+ add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some
+ paranoid checks to avoid integer overflow. */
if (lengthptr != NULL && repeat_max > 0)
- *lengthptr += repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
- 2 - 2*LINK_SIZE; /* Last one doesn't nest */
+ {
+ int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
+ 2 - 2*LINK_SIZE; /* Last one doesn't nest */
+ if ((double)repeat_max *
+ (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)
+ > (double)INT_MAX ||
+ OFLOW_MAX - *lengthptr < delta)
+ {
+ *errorcodeptr = ERR20;
+ goto FAILED;
+ }
+ *lengthptr += delta;
+ }
/* This is compiling for real */
@@ -3481,6 +4118,13 @@ for (;; ptr++)
}
}
+ /* If previous is OP_FAIL, it was generated by an empty class [] in
+ JavaScript mode. The other ways in which OP_FAIL can be generated, that is
+ by (*FAIL) or (?!) set previous to NULL, which gives a "nothing to repeat"
+ error above. We can just ignore the repeat in JS case. */
+
+ else if (*previous == OP_FAIL) goto END_REPEAT;
+
/* Else there's some kind of shambles */
else
@@ -3507,7 +4151,9 @@ for (;; ptr++)
int len;
if (*tempcode == OP_EXACT || *tempcode == OP_TYPEEXACT ||
*tempcode == OP_NOTEXACT)
- tempcode += _pcre_OP_lengths[*tempcode];
+ tempcode += _pcre_OP_lengths[*tempcode] +
+ ((*tempcode == OP_TYPEEXACT &&
+ (tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP))? 2:0);
len = code - tempcode;
if (len > 0) switch (*tempcode)
{
@@ -3551,17 +4197,55 @@ for (;; ptr++)
/* ===================================================================*/
/* Start of nested parenthesized sub-expression, or comment or lookahead or
lookbehind or option setting or condition or all the other extended
- parenthesis forms. First deal with the specials; all are introduced by ?,
- and the appearance of any of them means that this is not a capturing
- group. */
+ parenthesis forms. */
case '(':
newoptions = options;
skipbytes = 0;
bravalue = OP_CBRA;
save_hwm = cd->hwm;
+ reset_bracount = FALSE;
- if (*(++ptr) == '?')
+ /* First deal with various "verbs" that can be introduced by '*'. */
+
+ if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0)
+ {
+ int i, namelen;
+ const char *vn = verbnames;
+ const uschar *name = ++ptr;
+ previous = NULL;
+ while ((cd->ctypes[*++ptr] & ctype_letter) != 0);
+ if (*ptr == ':')
+ {
+ *errorcodeptr = ERR59; /* Not supported */
+ goto FAILED;
+ }
+ if (*ptr != ')')
+ {
+ *errorcodeptr = ERR60;
+ goto FAILED;
+ }
+ namelen = ptr - name;
+ for (i = 0; i < verbcount; i++)
+ {
+ if (namelen == verbs[i].len &&
+ strncmp((char *)name, vn, namelen) == 0)
+ {
+ *code = verbs[i].op;
+ if (*code++ == OP_ACCEPT) cd->had_accept = TRUE;
+ break;
+ }
+ vn += verbs[i].len + 1;
+ }
+ if (i < verbcount) continue;
+ *errorcodeptr = ERR60;
+ goto FAILED;
+ }
+
+ /* Deal with the extended parentheses; all are introduced by '?', and the
+ appearance of any of them means that this is not a capturing group. */
+
+ else if (*ptr == '?')
{
int i, set, unset, namelen;
int *optset;
@@ -3582,6 +4266,11 @@ for (;; ptr++)
/* ------------------------------------------------------------ */
+ case '|': /* Reset capture count for each branch */
+ reset_bracount = TRUE;
+ /* Fall through */
+
+ /* ------------------------------------------------------------ */
case ':': /* Non-capturing bracket */
bravalue = OP_BRA;
ptr++;
@@ -3617,6 +4306,7 @@ for (;; ptr++)
code[1+LINK_SIZE] = OP_CREF;
skipbytes = 3;
+ refsign = -1;
/* Check for a test for recursion in a named group. */
@@ -3640,7 +4330,11 @@ for (;; ptr++)
terminator = '\'';
ptr++;
}
- else terminator = 0;
+ else
+ {
+ terminator = 0;
+ if (ptr[1] == '-' || ptr[1] == '+') refsign = *(++ptr);
+ }
/* We now expect to read a name; any thing else is an error */
@@ -3676,7 +4370,29 @@ for (;; ptr++)
if (lengthptr != NULL) break;
/* In the real compile we do the work of looking for the actual
- reference. */
+ reference. If the string started with "+" or "-" we require the rest to
+ be digits, in which case recno will be set. */
+
+ if (refsign > 0)
+ {
+ if (recno <= 0)
+ {
+ *errorcodeptr = ERR58;
+ goto FAILED;
+ }
+ recno = (refsign == '-')?
+ cd->bracount - recno + 1 : recno +cd->bracount;
+ if (recno <= 0 || recno > cd->final_bracount)
+ {
+ *errorcodeptr = ERR15;
+ goto FAILED;
+ }
+ PUT2(code, 2+LINK_SIZE, recno);
+ break;
+ }
+
+ /* Otherwise (did not start with "+" or "-"), start by looking for the
+ name. */
slot = cd->name_table;
for (i = 0; i < cd->names_found; i++)
@@ -3695,7 +4411,7 @@ for (;; ptr++)
/* Search the pattern for a forward reference */
- else if ((i = find_parens(ptr, cd->bracount, name, namelen,
+ else if ((i = find_parens(ptr, cd, name, namelen,
(options & PCRE_EXTENDED) != 0)) > 0)
{
PUT2(code, 2+LINK_SIZE, i);
@@ -3742,9 +4458,10 @@ for (;; ptr++)
skipbytes = 1;
}
- /* Check for the "name" actually being a subpattern number. */
+ /* Check for the "name" actually being a subpattern number. We are
+ in the second pass here, so final_bracount is set. */
- else if (recno > 0)
+ else if (recno > 0 && recno <= cd->final_bracount)
{
PUT2(code, 2+LINK_SIZE, recno);
}
@@ -3768,8 +4485,14 @@ for (;; ptr++)
/* ------------------------------------------------------------ */
case '!': /* Negative lookahead */
- bravalue = OP_ASSERT_NOT;
ptr++;
+ if (*ptr == ')') /* Optimize (?!) */
+ {
+ *code++ = OP_FAIL;
+ previous = NULL;
+ continue;
+ }
+ bravalue = OP_ASSERT_NOT;
break;
@@ -3932,7 +4655,9 @@ for (;; ptr++)
/* We come here from the Python syntax above that handles both
references (?P=name) and recursion (?P>name), as well as falling
- through from the Perl recursion syntax (?&name). */
+ through from the Perl recursion syntax (?&name). We also come here from
+ the Perl \k<name> or \k'name' back reference syntax and the \k{name}
+ .NET syntax, and the Oniguruma \g<...> and \g'...' subroutine syntax. */
NAMED_REF_OR_RECURSE:
name = ++ptr;
@@ -3944,6 +4669,11 @@ for (;; ptr++)
if (lengthptr != NULL)
{
+ if (namelen == 0)
+ {
+ *errorcodeptr = ERR62;
+ goto FAILED;
+ }
if (*ptr != terminator)
{
*errorcodeptr = ERR42;
@@ -3957,14 +4687,19 @@ for (;; ptr++)
recno = 0;
}
- /* In the real compile, seek the name in the table */
+ /* In the real compile, seek the name in the table. We check the name
+ first, and then check that we have reached the end of the name in the
+ table. That way, if the name that is longer than any in the table,
+ the comparison will fail without reading beyond the table entry. */
else
{
slot = cd->name_table;
for (i = 0; i < cd->names_found; i++)
{
- if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
+ if (strncmp((char *)name, (char *)slot+2, namelen) == 0 &&
+ slot[2+namelen] == 0)
+ break;
slot += cd->name_entry_size;
}
@@ -3973,7 +4708,7 @@ for (;; ptr++)
recno = GET2(slot, 0);
}
else if ((recno = /* Forward back reference */
- find_parens(ptr, cd->bracount, name, namelen,
+ find_parens(ptr, cd, name, namelen,
(options & PCRE_EXTENDED) != 0)) <= 0)
{
*errorcodeptr = ERR15;
@@ -3995,19 +4730,71 @@ for (;; ptr++)
/* ------------------------------------------------------------ */
+ case '-': case '+':
case '0': case '1': case '2': case '3': case '4': /* Recursion or */
case '5': case '6': case '7': case '8': case '9': /* subroutine */
{
const uschar *called;
+ terminator = ')';
+
+ /* Come here from the \g<...> and \g'...' code (Oniguruma
+ compatibility). However, the syntax has been checked to ensure that
+ the ... are a (signed) number, so that neither ERR63 nor ERR29 will
+ be called on this path, nor with the jump to OTHER_CHAR_AFTER_QUERY
+ ever be taken. */
+
+ HANDLE_NUMERICAL_RECURSION:
+
+ if ((refsign = *ptr) == '+')
+ {
+ ptr++;
+ if ((digitab[*ptr] & ctype_digit) == 0)
+ {
+ *errorcodeptr = ERR63;
+ goto FAILED;
+ }
+ }
+ else if (refsign == '-')
+ {
+ if ((digitab[ptr[1]] & ctype_digit) == 0)
+ goto OTHER_CHAR_AFTER_QUERY;
+ ptr++;
+ }
+
recno = 0;
while((digitab[*ptr] & ctype_digit) != 0)
recno = recno * 10 + *ptr++ - '0';
- if (*ptr != ')')
+
+ if (*ptr != terminator)
{
*errorcodeptr = ERR29;
goto FAILED;
}
+ if (refsign == '-')
+ {
+ if (recno == 0)
+ {
+ *errorcodeptr = ERR58;
+ goto FAILED;
+ }
+ recno = cd->bracount - recno + 1;
+ if (recno <= 0)
+ {
+ *errorcodeptr = ERR15;
+ goto FAILED;
+ }
+ }
+ else if (refsign == '+')
+ {
+ if (recno == 0)
+ {
+ *errorcodeptr = ERR58;
+ goto FAILED;
+ }
+ recno += cd->bracount;
+ }
+
/* Come here from code above that handles a named recursion */
HANDLE_RECURSION:
@@ -4031,8 +4818,8 @@ for (;; ptr++)
if (called == NULL)
{
- if (find_parens(ptr, cd->bracount, NULL, recno,
- (options & PCRE_EXTENDED) != 0) < 0)
+ if (find_parens(ptr, cd, NULL, recno,
+ (options & PCRE_EXTENDED) != 0) < 0)
{
*errorcodeptr = ERR15;
goto FAILED;
@@ -4080,6 +4867,7 @@ for (;; ptr++)
/* ------------------------------------------------------------ */
default: /* Other characters: check option setting */
+ OTHER_CHAR_AFTER_QUERY:
set = unset = 0;
optset = &set;
@@ -4091,7 +4879,7 @@ for (;; ptr++)
case 'J': /* Record that it changed in the external options */
*optset |= PCRE_DUPNAMES;
- cd->external_options |= PCRE_JCHANGED;
+ cd->external_flags |= PCRE_JCHANGED;
break;
case 'i': *optset |= PCRE_CASELESS; break;
@@ -4141,7 +4929,7 @@ for (;; ptr++)
(lengthptr == NULL || *lengthptr == 2 + 2*LINK_SIZE))
{
cd->external_options = newoptions;
- options = newoptions;
+ options = *optionsptr = newoptions;
}
else
{
@@ -4214,6 +5002,7 @@ for (;; ptr++)
errorcodeptr, /* Where to put an error message */
(bravalue == OP_ASSERTBACK ||
bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */
+ reset_bracount, /* True if (?| group */
skipbytes, /* Skip over bracket number */
&subfirstbyte, /* For possible first char */
&subreqbyte, /* For possible last char */
@@ -4230,9 +5019,11 @@ for (;; ptr++)
is on the bracket. */
/* If this is a conditional bracket, check that there are no more than
- two branches in the group, or just one if it's a DEFINE group. */
+ two branches in the group, or just one if it's a DEFINE group. We do this
+ in the real compile phase, not in the pre-pass, where the whole group may
+ not be available. */
- if (bravalue == OP_COND)
+ if (bravalue == OP_COND && lengthptr == NULL)
{
uschar *tc = code;
int condcount = 0;
@@ -4279,23 +5070,29 @@ for (;; ptr++)
goto FAILED;
}
- /* In the pre-compile phase, update the length by the length of the nested
- group, less the brackets at either end. Then reduce the compiled code to
- just the brackets so that it doesn't use much memory if it is duplicated by
- a quantifier. */
+ /* In the pre-compile phase, update the length by the length of the group,
+ less the brackets at either end. Then reduce the compiled code to just a
+ set of non-capturing brackets so that it doesn't use much memory if it is
+ duplicated by a quantifier.*/
if (lengthptr != NULL)
{
+ if (OFLOW_MAX - *lengthptr < length_prevgroup - 2 - 2*LINK_SIZE)
+ {
+ *errorcodeptr = ERR20;
+ goto FAILED;
+ }
*lengthptr += length_prevgroup - 2 - 2*LINK_SIZE;
- code++;
+ *code++ = OP_BRA;
PUTINC(code, 0, 1 + LINK_SIZE);
*code++ = OP_KET;
PUTINC(code, 0, 1 + LINK_SIZE);
+ break; /* No need to waste time with special character handling */
}
/* Otherwise update the main code pointer to the end of the group. */
- else code = tempcode;
+ code = tempcode;
/* For a DEFINE group, required and first character settings are not
relevant. */
@@ -4392,12 +5189,71 @@ for (;; ptr++)
zerofirstbyte = firstbyte;
zeroreqbyte = reqbyte;
- /* \k<name> or \k'name' is a back reference by name (Perl syntax) */
+ /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
+ is a subroutine call by number (Oniguruma syntax). In fact, the value
+ -ESC_g is returned only for these cases. So we don't need to check for <
+ or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is
+ -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as
+ that is a synonym for a named back reference). */
- if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\''))
+ if (-c == ESC_g)
{
- is_recurse = FALSE;
+ const uschar *p;
+ save_hwm = cd->hwm; /* Normally this is set when '(' is read */
terminator = (*(++ptr) == '<')? '>' : '\'';
+
+ /* These two statements stop the compiler for warning about possibly
+ unset variables caused by the jump to HANDLE_NUMERICAL_RECURSION. In
+ fact, because we actually check for a number below, the paths that
+ would actually be in error are never taken. */
+
+ skipbytes = 0;
+ reset_bracount = FALSE;
+
+ /* Test for a name */
+
+ if (ptr[1] != '+' && ptr[1] != '-')
+ {
+ BOOL isnumber = TRUE;
+ for (p = ptr + 1; *p != 0 && *p != terminator; p++)
+ {
+ if ((cd->ctypes[*p] & ctype_digit) == 0) isnumber = FALSE;
+ if ((cd->ctypes[*p] & ctype_word) == 0) break;
+ }
+ if (*p != terminator)
+ {
+ *errorcodeptr = ERR57;
+ break;
+ }
+ if (isnumber)
+ {
+ ptr++;
+ goto HANDLE_NUMERICAL_RECURSION;
+ }
+ is_recurse = TRUE;
+ goto NAMED_REF_OR_RECURSE;
+ }
+
+ /* Test a signed number in angle brackets or quotes. */
+
+ p = ptr + 2;
+ while ((digitab[*p] & ctype_digit) != 0) p++;
+ if (*p != terminator)
+ {
+ *errorcodeptr = ERR57;
+ break;
+ }
+ ptr++;
+ goto HANDLE_NUMERICAL_RECURSION;
+ }
+
+ /* \k<name> or \k'name' is a back reference by name (Perl syntax).
+ We also support \k{name} (.NET syntax) */
+
+ if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\'' || ptr[1] == '{'))
+ {
+ is_recurse = FALSE;
+ terminator = (*(++ptr) == '<')? '>' : (*ptr == '\'')? '\'' : '}';
goto NAMED_REF_OR_RECURSE;
}
@@ -4498,6 +5354,11 @@ for (;; ptr++)
*code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARNC : OP_CHAR;
for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
+ /* Remember if \r or \n were seen */
+
+ if (mcbuffer[0] == '\r' || mcbuffer[0] == '\n')
+ cd->external_flags |= PCRE_HASCRORLF;
+
/* Set the first and required bytes appropriately. If no previous first
byte, set it from this character, but revert to none on a zero repeat.
Otherwise, leave the firstbyte value alone, and don't change it on a zero
@@ -4563,13 +5424,14 @@ This function is used during the pre-compile phase when we are trying to find
out the amount of memory needed, as well as during the real compile phase. The
value of lengthptr distinguishes the two phases.
-Argument:
+Arguments:
options option bits, including any changes for this subpattern
oldims previous settings of ims option bits
codeptr -> the address of the current code pointer
ptrptr -> the address of the current pattern pointer
errorcodeptr -> pointer to error code variable
lookbehind TRUE if this is a lookbehind assertion
+ reset_bracount TRUE to reset the count for each branch
skipbytes skip this many bytes at start (for brackets and OP_COND)
firstbyteptr place to put the first required character, or a negative number
reqbyteptr place to put the last required character, or a negative number
@@ -4583,8 +5445,9 @@ Returns: TRUE on success
static BOOL
compile_regex(int options, int oldims, uschar **codeptr, const uschar **ptrptr,
- int *errorcodeptr, BOOL lookbehind, int skipbytes, int *firstbyteptr,
- int *reqbyteptr, branch_chain *bcptr, compile_data *cd, int *lengthptr)
+ int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
+ int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd,
+ int *lengthptr)
{
const uschar *ptr = *ptrptr;
uschar *code = *codeptr;
@@ -4594,6 +5457,8 @@ uschar *reverse_count = NULL;
int firstbyte, reqbyte;
int branchfirstbyte, branchreqbyte;
int length;
+int orig_bracount;
+int max_bracount;
branch_chain bc;
bc.outer = bcptr;
@@ -4622,8 +5487,14 @@ code += 1 + LINK_SIZE + skipbytes;
/* Loop for each alternative branch */
+orig_bracount = max_bracount = cd->bracount;
for (;;)
{
+ /* For a (?| group, reset the capturing bracket count so that each branch
+ uses the same numbers. */
+
+ if (reset_bracount) cd->bracount = orig_bracount;
+
/* Handle a change of ims options at the start of the branch */
if ((options & PCRE_IMS) != oldims)
@@ -4653,6 +5524,11 @@ for (;;)
return FALSE;
}
+ /* Keep the highest bracket count in case (?| was used and some branch
+ has fewer than the rest. */
+
+ if (cd->bracount > max_bracount) max_bracount = cd->bracount;
+
/* In the real compile phase, there is some post-processing to be done. */
if (lengthptr == NULL)
@@ -4716,26 +5592,29 @@ for (;;)
}
}
- /* Reached end of expression, either ')' or end of pattern. Go back through
- the alternative branches and reverse the chain of offsets, with the field in
- the BRA item now becoming an offset to the first alternative. If there are
- no alternatives, it points to the end of the group. The length in the
- terminating ket is always the length of the whole bracketed item. If any of
- the ims options were changed inside the group, compile a resetting op-code
- following, except at the very end of the pattern. Return leaving the pointer
- at the terminating char. */
+ /* Reached end of expression, either ')' or end of pattern. In the real
+ compile phase, go back through the alternative branches and reverse the chain
+ of offsets, with the field in the BRA item now becoming an offset to the
+ first alternative. If there are no alternatives, it points to the end of the
+ group. The length in the terminating ket is always the length of the whole
+ bracketed item. If any of the ims options were changed inside the group,
+ compile a resetting op-code following, except at the very end of the pattern.
+ Return leaving the pointer at the terminating char. */
if (*ptr != '|')
{
- int branch_length = code - last_branch;
- do
+ if (lengthptr == NULL)
{
- int prev_length = GET(last_branch, 1);
- PUT(last_branch, 1, branch_length);
- branch_length = prev_length;
- last_branch -= branch_length;
+ int branch_length = code - last_branch;
+ do
+ {
+ int prev_length = GET(last_branch, 1);
+ PUT(last_branch, 1, branch_length);
+ branch_length = prev_length;
+ last_branch -= branch_length;
+ }
+ while (branch_length > 0);
}
- while (branch_length > 0);
/* Fill in the ket */
@@ -4752,27 +5631,51 @@ for (;;)
length += 2;
}
+ /* Retain the highest bracket number, in case resetting was used. */
+
+ cd->bracount = max_bracount;
+
/* Set values to pass back */
*codeptr = code;
*ptrptr = ptr;
*firstbyteptr = firstbyte;
*reqbyteptr = reqbyte;
- if (lengthptr != NULL) *lengthptr += length;
+ if (lengthptr != NULL)
+ {
+ if (OFLOW_MAX - *lengthptr < length)
+ {
+ *errorcodeptr = ERR20;
+ return FALSE;
+ }
+ *lengthptr += length;
+ }
return TRUE;
}
- /* Another branch follows; insert an "or" node. Its length field points back
+ /* Another branch follows. In the pre-compile phase, we can move the code
+ pointer back to where it was for the start of the first branch. (That is,
+ pretend that each branch is the only one.)
+
+ In the real compile phase, insert an ALT node. Its length field points back
to the previous branch while the bracket remains open. At the end the chain
is reversed. It's done like this so that the start of the bracket has a
zero offset until it is closed, making it possible to detect recursion. */
- *code = OP_ALT;
- PUT(code, 1, code - last_branch);
- bc.current = last_branch = code;
- code += 1 + LINK_SIZE;
+ if (lengthptr != NULL)
+ {
+ code = *codeptr + 1 + LINK_SIZE + skipbytes;
+ length += 1 + LINK_SIZE;
+ }
+ else
+ {
+ *code = OP_ALT;
+ PUT(code, 1, code - last_branch);
+ bc.current = last_branch = code;
+ code += 1 + LINK_SIZE;
+ }
+
ptr++;
- length += 1 + LINK_SIZE;
}
/* Control never reaches here */
}
@@ -4850,14 +5753,14 @@ do {
if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE;
}
- /* .* is not anchored unless DOTALL is set and it isn't in brackets that
- are or may be referenced. */
+ /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and
+ it isn't in brackets that are or may be referenced. */
else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||
- op == OP_TYPEPOSSTAR) &&
- (*options & PCRE_DOTALL) != 0)
+ op == OP_TYPEPOSSTAR))
{
- if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;
+ if (scode[1] != OP_ALLANY || (bracket_map & backref_map) != 0)
+ return FALSE;
}
/* Check for explicit anchoring */
@@ -5039,7 +5942,7 @@ Returns: pointer to compiled data block, or NULL on error,
with errorptr and erroroffset set
*/
-PCRE_DATA_SCOPE pcre *
+PCRE_EXP_DEFN pcre *
pcre_compile(const char *pattern, int options, const char **errorptr,
int *erroroffset, const unsigned char *tables)
{
@@ -5047,7 +5950,7 @@ return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
}
-PCRE_DATA_SCOPE pcre *
+PCRE_EXP_DEFN pcre *
pcre_compile2(const char *pattern, int options, int *errorcodeptr,
const char **errorptr, int *erroroffset, const unsigned char *tables)
{
@@ -5055,6 +5958,7 @@ real_pcre *re;
int length = 1; /* For final END opcode */
int firstbyte, reqbyte, newline;
int errorcode = 0;
+int skipatstart = 0;
#ifdef SUPPORT_UTF8
BOOL utf8;
#endif
@@ -5073,7 +5977,6 @@ to fill in forward references to subpatterns. */
uschar cworkspace[COMPILE_WORK_SIZE];
-
/* Set this early so that early errors get offset 0. */
ptr = (const uschar *)pattern;
@@ -5096,7 +5999,7 @@ if (errorcodeptr != NULL) *errorcodeptr = ERR0;
if (erroroffset == NULL)
{
errorcode = ERR16;
- goto PCRE_EARLY_ERROR_RETURN;
+ goto PCRE_EARLY_ERROR_RETURN2;
}
*erroroffset = 0;
@@ -5109,7 +6012,7 @@ if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
(*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)
{
errorcode = ERR44;
- goto PCRE_UTF8_ERROR_RETURN;
+ goto PCRE_EARLY_ERROR_RETURN2;
}
#else
if ((options & PCRE_UTF8) != 0)
@@ -5133,21 +6036,69 @@ cd->fcc = tables + fcc_offset;
cd->cbits = tables + cbits_offset;
cd->ctypes = tables + ctypes_offset;
+/* Check for global one-time settings at the start of the pattern, and remember
+the offset for later. */
+
+while (ptr[skipatstart] == '(' && ptr[skipatstart+1] == '*')
+ {
+ int newnl = 0;
+ int newbsr = 0;
+
+ if (strncmp((char *)(ptr+skipatstart+2), "CR)", 3) == 0)
+ { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
+ else if (strncmp((char *)(ptr+skipatstart+2), "LF)", 3) == 0)
+ { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }
+ else if (strncmp((char *)(ptr+skipatstart+2), "CRLF)", 5) == 0)
+ { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }
+ else if (strncmp((char *)(ptr+skipatstart+2), "ANY)", 4) == 0)
+ { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }
+ else if (strncmp((char *)(ptr+skipatstart+2), "ANYCRLF)", 8) == 0)
+ { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }
+
+ else if (strncmp((char *)(ptr+skipatstart+2), "BSR_ANYCRLF)", 12) == 0)
+ { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }
+ else if (strncmp((char *)(ptr+skipatstart+2), "BSR_UNICODE)", 12) == 0)
+ { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }
+
+ if (newnl != 0)
+ options = (options & ~PCRE_NEWLINE_BITS) | newnl;
+ else if (newbsr != 0)
+ options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;
+ else break;
+ }
+
+/* Check validity of \R options. */
+
+switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
+ {
+ case 0:
+ case PCRE_BSR_ANYCRLF:
+ case PCRE_BSR_UNICODE:
+ break;
+ default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN;
+ }
+
/* Handle different types of newline. The three bits give seven cases. The
-current code allows for fixed one- or two-byte sequences, plus "any". */
+current code allows for fixed one- or two-byte sequences, plus "any" and
+"anycrlf". */
-switch (options & (PCRE_NEWLINE_CRLF | PCRE_NEWLINE_ANY))
+switch (options & PCRE_NEWLINE_BITS)
{
- case 0: newline = NEWLINE; break; /* Compile-time default */
+ case 0: newline = NEWLINE; break; /* Build-time default */
case PCRE_NEWLINE_CR: newline = '\r'; break;
case PCRE_NEWLINE_LF: newline = '\n'; break;
case PCRE_NEWLINE_CR+
PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
case PCRE_NEWLINE_ANY: newline = -1; break;
+ case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN;
}
-if (newline < 0)
+if (newline == -2)
+ {
+ cd->nltype = NLTYPE_ANYCRLF;
+ }
+else if (newline < 0)
{
cd->nltype = NLTYPE_ANY;
}
@@ -5186,7 +6137,7 @@ to compile parts of the pattern into; the compiled code is discarded when it is
no longer needed, so hopefully this workspace will never overflow, though there
is a test for its doing so. */
-cd->bracount = 0;
+cd->bracount = cd->final_bracount = 0;
cd->names_found = 0;
cd->name_entry_size = 0;
cd->name_table = NULL;
@@ -5196,8 +6147,8 @@ cd->hwm = cworkspace;
cd->start_pattern = (const uschar *)pattern;
cd->end_pattern = (const uschar *)(pattern + strlen(pattern));
cd->req_varyopt = 0;
-cd->nopartial = FALSE;
cd->external_options = options;
+cd->external_flags = 0;
/* Now do the pre-compile. On error, errorcode will be set non-zero, so we
don't need to look at the result of the function here. The initial options have
@@ -5205,10 +6156,12 @@ been put into the cd block so that they can be changed if an option setting is
found within the regex right at the beginning. Bringing initial option settings
outside can help speed up starting point checks. */
+ptr += skipatstart;
code = cworkspace;
*code = OP_BRA;
(void)compile_regex(cd->external_options, cd->external_options & PCRE_IMS,
- &code, &ptr, &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, &length);
+ &code, &ptr, &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd,
+ &length);
if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
@@ -5234,14 +6187,16 @@ if (re == NULL)
goto PCRE_EARLY_ERROR_RETURN;
}
-/* Put in the magic number, and save the sizes, initial options, and character
-table pointer. NULL is used for the default character tables. The nullpad field
-is at the end; it's there to help in the case when a regex compiled on a system
-with 4-byte pointers is run on another with 8-byte pointers. */
+/* Put in the magic number, and save the sizes, initial options, internal
+flags, and character table pointer. NULL is used for the default character
+tables. The nullpad field is at the end; it's there to help in the case when a
+regex compiled on a system with 4-byte pointers is run on another with 8-byte
+pointers. */
re->magic_number = MAGIC_NUMBER;
re->size = size;
re->options = cd->external_options;
+re->flags = cd->external_flags;
re->dummy1 = 0;
re->first_byte = 0;
re->req_byte = 0;
@@ -5259,6 +6214,7 @@ field. Reset the bracket count and the names_found field. Also reset the hwm
field; this time it's used for remembering forward references to subpatterns.
*/
+cd->final_bracount = cd->bracount; /* Save for checking forward references */
cd->bracount = 0;
cd->names_found = 0;
cd->name_table = (uschar *)re + re->name_table_offset;
@@ -5266,21 +6222,22 @@ codestart = cd->name_table + re->name_entry_size * re->name_count;
cd->start_code = codestart;
cd->hwm = cworkspace;
cd->req_varyopt = 0;
-cd->nopartial = FALSE;
+cd->had_accept = FALSE;
/* Set up a starting, non-extracting bracket, then compile the expression. On
error, errorcode will be set non-zero, so we don't need to look at the result
of the function here. */
-ptr = (const uschar *)pattern;
+ptr = (const uschar *)pattern + skipatstart;
code = (uschar *)codestart;
*code = OP_BRA;
(void)compile_regex(re->options, re->options & PCRE_IMS, &code, &ptr,
- &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL);
+ &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL);
re->top_bracket = cd->bracount;
re->top_backref = cd->top_backref;
+re->flags = cd->external_flags;
-if (cd->nopartial) re->options |= PCRE_NOPARTIAL;
+if (cd->had_accept) reqbyte = -1; /* Must disable after (*ACCEPT) */
/* If not reached end of pattern on success, there's an excess bracket. */
@@ -5321,10 +6278,8 @@ if (errorcode != 0)
(pcre_free)(re);
PCRE_EARLY_ERROR_RETURN:
*erroroffset = ptr - (const uschar *)pattern;
-#ifdef SUPPORT_UTF8
- PCRE_UTF8_ERROR_RETURN:
-#endif
- *errorptr = error_texts[errorcode];
+ PCRE_EARLY_ERROR_RETURN2:
+ *errorptr = find_error_text(errorcode);
if (errorcodeptr != NULL) *errorcodeptr = errorcode;
return NULL;
}
@@ -5353,10 +6308,10 @@ if ((re->options & PCRE_ANCHORED) == 0)
int ch = firstbyte & 255;
re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&
cd->fcc[ch] == ch)? ch : firstbyte;
- re->options |= PCRE_FIRSTSET;
+ re->flags |= PCRE_FIRSTSET;
}
else if (is_startline(codestart, 0, cd->backref_map))
- re->options |= PCRE_STARTLINE;
+ re->flags |= PCRE_STARTLINE;
}
}
@@ -5370,7 +6325,7 @@ if (reqbyte >= 0 &&
int ch = reqbyte & 255;
re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&
cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;
- re->options |= PCRE_REQCHSET;
+ re->flags |= PCRE_REQCHSET;
}
/* Print out the compiled data if debugging is enabled. This is never the
@@ -5381,21 +6336,9 @@ case when building a production library. */
printf("Length = %d top_bracket = %d top_backref = %d\n",
length, re->top_bracket, re->top_backref);
-if (re->options != 0)
- {
- printf("%s%s%s%s%s%s%s%s%s\n",
- ((re->options & PCRE_NOPARTIAL) != 0)? "nopartial " : "",
- ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",
- ((re->options & PCRE_CASELESS) != 0)? "caseless " : "",
- ((re->options & PCRE_EXTENDED) != 0)? "extended " : "",
- ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",
- ((re->options & PCRE_DOTALL) != 0)? "dotall " : "",
- ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",
- ((re->options & PCRE_EXTRA) != 0)? "extra " : "",
- ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");
- }
+printf("Options=%08x\n", re->options);
-if ((re->options & PCRE_FIRSTSET) != 0)
+if ((re->flags & PCRE_FIRSTSET) != 0)
{
int ch = re->first_byte & 255;
const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)?
@@ -5404,7 +6347,7 @@ if ((re->options & PCRE_FIRSTSET) != 0)
else printf("First char = \\x%02x%s\n", ch, caseless);
}
-if ((re->options & PCRE_REQCHSET) != 0)
+if ((re->flags & PCRE_REQCHSET) != 0)
{
int ch = re->req_byte & 255;
const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)?
@@ -5413,7 +6356,7 @@ if ((re->options & PCRE_REQCHSET) != 0)
else printf("Req char = \\x%02x%s\n", ch, caseless);
}
-pcre_printint(re, stdout);
+pcre_printint(re, stdout, TRUE);
/* This check is done here in the debugging case so that the code that
was compiled can be seen. */
@@ -5421,7 +6364,7 @@ was compiled can be seen. */
if (code - codestart > length)
{
(pcre_free)(re);
- *errorptr = error_texts[ERR23];
+ *errorptr = find_error_text(ERR23);
*erroroffset = ptr - (uschar *)pattern;
if (errorcodeptr != NULL) *errorcodeptr = ERR23;
return NULL;
diff --git a/ext/pcre/pcrelib/pcre_config.c b/ext/pcre/pcrelib/pcre_config.c
index 29e6c1a358..32f9047b0e 100644
--- a/ext/pcre/pcrelib/pcre_config.c
+++ b/ext/pcre/pcrelib/pcre_config.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
/* This module contains the external function pcre_config(). */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -58,7 +60,7 @@ Arguments:
Returns: 0 if data returned, negative on error
*/
-PCRE_DATA_SCOPE int
+PCRE_EXP_DEFN int
pcre_config(int what, void *where)
{
switch (what)
@@ -83,6 +85,14 @@ switch (what)
*((int *)where) = NEWLINE;
break;
+ case PCRE_CONFIG_BSR:
+#ifdef BSR_ANYCRLF
+ *((int *)where) = 1;
+#else
+ *((int *)where) = 0;
+#endif
+ break;
+
case PCRE_CONFIG_LINK_SIZE:
*((int *)where) = LINK_SIZE;
break;
diff --git a/ext/pcre/pcrelib/pcre_exec.c b/ext/pcre/pcrelib/pcre_exec.c
index 890e0f731a..e28fe9ec86 100644
--- a/ext/pcre/pcrelib/pcre_exec.c
+++ b/ext/pcre/pcrelib/pcre_exec.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,22 +42,23 @@ POSSIBILITY OF SUCH DAMAGE.
pattern matching using an NFA algorithm, trying to mimic Perl as closely as
possible. There are also some static supporting functions. */
+#include "config.h"
+
#define NLBLOCK md /* Block containing newline information */
#define PSSTART start_subject /* Field containing processed string start */
#define PSEND end_subject /* Field containing processed string end */
#include "pcre_internal.h"
-/* The chain of eptrblocks for tail recursions uses memory in stack workspace,
-obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */
+/* Undefine some potentially clashing cpp symbols */
-#define EPTR_WORK_SIZE (1000)
+#undef min
+#undef max
/* Flag bits for the match() function */
#define match_condassert 0x01 /* Called to check a condition assertion */
#define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */
-#define match_tail_recursed 0x04 /* Tail recursive call */
/* Non-error returns from the match() function. Error returns are externally
defined PCRE_ERROR_xxx codes, which are all negative. */
@@ -65,6 +66,14 @@ defined PCRE_ERROR_xxx codes, which are all negative. */
#define MATCH_MATCH 1
#define MATCH_NOMATCH 0
+/* Special internal returns from the match() function. Make them sufficiently
+negative to avoid the external error codes. */
+
+#define MATCH_COMMIT (-999)
+#define MATCH_PRUNE (-998)
+#define MATCH_SKIP (-997)
+#define MATCH_THEN (-996)
+
/* Maximum number of ints of offset to save on the stack for recursive calls.
If the offset vector is bigger, malloc is used. This should be a multiple of 3,
because the offset vector is always a multiple of 3 long. */
@@ -183,20 +192,45 @@ calls by keeping local variables that need to be preserved in blocks of memory
obtained from malloc() instead instead of on the stack. Macros are used to
achieve this so that the actual code doesn't look very different to what it
always used to.
+
+The original heap-recursive code used longjmp(). However, it seems that this
+can be very slow on some operating systems. Following a suggestion from Stan
+Switzer, the use of longjmp() has been abolished, at the cost of having to
+provide a unique number for each call to RMATCH. There is no way of generating
+a sequence of numbers at compile time in C. I have given them names, to make
+them stand out more clearly.
+
+Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
+FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
+tests. Furthermore, not using longjmp() means that local dynamic variables
+don't have indeterminate values; this has meant that the frame size can be
+reduced because the result can be "passed back" by straight setting of the
+variable instead of being passed in the frame.
****************************************************************************
***************************************************************************/
+/* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
+below must be updated in sync. */
+
+enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10,
+ RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
+ RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
+ RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
+ RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
+ RM51, RM52, RM53, RM54 };
/* These versions of the macros use the stack, as normal. There are debugging
-versions and production versions. */
+versions and production versions. Note that the "rw" argument of RMATCH isn't
+actuall used in this definition. */
#ifndef NO_RECURSE
#define REGISTER register
+
#ifdef DEBUG
-#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \
+#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
{ \
printf("match() called in line %d\n", __LINE__); \
- rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \
+ rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
printf("to line %d\n", __LINE__); \
}
#define RRETURN(ra) \
@@ -205,43 +239,38 @@ versions and production versions. */
return ra; \
}
#else
-#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \
- rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)
+#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
+ rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
#define RRETURN(ra) return ra
#endif
#else
-/* These versions of the macros manage a private stack on the heap. Note
-that the rd argument of RMATCH isn't actually used. It's the md argument of
-match(), which never changes. */
+/* These versions of the macros manage a private stack on the heap. Note that
+the "rd" argument of RMATCH isn't actually used in this definition. It's the md
+argument of match(), which never changes. */
#define REGISTER
-#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\
+#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
{\
heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
- if (setjmp(frame->Xwhere) == 0)\
- {\
- newframe->Xeptr = ra;\
- newframe->Xecode = rb;\
- newframe->Xoffset_top = rc;\
- newframe->Xims = re;\
- newframe->Xeptrb = rf;\
- newframe->Xflags = rg;\
- newframe->Xrdepth = frame->Xrdepth + 1;\
- newframe->Xprevframe = frame;\
- frame = newframe;\
- DPRINTF(("restarting from line %d\n", __LINE__));\
- goto HEAP_RECURSE;\
- }\
- else\
- {\
- DPRINTF(("longjumped back to line %d\n", __LINE__));\
- frame = md->thisframe;\
- rx = frame->Xresult;\
- }\
+ frame->Xwhere = rw; \
+ newframe->Xeptr = ra;\
+ newframe->Xecode = rb;\
+ newframe->Xmstart = mstart;\
+ newframe->Xoffset_top = rc;\
+ newframe->Xims = re;\
+ newframe->Xeptrb = rf;\
+ newframe->Xflags = rg;\
+ newframe->Xrdepth = frame->Xrdepth + 1;\
+ newframe->Xprevframe = frame;\
+ frame = newframe;\
+ DPRINTF(("restarting from line %d\n", __LINE__));\
+ goto HEAP_RECURSE;\
+ L_##rw:\
+ DPRINTF(("jumped back to line %d\n", __LINE__));\
}
#define RRETURN(ra)\
@@ -251,9 +280,8 @@ match(), which never changes. */
(pcre_stack_free)(newframe);\
if (frame != NULL)\
{\
- frame->Xresult = ra;\
- md->thisframe = frame;\
- longjmp(frame->Xwhere, 1);\
+ rrc = ra;\
+ goto HEAP_RETURN;\
}\
return ra;\
}
@@ -268,6 +296,7 @@ typedef struct heapframe {
const uschar *Xeptr;
const uschar *Xecode;
+ const uschar *Xmstart;
int Xoffset_top;
long int Xims;
eptrblock *Xeptrb;
@@ -299,6 +328,8 @@ typedef struct heapframe {
int Xprop_category;
int Xprop_chartype;
int Xprop_script;
+ int Xoclength;
+ uschar Xocchars[8];
#endif
int Xctype;
@@ -316,10 +347,9 @@ typedef struct heapframe {
eptrblock Xnewptrb;
- /* Place to pass back result, and where to jump back to */
+ /* Where to jump back to */
- int Xresult;
- jmp_buf Xwhere;
+ int Xwhere;
} heapframe;
@@ -347,6 +377,8 @@ made performance worse.
Arguments:
eptr pointer to current character in subject
ecode pointer to current position in compiled code
+ mstart pointer to the current match start position (can be modified
+ by encountering \K)
offset_top current top pointer
md pointer to "static" info for the match
ims current /i, /m, and /s options
@@ -356,7 +388,6 @@ Arguments:
match_condassert - this is an assertion condition
match_cbegroup - this is the start of an unlimited repeat
group that can match an empty string
- match_tail_recursed - this is a tail_recursed group
rdepth the recursion depth
Returns: MATCH_MATCH if matched ) these values are >= 0
@@ -366,7 +397,7 @@ Returns: MATCH_MATCH if matched ) these values are >= 0
*/
static int
-match(REGISTER USPTR eptr, REGISTER const uschar *ecode,
+match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
int flags, unsigned int rdepth)
{
@@ -394,6 +425,7 @@ frame->Xprevframe = NULL; /* Marks the top level */
frame->Xeptr = eptr;
frame->Xecode = ecode;
+frame->Xmstart = mstart;
frame->Xoffset_top = offset_top;
frame->Xims = ims;
frame->Xeptrb = eptrb;
@@ -408,6 +440,7 @@ HEAP_RECURSE:
#define eptr frame->Xeptr
#define ecode frame->Xecode
+#define mstart frame->Xmstart
#define offset_top frame->Xoffset_top
#define ims frame->Xims
#define eptrb frame->Xeptrb
@@ -441,6 +474,8 @@ HEAP_RECURSE:
#define prop_category frame->Xprop_category
#define prop_chartype frame->Xprop_chartype
#define prop_script frame->Xprop_script
+#define oclength frame->Xoclength
+#define occhars frame->Xocchars
#endif
#define ctype frame->Xctype
@@ -494,6 +529,8 @@ int prop_fail_result;
int prop_category;
int prop_chartype;
int prop_script;
+int oclength;
+uschar occhars[8];
#endif
int ctype;
@@ -534,6 +571,12 @@ defined). However, RMATCH isn't like a function call because it's quite a
complicated macro. It has to be used in one particular way. This shouldn't,
however, impact performance when true recursion is being used. */
+#ifdef SUPPORT_UTF8
+utf8 = md->utf8; /* Local copy of the flag */
+#else
+utf8 = FALSE;
+#endif
+
/* First check that we haven't called match() too many times, or that we
haven't exceeded the recursive call limit. */
@@ -542,32 +585,20 @@ if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
original_ims = ims; /* Save for resetting on ')' */
-#ifdef SUPPORT_UTF8
-utf8 = md->utf8; /* Local copy of the flag */
-#else
-utf8 = FALSE;
-#endif
-
/* At the start of a group with an unlimited repeat that may match an empty
string, the match_cbegroup flag is set. When this is the case, add the current
subject pointer to the chain of such remembered pointers, to be checked when we
hit the closing ket, in order to break infinite loops that match no characters.
-When match() is called in other circumstances, don't add to the chain. If this
-is a tail recursion, use a block from the workspace, as the one on the stack is
-already used. */
+When match() is called in other circumstances, don't add to the chain. The
+match_cbegroup flag must NOT be used with tail recursion, because the memory
+block that is used is on the stack, so a new one may be required for each
+match(). */
if ((flags & match_cbegroup) != 0)
{
- eptrblock *p;
- if ((flags & match_tail_recursed) != 0)
- {
- if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);
- p = md->eptrchain + md->eptrn++;
- }
- else p = &newptrb;
- p->epb_saved_eptr = eptr;
- p->epb_prev = eptrb;
- eptrb = p;
+ newptrb.epb_saved_eptr = eptr;
+ newptrb.epb_prev = eptrb;
+ eptrb = &newptrb;
}
/* Now start processing the opcodes. */
@@ -582,11 +613,39 @@ for (;;)
if (md->partial &&
eptr >= md->end_subject &&
- eptr > md->start_match)
+ eptr > mstart)
md->hitend = TRUE;
switch(op)
{
+ case OP_FAIL:
+ RRETURN(MATCH_NOMATCH);
+
+ case OP_PRUNE:
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+ ims, eptrb, flags, RM51);
+ if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ RRETURN(MATCH_PRUNE);
+
+ case OP_COMMIT:
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+ ims, eptrb, flags, RM52);
+ if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ RRETURN(MATCH_COMMIT);
+
+ case OP_SKIP:
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+ ims, eptrb, flags, RM53);
+ if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ md->start_match_ptr = eptr; /* Pass back current position */
+ RRETURN(MATCH_SKIP);
+
+ case OP_THEN:
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+ ims, eptrb, flags, RM54);
+ if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ RRETURN(MATCH_THEN);
+
/* Handle a capturing bracket. If there is space in the offset vector, save
the current subject position in the working slot at the top of the vector.
We mustn't change the current values of the data slot, because they may be
@@ -626,9 +685,9 @@ for (;;)
flags = (op == OP_SCBRA)? match_cbegroup : 0;
do
{
- RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
- ims, eptrb, flags);
- if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+ ims, eptrb, flags, RM1);
+ if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
md->capture_last = save_capture_last;
ecode += GET(ecode, 1);
}
@@ -643,15 +702,22 @@ for (;;)
RRETURN(MATCH_NOMATCH);
}
- /* Insufficient room for saving captured contents. Treat as a non-capturing
- bracket. */
+ /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
+ as a non-capturing bracket. */
+
+ /* VVVVVVVVVVVVVVVVVVVVVVVVV */
+ /* VVVVVVVVVVVVVVVVVVVVVVVVV */
DPRINTF(("insufficient capture room: treat as non-capturing\n"));
+ /* VVVVVVVVVVVVVVVVVVVVVVVVV */
+ /* VVVVVVVVVVVVVVVVVVVVVVVVV */
+
/* Non-capturing bracket. Loop for all the alternatives. When we get to the
final alternative within the brackets, we would return the result of a
recursive call to match() whatever happened. We can reduce stack usage by
- turning this into a tail recursion. */
+ turning this into a tail recursion, except in the case when match_cbegroup
+ is set.*/
case OP_BRA:
case OP_SBRA:
@@ -659,20 +725,28 @@ for (;;)
flags = (op >= OP_SBRA)? match_cbegroup : 0;
for (;;)
{
- if (ecode[GET(ecode, 1)] != OP_ALT)
+ if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */
{
- ecode += _pcre_OP_lengths[*ecode];
- flags |= match_tail_recursed;
- DPRINTF(("bracket 0 tail recursion\n"));
- goto TAIL_RECURSE;
+ if (flags == 0) /* Not a possibly empty group */
+ {
+ ecode += _pcre_OP_lengths[*ecode];
+ DPRINTF(("bracket 0 tail recursion\n"));
+ goto TAIL_RECURSE;
+ }
+
+ /* Possibly empty group; can't use tail recursion. */
+
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
+ eptrb, flags, RM48);
+ RRETURN(rrc);
}
/* For non-final alternatives, continue the loop for a NOMATCH result;
otherwise return. */
- RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
- eptrb, flags);
- if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
+ eptrb, flags, RM2);
+ if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
ecode += GET(ecode, 1);
}
/* Control never reaches here. */
@@ -712,15 +786,15 @@ for (;;)
else
{
- RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
- match_condassert);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
+ match_condassert, RM3);
if (rrc == MATCH_MATCH)
{
condition = TRUE;
ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
while (*ecode == OP_ALT) ecode += GET(ecode, 1);
}
- else if (rrc != MATCH_NOMATCH)
+ else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
{
RRETURN(rrc); /* Need braces because of following else */
}
@@ -732,25 +806,36 @@ for (;;)
}
/* We are now at the branch that is to be obeyed. As there is only one,
- we can use tail recursion to avoid using another stack frame. If the second
- alternative doesn't exist, we can just plough on. */
+ we can use tail recursion to avoid using another stack frame, except when
+ match_cbegroup is required for an unlimited repeat of a possibly empty
+ group. If the second alternative doesn't exist, we can just plough on. */
if (condition || *ecode == OP_ALT)
{
ecode += 1 + LINK_SIZE;
- flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);
- goto TAIL_RECURSE;
+ if (op == OP_SCOND) /* Possibly empty group */
+ {
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
+ RRETURN(rrc);
+ }
+ else /* Group must match something */
+ {
+ flags = 0;
+ goto TAIL_RECURSE;
+ }
}
- else
+ else /* Condition false & no 2nd alternative */
{
ecode += 1 + LINK_SIZE;
}
break;
- /* End of the pattern. If we are in a top-level recursion, we should
- restore the offsets appropriately and continue from after the call. */
+ /* End of the pattern, either real or forced. If we are in a top-level
+ recursion, we should restore the offsets appropriately and continue from
+ after the call. */
+ case OP_ACCEPT:
case OP_END:
if (md->recursive != NULL && md->recursive->group_num == 0)
{
@@ -759,7 +844,7 @@ for (;;)
md->recursive = rec->prevrec;
memmove(md->offset_vector, rec->offset_save,
rec->saved_max * sizeof(int));
- md->start_match = rec->save_start;
+ mstart = rec->save_start;
ims = original_ims;
ecode = rec->after_call;
break;
@@ -768,9 +853,10 @@ for (;;)
/* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
string - backtracking will then try other alternatives, if any. */
- if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);
- md->end_match_ptr = eptr; /* Record where we ended */
- md->end_offset_top = offset_top; /* and how many extracts were taken */
+ if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
+ md->end_match_ptr = eptr; /* Record where we ended */
+ md->end_offset_top = offset_top; /* and how many extracts were taken */
+ md->start_match_ptr = mstart; /* and the start (\K can modify) */
RRETURN(MATCH_MATCH);
/* Change option settings */
@@ -791,9 +877,10 @@ for (;;)
case OP_ASSERTBACK:
do
{
- RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
+ RM4);
if (rrc == MATCH_MATCH) break;
- if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
ecode += GET(ecode, 1);
}
while (*ecode == OP_ALT);
@@ -817,9 +904,10 @@ for (;;)
case OP_ASSERTBACK_NOT:
do
{
- RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
+ RM5);
if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
- if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
ecode += GET(ecode,1);
}
while (*ecode == OP_ALT);
@@ -843,7 +931,7 @@ for (;;)
{
eptr--;
if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
- BACKCHAR(eptr)
+ BACKCHAR(eptr);
}
}
else
@@ -874,7 +962,7 @@ for (;;)
cb.offset_vector = md->offset_vector;
cb.subject = (PCRE_SPTR)md->start_subject;
cb.subject_length = md->end_subject - md->start_subject;
- cb.start_match = md->start_match - md->start_subject;
+ cb.start_match = mstart - md->start_subject;
cb.current_position = eptr - md->start_subject;
cb.pattern_position = GET(ecode, 2);
cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
@@ -936,8 +1024,8 @@ for (;;)
memcpy(new_recursive.offset_save, md->offset_vector,
new_recursive.saved_max * sizeof(int));
- new_recursive.save_start = md->start_match;
- md->start_match = eptr;
+ new_recursive.save_start = mstart;
+ mstart = eptr;
/* OK, now we can do the recursion. For each top-level alternative we
restore the offset and recursion data. */
@@ -946,8 +1034,8 @@ for (;;)
flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
do
{
- RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
- md, ims, eptrb, flags);
+ RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
+ md, ims, eptrb, flags, RM6);
if (rrc == MATCH_MATCH)
{
DPRINTF(("Recursion matched\n"));
@@ -956,7 +1044,7 @@ for (;;)
(pcre_free)(new_recursive.offset_save);
RRETURN(MATCH_MATCH);
}
- else if (rrc != MATCH_NOMATCH)
+ else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
{
DPRINTF(("Recursion gave error %d\n", rrc));
RRETURN(rrc);
@@ -990,10 +1078,9 @@ for (;;)
do
{
- RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,
- eptrb, 0);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
if (rrc == MATCH_MATCH) break;
- if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
ecode += GET(ecode,1);
}
while (*ecode == OP_ALT);
@@ -1036,18 +1123,18 @@ for (;;)
if (*ecode == OP_KETRMIN)
{
- RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
ecode = prev;
- flags = match_tail_recursed;
+ flags = 0;
goto TAIL_RECURSE;
}
else /* OP_KETRMAX */
{
- RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);
+ RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
ecode += 1 + LINK_SIZE;
- flags = match_tail_recursed;
+ flags = 0;
goto TAIL_RECURSE;
}
/* Control never gets here */
@@ -1059,16 +1146,16 @@ for (;;)
do ecode += GET(ecode,1); while (*ecode == OP_ALT);
break;
- /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating
- that it may occur zero times. It may repeat infinitely, or not at all -
- i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper
- repeat limits are compiled as a number of copies, with the optional ones
- preceded by BRAZERO or BRAMINZERO. */
+ /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
+ indicating that it may occur zero times. It may repeat infinitely, or not
+ at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
+ with fixed upper repeat limits are compiled as a number of copies, with the
+ optional ones preceded by BRAZERO or BRAMINZERO. */
case OP_BRAZERO:
{
next = ecode+1;
- RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
do next += GET(next,1); while (*next == OP_ALT);
ecode = next + 1 + LINK_SIZE;
@@ -1079,12 +1166,20 @@ for (;;)
{
next = ecode+1;
do next += GET(next, 1); while (*next == OP_ALT);
- RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
ecode++;
}
break;
+ case OP_SKIPZERO:
+ {
+ next = ecode+1;
+ do next += GET(next,1); while (*next == OP_ALT);
+ ecode = next + 1 + LINK_SIZE;
+ }
+ break;
+
/* End of a group, repeated or non-repeating. */
case OP_KET:
@@ -1149,7 +1244,7 @@ for (;;)
recursion_info *rec = md->recursive;
DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
md->recursive = rec->prevrec;
- md->start_match = rec->save_start;
+ mstart = rec->save_start;
memcpy(md->offset_vector, rec->offset_save,
rec->saved_max * sizeof(int));
ecode = rec->after_call;
@@ -1178,24 +1273,29 @@ for (;;)
/* The repeating kets try the rest of the pattern or restart from the
preceding bracket, in the appropriate order. In the second case, we can use
- tail recursion to avoid using another stack frame. */
+ tail recursion to avoid using another stack frame, unless we have an
+ unlimited repeat of a group that can match an empty string. */
flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
if (*ecode == OP_KETRMIN)
{
- RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ if (flags != 0) /* Could match an empty string */
+ {
+ RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
+ RRETURN(rrc);
+ }
ecode = prev;
- flags |= match_tail_recursed;
goto TAIL_RECURSE;
}
else /* OP_KETRMAX */
{
- RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);
+ RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
ecode += 1 + LINK_SIZE;
- flags = match_tail_recursed;
+ flags = 0;
goto TAIL_RECURSE;
}
/* Control never gets here */
@@ -1228,6 +1328,13 @@ for (;;)
ecode++;
break;
+ /* Reset the start of match point */
+
+ case OP_SET_SOM:
+ mstart = eptr;
+ ecode++;
+ break;
+
/* Assert before internal newline if multiline, or before a terminating
newline unless endonly is set, else end of subject unless noteol is set. */
@@ -1320,13 +1427,12 @@ for (;;)
/* Match a single character type; inline for speed */
case OP_ANY:
- if ((ims & PCRE_DOTALL) == 0)
- {
- if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
- }
+ if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
+ /* Fall through */
+
+ case OP_ALLANY:
if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
- if (utf8)
- while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
+ if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
ecode++;
break;
@@ -1425,12 +1531,112 @@ for (;;)
case 0x000d:
if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
break;
+
case 0x000a:
+ break;
+
case 0x000b:
case 0x000c:
case 0x0085:
case 0x2028:
case 0x2029:
+ if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
+ break;
+ }
+ ecode++;
+ break;
+
+ case OP_NOT_HSPACE:
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINCTEST(c, eptr);
+ switch(c)
+ {
+ default: break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ RRETURN(MATCH_NOMATCH);
+ }
+ ecode++;
+ break;
+
+ case OP_HSPACE:
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINCTEST(c, eptr);
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ break;
+ }
+ ecode++;
+ break;
+
+ case OP_NOT_VSPACE:
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINCTEST(c, eptr);
+ switch(c)
+ {
+ default: break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
+ RRETURN(MATCH_NOMATCH);
+ }
+ ecode++;
+ break;
+
+ case OP_VSPACE:
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINCTEST(c, eptr);
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
break;
}
ecode++;
@@ -1522,16 +1728,25 @@ for (;;)
case OP_REF:
{
offset = GET2(ecode, 1) << 1; /* Doubled ref number */
- ecode += 3; /* Advance past item */
+ ecode += 3;
+
+ /* If the reference is unset, there are two possibilities:
+
+ (a) In the default, Perl-compatible state, set the length to be longer
+ than the amount of subject left; this ensures that every attempt at a
+ match fails. We can't just fail here, because of the possibility of
+ quantifiers with zero minima.
- /* If the reference is unset, set the length to be longer than the amount
- of subject left; this ensures that every attempt at a match fails. We
- can't just fail here, because of the possibility of quantifiers with zero
- minima. */
+ (b) If the JavaScript compatibility flag is set, set the length to zero
+ so that the back reference matches an empty string.
- length = (offset >= offset_top || md->offset_vector[offset] < 0)?
- md->end_subject - eptr + 1 :
- md->offset_vector[offset+1] - md->offset_vector[offset];
+ Otherwise, set the length to the length of what was matched by the
+ referenced subpattern. */
+
+ if (offset >= offset_top || md->offset_vector[offset] < 0)
+ length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
+ else
+ length = md->offset_vector[offset+1] - md->offset_vector[offset];
/* Set up for repetition, or handle the non-repeated case */
@@ -1591,7 +1806,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || !match_ref(offset, eptr, length, md, ims))
RRETURN(MATCH_NOMATCH);
@@ -1612,7 +1827,7 @@ for (;;)
}
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
eptr -= length;
}
@@ -1717,7 +1932,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -1737,7 +1952,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
c = *eptr++;
@@ -1774,7 +1989,7 @@ for (;;)
}
for (;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
BACKCHAR(eptr);
@@ -1793,7 +2008,7 @@ for (;;)
}
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
eptr--;
}
@@ -1864,7 +2079,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -1888,10 +2103,10 @@ for (;;)
}
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
- BACKCHAR(eptr)
+ if (utf8) BACKCHAR(eptr);
}
RRETURN(MATCH_NOMATCH);
}
@@ -2045,19 +2260,18 @@ for (;;)
if (length > 1)
{
- int oclength = 0;
- uschar occhars[8];
-
#ifdef SUPPORT_UCP
unsigned int othercase;
if ((ims & PCRE_CASELESS) != 0 &&
(othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
oclength = _pcre_ord2utf8(othercase, occhars);
+ else oclength = 0;
#endif /* SUPPORT_UCP */
for (i = 1; i <= min; i++)
{
if (memcmp(eptr, charptr, length) == 0) eptr += length;
+#ifdef SUPPORT_UCP
/* Need braces because of following else */
else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
else
@@ -2065,6 +2279,9 @@ for (;;)
if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
eptr += oclength;
}
+#else /* without SUPPORT_UCP */
+ else { RRETURN(MATCH_NOMATCH); }
+#endif /* SUPPORT_UCP */
}
if (min == max) continue;
@@ -2073,10 +2290,11 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
if (memcmp(eptr, charptr, length) == 0) eptr += length;
+#ifdef SUPPORT_UCP
/* Need braces because of following else */
else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
else
@@ -2084,6 +2302,9 @@ for (;;)
if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
eptr += oclength;
}
+#else /* without SUPPORT_UCP */
+ else { RRETURN (MATCH_NOMATCH); }
+#endif /* SUPPORT_UCP */
}
/* Control never gets here */
}
@@ -2095,22 +2316,31 @@ for (;;)
{
if (eptr > md->end_subject - length) break;
if (memcmp(eptr, charptr, length) == 0) eptr += length;
+#ifdef SUPPORT_UCP
else if (oclength == 0) break;
else
{
if (memcmp(eptr, occhars, oclength) != 0) break;
eptr += oclength;
}
+#else /* without SUPPORT_UCP */
+ else break;
+#endif /* SUPPORT_UCP */
}
if (possessive) continue;
- while (eptr >= pp)
+ for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
+ if (eptr == pp) RRETURN(MATCH_NOMATCH);
+#ifdef SUPPORT_UCP
+ eptr--;
+ BACKCHAR(eptr);
+#else /* without SUPPORT_UCP */
eptr -= length;
+#endif /* SUPPORT_UCP */
}
- RRETURN(MATCH_NOMATCH);
}
/* Control never gets here */
}
@@ -2150,7 +2380,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject ||
fc != md->lcc[*eptr++])
@@ -2169,7 +2399,7 @@ for (;;)
if (possessive) continue;
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
eptr--;
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
}
@@ -2188,7 +2418,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
RRETURN(MATCH_NOMATCH);
@@ -2206,7 +2436,7 @@ for (;;)
if (possessive) continue;
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
eptr--;
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
}
@@ -2351,7 +2581,7 @@ for (;;)
register unsigned int d;
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
GETCHARINC(d, eptr);
if (d < 256) d = md->lcc[d];
@@ -2365,7 +2595,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
RRETURN(MATCH_NOMATCH);
@@ -2397,7 +2627,7 @@ for (;;)
if (possessive) continue;
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
BACKCHAR(eptr);
@@ -2415,7 +2645,7 @@ for (;;)
if (possessive) continue;
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
eptr--;
}
@@ -2460,7 +2690,7 @@ for (;;)
register unsigned int d;
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
GETCHARINC(d, eptr);
if (fi >= max || eptr >= md->end_subject || fc == d)
@@ -2473,7 +2703,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
RRETURN(MATCH_NOMATCH);
@@ -2504,7 +2734,7 @@ for (;;)
if (possessive) continue;
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
BACKCHAR(eptr);
@@ -2522,7 +2752,7 @@ for (;;)
if (possessive) continue;
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
eptr--;
}
@@ -2629,7 +2859,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
- GETCHARINC(c, eptr);
+ GETCHARINCTEST(c, eptr);
}
break;
@@ -2637,7 +2867,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
- GETCHARINC(c, eptr);
+ GETCHARINCTEST(c, eptr);
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
if ((prop_chartype == ucp_Lu ||
prop_chartype == ucp_Ll ||
@@ -2650,7 +2880,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
- GETCHARINC(c, eptr);
+ GETCHARINCTEST(c, eptr);
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
if ((prop_category == prop_value) == prop_fail_result)
RRETURN(MATCH_NOMATCH);
@@ -2661,7 +2891,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
- GETCHARINC(c, eptr);
+ GETCHARINCTEST(c, eptr);
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
if ((prop_chartype == prop_value) == prop_fail_result)
RRETURN(MATCH_NOMATCH);
@@ -2672,7 +2902,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
- GETCHARINC(c, eptr);
+ GETCHARINCTEST(c, eptr);
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
if ((prop_script == prop_value) == prop_fail_result)
RRETURN(MATCH_NOMATCH);
@@ -2719,14 +2949,22 @@ for (;;)
case OP_ANY:
for (i = 1; i <= min; i++)
{
- if (eptr >= md->end_subject ||
- ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
+ if (eptr >= md->end_subject || IS_NEWLINE(eptr))
RRETURN(MATCH_NOMATCH);
eptr++;
while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
}
break;
+ case OP_ALLANY:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ eptr++;
+ while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
+ }
+ break;
+
case OP_ANYBYTE:
eptr += min;
break;
@@ -2742,12 +2980,120 @@ for (;;)
case 0x000d:
if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
break;
+
case 0x000a:
+ break;
+
case 0x000b:
case 0x000c:
case 0x0085:
case 0x2028:
case 0x2029:
+ if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
+ break;
+ }
+ }
+ break;
+
+ case OP_NOT_HSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINC(c, eptr);
+ switch(c)
+ {
+ default: break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ RRETURN(MATCH_NOMATCH);
+ }
+ }
+ break;
+
+ case OP_HSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINC(c, eptr);
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ break;
+ }
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINC(c, eptr);
+ switch(c)
+ {
+ default: break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
+ RRETURN(MATCH_NOMATCH);
+ }
+ }
+ break;
+
+ case OP_VSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ GETCHARINC(c, eptr);
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
break;
}
}
@@ -2777,9 +3123,9 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject ||
- (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))
+ (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
RRETURN(MATCH_NOMATCH);
- while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
+ while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
}
break;
@@ -2797,9 +3143,9 @@ for (;;)
for (i = 1; i <= min; i++)
{
if (eptr >= md->end_subject ||
- (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))
+ (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
RRETURN(MATCH_NOMATCH);
- while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
+ while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
}
break;
@@ -2827,15 +3173,15 @@ for (;;)
switch(ctype)
{
case OP_ANY:
- if ((ims & PCRE_DOTALL) == 0)
+ for (i = 1; i <= min; i++)
{
- for (i = 1; i <= min; i++)
- {
- if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
- eptr++;
- }
+ if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
+ eptr++;
}
- else eptr += min;
+ break;
+
+ case OP_ALLANY:
+ eptr += min;
break;
case OP_ANYBYTE:
@@ -2856,9 +3202,76 @@ for (;;)
if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
break;
case 0x000a:
+ break;
+
case 0x000b:
case 0x000c:
case 0x0085:
+ if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
+ break;
+ }
+ }
+ break;
+
+ case OP_NOT_HSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ switch(*eptr++)
+ {
+ default: break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ RRETURN(MATCH_NOMATCH);
+ }
+ }
+ break;
+
+ case OP_HSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ switch(*eptr++)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ break;
+ }
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ switch(*eptr++)
+ {
+ default: break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ RRETURN(MATCH_NOMATCH);
+ }
+ }
+ break;
+
+ case OP_VSPACE:
+ for (i = 1; i <= min; i++)
+ {
+ if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+ switch(*eptr++)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
break;
}
}
@@ -2919,7 +3332,7 @@ for (;;)
case PT_ANY:
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -2930,7 +3343,7 @@ for (;;)
case PT_LAMP:
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -2945,7 +3358,7 @@ for (;;)
case PT_GC:
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -2958,7 +3371,7 @@ for (;;)
case PT_PC:
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -2971,7 +3384,7 @@ for (;;)
case PT_SC:
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
@@ -2993,7 +3406,7 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
GETCHARINCTEST(c, eptr);
@@ -3022,19 +3435,17 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject ||
- (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&
- IS_NEWLINE(eptr)))
+ (ctype == OP_ANY && IS_NEWLINE(eptr)))
RRETURN(MATCH_NOMATCH);
GETCHARINC(c, eptr);
switch(ctype)
{
- case OP_ANY: /* This is the DOTALL case */
- break;
-
+ case OP_ANY: /* This is the non-NL case */
+ case OP_ALLANY:
case OP_ANYBYTE:
break;
@@ -3046,11 +3457,98 @@ for (;;)
if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
break;
case 0x000a:
+ break;
+
case 0x000b:
case 0x000c:
case 0x0085:
case 0x2028:
case 0x2029:
+ if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
+ break;
+ }
+ break;
+
+ case OP_NOT_HSPACE:
+ switch(c)
+ {
+ default: break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ RRETURN(MATCH_NOMATCH);
+ }
+ break;
+
+ case OP_HSPACE:
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ break;
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ switch(c)
+ {
+ default: break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
+ RRETURN(MATCH_NOMATCH);
+ }
+ break;
+
+ case OP_VSPACE:
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
break;
}
break;
@@ -3096,18 +3594,17 @@ for (;;)
{
for (fi = min;; fi++)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (fi >= max || eptr >= md->end_subject ||
- ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
+ (ctype == OP_ANY && IS_NEWLINE(eptr)))
RRETURN(MATCH_NOMATCH);
c = *eptr++;
switch(ctype)
{
- case OP_ANY: /* This is the DOTALL case */
- break;
-
+ case OP_ANY: /* This is the non-NL case */
+ case OP_ALLANY:
case OP_ANYBYTE:
break;
@@ -3118,10 +3615,62 @@ for (;;)
case 0x000d:
if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
break;
+
case 0x000a:
+ break;
+
case 0x000b:
case 0x000c:
case 0x0085:
+ if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
+ break;
+ }
+ break;
+
+ case OP_NOT_HSPACE:
+ switch(c)
+ {
+ default: break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ RRETURN(MATCH_NOMATCH);
+ }
+ break;
+
+ case OP_HSPACE:
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ break;
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ switch(c)
+ {
+ default: break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ RRETURN(MATCH_NOMATCH);
+ }
+ break;
+
+ case OP_VSPACE:
+ switch(c)
+ {
+ default: RRETURN(MATCH_NOMATCH);
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
break;
}
break;
@@ -3242,10 +3791,10 @@ for (;;)
if (possessive) continue;
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
- BACKCHAR(eptr);
+ if (utf8) BACKCHAR(eptr);
}
}
@@ -3278,15 +3827,15 @@ for (;;)
if (possessive) continue;
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
for (;;) /* Move back over one extended */
{
int len = 1;
- BACKCHAR(eptr);
if (!utf8) c = *eptr; else
{
+ BACKCHAR(eptr);
GETCHARLEN(c, eptr, len);
}
prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
@@ -3307,30 +3856,13 @@ for (;;)
switch(ctype)
{
case OP_ANY:
-
- /* Special code is required for UTF8, but when the maximum is
- unlimited we don't need it, so we repeat the non-UTF8 code. This is
- probably worth it, because .* is quite a common idiom. */
-
if (max < INT_MAX)
{
- if ((ims & PCRE_DOTALL) == 0)
- {
- for (i = min; i < max; i++)
- {
- if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
- eptr++;
- while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
- }
- }
- else
+ for (i = min; i < max; i++)
{
- for (i = min; i < max; i++)
- {
- if (eptr >= md->end_subject) break;
- eptr++;
- while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
- }
+ if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
+ eptr++;
+ while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
}
}
@@ -3338,23 +3870,26 @@ for (;;)
else
{
- if ((ims & PCRE_DOTALL) == 0)
+ for (i = min; i < max; i++)
{
- for (i = min; i < max; i++)
- {
- if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
- eptr++;
- }
- break;
+ if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
+ eptr++;
+ while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
}
- else
+ }
+ break;
+
+ case OP_ALLANY:
+ if (max < INT_MAX)
+ {
+ for (i = min; i < max; i++)
{
- c = max - min;
- if (c > (unsigned int)(md->end_subject - eptr))
- c = md->end_subject - eptr;
- eptr += c;
+ if (eptr >= md->end_subject) break;
+ eptr++;
+ while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
}
}
+ else eptr = md->end_subject; /* Unlimited UTF-8 repeat */
break;
/* The byte case is the same as non-UTF8 */
@@ -3379,14 +3914,80 @@ for (;;)
}
else
{
- if (c != 0x000a && c != 0x000b && c != 0x000c &&
- c != 0x0085 && c != 0x2028 && c != 0x2029)
+ if (c != 0x000a &&
+ (md->bsr_anycrlf ||
+ (c != 0x000b && c != 0x000c &&
+ c != 0x0085 && c != 0x2028 && c != 0x2029)))
break;
eptr += len;
}
}
break;
+ case OP_NOT_HSPACE:
+ case OP_HSPACE:
+ for (i = min; i < max; i++)
+ {
+ BOOL gotspace;
+ int len = 1;
+ if (eptr >= md->end_subject) break;
+ GETCHARLEN(c, eptr, len);
+ switch(c)
+ {
+ default: gotspace = FALSE; break;
+ case 0x09: /* HT */
+ case 0x20: /* SPACE */
+ case 0xa0: /* NBSP */
+ case 0x1680: /* OGHAM SPACE MARK */
+ case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */
+ case 0x2000: /* EN QUAD */
+ case 0x2001: /* EM QUAD */
+ case 0x2002: /* EN SPACE */
+ case 0x2003: /* EM SPACE */
+ case 0x2004: /* THREE-PER-EM SPACE */
+ case 0x2005: /* FOUR-PER-EM SPACE */
+ case 0x2006: /* SIX-PER-EM SPACE */
+ case 0x2007: /* FIGURE SPACE */
+ case 0x2008: /* PUNCTUATION SPACE */
+ case 0x2009: /* THIN SPACE */
+ case 0x200A: /* HAIR SPACE */
+ case 0x202f: /* NARROW NO-BREAK SPACE */
+ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */
+ case 0x3000: /* IDEOGRAPHIC SPACE */
+ gotspace = TRUE;
+ break;
+ }
+ if (gotspace == (ctype == OP_NOT_HSPACE)) break;
+ eptr += len;
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ case OP_VSPACE:
+ for (i = min; i < max; i++)
+ {
+ BOOL gotspace;
+ int len = 1;
+ if (eptr >= md->end_subject) break;
+ GETCHARLEN(c, eptr, len);
+ switch(c)
+ {
+ default: gotspace = FALSE; break;
+ case 0x0a: /* LF */
+ case 0x0b: /* VT */
+ case 0x0c: /* FF */
+ case 0x0d: /* CR */
+ case 0x85: /* NEL */
+ case 0x2028: /* LINE SEPARATOR */
+ case 0x2029: /* PARAGRAPH SEPARATOR */
+ gotspace = TRUE;
+ break;
+ }
+ if (gotspace == (ctype == OP_NOT_VSPACE)) break;
+ eptr += len;
+ }
+ break;
+
case OP_NOT_DIGIT:
for (i = min; i < max; i++)
{
@@ -3462,31 +4063,28 @@ for (;;)
if (possessive) continue;
for(;;)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
if (eptr-- == pp) break; /* Stop if tried at original pos */
BACKCHAR(eptr);
}
}
else
-#endif
+#endif /* SUPPORT_UTF8 */
/* Not UTF-8 mode */
{
switch(ctype)
{
case OP_ANY:
- if ((ims & PCRE_DOTALL) == 0)
+ for (i = min; i < max; i++)
{
- for (i = min; i < max; i++)
- {
- if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
- eptr++;
- }
- break;
+ if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
+ eptr++;
}
- /* For DOTALL case, fall through and treat as \C */
+ break;
+ case OP_ALLANY:
case OP_ANYBYTE:
c = max - min;
if (c > (unsigned int)(md->end_subject - eptr))
@@ -3506,13 +4104,57 @@ for (;;)
}
else
{
- if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)
+ if (c != 0x000a &&
+ (md->bsr_anycrlf ||
+ (c != 0x000b && c != 0x000c && c != 0x0085)))
break;
eptr++;
}
}
break;
+ case OP_NOT_HSPACE:
+ for (i = min; i < max; i++)
+ {
+ if (eptr >= md->end_subject) break;
+ c = *eptr;
+ if (c == 0x09 || c == 0x20 || c == 0xa0) break;
+ eptr++;
+ }
+ break;
+
+ case OP_HSPACE:
+ for (i = min; i < max; i++)
+ {
+ if (eptr >= md->end_subject) break;
+ c = *eptr;
+ if (c != 0x09 && c != 0x20 && c != 0xa0) break;
+ eptr++;
+ }
+ break;
+
+ case OP_NOT_VSPACE:
+ for (i = min; i < max; i++)
+ {
+ if (eptr >= md->end_subject) break;
+ c = *eptr;
+ if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
+ break;
+ eptr++;
+ }
+ break;
+
+ case OP_VSPACE:
+ for (i = min; i < max; i++)
+ {
+ if (eptr >= md->end_subject) break;
+ c = *eptr;
+ if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
+ break;
+ eptr++;
+ }
+ break;
+
case OP_NOT_DIGIT:
for (i = min; i < max; i++)
{
@@ -3576,7 +4218,7 @@ for (;;)
if (possessive) continue;
while (eptr >= pp)
{
- RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
+ RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
eptr--;
if (rrc != MATCH_NOMATCH) RRETURN(rrc);
}
@@ -3602,6 +4244,35 @@ for (;;)
} /* End of main loop */
/* Control never reaches here */
+
+
+/* When compiling to use the heap rather than the stack for recursive calls to
+match(), the RRETURN() macro jumps here. The number that is saved in
+frame->Xwhere indicates which label we actually want to return to. */
+
+#ifdef NO_RECURSE
+#define LBL(val) case val: goto L_RM##val;
+HEAP_RETURN:
+switch (frame->Xwhere)
+ {
+ LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
+ LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
+ LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
+ LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
+ LBL(53) LBL(54)
+#ifdef SUPPORT_UTF8
+ LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
+ LBL(32) LBL(34) LBL(42) LBL(46)
+#ifdef SUPPORT_UCP
+ LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
+#endif /* SUPPORT_UCP */
+#endif /* SUPPORT_UTF8 */
+ default:
+ DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
+ return PCRE_ERROR_INTERNAL;
+ }
+#undef LBL
+#endif /* NO_RECURSE */
}
@@ -3614,6 +4285,7 @@ Undefine all the macros that were defined above to handle this. */
#ifdef NO_RECURSE
#undef eptr
#undef ecode
+#undef mstart
#undef offset_top
#undef ims
#undef eptrb
@@ -3686,7 +4358,7 @@ Returns: > 0 => success; value is the number of elements filled in
< -1 => some kind of unexpected problem
*/
-PCRE_DATA_SCOPE int
+PCRE_EXP_DEFN int
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
int offsetcount)
@@ -3711,7 +4383,6 @@ const uschar *start_bits = NULL;
USPTR start_match = (USPTR)subject + start_offset;
USPTR end_subject;
USPTR req_byte_ptr = start_match - 1;
-eptrblock eptrchain[EPTR_WORK_SIZE];
pcre_study_data internal_study;
const pcre_study_data *study;
@@ -3774,7 +4445,7 @@ if (re->magic_number != MAGIC_NUMBER)
/* Set up other data */
anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
-startline = (re->options & PCRE_STARTLINE) != 0;
+startline = (re->flags & PCRE_STARTLINE) != 0;
firstline = (re->options & PCRE_FIRSTLINE) != 0;
/* The code starts after the real_pcre block and the capture name table. */
@@ -3789,6 +4460,7 @@ end_subject = md->end_subject;
md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
+md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
md->notbol = (options & PCRE_NOTBOL) != 0;
md->noteol = (options & PCRE_NOTEOL) != 0;
@@ -3797,16 +4469,41 @@ md->partial = (options & PCRE_PARTIAL) != 0;
md->hitend = FALSE;
md->recursive = NULL; /* No recursion at top level */
-md->eptrchain = eptrchain; /* Make workspace generally available */
md->lcc = tables + lcc_offset;
md->ctypes = tables + ctypes_offset;
-/* Handle different types of newline. The two bits give four cases. If nothing
-is set at run time, whatever was used at compile time applies. */
+/* Handle different \R options. */
+
+switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
+ {
+ case 0:
+ if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
+ md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
+ else
+#ifdef BSR_ANYCRLF
+ md->bsr_anycrlf = TRUE;
+#else
+ md->bsr_anycrlf = FALSE;
+#endif
+ break;
+
+ case PCRE_BSR_ANYCRLF:
+ md->bsr_anycrlf = TRUE;
+ break;
+
+ case PCRE_BSR_UNICODE:
+ md->bsr_anycrlf = FALSE;
+ break;
+
+ default: return PCRE_ERROR_BADNEWLINE;
+ }
+
+/* Handle different types of newline. The three bits give eight cases. If
+nothing is set at run time, whatever was used at compile time applies. */
-switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
- PCRE_NEWLINE_BITS)
+switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
+ (pcre_uint32)options) & PCRE_NEWLINE_BITS)
{
case 0: newline = NEWLINE; break; /* Compile-time default */
case PCRE_NEWLINE_CR: newline = '\r'; break;
@@ -3814,10 +4511,15 @@ switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
case PCRE_NEWLINE_CR+
PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
case PCRE_NEWLINE_ANY: newline = -1; break;
+ case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
default: return PCRE_ERROR_BADNEWLINE;
}
-if (newline < 0)
+if (newline == -2)
+ {
+ md->nltype = NLTYPE_ANYCRLF;
+ }
+else if (newline < 0)
{
md->nltype = NLTYPE_ANY;
}
@@ -3840,7 +4542,7 @@ else
/* Partial matching is supported only for a restricted set of regexes at the
moment. */
-if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)
+if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
return PCRE_ERROR_BADPARTIAL;
/* Check a UTF-8 string if required. Unfortunately there's no way of passing
@@ -3917,7 +4619,7 @@ studied, there may be a bitmap of possible first characters. */
if (!anchored)
{
- if ((re->options & PCRE_FIRSTSET) != 0)
+ if ((re->flags & PCRE_FIRSTSET) != 0)
{
first_byte = re->first_byte & 255;
if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
@@ -3932,7 +4634,7 @@ if (!anchored)
/* For anchored or unanchored matches, there may be a "last known required
character" set. */
-if ((re->options & PCRE_REQCHSET) != 0)
+if ((re->flags & PCRE_REQCHSET) != 0)
{
req_byte = re->req_byte & 255;
req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
@@ -3948,6 +4650,7 @@ the loop runs just once. */
for(;;)
{
USPTR save_end_subject = end_subject;
+ USPTR new_start_match;
/* Reset the maximum number of extractions we might see. */
@@ -3978,10 +4681,10 @@ for(;;)
if (first_byte_caseless)
while (start_match < end_subject &&
md->lcc[*start_match] != first_byte)
- start_match++;
+ { NEXTCHAR(start_match); }
else
while (start_match < end_subject && *start_match != first_byte)
- start_match++;
+ { NEXTCHAR(start_match); }
}
/* Or to just after a linebreak for a multiline match if possible */
@@ -3991,6 +4694,16 @@ for(;;)
if (start_match > md->start_subject + start_offset)
{
while (start_match <= end_subject && !WAS_NEWLINE(start_match))
+ { NEXTCHAR(start_match); }
+
+ /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
+ and we are now at a LF, advance the match position by one more character.
+ */
+
+ if (start_match[-1] == '\r' &&
+ (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
+ start_match < end_subject &&
+ *start_match == '\n')
start_match++;
}
}
@@ -4002,7 +4715,9 @@ for(;;)
while (start_match < end_subject)
{
register unsigned int c = *start_match;
- if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;
+ if ((start_bits[c/8] & (1 << (c&7))) == 0)
+ { NEXTCHAR(start_match); }
+ else break;
}
}
@@ -4078,14 +4793,48 @@ for(;;)
/* OK, we can now run the match. */
- md->start_match = start_match;
+ md->start_match_ptr = start_match;
md->match_call_count = 0;
- md->eptrn = 0; /* Next free eptrchain slot */
- rc = match(start_match, md->start_code, 2, md, ims, NULL, 0, 0);
+ rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
+
+ switch(rc)
+ {
+ /* NOMATCH and PRUNE advance by one character. THEN at this level acts
+ exactly like PRUNE. */
- /* Any return other than MATCH_NOMATCH breaks the loop. */
+ case MATCH_NOMATCH:
+ case MATCH_PRUNE:
+ case MATCH_THEN:
+ new_start_match = start_match + 1;
+#ifdef SUPPORT_UTF8
+ if (utf8)
+ while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
+ new_start_match++;
+#endif
+ break;
- if (rc != MATCH_NOMATCH) break;
+ /* SKIP passes back the next starting point explicitly. */
+
+ case MATCH_SKIP:
+ new_start_match = md->start_match_ptr;
+ break;
+
+ /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
+
+ case MATCH_COMMIT:
+ rc = MATCH_NOMATCH;
+ goto ENDLOOP;
+
+ /* Any other return is some kind of error. */
+
+ default:
+ goto ENDLOOP;
+ }
+
+ /* Control reaches here for the various types of "no match at this point"
+ result. Reset the code to MATCH_NOMATCH for subsequent checking. */
+
+ rc = MATCH_NOMATCH;
/* If PCRE_FIRSTLINE is set, the match must happen before or at the first
newline in the subject (though it may continue over the newline). Therefore,
@@ -4093,27 +4842,26 @@ for(;;)
if (firstline && IS_NEWLINE(start_match)) break;
- /* Advance the match position by one character. */
+ /* Advance to new matching position */
- start_match++;
-#ifdef SUPPORT_UTF8
- if (utf8)
- while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
- start_match++;
-#endif
+ start_match = new_start_match;
/* Break the loop if the pattern is anchored or if we have passed the end of
the subject. */
if (anchored || start_match > end_subject) break;
- /* If we have just passed a CR and the newline option is CRLF or ANY, and we
- are now at a LF, advance the match position by one more character. */
+ /* If we have just passed a CR and we are now at a LF, and the pattern does
+ not contain any explicit matches for \r or \n, and the newline option is CRLF
+ or ANY or ANYCRLF, advance the match position by one more character. */
if (start_match[-1] == '\r' &&
- (md->nltype == NLTYPE_ANY || md->nllen == 2) &&
- start_match < end_subject &&
- *start_match == '\n')
+ start_match < end_subject &&
+ *start_match == '\n' &&
+ (re->flags & PCRE_HASCRORLF) == 0 &&
+ (md->nltype == NLTYPE_ANY ||
+ md->nltype == NLTYPE_ANYCRLF ||
+ md->nllen == 2))
start_match++;
} /* End of for(;;) "bumpalong" loop */
@@ -4123,7 +4871,7 @@ for(;;)
/* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
conditions is true:
-(1) The pattern is anchored;
+(1) The pattern is anchored or the match was failed by (*COMMIT);
(2) We are past the end of the subject;
@@ -4138,6 +4886,8 @@ processing, copy those that we can. In this case there need not be overflow if
certain parts of the pattern were not used, even though there are more
capturing parentheses than vector slots. */
+ENDLOOP:
+
if (rc == MATCH_MATCH)
{
if (using_temporary_offsets)
@@ -4158,11 +4908,13 @@ if (rc == MATCH_MATCH)
rc = md->offset_overflow? 0 : md->end_offset_top/2;
- /* If there is space, set up the whole thing as substring 0. */
+ /* If there is space, set up the whole thing as substring 0. The value of
+ md->start_match_ptr might be modified if \K was encountered on the success
+ matching path. */
if (offsetcount < 2) rc = 0; else
{
- offsets[0] = start_match - md->start_subject;
+ offsets[0] = md->start_match_ptr - md->start_subject;
offsets[1] = md->end_match_ptr - md->start_subject;
}
diff --git a/ext/pcre/pcrelib/pcre_fullinfo.c b/ext/pcre/pcrelib/pcre_fullinfo.c
index 4a8edc6f47..b91ea035ec 100644
--- a/ext/pcre/pcrelib/pcre_fullinfo.c
+++ b/ext/pcre/pcrelib/pcre_fullinfo.c
@@ -2,11 +2,11 @@
* Perl-Compatible Regular Expressions *
*************************************************/
-/*PCRE is a library of functions to support regular expressions whose syntax
+/* PCRE is a library of functions to support regular expressions whose syntax
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
information about a compiled pattern. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -61,7 +63,7 @@ Arguments:
Returns: 0 if data returned, negative on error
*/
-PCRE_DATA_SCOPE int
+PCRE_EXP_DEFN int
pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
void *where)
{
@@ -106,8 +108,8 @@ switch (what)
case PCRE_INFO_FIRSTBYTE:
*((int *)where) =
- ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte :
- ((re->options & PCRE_STARTLINE) != 0)? -1 : -2;
+ ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
+ ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
break;
/* Make sure we pass back the pointer to the bit vector in the external
@@ -121,7 +123,7 @@ switch (what)
case PCRE_INFO_LASTLITERAL:
*((int *)where) =
- ((re->options & PCRE_REQCHSET) != 0)? re->req_byte : -1;
+ ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1;
break;
case PCRE_INFO_NAMEENTRYSIZE:
@@ -140,6 +142,18 @@ switch (what)
*((const uschar **)where) = (const uschar *)(_pcre_default_tables);
break;
+ case PCRE_INFO_OKPARTIAL:
+ *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
+ break;
+
+ case PCRE_INFO_JCHANGED:
+ *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
+ break;
+
+ case PCRE_INFO_HASCRORLF:
+ *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
+ break;
+
default: return PCRE_ERROR_BADOPTION;
}
diff --git a/ext/pcre/pcrelib/pcre_get.c b/ext/pcre/pcrelib/pcre_get.c
index 856e955a5c..c185c331ab 100644
--- a/ext/pcre/pcrelib/pcre_get.c
+++ b/ext/pcre/pcrelib/pcre_get.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@ from the subject string after a regex match has succeeded. The original idea
for these functions came from Scott Wimer. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -185,7 +187,7 @@ const real_pcre *re = (const real_pcre *)code;
int entrysize;
char *first, *last;
uschar *entry;
-if ((re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0)
+if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0)
return pcre_get_stringnumber(code, stringname);
entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last);
if (entrysize <= 0) return entrysize;
diff --git a/ext/pcre/pcrelib/pcre_globals.c b/ext/pcre/pcrelib/pcre_globals.c
index f29983e53b..aa3ef90a2a 100644
--- a/ext/pcre/pcrelib/pcre_globals.c
+++ b/ext/pcre/pcrelib/pcre_globals.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -46,37 +46,16 @@ indirection. These values can be changed by the caller, but are shared between
all threads. However, when compiling for Virtual Pascal, things are done
differently, and global variables are not used (see pcre.in). */
+#include "config.h"
#include "pcre_internal.h"
-
#ifndef VPCOMPAT
-
-/**************************************************************************
-This code used to be here for use when compiling as a C++ library. However,
-according to Dair Grant it is not needed: "
-
- Including 'extern "C"' in the declaration generates an "initialized and
- declared `extern'" warning from gcc 4.0.1. Since we include pcre_internal.h,
- which includes pcre.h, which declares these prototypes within an extern "C" {}
- block, we shouldn't need the prefix here.
-
-So, from Release 7.0 I have cut this out.
-
-#ifdef __cplusplus
-extern "C" void *(*pcre_malloc)(size_t) = malloc;
-extern "C" void (*pcre_free)(void *) = free;
-extern "C" void *(*pcre_stack_malloc)(size_t) = malloc;
-extern "C" void (*pcre_stack_free)(void *) = free;
-extern "C" int (*pcre_callout)(pcre_callout_block *) = NULL;
-#else
-**************************************************************************/
-
-void *(*pcre_malloc)(size_t) = malloc;
-void (*pcre_free)(void *) = free;
-void *(*pcre_stack_malloc)(size_t) = malloc;
-void (*pcre_stack_free)(void *) = free;
-int (*pcre_callout)(pcre_callout_block *) = NULL;
+PCRE_EXP_DATA_DEFN void *(*pcre_malloc)(size_t) = malloc;
+PCRE_EXP_DATA_DEFN void (*pcre_free)(void *) = free;
+PCRE_EXP_DATA_DEFN void *(*pcre_stack_malloc)(size_t) = malloc;
+PCRE_EXP_DATA_DEFN void (*pcre_stack_free)(void *) = free;
+PCRE_EXP_DATA_DEFN int (*pcre_callout)(pcre_callout_block *) = NULL;
#endif
/* End of pcre_globals.c */
diff --git a/ext/pcre/pcrelib/pcre_info.c b/ext/pcre/pcrelib/pcre_info.c
index b318b93eaa..f653d70bd3 100644
--- a/ext/pcre/pcrelib/pcre_info.c
+++ b/ext/pcre/pcrelib/pcre_info.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@ information about a compiled pattern. However, use of this function is now
deprecated, as it has been superseded by pcre_fullinfo(). */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -68,7 +70,7 @@ Returns: number of capturing subpatterns
or negative values on error
*/
-PCRE_DATA_SCOPE int
+PCRE_EXP_DEFN int
pcre_info(const pcre *argument_re, int *optptr, int *first_byte)
{
real_pcre internal_re;
@@ -81,8 +83,8 @@ if (re->magic_number != MAGIC_NUMBER)
}
if (optptr != NULL) *optptr = (int)(re->options & PUBLIC_OPTIONS);
if (first_byte != NULL)
- *first_byte = ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte :
- ((re->options & PCRE_STARTLINE) != 0)? -1 : -2;
+ *first_byte = ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
+ ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
return re->top_bracket;
}
diff --git a/ext/pcre/pcrelib/pcre_internal.h b/ext/pcre/pcrelib/pcre_internal.h
index 4034cf4574..102e2d01e2 100644
--- a/ext/pcre/pcrelib/pcre_internal.h
+++ b/ext/pcre/pcrelib/pcre_internal.h
@@ -7,7 +7,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -67,14 +67,6 @@ be absolutely sure we get our version. */
#endif
-/* Get the definitions provided by running "configure" */
-
-#ifdef PHP_WIN32
-# include "config.w32.h"
-#else
-# include <php_config.h>
-#endif
-
/* Standard C headers plus the external interface definition. The only time
setjmp and stdarg are used is when NO_RECURSE is set. */
@@ -87,8 +79,57 @@ setjmp and stdarg are used is when NO_RECURSE is set. */
#include <stdlib.h>
#include <string.h>
-#ifndef PCRE_SPY
-#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */
+/* When compiling a DLL for Windows, the exported symbols have to be declared
+using some MS magic. I found some useful information on this web page:
+http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
+information there, using __declspec(dllexport) without "extern" we have a
+definition; with "extern" we have a declaration. The settings here override the
+setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL,
+which is all that is needed for applications (they just import the symbols). We
+use:
+
+ PCRE_EXP_DECL for declarations
+ PCRE_EXP_DEFN for definitions of exported functions
+ PCRE_EXP_DATA_DEFN for definitions of exported variables
+
+The reason for the two DEFN macros is that in non-Windows environments, one
+does not want to have "extern" before variable definitions because it leads to
+compiler warnings. So we distinguish between functions and variables. In
+Windows, the two should always be the same.
+
+The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest,
+which is an application, but needs to import this file in order to "peek" at
+internals, can #include pcre.h first to get an application's-eye view.
+
+In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
+special-purpose environments) might want to stick other stuff in front of
+exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and
+PCRE_EXP_DATA_DEFN only if they are not already set. */
+
+#ifndef PCRE_EXP_DECL
+# ifdef _WIN32
+# ifndef PCRE_STATIC
+# define PCRE_EXP_DECL extern __declspec(dllexport)
+# define PCRE_EXP_DEFN __declspec(dllexport)
+# define PCRE_EXP_DATA_DEFN __declspec(dllexport)
+# else
+# define PCRE_EXP_DECL extern
+# define PCRE_EXP_DEFN
+# define PCRE_EXP_DATA_DEFN
+# endif
+# else
+# ifdef __cplusplus
+# define PCRE_EXP_DECL extern "C"
+# else
+# define PCRE_EXP_DECL extern
+# endif
+# ifndef PCRE_EXP_DEFN
+# define PCRE_EXP_DEFN PCRE_EXP_DECL
+# endif
+# ifndef PCRE_EXP_DATA_DEFN
+# define PCRE_EXP_DATA_DEFN
+# endif
+# endif
#endif
/* We need to have types that specify unsigned 16-bit and 32-bit integers. We
@@ -129,21 +170,22 @@ characters only go up to 0x7fffffff (though Unicode doesn't go beyond
#define NOTACHAR 0xffffffff
/* PCRE is able to support several different kinds of newline (CR, LF, CRLF,
-and "all" at present). The following macros are used to package up testing for
-newlines. NLBLOCK, PSSTART, and PSEND are defined in the various modules to
-indicate in which datablock the parameters exist, and what the start/end of
-string field names are. */
+"any" and "anycrlf" at present). The following macros are used to package up
+testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
+modules to indicate in which datablock the parameters exist, and what the
+start/end of string field names are. */
-#define NLTYPE_FIXED 0 /* Newline is a fixed length string */
-#define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
+#define NLTYPE_FIXED 0 /* Newline is a fixed length string */
+#define NLTYPE_ANY 1 /* Newline is any Unicode line ending */
+#define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */
/* This macro checks for a newline at the given position */
#define IS_NEWLINE(p) \
((NLBLOCK->nltype != NLTYPE_FIXED)? \
((p) < NLBLOCK->PSEND && \
- _pcre_is_newline((p), NLBLOCK->PSEND, &(NLBLOCK->nllen), utf8) \
- ) \
+ _pcre_is_newline((p), NLBLOCK->nltype, NLBLOCK->PSEND, &(NLBLOCK->nllen),\
+ utf8)) \
: \
((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
(p)[0] == NLBLOCK->nl[0] && \
@@ -156,8 +198,8 @@ string field names are. */
#define WAS_NEWLINE(p) \
((NLBLOCK->nltype != NLTYPE_FIXED)? \
((p) > NLBLOCK->PSSTART && \
- _pcre_was_newline((p), NLBLOCK->PSSTART, &(NLBLOCK->nllen), utf8) \
- ) \
+ _pcre_was_newline((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
+ &(NLBLOCK->nllen), utf8)) \
: \
((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
(p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \
@@ -182,6 +224,8 @@ must begin with PCRE_. */
#define USPTR const unsigned char *
#endif
+
+
/* Include the public PCRE header and the definitions of UCP character property
values. */
@@ -193,7 +237,9 @@ need to have their names changed. PCRE must be compiled with the -DVPCOMPAT
option on the command line. */
#ifdef VPCOMPAT
+#define strlen(s) _strlen(s)
#define strncmp(s1,s2,m) _strncmp(s1,s2,m)
+#define memcmp(s,c,n) _memcmp(s,c,n)
#define memcpy(d,s,n) _memcpy(d,s,n)
#define memmove(d,s,n) _memmove(d,s,n)
#define memset(s,c,n) _memset(s,c,n)
@@ -202,23 +248,31 @@ option on the command line. */
/* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
is set. Otherwise, include an emulating function for those systems that have
-neither (there some non-Unix environments where this is the case). This assumes
-that all calls to memmove are moving strings upwards in store, which is the
-case in PCRE. */
+neither (there some non-Unix environments where this is the case). */
-#if ! HAVE_MEMMOVE
+#ifndef HAVE_MEMMOVE
#undef memmove /* some systems may have a macro */
-#if HAVE_BCOPY
+#ifdef HAVE_BCOPY
#define memmove(a, b, c) bcopy(b, a, c)
#else /* HAVE_BCOPY */
static void *
-pcre_memmove(unsigned char *dest, const unsigned char *src, size_t n)
+pcre_memmove(void *d, const void *s, size_t n)
{
size_t i;
-dest += n;
-src += n;
-for (i = 0; i < n; ++i) *(--dest) = *(--src);
-return dest;
+unsigned char *dest = (unsigned char *)d;
+const unsigned char *src = (const unsigned char *)s;
+if (dest > src)
+ {
+ dest += n;
+ src += n;
+ for (i = 0; i < n; ++i) *(--dest) = *(--src);
+ return (void *)dest;
+ }
+else
+ {
+ for (i = 0; i < n; ++i) *dest++ = *src++;
+ return (void *)(dest - n);
+ }
}
#define memmove(a, b, c) pcre_memmove(a, b, c)
#endif /* not HAVE_BCOPY */
@@ -304,18 +358,28 @@ capturing parenthesis numbers in back references. */
/* When UTF-8 encoding is being used, a character is no longer just a single
byte. The macros for character handling generate simple sequences when used in
-byte-mode, and more complicated ones for UTF-8 characters. */
+byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should
+never be called in byte mode. To make sure it can never even appear when UTF-8
+support is omitted, we don't even define it. */
#ifndef SUPPORT_UTF8
+#define NEXTCHAR(p) p++;
#define GETCHAR(c, eptr) c = *eptr;
#define GETCHARTEST(c, eptr) c = *eptr;
#define GETCHARINC(c, eptr) c = *eptr++;
#define GETCHARINCTEST(c, eptr) c = *eptr++;
#define GETCHARLEN(c, eptr, len) c = *eptr;
-#define BACKCHAR(eptr)
+/* #define BACKCHAR(eptr) */
#else /* SUPPORT_UTF8 */
+/* Advance a character pointer one byte in non-UTF-8 mode and by one character
+in UTF-8 mode. */
+
+#define NEXTCHAR(p) \
+ p++; \
+ if (utf8) { while((*p & 0xc0) == 0x80) p++; }
+
/* Get the next UTF-8 character, not advancing the pointer. This is called when
we know we are in UTF-8 mode. */
@@ -405,9 +469,10 @@ if there are extra bytes. This is called when we know we are in UTF-8 mode. */
}
/* If the pointer is not at the start of a character, move it back until
-it is. Called only in UTF-8 mode. */
+it is. This is called only in UTF-8 mode - we don't put a test within the macro
+because almost all calls are already within a block of UTF-8 only code. */
-#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--;
+#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--
#endif
@@ -424,17 +489,16 @@ Standard C system should have one. */
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
-/* Private options flags start at the most significant end of the four bytes.
-The public options defined in pcre.h start at the least significant end. Make
-sure they don't overlap! The bits are getting a bit scarce now -- when we run
-out, there is a dummy word in the structure that could be used for the private
-bits. */
+/* Private flags containing information about the compiled regex. They used to
+live at the top end of the options word, but that got almost full, so now they
+are in a 16-bit flags word. */
-#define PCRE_NOPARTIAL 0x80000000 /* can't use partial with this regex */
-#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */
-#define PCRE_REQCHSET 0x20000000 /* req_byte is set */
-#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */
-#define PCRE_JCHANGED 0x08000000 /* j option changes within regex */
+#define PCRE_NOPARTIAL 0x0001 /* can't use partial with this regex */
+#define PCRE_FIRSTSET 0x0002 /* first_byte is set */
+#define PCRE_REQCHSET 0x0004 /* req_byte is set */
+#define PCRE_STARTLINE 0x0008 /* start after \n for multiline */
+#define PCRE_JCHANGED 0x0010 /* j option used in regex */
+#define PCRE_HASCRORLF 0x0020 /* explicit \r or \n in pattern */
/* Options for the "extra" block produced by pcre_study(). */
@@ -443,21 +507,24 @@ bits. */
/* Masks for identifying the public options that are permitted at compile
time, run time, or study time, respectively. */
-#define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY)
+#define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \
+ PCRE_NEWLINE_ANYCRLF)
#define PUBLIC_OPTIONS \
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \
- PCRE_DUPNAMES|PCRE_NEWLINE_BITS)
+ PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
+ PCRE_JAVASCRIPT_COMPAT)
#define PUBLIC_EXEC_OPTIONS \
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
- PCRE_PARTIAL|PCRE_NEWLINE_BITS)
+ PCRE_PARTIAL|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)
#define PUBLIC_DFA_EXEC_OPTIONS \
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
- PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS)
+ PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS| \
+ PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */
@@ -538,26 +605,25 @@ contain UTF-8 characters with values greater than 255. */
value such as \n. They must have non-zero values, as check_escape() returns
their negation. Also, they must appear in the same order as in the opcode
definitions below, up to ESC_z. There's a dummy for OP_ANY because it
-corresponds to "." rather than an escape sequence. The final one must be
-ESC_REF as subsequent values are used for backreferences (\1, \2, \3, etc).
-There are two tests in the code for an escape greater than ESC_b and less than
-ESC_Z to detect the types that may be repeated. These are the types that
-consume characters. If any new escapes are put in between that don't consume a
-character, that code will have to change. */
+corresponds to "." rather than an escape sequence, and another for OP_ALLANY
+(which is used for [^] in JavaScript compatibility mode).
+
+The final escape must be ESC_REF as subsequent values are used for
+backreferences (\1, \2, \3, etc). There are two tests in the code for an escape
+greater than ESC_b and less than ESC_Z to detect the types that may be
+repeated. These are the types that consume characters. If any new escapes are
+put in between that don't consume a character, that code will have to change.
+*/
-enum { ESC_A = 1, ESC_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W,
- ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_R, ESC_X, ESC_Z, ESC_z,
- ESC_E, ESC_Q, ESC_k, ESC_REF };
+enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
+ ESC_W, ESC_w, ESC_dum1, ESC_dum2, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
+ ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_g, ESC_k,
+ ESC_REF };
-/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
-that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
+/* Opcode table: Starting from 1 (i.e. after OP_END), the values up to
OP_EOD must correspond in order to the list of escapes immediately above.
-To keep stored, compiled patterns compatible, new opcodes should be added
-immediately before OP_BRA, where (since release 7.0) a gap is left for this
-purpose.
-
*** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions
that follow must also be updated to match. There is also a table called
"coptable" in pcre_dfa_exec.c that must be updated. */
@@ -569,133 +635,155 @@ enum {
OP_SOD, /* 1 Start of data: \A */
OP_SOM, /* 2 Start of match (subject + offset): \G */
- OP_NOT_WORD_BOUNDARY, /* 3 \B */
- OP_WORD_BOUNDARY, /* 4 \b */
- OP_NOT_DIGIT, /* 5 \D */
- OP_DIGIT, /* 6 \d */
- OP_NOT_WHITESPACE, /* 7 \S */
- OP_WHITESPACE, /* 8 \s */
- OP_NOT_WORDCHAR, /* 9 \W */
- OP_WORDCHAR, /* 10 \w */
- OP_ANY, /* 11 Match any character */
- OP_ANYBYTE, /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */
- OP_NOTPROP, /* 13 \P (not Unicode property) */
- OP_PROP, /* 14 \p (Unicode property) */
- OP_ANYNL, /* 15 \R (any newline sequence) */
- OP_EXTUNI, /* 16 \X (extended Unicode sequence */
- OP_EODN, /* 17 End of data or \n at end of data: \Z. */
- OP_EOD, /* 18 End of data: \z */
-
- OP_OPT, /* 19 Set runtime options */
- OP_CIRC, /* 20 Start of line - varies with multiline switch */
- OP_DOLL, /* 21 End of line - varies with multiline switch */
- OP_CHAR, /* 22 Match one character, casefully */
- OP_CHARNC, /* 23 Match one character, caselessly */
- OP_NOT, /* 24 Match one character, not the following one */
-
- OP_STAR, /* 25 The maximizing and minimizing versions of */
- OP_MINSTAR, /* 26 these six opcodes must come in pairs, with */
- OP_PLUS, /* 27 the minimizing one second. */
- OP_MINPLUS, /* 28 This first set applies to single characters.*/
- OP_QUERY, /* 29 */
- OP_MINQUERY, /* 30 */
-
- OP_UPTO, /* 31 From 0 to n matches */
- OP_MINUPTO, /* 32 */
- OP_EXACT, /* 33 Exactly n matches */
-
- OP_POSSTAR, /* 34 Possessified star */
- OP_POSPLUS, /* 35 Possessified plus */
- OP_POSQUERY, /* 36 Posesssified query */
- OP_POSUPTO, /* 37 Possessified upto */
-
- OP_NOTSTAR, /* 38 The maximizing and minimizing versions of */
- OP_NOTMINSTAR, /* 39 these six opcodes must come in pairs, with */
- OP_NOTPLUS, /* 40 the minimizing one second. They must be in */
- OP_NOTMINPLUS, /* 41 exactly the same order as those above. */
- OP_NOTQUERY, /* 42 This set applies to "not" single characters. */
- OP_NOTMINQUERY, /* 43 */
-
- OP_NOTUPTO, /* 44 From 0 to n matches */
- OP_NOTMINUPTO, /* 45 */
- OP_NOTEXACT, /* 46 Exactly n matches */
-
- OP_NOTPOSSTAR, /* 47 Possessified versions */
- OP_NOTPOSPLUS, /* 48 */
- OP_NOTPOSQUERY, /* 49 */
- OP_NOTPOSUPTO, /* 50 */
-
- OP_TYPESTAR, /* 51 The maximizing and minimizing versions of */
- OP_TYPEMINSTAR, /* 52 these six opcodes must come in pairs, with */
- OP_TYPEPLUS, /* 53 the minimizing one second. These codes must */
- OP_TYPEMINPLUS, /* 54 be in exactly the same order as those above. */
- OP_TYPEQUERY, /* 55 This set applies to character types such as \d */
- OP_TYPEMINQUERY, /* 56 */
-
- OP_TYPEUPTO, /* 57 From 0 to n matches */
- OP_TYPEMINUPTO, /* 58 */
- OP_TYPEEXACT, /* 59 Exactly n matches */
-
- OP_TYPEPOSSTAR, /* 60 Possessified versions */
- OP_TYPEPOSPLUS, /* 61 */
- OP_TYPEPOSQUERY, /* 62 */
- OP_TYPEPOSUPTO, /* 63 */
-
- OP_CRSTAR, /* 64 The maximizing and minimizing versions of */
- OP_CRMINSTAR, /* 65 all these opcodes must come in pairs, with */
- OP_CRPLUS, /* 66 the minimizing one second. These codes must */
- OP_CRMINPLUS, /* 67 be in exactly the same order as those above. */
- OP_CRQUERY, /* 68 These are for character classes and back refs */
- OP_CRMINQUERY, /* 69 */
- OP_CRRANGE, /* 70 These are different to the three sets above. */
- OP_CRMINRANGE, /* 71 */
-
- OP_CLASS, /* 72 Match a character class, chars < 256 only */
- OP_NCLASS, /* 73 Same, but the bitmap was created from a negative
+ OP_SET_SOM, /* 3 Set start of match (\K) */
+ OP_NOT_WORD_BOUNDARY, /* 4 \B */
+ OP_WORD_BOUNDARY, /* 5 \b */
+ OP_NOT_DIGIT, /* 6 \D */
+ OP_DIGIT, /* 7 \d */
+ OP_NOT_WHITESPACE, /* 8 \S */
+ OP_WHITESPACE, /* 9 \s */
+ OP_NOT_WORDCHAR, /* 10 \W */
+ OP_WORDCHAR, /* 11 \w */
+ OP_ANY, /* 12 Match any character (subject to DOTALL) */
+ OP_ALLANY, /* 13 Match any character (not subject to DOTALL) */
+ OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
+ OP_NOTPROP, /* 15 \P (not Unicode property) */
+ OP_PROP, /* 16 \p (Unicode property) */
+ OP_ANYNL, /* 17 \R (any newline sequence) */
+ OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */
+ OP_HSPACE, /* 19 \h (horizontal whitespace) */
+ OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */
+ OP_VSPACE, /* 21 \v (vertical whitespace) */
+ OP_EXTUNI, /* 22 \X (extended Unicode sequence */
+ OP_EODN, /* 23 End of data or \n at end of data: \Z. */
+ OP_EOD, /* 24 End of data: \z */
+
+ OP_OPT, /* 25 Set runtime options */
+ OP_CIRC, /* 26 Start of line - varies with multiline switch */
+ OP_DOLL, /* 27 End of line - varies with multiline switch */
+ OP_CHAR, /* 28 Match one character, casefully */
+ OP_CHARNC, /* 29 Match one character, caselessly */
+ OP_NOT, /* 30 Match one character, not the following one */
+
+ OP_STAR, /* 31 The maximizing and minimizing versions of */
+ OP_MINSTAR, /* 32 these six opcodes must come in pairs, with */
+ OP_PLUS, /* 33 the minimizing one second. */
+ OP_MINPLUS, /* 34 This first set applies to single characters.*/
+ OP_QUERY, /* 35 */
+ OP_MINQUERY, /* 36 */
+
+ OP_UPTO, /* 37 From 0 to n matches */
+ OP_MINUPTO, /* 38 */
+ OP_EXACT, /* 39 Exactly n matches */
+
+ OP_POSSTAR, /* 40 Possessified star */
+ OP_POSPLUS, /* 41 Possessified plus */
+ OP_POSQUERY, /* 42 Posesssified query */
+ OP_POSUPTO, /* 43 Possessified upto */
+
+ OP_NOTSTAR, /* 44 The maximizing and minimizing versions of */
+ OP_NOTMINSTAR, /* 45 these six opcodes must come in pairs, with */
+ OP_NOTPLUS, /* 46 the minimizing one second. They must be in */
+ OP_NOTMINPLUS, /* 47 exactly the same order as those above. */
+ OP_NOTQUERY, /* 48 This set applies to "not" single characters. */
+ OP_NOTMINQUERY, /* 49 */
+
+ OP_NOTUPTO, /* 50 From 0 to n matches */
+ OP_NOTMINUPTO, /* 51 */
+ OP_NOTEXACT, /* 52 Exactly n matches */
+
+ OP_NOTPOSSTAR, /* 53 Possessified versions */
+ OP_NOTPOSPLUS, /* 54 */
+ OP_NOTPOSQUERY, /* 55 */
+ OP_NOTPOSUPTO, /* 56 */
+
+ OP_TYPESTAR, /* 57 The maximizing and minimizing versions of */
+ OP_TYPEMINSTAR, /* 58 these six opcodes must come in pairs, with */
+ OP_TYPEPLUS, /* 59 the minimizing one second. These codes must */
+ OP_TYPEMINPLUS, /* 60 be in exactly the same order as those above. */
+ OP_TYPEQUERY, /* 61 This set applies to character types such as \d */
+ OP_TYPEMINQUERY, /* 62 */
+
+ OP_TYPEUPTO, /* 63 From 0 to n matches */
+ OP_TYPEMINUPTO, /* 64 */
+ OP_TYPEEXACT, /* 65 Exactly n matches */
+
+ OP_TYPEPOSSTAR, /* 66 Possessified versions */
+ OP_TYPEPOSPLUS, /* 67 */
+ OP_TYPEPOSQUERY, /* 68 */
+ OP_TYPEPOSUPTO, /* 69 */
+
+ OP_CRSTAR, /* 70 The maximizing and minimizing versions of */
+ OP_CRMINSTAR, /* 71 all these opcodes must come in pairs, with */
+ OP_CRPLUS, /* 72 the minimizing one second. These codes must */
+ OP_CRMINPLUS, /* 73 be in exactly the same order as those above. */
+ OP_CRQUERY, /* 74 These are for character classes and back refs */
+ OP_CRMINQUERY, /* 75 */
+ OP_CRRANGE, /* 76 These are different to the three sets above. */
+ OP_CRMINRANGE, /* 77 */
+
+ OP_CLASS, /* 78 Match a character class, chars < 256 only */
+ OP_NCLASS, /* 79 Same, but the bitmap was created from a negative
class - the difference is relevant only when a UTF-8
character > 255 is encountered. */
- OP_XCLASS, /* 74 Extended class for handling UTF-8 chars within the
+ OP_XCLASS, /* 80 Extended class for handling UTF-8 chars within the
class. This does both positive and negative. */
- OP_REF, /* 75 Match a back reference */
- OP_RECURSE, /* 76 Match a numbered subpattern (possibly recursive) */
- OP_CALLOUT, /* 77 Call out to external function if provided */
+ OP_REF, /* 81 Match a back reference */
+ OP_RECURSE, /* 82 Match a numbered subpattern (possibly recursive) */
+ OP_CALLOUT, /* 83 Call out to external function if provided */
- OP_ALT, /* 78 Start of alternation */
- OP_KET, /* 79 End of group that doesn't have an unbounded repeat */
- OP_KETRMAX, /* 80 These two must remain together and in this */
- OP_KETRMIN, /* 81 order. They are for groups the repeat for ever. */
+ OP_ALT, /* 84 Start of alternation */
+ OP_KET, /* 85 End of group that doesn't have an unbounded repeat */
+ OP_KETRMAX, /* 86 These two must remain together and in this */
+ OP_KETRMIN, /* 87 order. They are for groups the repeat for ever. */
/* The assertions must come before BRA, CBRA, ONCE, and COND.*/
- OP_ASSERT, /* 82 Positive lookahead */
- OP_ASSERT_NOT, /* 83 Negative lookahead */
- OP_ASSERTBACK, /* 84 Positive lookbehind */
- OP_ASSERTBACK_NOT, /* 85 Negative lookbehind */
- OP_REVERSE, /* 86 Move pointer back - used in lookbehind assertions */
+ OP_ASSERT, /* 88 Positive lookahead */
+ OP_ASSERT_NOT, /* 89 Negative lookahead */
+ OP_ASSERTBACK, /* 90 Positive lookbehind */
+ OP_ASSERTBACK_NOT, /* 91 Negative lookbehind */
+ OP_REVERSE, /* 92 Move pointer back - used in lookbehind assertions */
/* ONCE, BRA, CBRA, and COND must come after the assertions, with ONCE first,
as there's a test for >= ONCE for a subpattern that isn't an assertion. */
- OP_ONCE, /* 87 Atomic group */
- OP_BRA, /* 88 Start of non-capturing bracket */
- OP_CBRA, /* 89 Start of capturing bracket */
- OP_COND, /* 90 Conditional group */
+ OP_ONCE, /* 93 Atomic group */
+ OP_BRA, /* 94 Start of non-capturing bracket */
+ OP_CBRA, /* 95 Start of capturing bracket */
+ OP_COND, /* 96 Conditional group */
/* These three must follow the previous three, in the same order. There's a
check for >= SBRA to distinguish the two sets. */
- OP_SBRA, /* 91 Start of non-capturing bracket, check empty */
- OP_SCBRA, /* 92 Start of capturing bracket, check empty */
- OP_SCOND, /* 93 Conditional group, check empty */
+ OP_SBRA, /* 97 Start of non-capturing bracket, check empty */
+ OP_SCBRA, /* 98 Start of capturing bracket, check empty */
+ OP_SCOND, /* 99 Conditional group, check empty */
+
+ OP_CREF, /* 100 Used to hold a capture number as condition */
+ OP_RREF, /* 101 Used to hold a recursion number as condition */
+ OP_DEF, /* 102 The DEFINE condition */
+
+ OP_BRAZERO, /* 103 These two must remain together and in this */
+ OP_BRAMINZERO, /* 104 order. */
+
+ /* These are backtracking control verbs */
+
+ OP_PRUNE, /* 105 */
+ OP_SKIP, /* 106 */
+ OP_THEN, /* 107 */
+ OP_COMMIT, /* 108 */
+
+ /* These are forced failure and success verbs */
- OP_CREF, /* 94 Used to hold a capture number as condition */
- OP_RREF, /* 95 Used to hold a recursion number as condition */
- OP_DEF, /* 96 The DEFINE condition */
+ OP_FAIL, /* 109 */
+ OP_ACCEPT, /* 110 */
- OP_BRAZERO, /* 97 These two must remain together and in this */
- OP_BRAMINZERO /* 98 order. */
+ /* This is used to skip a subpattern with a {0} quantifier */
+
+ OP_SKIPZERO /* 111 */
};
@@ -703,10 +791,10 @@ enum {
for debugging. The macro is referenced only in pcre_printint.c. */
#define OP_NAME_LIST \
- "End", "\\A", "\\G", "\\B", "\\b", "\\D", "\\d", \
- "\\S", "\\s", "\\W", "\\w", "Any", "Anybyte", \
- "notprop", "prop", "anynl", "extuni", \
- "\\Z", "\\z", \
+ "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \
+ "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \
+ "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \
+ "extuni", "\\Z", "\\z", \
"Opt", "^", "$", "char", "charnc", "not", \
"*", "*?", "+", "+?", "?", "??", "{", "{", "{", \
"*+","++", "?+", "{", \
@@ -718,8 +806,10 @@ for debugging. The macro is referenced only in pcre_printint.c. */
"class", "nclass", "xclass", "Ref", "Recurse", "Callout", \
"Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \
"AssertB", "AssertB not", "Reverse", \
- "Once", "Bra 0", "Bra", "Cond", "SBra 0", "SBra", "SCond", \
- "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero"
+ "Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond", \
+ "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero", \
+ "*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT", \
+ "Skip zero"
/* This macro defines the length of fixed length operations in the compiled
@@ -733,9 +823,11 @@ in UTF-8 mode. The code that uses this table must know about such things. */
#define OP_LENGTHS \
1, /* End */ \
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* \A, \G, \B, \B, \D, \d, \S, \s, \W, \w */ \
- 1, 1, /* Any, Anybyte */ \
- 3, 3, 1, 1, /* NOTPROP, PROP, EXTUNI, ANYNL */ \
+ 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \
+ 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \
+ 1, 1, 1, /* Any, AllAny, Anybyte */ \
+ 3, 3, 1, /* NOTPROP, PROP, EXTUNI */ \
+ 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \
1, 1, 2, 1, 1, /* \Z, \z, Opt, ^, $ */ \
2, /* Char - the minimum length */ \
2, /* Charnc - the minimum length */ \
@@ -781,6 +873,8 @@ in UTF-8 mode. The code that uses this table must know about such things. */
3, /* RREF */ \
1, /* DEF */ \
1, 1, /* BRAZERO, BRAMINZERO */ \
+ 1, 1, 1, 1, /* PRUNE, SKIP, THEN, COMMIT, */ \
+ 1, 1, 1 /* FAIL, ACCEPT, SKIPZERO */
/* A magic value for OP_RREF to indicate the "any recursion" condition. */
@@ -795,7 +889,8 @@ enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9,
ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
- ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57 };
+ ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
+ ERR60, ERR61, ERR62, ERR63, ERR64 };
/* The real format of the start of the pcre block; the index of names and the
code vector run on as long as necessary after the end. We store an explicit
@@ -817,9 +912,9 @@ NOTE NOTE NOTE:
typedef struct real_pcre {
pcre_uint32 magic_number;
pcre_uint32 size; /* Total that was malloced */
- pcre_uint32 options;
- pcre_uint32 dummy1; /* For future use, maybe */
-
+ pcre_uint32 options; /* Public options */
+ pcre_uint16 flags; /* Private flags */
+ pcre_uint16 dummy1; /* For future use */
pcre_uint16 top_bracket;
pcre_uint16 top_backref;
pcre_uint16 first_byte;
@@ -858,12 +953,14 @@ typedef struct compile_data {
uschar *name_table; /* The name/number table */
int names_found; /* Number of entries so far */
int name_entry_size; /* Size of each entry */
- int bracount; /* Count of capturing parens */
+ int bracount; /* Count of capturing parens as we compile */
+ int final_bracount; /* Saved value after first pass */
int top_backref; /* Maximum back reference */
unsigned int backref_map; /* Bitmap of low back refs */
int external_options; /* External (initial) options */
+ int external_flags; /* External flag bits to be set */
int req_varyopt; /* "After variable item" flag for reqbyte */
- BOOL nopartial; /* Set TRUE if partial won't work */
+ BOOL had_accept; /* (*ACCEPT) encountered */
int nltype; /* Newline type */
int nllen; /* Newline string length */
uschar nl[4]; /* Newline string when fixed length */
@@ -884,21 +981,11 @@ typedef struct recursion_info {
struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
int group_num; /* Number of group that was called */
const uschar *after_call; /* "Return value": points after the call in the expr */
- USPTR save_start; /* Old value of md->start_match */
+ USPTR save_start; /* Old value of mstart */
int *offset_save; /* Pointer to start of saved offsets */
int saved_max; /* Number of saved offsets */
} recursion_info;
-/* When compiling in a mode that doesn't use recursive calls to match(),
-a structure is used to remember local variables on the heap. It is defined in
-pcre_exec.c, close to the match() function, so that it is easy to keep it in
-step with any changes of local variable. However, the pointer to the current
-frame must be saved in some "static" place over a longjmp(). We declare the
-structure here so that we can put a pointer in the match_data structure. NOTE:
-This isn't used for a "normal" compilation of pcre. */
-
-struct heapframe;
-
/* Structure for building a chain of data for holding the values of the subject
pointer at the start of each subpattern, so as to detect when an empty string
has been matched by a subpattern - to break infinite loops. */
@@ -928,14 +1015,16 @@ typedef struct match_data {
BOOL notbol; /* NOTBOL flag */
BOOL noteol; /* NOTEOL flag */
BOOL utf8; /* UTF8 flag */
+ BOOL jscript_compat; /* JAVASCRIPT_COMPAT flag */
BOOL endonly; /* Dollar not before final \n */
BOOL notempty; /* Empty string match not wanted */
BOOL partial; /* PARTIAL flag */
BOOL hitend; /* Hit the end of the subject at some point */
+ BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */
const uschar *start_code; /* For use when recursing */
USPTR start_subject; /* Start of the subject string */
USPTR end_subject; /* End of the subject string */
- USPTR start_match; /* Start of this match attempt */
+ USPTR start_match_ptr; /* Start of matched string */
USPTR end_match_ptr; /* Subject position at end match */
int end_offset_top; /* Highwater mark at end of match */
int capture_last; /* Most recent capture number */
@@ -944,7 +1033,6 @@ typedef struct match_data {
int eptrn; /* Next free eptrblock */
recursion_info *recursive; /* Linked list of recursion data */
void *callout_data; /* To pass back to callouts */
- struct heapframe *thisframe; /* Used only when compiling for no recursion */
} match_data;
/* A similar structure is used for the same purpose by the DFA matching
@@ -969,7 +1057,7 @@ typedef struct dfa_match_data {
#define ctype_letter 0x02
#define ctype_digit 0x04
#define ctype_xdigit 0x08
-#define ctype_word 0x10 /* alphameric or '_' */
+#define ctype_word 0x10 /* alphanumeric or '_' */
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
@@ -997,10 +1085,12 @@ total length. */
#define tables_length (ctypes_offset + 256)
/* Layout of the UCP type table that translates property names into types and
-codes. */
+codes. Each entry used to point directly to a name, but to reduce the number of
+relocations in shared libraries, it now has an offset into a single string
+instead. */
typedef struct {
- const char *name;
+ pcre_uint16 name_offset;
pcre_uint16 type;
pcre_uint16 value;
} ucp_type_table;
@@ -1018,6 +1108,7 @@ extern const uschar _pcre_utf8_table4[];
extern const int _pcre_utf8_table1_size;
+extern const char _pcre_utt_names[];
extern const ucp_type_table _pcre_utt[];
extern const int _pcre_utt_size;
@@ -1030,16 +1121,16 @@ extern const uschar _pcre_OP_lengths[];
one of the exported public functions. They have to be "external" in the C
sense, but are not part of the PCRE public API. */
-extern BOOL _pcre_is_newline(const uschar *, const uschar *, int *,
- BOOL);
+extern BOOL _pcre_is_newline(const uschar *, int, const uschar *,
+ int *, BOOL);
extern int _pcre_ord2utf8(int, uschar *);
extern real_pcre *_pcre_try_flipped(const real_pcre *, real_pcre *,
const pcre_study_data *, pcre_study_data *);
extern int _pcre_ucp_findprop(const unsigned int, int *, int *);
extern unsigned int _pcre_ucp_othercase(const unsigned int);
extern int _pcre_valid_utf8(const uschar *, int);
-extern BOOL _pcre_was_newline(const uschar *, const uschar *, int *,
- BOOL);
+extern BOOL _pcre_was_newline(const uschar *, int, const uschar *,
+ int *, BOOL);
extern BOOL _pcre_xclass(int, const uschar *);
#endif
diff --git a/ext/pcre/pcrelib/pcre_maketables.c b/ext/pcre/pcrelib/pcre_maketables.c
index 29e40989bf..2ba612cec7 100644
--- a/ext/pcre/pcrelib/pcre_maketables.c
+++ b/ext/pcre/pcrelib/pcre_maketables.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,8 @@ compilation of dftables.c, in which case the macro DFTABLES is defined. */
#ifndef DFTABLES
-#include "pcre_internal.h"
+# include "config.h"
+# include "pcre_internal.h"
#endif
diff --git a/ext/pcre/pcrelib/pcre_newline.c b/ext/pcre/pcrelib/pcre_newline.c
index 348791b1ed..e4223cbb62 100644
--- a/ext/pcre/pcrelib/pcre_newline.c
+++ b/ext/pcre/pcrelib/pcre_newline.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,12 +42,13 @@ POSSIBILITY OF SUCH DAMAGE.
one kind of newline is to be recognized. When a newline is found, its length is
returned. In principle, we could implement several newline "types", each
referring to a different set of newline characters. At present, PCRE supports
-only NLTYPE_FIXED, which gets handled without these functions, and NLTYPE_ALL,
-so for now the type isn't passed into the functions. It can easily be added
-later if required. The full list of Unicode newline characters is taken from
+only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF,
+and NLTYPE_ANY. The full list of Unicode newline characters is taken from
http://unicode.org/unicode/reports/tr18/. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -61,6 +62,7 @@ string that is being processed.
Arguments:
ptr pointer to possible newline
+ type the newline type
endptr pointer to the end of the string
lenptr where to return the length
utf8 TRUE if in utf8 mode
@@ -69,12 +71,23 @@ Returns: TRUE or FALSE
*/
BOOL
-_pcre_is_newline(const uschar *ptr, const uschar *endptr, int *lenptr,
- BOOL utf8)
+_pcre_is_newline(const uschar *ptr, int type, const uschar *endptr,
+ int *lenptr, BOOL utf8)
{
int c;
if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
-switch(c)
+
+if (type == NLTYPE_ANYCRLF) switch(c)
+ {
+ case 0x000a: *lenptr = 1; return TRUE; /* LF */
+ case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
+ return TRUE; /* CR */
+ default: return FALSE;
+ }
+
+/* NLTYPE_ANY */
+
+else switch(c)
{
case 0x000a: /* LF */
case 0x000b: /* VT */
@@ -99,6 +112,7 @@ the string that is being processed.
Arguments:
ptr pointer to possible newline
+ type the newline type
startptr pointer to the start of the string
lenptr where to return the length
utf8 TRUE if in utf8 mode
@@ -107,18 +121,31 @@ Returns: TRUE or FALSE
*/
BOOL
-_pcre_was_newline(const uschar *ptr, const uschar *startptr, int *lenptr,
- BOOL utf8)
+_pcre_was_newline(const uschar *ptr, int type, const uschar *startptr,
+ int *lenptr, BOOL utf8)
{
int c;
ptr--;
+#ifdef SUPPORT_UTF8
if (utf8)
{
BACKCHAR(ptr);
GETCHAR(c, ptr);
}
else c = *ptr;
-switch(c)
+#else /* no UTF-8 support */
+c = *ptr;
+#endif /* SUPPORT_UTF8 */
+
+if (type == NLTYPE_ANYCRLF) switch(c)
+ {
+ case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
+ return TRUE; /* LF */
+ case 0x000d: *lenptr = 1; return TRUE; /* CR */
+ default: return FALSE;
+ }
+
+else switch(c)
{
case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
return TRUE; /* LF */
diff --git a/ext/pcre/pcrelib/pcre_ord2utf8.c b/ext/pcre/pcrelib/pcre_ord2utf8.c
index fc4d6de812..dfd88bcdb4 100644
--- a/ext/pcre/pcrelib/pcre_ord2utf8.c
+++ b/ext/pcre/pcrelib/pcre_ord2utf8.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
/* This file contains a private PCRE function that converts an ordinal
character value into a UTF8 string. */
+#include "config.h"
#include "pcre_internal.h"
@@ -62,6 +63,7 @@ Returns: number of characters placed in the buffer
int
_pcre_ord2utf8(int cvalue, uschar *buffer)
{
+#ifdef SUPPORT_UTF8
register int i, j;
for (i = 0; i < _pcre_utf8_table1_size; i++)
if (cvalue <= _pcre_utf8_table1[i]) break;
@@ -73,6 +75,9 @@ for (j = i; j > 0; j--)
}
*buffer = _pcre_utf8_table2[i] | cvalue;
return i + 1;
+#else
+return 0; /* Keep compiler happy; this function won't ever be */
+#endif /* called when SUPPORT_UTF8 is not defined. */
}
/* End of pcre_ord2utf8.c */
diff --git a/ext/pcre/pcrelib/pcre_printint.src b/ext/pcre/pcrelib/pcre_printint.src
index a6f433368a..98b42aa804 100644
--- a/ext/pcre/pcrelib/pcre_printint.src
+++ b/ext/pcre/pcrelib/pcre_printint.src
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2005 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,12 @@ print_char(FILE *f, uschar *ptr, BOOL utf8)
{
int c = *ptr;
+#ifndef SUPPORT_UTF8
+utf8 = utf8; /* Avoid compiler warning */
+if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
+return 0;
+
+#else
if (!utf8 || (c & 0xc0) != 0xc0)
{
if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
@@ -102,6 +108,7 @@ else
if (c < 128) fprintf(f, "\\x%02x", c); else fprintf(f, "\\x{%x}", c);
return a;
}
+#endif
}
@@ -115,11 +122,11 @@ get_ucpname(int ptype, int pvalue)
{
#ifdef SUPPORT_UCP
int i;
-for (i = _pcre_utt_size; i >= 0; i--)
+for (i = _pcre_utt_size - 1; i >= 0; i--)
{
if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;
}
-return (i >= 0)? _pcre_utt[i].name : "??";
+return (i >= 0)? _pcre_utt_names + _pcre_utt[i].name_offset : "??";
#else
/* It gets harder and harder to shut off unwanted compiler warnings. */
ptype = ptype * pvalue;
@@ -134,10 +141,13 @@ return (ptype == pvalue)? "??" : "??";
*************************************************/
/* Make this function work for a regex with integers either byte order.
-However, we assume that what we are passed is a compiled regex. */
+However, we assume that what we are passed is a compiled regex. The
+print_lengths flag controls whether offsets and lengths of items are printed.
+They can be turned off from pcretest so that automatic tests on bytecode can be
+written that do not depend on the value of LINK_SIZE. */
static void
-pcre_printint(pcre *external_re, FILE *f)
+pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths)
{
real_pcre *re = (real_pcre *)external_re;
uschar *codestart, *code;
@@ -168,7 +178,10 @@ for(;;)
int c;
int extra = 0;
- fprintf(f, "%3d ", (int)(code - codestart));
+ if (print_lengths)
+ fprintf(f, "%3d ", (int)(code - codestart));
+ else
+ fprintf(f, " ");
switch(*code)
{
@@ -205,8 +218,9 @@ for(;;)
case OP_CBRA:
case OP_SCBRA:
- fprintf(f, "%3d %s %d", GET(code, 1), OP_names[*code],
- GET2(code, 1+LINK_SIZE));
+ if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+ else fprintf(f, " ");
+ fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));
break;
case OP_BRA:
@@ -223,7 +237,9 @@ for(;;)
case OP_COND:
case OP_SCOND:
case OP_REVERSE:
- fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);
+ if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+ else fprintf(f, " ");
+ fprintf(f, "%s", OP_names[*code]);
break;
case OP_CREF:
@@ -339,7 +355,9 @@ for(;;)
break;
case OP_RECURSE:
- fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);
+ if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+ else fprintf(f, " ");
+ fprintf(f, "%s", OP_names[*code]);
break;
case OP_REF:
diff --git a/ext/pcre/pcrelib/pcre_refcount.c b/ext/pcre/pcrelib/pcre_refcount.c
index e6965812ef..f31399ea24 100644
--- a/ext/pcre/pcrelib/pcre_refcount.c
+++ b/ext/pcre/pcrelib/pcre_refcount.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,9 @@ auxiliary function that can be used to maintain a reference count in a compiled
pattern data block. This might be helpful in applications where the block is
shared by different users. */
+
+#include "config.h"
+
#include "pcre_internal.h"
@@ -63,7 +66,7 @@ Returns: the (possibly updated) count value (a non-negative number), or
a negative error number
*/
-PCRE_DATA_SCOPE int
+PCRE_EXP_DEFN int
pcre_refcount(pcre *argument_re, int adjust)
{
real_pcre *re = (real_pcre *)argument_re;
diff --git a/ext/pcre/pcrelib/pcre_scanner.cc b/ext/pcre/pcrelib/pcre_scanner.cc
deleted file mode 100644
index bdc8d4df56..0000000000
--- a/ext/pcre/pcrelib/pcre_scanner.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-
-#include <vector>
-#include <assert.h>
-#include "config.h"
-#include "pcre_scanner.h"
-
-using std::vector;
-
-namespace pcrecpp {
-
-Scanner::Scanner()
- : data_(),
- input_(data_),
- skip_(NULL),
- should_skip_(false),
- skip_repeat_(false),
- save_comments_(false),
- comments_(NULL),
- comments_offset_(0) {
-}
-
-Scanner::Scanner(const string& in)
- : data_(in),
- input_(data_),
- skip_(NULL),
- should_skip_(false),
- skip_repeat_(false),
- save_comments_(false),
- comments_(NULL),
- comments_offset_(0) {
-}
-
-Scanner::~Scanner() {
- delete skip_;
- delete comments_;
-}
-
-void Scanner::SetSkipExpression(const char* re) {
- delete skip_;
- if (re != NULL) {
- skip_ = new RE(re);
- should_skip_ = true;
- skip_repeat_ = true;
- ConsumeSkip();
- } else {
- skip_ = NULL;
- should_skip_ = false;
- skip_repeat_ = false;
- }
-}
-
-void Scanner::Skip(const char* re) {
- delete skip_;
- if (re != NULL) {
- skip_ = new RE(re);
- should_skip_ = true;
- skip_repeat_ = false;
- ConsumeSkip();
- } else {
- skip_ = NULL;
- should_skip_ = false;
- skip_repeat_ = false;
- }
-}
-
-void Scanner::DisableSkip() {
- assert(skip_ != NULL);
- should_skip_ = false;
-}
-
-void Scanner::EnableSkip() {
- assert(skip_ != NULL);
- should_skip_ = true;
- ConsumeSkip();
-}
-
-int Scanner::LineNumber() const {
- // TODO: Make it more efficient by keeping track of the last point
- // where we computed line numbers and counting newlines since then.
- // We could use std:count, but not all systems have it. :-(
- int count = 1;
- for (const char* p = data_.data(); p < input_.data(); ++p)
- if (*p == '\n')
- ++count;
- return count;
-}
-
-int Scanner::Offset() const {
- return input_.data() - data_.c_str();
-}
-
-bool Scanner::LookingAt(const RE& re) const {
- int consumed;
- return re.DoMatch(input_, RE::ANCHOR_START, &consumed, 0, 0);
-}
-
-
-bool Scanner::Consume(const RE& re,
- const Arg& arg0,
- const Arg& arg1,
- const Arg& arg2) {
- const bool result = re.Consume(&input_, arg0, arg1, arg2);
- if (result && should_skip_) ConsumeSkip();
- return result;
-}
-
-// helper function to consume *skip_ and honour save_comments_
-void Scanner::ConsumeSkip() {
- const char* start_data = input_.data();
- while (skip_->Consume(&input_)) {
- if (!skip_repeat_) {
- // Only one skip allowed.
- break;
- }
- }
- if (save_comments_) {
- if (comments_ == NULL) {
- comments_ = new vector<StringPiece>;
- }
- // already pointing one past end, so no need to +1
- int length = input_.data() - start_data;
- if (length > 0) {
- comments_->push_back(StringPiece(start_data, length));
- }
- }
-}
-
-
-void Scanner::GetComments(int start, int end, vector<StringPiece> *ranges) {
- // short circuit out if we've not yet initialized comments_
- // (e.g., when save_comments is false)
- if (!comments_) {
- return;
- }
- // TODO: if we guarantee that comments_ will contain StringPieces
- // that are ordered by their start, then we can do a binary search
- // for the first StringPiece at or past start and then scan for the
- // ones contained in the range, quit early (use equal_range or
- // lower_bound)
- for (vector<StringPiece>::const_iterator it = comments_->begin();
- it != comments_->end(); ++it) {
- if ((it->data() >= data_.c_str() + start &&
- it->data() + it->size() <= data_.c_str() + end)) {
- ranges->push_back(*it);
- }
- }
-}
-
-
-void Scanner::GetNextComments(vector<StringPiece> *ranges) {
- // short circuit out if we've not yet initialized comments_
- // (e.g., when save_comments is false)
- if (!comments_) {
- return;
- }
- for (vector<StringPiece>::const_iterator it =
- comments_->begin() + comments_offset_;
- it != comments_->end(); ++it) {
- ranges->push_back(*it);
- ++comments_offset_;
- }
-}
-
-} // namespace pcrecpp
diff --git a/ext/pcre/pcrelib/pcre_scanner.h b/ext/pcre/pcrelib/pcre_scanner.h
deleted file mode 100644
index ab4583ee41..0000000000
--- a/ext/pcre/pcrelib/pcre_scanner.h
+++ /dev/null
@@ -1,171 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-//
-// Regular-expression based scanner for parsing an input stream.
-//
-// Example 1: parse a sequence of "var = number" entries from input:
-//
-// Scanner scanner(input);
-// string var;
-// int number;
-// scanner.SetSkipExpression("\\s+"); // Skip any white space we encounter
-// while (scanner.Consume("(\\w+) = (\\d+)", &var, &number)) {
-// ...;
-// }
-
-#ifndef _PCRE_SCANNER_H
-#define _PCRE_SCANNER_H
-
-#include <assert.h>
-#include <string>
-#include <vector>
-#include <pcrecpp.h>
-#include <pcre_stringpiece.h>
-
-namespace pcrecpp {
-
-class Scanner {
- public:
- Scanner();
- explicit Scanner(const std::string& input);
- ~Scanner();
-
- // Return current line number. The returned line-number is
- // one-based. I.e. it returns 1 + the number of consumed newlines.
- //
- // Note: this method may be slow. It may take time proportional to
- // the size of the input.
- int LineNumber() const;
-
- // Return the byte-offset that the scanner is looking in the
- // input data;
- int Offset() const;
-
- // Return true iff the start of the remaining input matches "re"
- bool LookingAt(const RE& re) const;
-
- // Return true iff all of the following are true
- // a. the start of the remaining input matches "re",
- // b. if any arguments are supplied, matched sub-patterns can be
- // parsed and stored into the arguments.
- // If it returns true, it skips over the matched input and any
- // following input that matches the "skip" regular expression.
- bool Consume(const RE& re,
- const Arg& arg0 = no_arg,
- const Arg& arg1 = no_arg,
- const Arg& arg2 = no_arg
- // TODO: Allow more arguments?
- );
-
- // Set the "skip" regular expression. If after consuming some data,
- // a prefix of the input matches this RE, it is automatically
- // skipped. For example, a programming language scanner would use
- // a skip RE that matches white space and comments.
- //
- // scanner.SetSkipExpression("\\s+|//.*|/[*](.|\n)*?[*]/");
- //
- // Skipping repeats as long as it succeeds. We used to let people do
- // this by writing "(...)*" in the regular expression, but that added
- // up to lots of recursive calls within the pcre library, so now we
- // control repetition explicitly via the function call API.
- //
- // You can pass NULL for "re" if you do not want any data to be skipped.
- void Skip(const char* re); // DEPRECATED; does *not* repeat
- void SetSkipExpression(const char* re);
-
- // Temporarily pause "skip"ing. This
- // Skip("Foo"); code ; DisableSkip(); code; EnableSkip()
- // is similar to
- // Skip("Foo"); code ; Skip(NULL); code ; Skip("Foo");
- // but avoids creating/deleting new RE objects.
- void DisableSkip();
-
- // Reenable previously paused skipping. Any prefix of the input
- // that matches the skip pattern is immediately dropped.
- void EnableSkip();
-
- /***** Special wrappers around SetSkip() for some common idioms *****/
-
- // Arranges to skip whitespace, C comments, C++ comments.
- // The overall RE is a disjunction of the following REs:
- // \\s whitespace
- // //.*\n C++ comment
- // /[*](.|\n)*?[*]/ C comment (x*? means minimal repetitions of x)
- // We get repetition via the semantics of SetSkipExpression, not by using *
- void SkipCXXComments() {
- SetSkipExpression("\\s|//.*\n|/[*](?:\n|.)*?[*]/");
- }
-
- void set_save_comments(bool comments) {
- save_comments_ = comments;
- }
-
- bool save_comments() {
- return save_comments_;
- }
-
- // Append to vector ranges the comments found in the
- // byte range [start,end] (inclusive) of the input data.
- // Only comments that were extracted entirely within that
- // range are returned: no range splitting of atomically-extracted
- // comments is performed.
- void GetComments(int start, int end, std::vector<StringPiece> *ranges);
-
- // Append to vector ranges the comments added
- // since the last time this was called. This
- // functionality is provided for efficiency when
- // interleaving scanning with parsing.
- void GetNextComments(std::vector<StringPiece> *ranges);
-
- private:
- std::string data_; // All the input data
- StringPiece input_; // Unprocessed input
- RE* skip_; // If non-NULL, RE for skipping input
- bool should_skip_; // If true, use skip_
- bool skip_repeat_; // If true, repeat skip_ as long as it works
- bool save_comments_; // If true, aggregate the skip expression
-
- // the skipped comments
- // TODO: later consider requiring that the StringPieces be added
- // in order by their start position
- std::vector<StringPiece> *comments_;
-
- // the offset into comments_ that has been returned by GetNextComments
- int comments_offset_;
-
- // helper function to consume *skip_ and honour
- // save_comments_
- void ConsumeSkip();
-};
-
-} // namespace pcrecpp
-
-#endif /* _PCRE_SCANNER_H */
diff --git a/ext/pcre/pcrelib/pcre_scanner_unittest.cc b/ext/pcre/pcrelib/pcre_scanner_unittest.cc
deleted file mode 100644
index d939fedeca..0000000000
--- a/ext/pcre/pcrelib/pcre_scanner_unittest.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Greg J. Badros
-//
-// Unittest for scanner, especially GetNextComments and GetComments()
-// functionality.
-
-#include <stdio.h>
-#include <string>
-#include <vector>
-#include <pcre_stringpiece.h>
-#include <pcre_scanner.h>
-
-#define FLAGS_unittest_stack_size 49152
-
-// Dies with a fatal error if the two values are not equal.
-#define CHECK_EQ(a, b) do { \
- if ( (a) != (b) ) { \
- fprintf(stderr, "%s:%d: Check failed because %s != %s\n", \
- __FILE__, __LINE__, #a, #b); \
- exit(1); \
- } \
-} while (0)
-
-using std::vector;
-using pcrecpp::StringPiece;
-using pcrecpp::Scanner;
-
-static void TestScanner() {
- const char input[] = "\n"
- "alpha = 1; // this sets alpha\n"
- "bravo = 2; // bravo is set here\n"
- "gamma = 33; /* and here is gamma */\n";
-
- const char *re = "(\\w+) = (\\d+);";
-
- Scanner s(input);
- string var;
- int number;
- s.SkipCXXComments();
- s.set_save_comments(true);
- vector<StringPiece> comments;
-
- s.Consume(re, &var, &number);
- CHECK_EQ(var, "alpha");
- CHECK_EQ(number, 1);
- CHECK_EQ(s.LineNumber(), 3);
- s.GetNextComments(&comments);
- CHECK_EQ(comments.size(), 1);
- CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");
- comments.resize(0);
-
- s.Consume(re, &var, &number);
- CHECK_EQ(var, "bravo");
- CHECK_EQ(number, 2);
- s.GetNextComments(&comments);
- CHECK_EQ(comments.size(), 1);
- CHECK_EQ(comments[0].as_string(), " // bravo is set here\n");
- comments.resize(0);
-
- s.Consume(re, &var, &number);
- CHECK_EQ(var, "gamma");
- CHECK_EQ(number, 33);
- s.GetNextComments(&comments);
- CHECK_EQ(comments.size(), 1);
- CHECK_EQ(comments[0].as_string(), " /* and here is gamma */\n");
- comments.resize(0);
-
- s.GetComments(0, sizeof(input), &comments);
- CHECK_EQ(comments.size(), 3);
- CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");
- CHECK_EQ(comments[1].as_string(), " // bravo is set here\n");
- CHECK_EQ(comments[2].as_string(), " /* and here is gamma */\n");
- comments.resize(0);
-
- s.GetComments(0, strchr(input, '/') - input, &comments);
- CHECK_EQ(comments.size(), 0);
- comments.resize(0);
-
- s.GetComments(strchr(input, '/') - input - 1, sizeof(input),
- &comments);
- CHECK_EQ(comments.size(), 3);
- CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");
- CHECK_EQ(comments[1].as_string(), " // bravo is set here\n");
- CHECK_EQ(comments[2].as_string(), " /* and here is gamma */\n");
- comments.resize(0);
-
- s.GetComments(strchr(input, '/') - input - 1,
- strchr(input + 1, '\n') - input + 1, &comments);
- CHECK_EQ(comments.size(), 1);
- CHECK_EQ(comments[0].as_string(), " // this sets alpha\n");
- comments.resize(0);
-}
-
-static void TestBigComment() {
- string input;
- for (int i = 0; i < 1024; ++i) {
- char buf[1024];
- snprintf(buf, sizeof(buf), " # Comment %d\n", i);
- input += buf;
- }
- input += "name = value;\n";
-
- Scanner s(input.c_str());
- s.SetSkipExpression("\\s+|#.*\n");
-
- string name;
- string value;
- s.Consume("(\\w+) = (\\w+);", &name, &value);
- CHECK_EQ(name, "name");
- CHECK_EQ(value, "value");
-}
-
-// TODO: also test scanner and big-comment in a thread with a
-// small stack size
-
-int main(int argc, char** argv) {
- TestScanner();
- TestBigComment();
-
- // Done
- printf("OK\n");
-
- return 0;
-}
diff --git a/ext/pcre/pcrelib/pcre_stringpiece.cc b/ext/pcre/pcrelib/pcre_stringpiece.cc
deleted file mode 100644
index dbdb509b3b..0000000000
--- a/ext/pcre/pcrelib/pcre_stringpiece.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: wilsonh@google.com (Wilson Hsieh)
-//
-
-#include <iostream>
-#include "config.h"
-#include "pcre_stringpiece.h"
-
-std::ostream& operator<<(std::ostream& o, const pcrecpp::StringPiece& piece) {
- return (o << piece.as_string());
-}
diff --git a/ext/pcre/pcrelib/pcre_stringpiece.h b/ext/pcre/pcrelib/pcre_stringpiece.h
deleted file mode 100644
index 89d5449651..0000000000
--- a/ext/pcre/pcrelib/pcre_stringpiece.h
+++ /dev/null
@@ -1,172 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-//
-// A string like object that points into another piece of memory.
-// Useful for providing an interface that allows clients to easily
-// pass in either a "const char*" or a "string".
-//
-// Arghh! I wish C++ literals were automatically of type "string".
-
-#ifndef _PCRE_STRINGPIECE_H
-#define _PCRE_STRINGPIECE_H
-
-#include <string.h>
-#include <string>
-#include <iosfwd> // for ostream forward-declaration
-
-#if 1
-#define HAVE_TYPE_TRAITS
-#include <type_traits.h>
-#elif 0
-#define HAVE_TYPE_TRAITS
-#include <bits/type_traits.h>
-#endif
-
-using std::string;
-
-namespace pcrecpp {
-
-class StringPiece {
- private:
- const char* ptr_;
- int length_;
-
- public:
- // We provide non-explicit singleton constructors so users can pass
- // in a "const char*" or a "string" wherever a "StringPiece" is
- // expected.
- StringPiece()
- : ptr_(NULL), length_(0) { }
- StringPiece(const char* str)
- : ptr_(str), length_(static_cast<int>(strlen(str))) { }
- StringPiece(const string& str)
- : ptr_(str.data()), length_(static_cast<int>(str.size())) { }
- StringPiece(const char* offset, int len)
- : ptr_(offset), length_(len) { }
-
- // data() may return a pointer to a buffer with embedded NULs, and the
- // returned buffer may or may not be null terminated. Therefore it is
- // typically a mistake to pass data() to a routine that expects a NUL
- // terminated string. Use "as_string().c_str()" if you really need to do
- // this. Or better yet, change your routine so it does not rely on NUL
- // termination.
- const char* data() const { return ptr_; }
- int size() const { return length_; }
- bool empty() const { return length_ == 0; }
-
- void clear() { ptr_ = NULL; length_ = 0; }
- void set(const char* buffer, int len) { ptr_ = buffer; length_ = len; }
- void set(const char* str) {
- ptr_ = str;
- length_ = static_cast<int>(strlen(str));
- }
- void set(const void* buffer, int len) {
- ptr_ = reinterpret_cast<const char*>(buffer);
- length_ = len;
- }
-
- char operator[](int i) const { return ptr_[i]; }
-
- void remove_prefix(int n) {
- ptr_ += n;
- length_ -= n;
- }
-
- void remove_suffix(int n) {
- length_ -= n;
- }
-
- bool operator==(const StringPiece& x) const {
- return ((length_ == x.length_) &&
- (memcmp(ptr_, x.ptr_, length_) == 0));
- }
- bool operator!=(const StringPiece& x) const {
- return !(*this == x);
- }
-
-#define STRINGPIECE_BINARY_PREDICATE(cmp,auxcmp) \
- bool operator cmp (const StringPiece& x) const { \
- int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_); \
- return ((r auxcmp 0) || ((r == 0) && (length_ cmp x.length_))); \
- }
- STRINGPIECE_BINARY_PREDICATE(<, <);
- STRINGPIECE_BINARY_PREDICATE(<=, <);
- STRINGPIECE_BINARY_PREDICATE(>=, >);
- STRINGPIECE_BINARY_PREDICATE(>, >);
-#undef STRINGPIECE_BINARY_PREDICATE
-
- int compare(const StringPiece& x) const {
- int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_);
- if (r == 0) {
- if (length_ < x.length_) r = -1;
- else if (length_ > x.length_) r = +1;
- }
- return r;
- }
-
- string as_string() const {
- return string(data(), size());
- }
-
- void CopyToString(string* target) const {
- target->assign(ptr_, length_);
- }
-
- // Does "this" start with "x"
- bool starts_with(const StringPiece& x) const {
- return ((length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0));
- }
-};
-
-} // namespace pcrecpp
-
-// ------------------------------------------------------------------
-// Functions used to create STL containers that use StringPiece
-// Remember that a StringPiece's lifetime had better be less than
-// that of the underlying string or char*. If it is not, then you
-// cannot safely store a StringPiece into an STL container
-// ------------------------------------------------------------------
-
-#ifdef HAVE_TYPE_TRAITS
-// This makes vector<StringPiece> really fast for some STL implementations
-template<> struct __type_traits<pcrecpp::StringPiece> {
- typedef __true_type has_trivial_default_constructor;
- typedef __true_type has_trivial_copy_constructor;
- typedef __true_type has_trivial_assignment_operator;
- typedef __true_type has_trivial_destructor;
- typedef __true_type is_POD_type;
-};
-#endif
-
-// allow StringPiece to be logged
-std::ostream& operator<<(std::ostream& o, const pcrecpp::StringPiece& piece);
-
-#endif /* _PCRE_STRINGPIECE_H */
diff --git a/ext/pcre/pcrelib/pcre_stringpiece_unittest.cc b/ext/pcre/pcrelib/pcre_stringpiece_unittest.cc
deleted file mode 100644
index d6a89e8c7a..0000000000
--- a/ext/pcre/pcrelib/pcre_stringpiece_unittest.cc
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2003 and onwards Google Inc.
-// Author: Sanjay Ghemawat
-
-#include <stdio.h>
-#include <map>
-#include <algorithm> // for make_pair
-#include <pcre_stringpiece.h>
-
-// CHECK dies with a fatal error if condition is not true. It is *not*
-// controlled by NDEBUG, so the check will be executed regardless of
-// compilation mode. Therefore, it is safe to do things like:
-// CHECK(fp->Write(x) == 4)
-#define CHECK(condition) do { \
- if (!(condition)) { \
- fprintf(stderr, "%s:%d: Check failed: %s\n", \
- __FILE__, __LINE__, #condition); \
- exit(1); \
- } \
-} while (0)
-
-using std::map;
-using std::make_pair;
-using pcrecpp::StringPiece;
-
-static void CheckSTLComparator() {
- string s1("foo");
- string s2("bar");
- string s3("baz");
-
- StringPiece p1(s1);
- StringPiece p2(s2);
- StringPiece p3(s3);
-
- typedef map<StringPiece, int> TestMap;
- TestMap map;
-
- map.insert(make_pair(p1, 0));
- map.insert(make_pair(p2, 1));
- map.insert(make_pair(p3, 2));
- CHECK(map.size() == 3);
-
- TestMap::const_iterator iter = map.begin();
- CHECK(iter->second == 1);
- ++iter;
- CHECK(iter->second == 2);
- ++iter;
- CHECK(iter->second == 0);
- ++iter;
- CHECK(iter == map.end());
-
- TestMap::iterator new_iter = map.find("zot");
- CHECK(new_iter == map.end());
-
- new_iter = map.find("bar");
- CHECK(new_iter != map.end());
-
- map.erase(new_iter);
- CHECK(map.size() == 2);
-
- iter = map.begin();
- CHECK(iter->second == 2);
- ++iter;
- CHECK(iter->second == 0);
- ++iter;
- CHECK(iter == map.end());
-}
-
-static void CheckComparisonOperators() {
-#define CMP_Y(op, x, y) \
- CHECK( (StringPiece((x)) op StringPiece((y)))); \
- CHECK( (StringPiece((x)).compare(StringPiece((y))) op 0))
-
-#define CMP_N(op, x, y) \
- CHECK(!(StringPiece((x)) op StringPiece((y)))); \
- CHECK(!(StringPiece((x)).compare(StringPiece((y))) op 0))
-
- CMP_Y(==, "", "");
- CMP_Y(==, "a", "a");
- CMP_Y(==, "aa", "aa");
- CMP_N(==, "a", "");
- CMP_N(==, "", "a");
- CMP_N(==, "a", "b");
- CMP_N(==, "a", "aa");
- CMP_N(==, "aa", "a");
-
- CMP_N(!=, "", "");
- CMP_N(!=, "a", "a");
- CMP_N(!=, "aa", "aa");
- CMP_Y(!=, "a", "");
- CMP_Y(!=, "", "a");
- CMP_Y(!=, "a", "b");
- CMP_Y(!=, "a", "aa");
- CMP_Y(!=, "aa", "a");
-
- CMP_Y(<, "a", "b");
- CMP_Y(<, "a", "aa");
- CMP_Y(<, "aa", "b");
- CMP_Y(<, "aa", "bb");
- CMP_N(<, "a", "a");
- CMP_N(<, "b", "a");
- CMP_N(<, "aa", "a");
- CMP_N(<, "b", "aa");
- CMP_N(<, "bb", "aa");
-
- CMP_Y(<=, "a", "a");
- CMP_Y(<=, "a", "b");
- CMP_Y(<=, "a", "aa");
- CMP_Y(<=, "aa", "b");
- CMP_Y(<=, "aa", "bb");
- CMP_N(<=, "b", "a");
- CMP_N(<=, "aa", "a");
- CMP_N(<=, "b", "aa");
- CMP_N(<=, "bb", "aa");
-
- CMP_N(>=, "a", "b");
- CMP_N(>=, "a", "aa");
- CMP_N(>=, "aa", "b");
- CMP_N(>=, "aa", "bb");
- CMP_Y(>=, "a", "a");
- CMP_Y(>=, "b", "a");
- CMP_Y(>=, "aa", "a");
- CMP_Y(>=, "b", "aa");
- CMP_Y(>=, "bb", "aa");
-
- CMP_N(>, "a", "a");
- CMP_N(>, "a", "b");
- CMP_N(>, "a", "aa");
- CMP_N(>, "aa", "b");
- CMP_N(>, "aa", "bb");
- CMP_Y(>, "b", "a");
- CMP_Y(>, "aa", "a");
- CMP_Y(>, "b", "aa");
- CMP_Y(>, "bb", "aa");
-
-#undef CMP_Y
-#undef CMP_N
-}
-
-int main(int argc, char** argv) {
- CheckComparisonOperators();
- CheckSTLComparator();
-
- printf("OK\n");
- return 0;
-}
diff --git a/ext/pcre/pcrelib/pcre_study.c b/ext/pcre/pcrelib/pcre_study.c
index 87f8c6fb51..25d5e1786e 100644
--- a/ext/pcre/pcrelib/pcre_study.c
+++ b/ext/pcre/pcrelib/pcre_study.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
supporting functions. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -213,6 +215,13 @@ do
tcode += 1 + LINK_SIZE;
break;
+ /* SKIPZERO skips the bracket. */
+
+ case OP_SKIPZERO:
+ do tcode += GET(tcode,1); while (*tcode == OP_ALT);
+ tcode += 1 + LINK_SIZE;
+ break;
+
/* Single-char * or ? sets the bit and tries the next item */
case OP_STAR:
@@ -337,6 +346,7 @@ do
switch(tcode[1])
{
case OP_ANY:
+ case OP_ALLANY:
return SSB_FAIL;
case OP_NOT_DIGIT:
@@ -394,11 +404,13 @@ do
character with a value > 255. */
case OP_NCLASS:
+#ifdef SUPPORT_UTF8
if (utf8)
{
start_bits[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */
memset(start_bits+25, 0xff, 7); /* Bits for 0xc9 - 0xff */
}
+#endif
/* Fall through */
case OP_CLASS:
@@ -411,6 +423,7 @@ do
value is > 127. In fact, there are only two possible starting bytes for
characters in the range 128 - 255. */
+#ifdef SUPPORT_UTF8
if (utf8)
{
for (c = 0; c < 16; c++) start_bits[c] |= tcode[c];
@@ -428,6 +441,7 @@ do
/* In non-UTF-8 mode, the two bit maps are completely compatible. */
else
+#endif
{
for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];
}
@@ -487,7 +501,7 @@ Returns: pointer to a pcre_extra block, with study_data filled in and the
NULL on error or if no optimization possible
*/
-PCRE_DATA_SCOPE pcre_extra *
+PCRE_EXP_DEFN pcre_extra *
pcre_study(const pcre *external_re, int options, const char **errorptr)
{
uschar start_bits[32];
@@ -519,7 +533,8 @@ code = (uschar *)re + re->name_table_offset +
a multiline pattern that matches only at "line starts", no further processing
at present. */
-if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)
+if ((re->options & PCRE_ANCHORED) != 0 ||
+ (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)
return NULL;
/* Set the character tables in the block that is passed around */
diff --git a/ext/pcre/pcrelib/pcre_tables.c b/ext/pcre/pcrelib/pcre_tables.c
index 53690d7c9b..646ddb568a 100644
--- a/ext/pcre/pcrelib/pcre_tables.c
+++ b/ext/pcre/pcrelib/pcre_tables.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,8 @@ uses macros to change their names from _pcre_xxx to xxxx, thereby avoiding name
clashes with the library. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -61,6 +63,8 @@ const uschar _pcre_OP_lengths[] = { OP_LENGTHS };
/* These are the breakpoints for different numbers of bytes in a UTF-8
character. */
+#ifdef SUPPORT_UTF8
+
const int _pcre_utf8_table1[] =
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff};
@@ -81,117 +85,232 @@ const uschar _pcre_utf8_table4[] = {
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };
-/* This table translates Unicode property names into type and code values. It
-is searched by binary chop, so must be in collating sequence of name. */
+/* The pcre_utt[] table below translates Unicode property names into type and
+code values. It is searched by binary chop, so must be in collating sequence of
+name. Originally, the table contained pointers to the name strings in the first
+field of each entry. However, that leads to a large number of relocations when
+a shared library is dynamically loaded. A significant reduction is made by
+putting all the names into a single, large string and then using offsets in the
+table itself. Maintenance is more error-prone, but frequent changes to this
+data is unlikely. */
+
+const char _pcre_utt_names[] =
+ "Any\0"
+ "Arabic\0"
+ "Armenian\0"
+ "Balinese\0"
+ "Bengali\0"
+ "Bopomofo\0"
+ "Braille\0"
+ "Buginese\0"
+ "Buhid\0"
+ "C\0"
+ "Canadian_Aboriginal\0"
+ "Cc\0"
+ "Cf\0"
+ "Cherokee\0"
+ "Cn\0"
+ "Co\0"
+ "Common\0"
+ "Coptic\0"
+ "Cs\0"
+ "Cuneiform\0"
+ "Cypriot\0"
+ "Cyrillic\0"
+ "Deseret\0"
+ "Devanagari\0"
+ "Ethiopic\0"
+ "Georgian\0"
+ "Glagolitic\0"
+ "Gothic\0"
+ "Greek\0"
+ "Gujarati\0"
+ "Gurmukhi\0"
+ "Han\0"
+ "Hangul\0"
+ "Hanunoo\0"
+ "Hebrew\0"
+ "Hiragana\0"
+ "Inherited\0"
+ "Kannada\0"
+ "Katakana\0"
+ "Kharoshthi\0"
+ "Khmer\0"
+ "L\0"
+ "L&\0"
+ "Lao\0"
+ "Latin\0"
+ "Limbu\0"
+ "Linear_B\0"
+ "Ll\0"
+ "Lm\0"
+ "Lo\0"
+ "Lt\0"
+ "Lu\0"
+ "M\0"
+ "Malayalam\0"
+ "Mc\0"
+ "Me\0"
+ "Mn\0"
+ "Mongolian\0"
+ "Myanmar\0"
+ "N\0"
+ "Nd\0"
+ "New_Tai_Lue\0"
+ "Nko\0"
+ "Nl\0"
+ "No\0"
+ "Ogham\0"
+ "Old_Italic\0"
+ "Old_Persian\0"
+ "Oriya\0"
+ "Osmanya\0"
+ "P\0"
+ "Pc\0"
+ "Pd\0"
+ "Pe\0"
+ "Pf\0"
+ "Phags_Pa\0"
+ "Phoenician\0"
+ "Pi\0"
+ "Po\0"
+ "Ps\0"
+ "Runic\0"
+ "S\0"
+ "Sc\0"
+ "Shavian\0"
+ "Sinhala\0"
+ "Sk\0"
+ "Sm\0"
+ "So\0"
+ "Syloti_Nagri\0"
+ "Syriac\0"
+ "Tagalog\0"
+ "Tagbanwa\0"
+ "Tai_Le\0"
+ "Tamil\0"
+ "Telugu\0"
+ "Thaana\0"
+ "Thai\0"
+ "Tibetan\0"
+ "Tifinagh\0"
+ "Ugaritic\0"
+ "Yi\0"
+ "Z\0"
+ "Zl\0"
+ "Zp\0"
+ "Zs\0";
const ucp_type_table _pcre_utt[] = {
- { "Any", PT_ANY, 0 },
- { "Arabic", PT_SC, ucp_Arabic },
- { "Armenian", PT_SC, ucp_Armenian },
- { "Balinese", PT_SC, ucp_Balinese },
- { "Bengali", PT_SC, ucp_Bengali },
- { "Bopomofo", PT_SC, ucp_Bopomofo },
- { "Braille", PT_SC, ucp_Braille },
- { "Buginese", PT_SC, ucp_Buginese },
- { "Buhid", PT_SC, ucp_Buhid },
- { "C", PT_GC, ucp_C },
- { "Canadian_Aboriginal", PT_SC, ucp_Canadian_Aboriginal },
- { "Cc", PT_PC, ucp_Cc },
- { "Cf", PT_PC, ucp_Cf },
- { "Cherokee", PT_SC, ucp_Cherokee },
- { "Cn", PT_PC, ucp_Cn },
- { "Co", PT_PC, ucp_Co },
- { "Common", PT_SC, ucp_Common },
- { "Coptic", PT_SC, ucp_Coptic },
- { "Cs", PT_PC, ucp_Cs },
- { "Cuneiform", PT_SC, ucp_Cuneiform },
- { "Cypriot", PT_SC, ucp_Cypriot },
- { "Cyrillic", PT_SC, ucp_Cyrillic },
- { "Deseret", PT_SC, ucp_Deseret },
- { "Devanagari", PT_SC, ucp_Devanagari },
- { "Ethiopic", PT_SC, ucp_Ethiopic },
- { "Georgian", PT_SC, ucp_Georgian },
- { "Glagolitic", PT_SC, ucp_Glagolitic },
- { "Gothic", PT_SC, ucp_Gothic },
- { "Greek", PT_SC, ucp_Greek },
- { "Gujarati", PT_SC, ucp_Gujarati },
- { "Gurmukhi", PT_SC, ucp_Gurmukhi },
- { "Han", PT_SC, ucp_Han },
- { "Hangul", PT_SC, ucp_Hangul },
- { "Hanunoo", PT_SC, ucp_Hanunoo },
- { "Hebrew", PT_SC, ucp_Hebrew },
- { "Hiragana", PT_SC, ucp_Hiragana },
- { "Inherited", PT_SC, ucp_Inherited },
- { "Kannada", PT_SC, ucp_Kannada },
- { "Katakana", PT_SC, ucp_Katakana },
- { "Kharoshthi", PT_SC, ucp_Kharoshthi },
- { "Khmer", PT_SC, ucp_Khmer },
- { "L", PT_GC, ucp_L },
- { "L&", PT_LAMP, 0 },
- { "Lao", PT_SC, ucp_Lao },
- { "Latin", PT_SC, ucp_Latin },
- { "Limbu", PT_SC, ucp_Limbu },
- { "Linear_B", PT_SC, ucp_Linear_B },
- { "Ll", PT_PC, ucp_Ll },
- { "Lm", PT_PC, ucp_Lm },
- { "Lo", PT_PC, ucp_Lo },
- { "Lt", PT_PC, ucp_Lt },
- { "Lu", PT_PC, ucp_Lu },
- { "M", PT_GC, ucp_M },
- { "Malayalam", PT_SC, ucp_Malayalam },
- { "Mc", PT_PC, ucp_Mc },
- { "Me", PT_PC, ucp_Me },
- { "Mn", PT_PC, ucp_Mn },
- { "Mongolian", PT_SC, ucp_Mongolian },
- { "Myanmar", PT_SC, ucp_Myanmar },
- { "N", PT_GC, ucp_N },
- { "Nd", PT_PC, ucp_Nd },
- { "New_Tai_Lue", PT_SC, ucp_New_Tai_Lue },
- { "Nko", PT_SC, ucp_Nko },
- { "Nl", PT_PC, ucp_Nl },
- { "No", PT_PC, ucp_No },
- { "Ogham", PT_SC, ucp_Ogham },
- { "Old_Italic", PT_SC, ucp_Old_Italic },
- { "Old_Persian", PT_SC, ucp_Old_Persian },
- { "Oriya", PT_SC, ucp_Oriya },
- { "Osmanya", PT_SC, ucp_Osmanya },
- { "P", PT_GC, ucp_P },
- { "Pc", PT_PC, ucp_Pc },
- { "Pd", PT_PC, ucp_Pd },
- { "Pe", PT_PC, ucp_Pe },
- { "Pf", PT_PC, ucp_Pf },
- { "Phags_Pa", PT_SC, ucp_Phags_Pa },
- { "Phoenician", PT_SC, ucp_Phoenician },
- { "Pi", PT_PC, ucp_Pi },
- { "Po", PT_PC, ucp_Po },
- { "Ps", PT_PC, ucp_Ps },
- { "Runic", PT_SC, ucp_Runic },
- { "S", PT_GC, ucp_S },
- { "Sc", PT_PC, ucp_Sc },
- { "Shavian", PT_SC, ucp_Shavian },
- { "Sinhala", PT_SC, ucp_Sinhala },
- { "Sk", PT_PC, ucp_Sk },
- { "Sm", PT_PC, ucp_Sm },
- { "So", PT_PC, ucp_So },
- { "Syloti_Nagri", PT_SC, ucp_Syloti_Nagri },
- { "Syriac", PT_SC, ucp_Syriac },
- { "Tagalog", PT_SC, ucp_Tagalog },
- { "Tagbanwa", PT_SC, ucp_Tagbanwa },
- { "Tai_Le", PT_SC, ucp_Tai_Le },
- { "Tamil", PT_SC, ucp_Tamil },
- { "Telugu", PT_SC, ucp_Telugu },
- { "Thaana", PT_SC, ucp_Thaana },
- { "Thai", PT_SC, ucp_Thai },
- { "Tibetan", PT_SC, ucp_Tibetan },
- { "Tifinagh", PT_SC, ucp_Tifinagh },
- { "Ugaritic", PT_SC, ucp_Ugaritic },
- { "Yi", PT_SC, ucp_Yi },
- { "Z", PT_GC, ucp_Z },
- { "Zl", PT_PC, ucp_Zl },
- { "Zp", PT_PC, ucp_Zp },
- { "Zs", PT_PC, ucp_Zs }
+ { 0, PT_ANY, 0 },
+ { 4, PT_SC, ucp_Arabic },
+ { 11, PT_SC, ucp_Armenian },
+ { 20, PT_SC, ucp_Balinese },
+ { 29, PT_SC, ucp_Bengali },
+ { 37, PT_SC, ucp_Bopomofo },
+ { 46, PT_SC, ucp_Braille },
+ { 54, PT_SC, ucp_Buginese },
+ { 63, PT_SC, ucp_Buhid },
+ { 69, PT_GC, ucp_C },
+ { 71, PT_SC, ucp_Canadian_Aboriginal },
+ { 91, PT_PC, ucp_Cc },
+ { 94, PT_PC, ucp_Cf },
+ { 97, PT_SC, ucp_Cherokee },
+ { 106, PT_PC, ucp_Cn },
+ { 109, PT_PC, ucp_Co },
+ { 112, PT_SC, ucp_Common },
+ { 119, PT_SC, ucp_Coptic },
+ { 126, PT_PC, ucp_Cs },
+ { 129, PT_SC, ucp_Cuneiform },
+ { 139, PT_SC, ucp_Cypriot },
+ { 147, PT_SC, ucp_Cyrillic },
+ { 156, PT_SC, ucp_Deseret },
+ { 164, PT_SC, ucp_Devanagari },
+ { 175, PT_SC, ucp_Ethiopic },
+ { 184, PT_SC, ucp_Georgian },
+ { 193, PT_SC, ucp_Glagolitic },
+ { 204, PT_SC, ucp_Gothic },
+ { 211, PT_SC, ucp_Greek },
+ { 217, PT_SC, ucp_Gujarati },
+ { 226, PT_SC, ucp_Gurmukhi },
+ { 235, PT_SC, ucp_Han },
+ { 239, PT_SC, ucp_Hangul },
+ { 246, PT_SC, ucp_Hanunoo },
+ { 254, PT_SC, ucp_Hebrew },
+ { 261, PT_SC, ucp_Hiragana },
+ { 270, PT_SC, ucp_Inherited },
+ { 280, PT_SC, ucp_Kannada },
+ { 288, PT_SC, ucp_Katakana },
+ { 297, PT_SC, ucp_Kharoshthi },
+ { 308, PT_SC, ucp_Khmer },
+ { 314, PT_GC, ucp_L },
+ { 316, PT_LAMP, 0 },
+ { 319, PT_SC, ucp_Lao },
+ { 323, PT_SC, ucp_Latin },
+ { 329, PT_SC, ucp_Limbu },
+ { 335, PT_SC, ucp_Linear_B },
+ { 344, PT_PC, ucp_Ll },
+ { 347, PT_PC, ucp_Lm },
+ { 350, PT_PC, ucp_Lo },
+ { 353, PT_PC, ucp_Lt },
+ { 356, PT_PC, ucp_Lu },
+ { 359, PT_GC, ucp_M },
+ { 361, PT_SC, ucp_Malayalam },
+ { 371, PT_PC, ucp_Mc },
+ { 374, PT_PC, ucp_Me },
+ { 377, PT_PC, ucp_Mn },
+ { 380, PT_SC, ucp_Mongolian },
+ { 390, PT_SC, ucp_Myanmar },
+ { 398, PT_GC, ucp_N },
+ { 400, PT_PC, ucp_Nd },
+ { 403, PT_SC, ucp_New_Tai_Lue },
+ { 415, PT_SC, ucp_Nko },
+ { 419, PT_PC, ucp_Nl },
+ { 422, PT_PC, ucp_No },
+ { 425, PT_SC, ucp_Ogham },
+ { 431, PT_SC, ucp_Old_Italic },
+ { 442, PT_SC, ucp_Old_Persian },
+ { 454, PT_SC, ucp_Oriya },
+ { 460, PT_SC, ucp_Osmanya },
+ { 468, PT_GC, ucp_P },
+ { 470, PT_PC, ucp_Pc },
+ { 473, PT_PC, ucp_Pd },
+ { 476, PT_PC, ucp_Pe },
+ { 479, PT_PC, ucp_Pf },
+ { 482, PT_SC, ucp_Phags_Pa },
+ { 491, PT_SC, ucp_Phoenician },
+ { 502, PT_PC, ucp_Pi },
+ { 505, PT_PC, ucp_Po },
+ { 508, PT_PC, ucp_Ps },
+ { 511, PT_SC, ucp_Runic },
+ { 517, PT_GC, ucp_S },
+ { 519, PT_PC, ucp_Sc },
+ { 522, PT_SC, ucp_Shavian },
+ { 530, PT_SC, ucp_Sinhala },
+ { 538, PT_PC, ucp_Sk },
+ { 541, PT_PC, ucp_Sm },
+ { 544, PT_PC, ucp_So },
+ { 547, PT_SC, ucp_Syloti_Nagri },
+ { 560, PT_SC, ucp_Syriac },
+ { 567, PT_SC, ucp_Tagalog },
+ { 575, PT_SC, ucp_Tagbanwa },
+ { 584, PT_SC, ucp_Tai_Le },
+ { 591, PT_SC, ucp_Tamil },
+ { 597, PT_SC, ucp_Telugu },
+ { 604, PT_SC, ucp_Thaana },
+ { 611, PT_SC, ucp_Thai },
+ { 616, PT_SC, ucp_Tibetan },
+ { 624, PT_SC, ucp_Tifinagh },
+ { 633, PT_SC, ucp_Ugaritic },
+ { 642, PT_SC, ucp_Yi },
+ { 645, PT_GC, ucp_Z },
+ { 647, PT_PC, ucp_Zl },
+ { 650, PT_PC, ucp_Zp },
+ { 653, PT_PC, ucp_Zs }
};
const int _pcre_utt_size = sizeof(_pcre_utt)/sizeof(ucp_type_table);
+#endif /* SUPPORT_UTF8 */
+
/* End of pcre_tables.c */
diff --git a/ext/pcre/pcrelib/pcre_try_flipped.c b/ext/pcre/pcrelib/pcre_try_flipped.c
index 00c94fccf5..5e67943cc0 100644
--- a/ext/pcre/pcrelib/pcre_try_flipped.c
+++ b/ext/pcre/pcrelib/pcre_try_flipped.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@ see if it was compiled with the opposite endianness. If so, it uses an
auxiliary local function to flip the appropriate bytes. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -104,6 +106,7 @@ if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER)
*internal_re = *re; /* To copy other fields */
internal_re->size = byteflip(re->size, sizeof(re->size));
internal_re->options = byteflip(re->options, sizeof(re->options));
+internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags));
internal_re->top_bracket =
(pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket));
internal_re->top_backref =
diff --git a/ext/pcre/pcrelib/pcre_ucp_searchfuncs.c b/ext/pcre/pcrelib/pcre_ucp_searchfuncs.c
index 20bb7be832..668ae154de 100644
--- a/ext/pcre/pcrelib/pcre_ucp_searchfuncs.c
+++ b/ext/pcre/pcrelib/pcre_ucp_searchfuncs.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -41,16 +41,18 @@ POSSIBILITY OF SUCH DAMAGE.
/* This module contains code for searching the table of Unicode character
properties. */
+#include "config.h"
+
#include "pcre_internal.h"
#include "ucp.h" /* Category definitions */
#include "ucpinternal.h" /* Internal table details */
-#include "ucptable.c" /* The table itself */
+#include "ucptable.h" /* The table itself */
/* Table to translate from particular type value to the general value. */
-static int ucp_gentype[] = {
+static const int ucp_gentype[] = {
ucp_C, ucp_C, ucp_C, ucp_C, ucp_C, /* Cc, Cf, Cn, Co, Cs */
ucp_L, ucp_L, ucp_L, ucp_L, ucp_L, /* Ll, Lu, Lm, Lo, Lt */
ucp_M, ucp_M, ucp_M, /* Mc, Me, Mn */
diff --git a/ext/pcre/pcrelib/pcre_valid_utf8.c b/ext/pcre/pcrelib/pcre_valid_utf8.c
index 727fbe8d0a..6b341c195e 100644
--- a/ext/pcre/pcrelib/pcre_valid_utf8.c
+++ b/ext/pcre/pcrelib/pcre_valid_utf8.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
strings. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -55,6 +57,13 @@ that subsequent code can assume it is dealing with a valid string. The check
can be turned off for maximum performance, but the consequences of supplying
an invalid string are then undefined.
+Originally, this function checked according to RFC 2279, allowing for values in
+the range 0 to 0x7fffffff, up to 6 bytes long, but ensuring that they were in
+the canonical format. Once somebody had pointed out RFC 3629 to me (it
+obsoletes 2279), additional restrictions were applied. The values are now
+limited to be between 0 and 0x0010ffff, no more than 4 bytes long, and the
+subrange 0xd000 to 0xdfff is excluded.
+
Arguments:
string points to the string
length length of string, or -1 if the string is zero-terminated
@@ -66,6 +75,7 @@ Returns: < 0 if the string is a valid UTF-8 string
int
_pcre_valid_utf8(const uschar *string, int length)
{
+#ifdef SUPPORT_UTF8
register const uschar *p;
if (length < 0)
@@ -80,31 +90,48 @@ for (p = string; length-- > 0; p++)
register int c = *p;
if (c < 128) continue;
if (c < 0xc0) return p - string;
- ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */
- if (length < ab) return p - string;
+ ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */
+ if (length < ab || ab > 3) return p - string;
length -= ab;
/* Check top bits in the second byte */
if ((*(++p) & 0xc0) != 0x80) return p - string;
- /* Check for overlong sequences for each different length */
+ /* Check for overlong sequences for each different length, and for the
+ excluded range 0xd000 to 0xdfff. */
+
switch (ab)
{
- /* Check for xx00 000x */
+ /* Check for xx00 000x (overlong sequence) */
+
case 1:
if ((c & 0x3e) == 0) return p - string;
continue; /* We know there aren't any more bytes to check */
- /* Check for 1110 0000, xx0x xxxx */
+ /* Check for 1110 0000, xx0x xxxx (overlong sequence) or
+ 1110 1101, 1010 xxxx (0xd000 - 0xdfff) */
+
case 2:
- if (c == 0xe0 && (*p & 0x20) == 0) return p - string;
+ if ((c == 0xe0 && (*p & 0x20) == 0) ||
+ (c == 0xed && *p >= 0xa0))
+ return p - string;
break;
- /* Check for 1111 0000, xx00 xxxx */
+ /* Check for 1111 0000, xx00 xxxx (overlong sequence) or
+ greater than 0x0010ffff (f4 8f bf bf) */
+
case 3:
- if (c == 0xf0 && (*p & 0x30) == 0) return p - string;
+ if ((c == 0xf0 && (*p & 0x30) == 0) ||
+ (c > 0xf4 ) ||
+ (c == 0xf4 && *p > 0x8f))
+ return p - string;
break;
+#if 0
+ /* These cases can no longer occur, as we restrict to a maximum of four
+ bytes nowadays. Leave the code here in case we ever want to add an option
+ for longer sequences. */
+
/* Check for 1111 1000, xx00 0xxx */
case 4:
if (c == 0xf8 && (*p & 0x38) == 0) return p - string;
@@ -115,6 +142,8 @@ for (p = string; length-- > 0; p++)
if (c == 0xfe || c == 0xff ||
(c == 0xfc && (*p & 0x3c) == 0)) return p - string;
break;
+#endif
+
}
/* Check for valid bytes after the 2nd, if any; all must start 10 */
@@ -123,6 +152,7 @@ for (p = string; length-- > 0; p++)
if ((*(++p) & 0xc0) != 0x80) return p - string;
}
}
+#endif
return -1;
}
diff --git a/ext/pcre/pcrelib/pcre_version.c b/ext/pcre/pcrelib/pcre_version.c
index 9edf3e013e..36ee93e716 100644
--- a/ext/pcre/pcrelib/pcre_version.c
+++ b/ext/pcre/pcrelib/pcre_version.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE.
string that identifies the PCRE version that is in use. */
+#include "config.h"
+
#include "pcre_internal.h"
@@ -75,7 +77,7 @@ I could find no way of detecting that a macro is defined as an empty string at
pre-processor time. This hack uses a standard trick for avoiding calling
the STRING macro with an empty argument when doing the test. */
-PCRE_DATA_SCOPE const char *
+PCRE_EXP_DEFN const char *
pcre_version(void)
{
return (XSTRING(Z PCRE_PRERELEASE)[1] == 0)?
diff --git a/ext/pcre/pcrelib/pcre_xclass.c b/ext/pcre/pcrelib/pcre_xclass.c
index 57c514b78a..d22d9e6488 100644
--- a/ext/pcre/pcrelib/pcre_xclass.c
+++ b/ext/pcre/pcrelib/pcre_xclass.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@ class (one that contains characters whose values are > 255). It is used by both
pcre_exec() and pcre_def_exec(). */
+#include "config.h"
+
#include "pcre_internal.h"
diff --git a/ext/pcre/pcrelib/pcrecpp.cc b/ext/pcre/pcrelib/pcrecpp.cc
deleted file mode 100644
index b75738b36c..0000000000
--- a/ext/pcre/pcrelib/pcrecpp.cc
+++ /dev/null
@@ -1,857 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <limits.h> /* for SHRT_MIN, USHRT_MAX, etc */
-#include <assert.h>
-#include <errno.h>
-#include <string>
-#include <algorithm>
-#include "config.h"
-// We need this to compile the proper dll on windows/msys. This is copied
-// from pcre_internal.h. It would probably be better just to include that.
-#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */
-#include "pcre.h"
-#include "pcre_stringpiece.h"
-#include "pcrecpp.h"
-
-
-namespace pcrecpp {
-
-// Maximum number of args we can set
-static const int kMaxArgs = 16;
-static const int kVecSize = (1 + kMaxArgs) * 3; // results + PCRE workspace
-
-// Special object that stands-in for no argument
-Arg no_arg((void*)NULL);
-
-// If a regular expression has no error, its error_ field points here
-static const string empty_string;
-
-// If the user doesn't ask for any options, we just use this one
-static RE_Options default_options;
-
-void RE::Init(const string& pat, const RE_Options* options) {
- pattern_ = pat;
- if (options == NULL) {
- options_ = default_options;
- } else {
- options_ = *options;
- }
- error_ = &empty_string;
- re_full_ = NULL;
- re_partial_ = NULL;
-
- re_partial_ = Compile(UNANCHORED);
- if (re_partial_ != NULL) {
- // Check for complicated patterns. The following change is
- // conservative in that it may treat some "simple" patterns
- // as "complex" (e.g., if the vertical bar is in a character
- // class or is escaped). But it seems good enough.
- if (strchr(pat.c_str(), '|') == NULL) {
- // Simple pattern: we can use position-based checks to perform
- // fully anchored matches
- re_full_ = re_partial_;
- } else {
- // We need a special pattern for anchored matches
- re_full_ = Compile(ANCHOR_BOTH);
- }
- }
-}
-
-void RE::Cleanup() {
- if (re_full_ != NULL && re_full_ != re_partial_) (*pcre_free)(re_full_);
- if (re_partial_ != NULL) (*pcre_free)(re_partial_);
- if (error_ != &empty_string) delete error_;
-}
-
-
-RE::~RE() {
- Cleanup();
-}
-
-
-pcre* RE::Compile(Anchor anchor) {
- // First, convert RE_Options into pcre options
- int pcre_options = 0;
- pcre_options = options_.all_options();
-
- // Special treatment for anchoring. This is needed because at
- // runtime pcre only provides an option for anchoring at the
- // beginning of a string (unless you use offset).
- //
- // There are three types of anchoring we want:
- // UNANCHORED Compile the original pattern, and use
- // a pcre unanchored match.
- // ANCHOR_START Compile the original pattern, and use
- // a pcre anchored match.
- // ANCHOR_BOTH Tack a "\z" to the end of the original pattern
- // and use a pcre anchored match.
-
- const char* compile_error;
- int eoffset;
- pcre* re;
- if (anchor != ANCHOR_BOTH) {
- re = pcre_compile(pattern_.c_str(), pcre_options,
- &compile_error, &eoffset, NULL);
- } else {
- // Tack a '\z' at the end of RE. Parenthesize it first so that
- // the '\z' applies to all top-level alternatives in the regexp.
- string wrapped = "(?:"; // A non-counting grouping operator
- wrapped += pattern_;
- wrapped += ")\\z";
- re = pcre_compile(wrapped.c_str(), pcre_options,
- &compile_error, &eoffset, NULL);
- }
- if (re == NULL) {
- if (error_ == &empty_string) error_ = new string(compile_error);
- }
- return re;
-}
-
-/***** Matching interfaces *****/
-
-bool RE::FullMatch(const StringPiece& text,
- const Arg& ptr1,
- const Arg& ptr2,
- const Arg& ptr3,
- const Arg& ptr4,
- const Arg& ptr5,
- const Arg& ptr6,
- const Arg& ptr7,
- const Arg& ptr8,
- const Arg& ptr9,
- const Arg& ptr10,
- const Arg& ptr11,
- const Arg& ptr12,
- const Arg& ptr13,
- const Arg& ptr14,
- const Arg& ptr15,
- const Arg& ptr16) const {
- const Arg* args[kMaxArgs];
- int n = 0;
- if (&ptr1 == &no_arg) goto done; args[n++] = &ptr1;
- if (&ptr2 == &no_arg) goto done; args[n++] = &ptr2;
- if (&ptr3 == &no_arg) goto done; args[n++] = &ptr3;
- if (&ptr4 == &no_arg) goto done; args[n++] = &ptr4;
- if (&ptr5 == &no_arg) goto done; args[n++] = &ptr5;
- if (&ptr6 == &no_arg) goto done; args[n++] = &ptr6;
- if (&ptr7 == &no_arg) goto done; args[n++] = &ptr7;
- if (&ptr8 == &no_arg) goto done; args[n++] = &ptr8;
- if (&ptr9 == &no_arg) goto done; args[n++] = &ptr9;
- if (&ptr10 == &no_arg) goto done; args[n++] = &ptr10;
- if (&ptr11 == &no_arg) goto done; args[n++] = &ptr11;
- if (&ptr12 == &no_arg) goto done; args[n++] = &ptr12;
- if (&ptr13 == &no_arg) goto done; args[n++] = &ptr13;
- if (&ptr14 == &no_arg) goto done; args[n++] = &ptr14;
- if (&ptr15 == &no_arg) goto done; args[n++] = &ptr15;
- if (&ptr16 == &no_arg) goto done; args[n++] = &ptr16;
- done:
-
- int consumed;
- int vec[kVecSize];
- return DoMatchImpl(text, ANCHOR_BOTH, &consumed, args, n, vec, kVecSize);
-}
-
-bool RE::PartialMatch(const StringPiece& text,
- const Arg& ptr1,
- const Arg& ptr2,
- const Arg& ptr3,
- const Arg& ptr4,
- const Arg& ptr5,
- const Arg& ptr6,
- const Arg& ptr7,
- const Arg& ptr8,
- const Arg& ptr9,
- const Arg& ptr10,
- const Arg& ptr11,
- const Arg& ptr12,
- const Arg& ptr13,
- const Arg& ptr14,
- const Arg& ptr15,
- const Arg& ptr16) const {
- const Arg* args[kMaxArgs];
- int n = 0;
- if (&ptr1 == &no_arg) goto done; args[n++] = &ptr1;
- if (&ptr2 == &no_arg) goto done; args[n++] = &ptr2;
- if (&ptr3 == &no_arg) goto done; args[n++] = &ptr3;
- if (&ptr4 == &no_arg) goto done; args[n++] = &ptr4;
- if (&ptr5 == &no_arg) goto done; args[n++] = &ptr5;
- if (&ptr6 == &no_arg) goto done; args[n++] = &ptr6;
- if (&ptr7 == &no_arg) goto done; args[n++] = &ptr7;
- if (&ptr8 == &no_arg) goto done; args[n++] = &ptr8;
- if (&ptr9 == &no_arg) goto done; args[n++] = &ptr9;
- if (&ptr10 == &no_arg) goto done; args[n++] = &ptr10;
- if (&ptr11 == &no_arg) goto done; args[n++] = &ptr11;
- if (&ptr12 == &no_arg) goto done; args[n++] = &ptr12;
- if (&ptr13 == &no_arg) goto done; args[n++] = &ptr13;
- if (&ptr14 == &no_arg) goto done; args[n++] = &ptr14;
- if (&ptr15 == &no_arg) goto done; args[n++] = &ptr15;
- if (&ptr16 == &no_arg) goto done; args[n++] = &ptr16;
- done:
-
- int consumed;
- int vec[kVecSize];
- return DoMatchImpl(text, UNANCHORED, &consumed, args, n, vec, kVecSize);
-}
-
-bool RE::Consume(StringPiece* input,
- const Arg& ptr1,
- const Arg& ptr2,
- const Arg& ptr3,
- const Arg& ptr4,
- const Arg& ptr5,
- const Arg& ptr6,
- const Arg& ptr7,
- const Arg& ptr8,
- const Arg& ptr9,
- const Arg& ptr10,
- const Arg& ptr11,
- const Arg& ptr12,
- const Arg& ptr13,
- const Arg& ptr14,
- const Arg& ptr15,
- const Arg& ptr16) const {
- const Arg* args[kMaxArgs];
- int n = 0;
- if (&ptr1 == &no_arg) goto done; args[n++] = &ptr1;
- if (&ptr2 == &no_arg) goto done; args[n++] = &ptr2;
- if (&ptr3 == &no_arg) goto done; args[n++] = &ptr3;
- if (&ptr4 == &no_arg) goto done; args[n++] = &ptr4;
- if (&ptr5 == &no_arg) goto done; args[n++] = &ptr5;
- if (&ptr6 == &no_arg) goto done; args[n++] = &ptr6;
- if (&ptr7 == &no_arg) goto done; args[n++] = &ptr7;
- if (&ptr8 == &no_arg) goto done; args[n++] = &ptr8;
- if (&ptr9 == &no_arg) goto done; args[n++] = &ptr9;
- if (&ptr10 == &no_arg) goto done; args[n++] = &ptr10;
- if (&ptr11 == &no_arg) goto done; args[n++] = &ptr11;
- if (&ptr12 == &no_arg) goto done; args[n++] = &ptr12;
- if (&ptr13 == &no_arg) goto done; args[n++] = &ptr13;
- if (&ptr14 == &no_arg) goto done; args[n++] = &ptr14;
- if (&ptr15 == &no_arg) goto done; args[n++] = &ptr15;
- if (&ptr16 == &no_arg) goto done; args[n++] = &ptr16;
- done:
-
- int consumed;
- int vec[kVecSize];
- if (DoMatchImpl(*input, ANCHOR_START, &consumed,
- args, n, vec, kVecSize)) {
- input->remove_prefix(consumed);
- return true;
- } else {
- return false;
- }
-}
-
-bool RE::FindAndConsume(StringPiece* input,
- const Arg& ptr1,
- const Arg& ptr2,
- const Arg& ptr3,
- const Arg& ptr4,
- const Arg& ptr5,
- const Arg& ptr6,
- const Arg& ptr7,
- const Arg& ptr8,
- const Arg& ptr9,
- const Arg& ptr10,
- const Arg& ptr11,
- const Arg& ptr12,
- const Arg& ptr13,
- const Arg& ptr14,
- const Arg& ptr15,
- const Arg& ptr16) const {
- const Arg* args[kMaxArgs];
- int n = 0;
- if (&ptr1 == &no_arg) goto done; args[n++] = &ptr1;
- if (&ptr2 == &no_arg) goto done; args[n++] = &ptr2;
- if (&ptr3 == &no_arg) goto done; args[n++] = &ptr3;
- if (&ptr4 == &no_arg) goto done; args[n++] = &ptr4;
- if (&ptr5 == &no_arg) goto done; args[n++] = &ptr5;
- if (&ptr6 == &no_arg) goto done; args[n++] = &ptr6;
- if (&ptr7 == &no_arg) goto done; args[n++] = &ptr7;
- if (&ptr8 == &no_arg) goto done; args[n++] = &ptr8;
- if (&ptr9 == &no_arg) goto done; args[n++] = &ptr9;
- if (&ptr10 == &no_arg) goto done; args[n++] = &ptr10;
- if (&ptr11 == &no_arg) goto done; args[n++] = &ptr11;
- if (&ptr12 == &no_arg) goto done; args[n++] = &ptr12;
- if (&ptr13 == &no_arg) goto done; args[n++] = &ptr13;
- if (&ptr14 == &no_arg) goto done; args[n++] = &ptr14;
- if (&ptr15 == &no_arg) goto done; args[n++] = &ptr15;
- if (&ptr16 == &no_arg) goto done; args[n++] = &ptr16;
- done:
-
- int consumed;
- int vec[kVecSize];
- if (DoMatchImpl(*input, UNANCHORED, &consumed,
- args, n, vec, kVecSize)) {
- input->remove_prefix(consumed);
- return true;
- } else {
- return false;
- }
-}
-
-bool RE::Replace(const StringPiece& rewrite,
- string *str) const {
- int vec[kVecSize];
- int matches = TryMatch(*str, 0, UNANCHORED, vec, kVecSize);
- if (matches == 0)
- return false;
-
- string s;
- if (!Rewrite(&s, rewrite, *str, vec, matches))
- return false;
-
- assert(vec[0] >= 0);
- assert(vec[1] >= 0);
- str->replace(vec[0], vec[1] - vec[0], s);
- return true;
-}
-
-// Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF.
-// Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF.
-static int NewlineMode(int pcre_options) {
- // TODO: if we can make it threadsafe, cache this var
- int newline_mode = 0;
- /* if (newline_mode) return newline_mode; */ // do this once it's cached
- if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)) {
- newline_mode = (pcre_options &
- (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF));
- } else {
- int newline;
- pcre_config(PCRE_CONFIG_NEWLINE, &newline);
- if (newline == 10)
- newline_mode = PCRE_NEWLINE_LF;
- else if (newline == 13)
- newline_mode = PCRE_NEWLINE_CR;
- else if (newline == 3338)
- newline_mode = PCRE_NEWLINE_CRLF;
- else
- assert("" == "Unexpected return value from pcre_config(NEWLINE)");
- }
- return newline_mode;
-}
-
-int RE::GlobalReplace(const StringPiece& rewrite,
- string *str) const {
- int count = 0;
- int vec[kVecSize];
- string out;
- int start = 0;
- int lastend = -1;
-
- for (; start <= static_cast<int>(str->length()); count++) {
- int matches = TryMatch(*str, start, UNANCHORED, vec, kVecSize);
- if (matches <= 0)
- break;
- int matchstart = vec[0], matchend = vec[1];
- assert(matchstart >= start);
- assert(matchend >= matchstart);
- if (matchstart == matchend && matchstart == lastend) {
- // advance one character if we matched an empty string at the same
- // place as the last match occurred
- matchend = start + 1;
- // If the current char is CR and we're in CRLF mode, skip LF too.
- // Note it's better to call pcre_fullinfo() than to examine
- // all_options(), since options_ could have changed bewteen
- // compile-time and now, but this is simpler and safe enough.
- if (start+1 < static_cast<int>(str->length()) &&
- (*str)[start] == '\r' && (*str)[start+1] == '\n' &&
- NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF) {
- matchend++;
- }
- // We also need to advance more than one char if we're in utf8 mode.
-#ifdef SUPPORT_UTF8
- if (options_.utf8()) {
- while (matchend < static_cast<int>(str->length()) &&
- ((*str)[matchend] & 0xc0) == 0x80)
- matchend++;
- }
-#endif
- if (matchend <= static_cast<int>(str->length()))
- out.append(*str, start, matchend - start);
- start = matchend;
- } else {
- out.append(*str, start, matchstart - start);
- Rewrite(&out, rewrite, *str, vec, matches);
- start = matchend;
- lastend = matchend;
- count++;
- }
- }
-
- if (count == 0)
- return 0;
-
- if (start < static_cast<int>(str->length()))
- out.append(*str, start, str->length() - start);
- swap(out, *str);
- return count;
-}
-
-bool RE::Extract(const StringPiece& rewrite,
- const StringPiece& text,
- string *out) const {
- int vec[kVecSize];
- int matches = TryMatch(text, 0, UNANCHORED, vec, kVecSize);
- if (matches == 0)
- return false;
- out->erase();
- return Rewrite(out, rewrite, text, vec, matches);
-}
-
-/*static*/ string RE::QuoteMeta(const StringPiece& unquoted) {
- string result;
-
- // Escape any ascii character not in [A-Za-z_0-9].
- //
- // Note that it's legal to escape a character even if it has no
- // special meaning in a regular expression -- so this function does
- // that. (This also makes it identical to the perl function of the
- // same name; see `perldoc -f quotemeta`.)
- for (int ii = 0; ii < unquoted.size(); ++ii) {
- // Note that using 'isalnum' here raises the benchmark time from
- // 32ns to 58ns:
- if ((unquoted[ii] < 'a' || unquoted[ii] > 'z') &&
- (unquoted[ii] < 'A' || unquoted[ii] > 'Z') &&
- (unquoted[ii] < '0' || unquoted[ii] > '9') &&
- unquoted[ii] != '_' &&
- // If this is the part of a UTF8 or Latin1 character, we need
- // to copy this byte without escaping. Experimentally this is
- // what works correctly with the regexp library.
- !(unquoted[ii] & 128)) {
- result += '\\';
- }
- result += unquoted[ii];
- }
-
- return result;
-}
-
-/***** Actual matching and rewriting code *****/
-
-int RE::TryMatch(const StringPiece& text,
- int startpos,
- Anchor anchor,
- int *vec,
- int vecsize) const {
- pcre* re = (anchor == ANCHOR_BOTH) ? re_full_ : re_partial_;
- if (re == NULL) {
- //fprintf(stderr, "Matching against invalid re: %s\n", error_->c_str());
- return 0;
- }
-
- pcre_extra extra = { 0 };
- if (options_.match_limit() > 0) {
- extra.flags |= PCRE_EXTRA_MATCH_LIMIT;
- extra.match_limit = options_.match_limit();
- }
- if (options_.match_limit_recursion() > 0) {
- extra.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
- extra.match_limit_recursion = options_.match_limit_recursion();
- }
- int rc = pcre_exec(re, // The regular expression object
- &extra,
- (text.data() == NULL) ? "" : text.data(),
- text.size(),
- startpos,
- (anchor == UNANCHORED) ? 0 : PCRE_ANCHORED,
- vec,
- vecsize);
-
- // Handle errors
- if (rc == PCRE_ERROR_NOMATCH) {
- return 0;
- } else if (rc < 0) {
- //fprintf(stderr, "Unexpected return code: %d when matching '%s'\n",
- // re, pattern_.c_str());
- return 0;
- } else if (rc == 0) {
- // pcre_exec() returns 0 as a special case when the number of
- // capturing subpatterns exceeds the size of the vector.
- // When this happens, there is a match and the output vector
- // is filled, but we miss out on the positions of the extra subpatterns.
- rc = vecsize / 2;
- }
-
- if ((anchor == ANCHOR_BOTH) && (re_full_ == re_partial_)) {
- // We need an extra check to make sure that the match extended
- // to the end of the input string
- assert(vec[0] == 0); // PCRE_ANCHORED forces starting match
- if (vec[1] != text.size()) return 0; // Did not get ending match
- }
-
- return rc;
-}
-
-bool RE::DoMatchImpl(const StringPiece& text,
- Anchor anchor,
- int* consumed,
- const Arg* const* args,
- int n,
- int* vec,
- int vecsize) const {
- assert((1 + n) * 3 <= vecsize); // results + PCRE workspace
- int matches = TryMatch(text, 0, anchor, vec, vecsize);
- assert(matches >= 0); // TryMatch never returns negatives
- if (matches == 0)
- return false;
-
- *consumed = vec[1];
-
- if (n == 0 || args == NULL) {
- // We are not interested in results
- return true;
- }
-
- if (NumberOfCapturingGroups() < n) {
- // RE has fewer capturing groups than number of arg pointers passed in
- return false;
- }
-
- // If we got here, we must have matched the whole pattern.
- // We do not need (can not do) any more checks on the value of 'matches' here
- // -- see the comment for TryMatch.
- for (int i = 0; i < n; i++) {
- const int start = vec[2*(i+1)];
- const int limit = vec[2*(i+1)+1];
- if (!args[i]->Parse(text.data() + start, limit-start)) {
- // TODO: Should we indicate what the error was?
- return false;
- }
- }
-
- return true;
-}
-
-bool RE::DoMatch(const StringPiece& text,
- Anchor anchor,
- int* consumed,
- const Arg* const args[],
- int n) const {
- assert(n >= 0);
- size_t const vecsize = (1 + n) * 3; // results + PCRE workspace
- // (as for kVecSize)
- int space[21]; // use stack allocation for small vecsize (common case)
- int* vec = vecsize <= 21 ? space : new int[vecsize];
- bool retval = DoMatchImpl(text, anchor, consumed, args, n, vec, vecsize);
- if (vec != space) delete [] vec;
- return retval;
-}
-
-bool RE::Rewrite(string *out, const StringPiece &rewrite,
- const StringPiece &text, int *vec, int veclen) const {
- for (const char *s = rewrite.data(), *end = s + rewrite.size();
- s < end; s++) {
- int c = *s;
- if (c == '\\') {
- c = *++s;
- if (isdigit(c)) {
- int n = (c - '0');
- if (n >= veclen) {
- //fprintf(stderr, requested group %d in regexp %.*s\n",
- // n, rewrite.size(), rewrite.data());
- return false;
- }
- int start = vec[2 * n];
- if (start >= 0)
- out->append(text.data() + start, vec[2 * n + 1] - start);
- } else if (c == '\\') {
- out->push_back('\\');
- } else {
- //fprintf(stderr, "invalid rewrite pattern: %.*s\n",
- // rewrite.size(), rewrite.data());
- return false;
- }
- } else {
- out->push_back(c);
- }
- }
- return true;
-}
-
-// Return the number of capturing subpatterns, or -1 if the
-// regexp wasn't valid on construction.
-int RE::NumberOfCapturingGroups() const {
- if (re_partial_ == NULL) return -1;
-
- int result;
- int pcre_retval = pcre_fullinfo(re_partial_, // The regular expression object
- NULL, // We did not study the pattern
- PCRE_INFO_CAPTURECOUNT,
- &result);
- assert(pcre_retval == 0);
- return result;
-}
-
-/***** Parsers for various types *****/
-
-bool Arg::parse_null(const char* str, int n, void* dest) {
- // We fail if somebody asked us to store into a non-NULL void* pointer
- return (dest == NULL);
-}
-
-bool Arg::parse_string(const char* str, int n, void* dest) {
- reinterpret_cast<string*>(dest)->assign(str, n);
- return true;
-}
-
-bool Arg::parse_stringpiece(const char* str, int n, void* dest) {
- reinterpret_cast<StringPiece*>(dest)->set(str, n);
- return true;
-}
-
-bool Arg::parse_char(const char* str, int n, void* dest) {
- if (n != 1) return false;
- *(reinterpret_cast<char*>(dest)) = str[0];
- return true;
-}
-
-bool Arg::parse_uchar(const char* str, int n, void* dest) {
- if (n != 1) return false;
- *(reinterpret_cast<unsigned char*>(dest)) = str[0];
- return true;
-}
-
-// Largest number spec that we are willing to parse
-static const int kMaxNumberLength = 32;
-
-// REQUIRES "buf" must have length at least kMaxNumberLength+1
-// REQUIRES "n > 0"
-// Copies "str" into "buf" and null-terminates if necessary.
-// Returns one of:
-// a. "str" if no termination is needed
-// b. "buf" if the string was copied and null-terminated
-// c. "" if the input was invalid and has no hope of being parsed
-static const char* TerminateNumber(char* buf, const char* str, int n) {
- if ((n > 0) && isspace(*str)) {
- // We are less forgiving than the strtoxxx() routines and do not
- // allow leading spaces.
- return "";
- }
-
- // See if the character right after the input text may potentially
- // look like a digit.
- if (isdigit(str[n]) ||
- ((str[n] >= 'a') && (str[n] <= 'f')) ||
- ((str[n] >= 'A') && (str[n] <= 'F'))) {
- if (n > kMaxNumberLength) return ""; // Input too big to be a valid number
- memcpy(buf, str, n);
- buf[n] = '\0';
- return buf;
- } else {
- // We can parse right out of the supplied string, so return it.
- return str;
- }
-}
-
-bool Arg::parse_long_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- if (n == 0) return false;
- char buf[kMaxNumberLength+1];
- str = TerminateNumber(buf, str, n);
- char* end;
- errno = 0;
- long r = strtol(str, &end, radix);
- if (end != str + n) return false; // Leftover junk
- if (errno) return false;
- *(reinterpret_cast<long*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_ulong_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- if (n == 0) return false;
- char buf[kMaxNumberLength+1];
- str = TerminateNumber(buf, str, n);
- if (str[0] == '-') return false; // strtoul() on a negative number?!
- char* end;
- errno = 0;
- unsigned long r = strtoul(str, &end, radix);
- if (end != str + n) return false; // Leftover junk
- if (errno) return false;
- *(reinterpret_cast<unsigned long*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_short_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- long r;
- if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse
- if (r < SHRT_MIN || r > SHRT_MAX) return false; // Out of range
- *(reinterpret_cast<short*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_ushort_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- unsigned long r;
- if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse
- if (r > USHRT_MAX) return false; // Out of range
- *(reinterpret_cast<unsigned short*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_int_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- long r;
- if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse
- if (r < INT_MIN || r > INT_MAX) return false; // Out of range
- *(reinterpret_cast<int*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_uint_radix(const char* str,
- int n,
- void* dest,
- int radix) {
- unsigned long r;
- if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse
- if (r > UINT_MAX) return false; // Out of range
- *(reinterpret_cast<unsigned int*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_longlong_radix(const char* str,
- int n,
- void* dest,
- int radix) {
-#ifndef HAVE_LONG_LONG
- return false;
-#else
- if (n == 0) return false;
- char buf[kMaxNumberLength+1];
- str = TerminateNumber(buf, str, n);
- char* end;
- errno = 0;
-#if defined HAVE_STRTOQ
- long long r = strtoq(str, &end, radix);
-#elif defined HAVE_STRTOLL
- long long r = strtoll(str, &end, radix);
-#else
-#error parse_longlong_radix: cannot convert input to a long-long
-#endif
- if (end != str + n) return false; // Leftover junk
- if (errno) return false;
- *(reinterpret_cast<long long*>(dest)) = r;
- return true;
-#endif /* HAVE_LONG_LONG */
-}
-
-bool Arg::parse_ulonglong_radix(const char* str,
- int n,
- void* dest,
- int radix) {
-#ifndef HAVE_UNSIGNED_LONG_LONG
- return false;
-#else
- if (n == 0) return false;
- char buf[kMaxNumberLength+1];
- str = TerminateNumber(buf, str, n);
- if (str[0] == '-') return false; // strtoull() on a negative number?!
- char* end;
- errno = 0;
-#if defined HAVE_STRTOQ
- unsigned long long r = strtouq(str, &end, radix);
-#elif defined HAVE_STRTOLL
- unsigned long long r = strtoull(str, &end, radix);
-#else
-#error parse_ulonglong_radix: cannot convert input to a long-long
-#endif
- if (end != str + n) return false; // Leftover junk
- if (errno) return false;
- *(reinterpret_cast<unsigned long long*>(dest)) = r;
- return true;
-#endif /* HAVE_UNSIGNED_LONG_LONG */
-}
-
-bool Arg::parse_double(const char* str, int n, void* dest) {
- if (n == 0) return false;
- static const int kMaxLength = 200;
- char buf[kMaxLength];
- if (n >= kMaxLength) return false;
- memcpy(buf, str, n);
- buf[n] = '\0';
- errno = 0;
- char* end;
- double r = strtod(buf, &end);
- if (end != buf + n) return false; // Leftover junk
- if (errno) return false;
- *(reinterpret_cast<double*>(dest)) = r;
- return true;
-}
-
-bool Arg::parse_float(const char* str, int n, void* dest) {
- double r;
- if (!parse_double(str, n, &r)) return false;
- *(reinterpret_cast<float*>(dest)) = static_cast<float>(r);
- return true;
-}
-
-
-#define DEFINE_INTEGER_PARSERS(name) \
- bool Arg::parse_##name(const char* str, int n, void* dest) { \
- return parse_##name##_radix(str, n, dest, 10); \
- } \
- bool Arg::parse_##name##_hex(const char* str, int n, void* dest) { \
- return parse_##name##_radix(str, n, dest, 16); \
- } \
- bool Arg::parse_##name##_octal(const char* str, int n, void* dest) { \
- return parse_##name##_radix(str, n, dest, 8); \
- } \
- bool Arg::parse_##name##_cradix(const char* str, int n, void* dest) { \
- return parse_##name##_radix(str, n, dest, 0); \
- }
-
-DEFINE_INTEGER_PARSERS(short) /* */
-DEFINE_INTEGER_PARSERS(ushort) /* */
-DEFINE_INTEGER_PARSERS(int) /* Don't use semicolons after these */
-DEFINE_INTEGER_PARSERS(uint) /* statements because they can cause */
-DEFINE_INTEGER_PARSERS(long) /* compiler warnings if the checking */
-DEFINE_INTEGER_PARSERS(ulong) /* level is turned up high enough. */
-DEFINE_INTEGER_PARSERS(longlong) /* */
-DEFINE_INTEGER_PARSERS(ulonglong) /* */
-
-#undef DEFINE_INTEGER_PARSERS
-
-} // namespace pcrecpp
diff --git a/ext/pcre/pcrelib/pcrecpp.h b/ext/pcre/pcrelib/pcrecpp.h
deleted file mode 100644
index e3f1b716c2..0000000000
--- a/ext/pcre/pcrelib/pcrecpp.h
+++ /dev/null
@@ -1,695 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-// Support for PCRE_XXX modifiers added by Giuseppe Maxia, July 2005
-
-#ifndef _PCRECPP_H
-#define _PCRECPP_H
-
-// C++ interface to the pcre regular-expression library. RE supports
-// Perl-style regular expressions (with extensions like \d, \w, \s,
-// ...).
-//
-// -----------------------------------------------------------------------
-// REGEXP SYNTAX:
-//
-// This module is part of the pcre library and hence supports its syntax
-// for regular expressions.
-//
-// The syntax is pretty similar to Perl's. For those not familiar
-// with Perl's regular expressions, here are some examples of the most
-// commonly used extensions:
-//
-// "hello (\\w+) world" -- \w matches a "word" character
-// "version (\\d+)" -- \d matches a digit
-// "hello\\s+world" -- \s matches any whitespace character
-// "\\b(\\w+)\\b" -- \b matches empty string at a word boundary
-// "(?i)hello" -- (?i) turns on case-insensitive matching
-// "/\\*(.*?)\\*/" -- .*? matches . minimum no. of times possible
-//
-// -----------------------------------------------------------------------
-// MATCHING INTERFACE:
-//
-// The "FullMatch" operation checks that supplied text matches a
-// supplied pattern exactly.
-//
-// Example: successful match
-// pcrecpp::RE re("h.*o");
-// re.FullMatch("hello");
-//
-// Example: unsuccessful match (requires full match):
-// pcrecpp::RE re("e");
-// !re.FullMatch("hello");
-//
-// Example: creating a temporary RE object:
-// pcrecpp::RE("h.*o").FullMatch("hello");
-//
-// You can pass in a "const char*" or a "string" for "text". The
-// examples below tend to use a const char*.
-//
-// You can, as in the different examples above, store the RE object
-// explicitly in a variable or use a temporary RE object. The
-// examples below use one mode or the other arbitrarily. Either
-// could correctly be used for any of these examples.
-//
-// -----------------------------------------------------------------------
-// MATCHING WITH SUB-STRING EXTRACTION:
-//
-// You can supply extra pointer arguments to extract matched subpieces.
-//
-// Example: extracts "ruby" into "s" and 1234 into "i"
-// int i;
-// string s;
-// pcrecpp::RE re("(\\w+):(\\d+)");
-// re.FullMatch("ruby:1234", &s, &i);
-//
-// Example: does not try to extract any extra sub-patterns
-// re.FullMatch("ruby:1234", &s);
-//
-// Example: does not try to extract into NULL
-// re.FullMatch("ruby:1234", NULL, &i);
-//
-// Example: integer overflow causes failure
-// !re.FullMatch("ruby:1234567891234", NULL, &i);
-//
-// Example: fails because there aren't enough sub-patterns:
-// !pcrecpp::RE("\\w+:\\d+").FullMatch("ruby:1234", &s);
-//
-// Example: fails because string cannot be stored in integer
-// !pcrecpp::RE("(.*)").FullMatch("ruby", &i);
-//
-// The provided pointer arguments can be pointers to any scalar numeric
-// type, or one of
-// string (matched piece is copied to string)
-// StringPiece (StringPiece is mutated to point to matched piece)
-// T (where "bool T::ParseFrom(const char*, int)" exists)
-// NULL (the corresponding matched sub-pattern is not copied)
-//
-// CAVEAT: An optional sub-pattern that does not exist in the matched
-// string is assigned the empty string. Therefore, the following will
-// return false (because the empty string is not a valid number):
-// int number;
-// pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number);
-//
-// -----------------------------------------------------------------------
-// DO_MATCH
-//
-// The matching interface supports at most 16 arguments per call.
-// If you need more, consider using the more general interface
-// pcrecpp::RE::DoMatch(). See pcrecpp.h for the signature for DoMatch.
-//
-// -----------------------------------------------------------------------
-// PARTIAL MATCHES
-//
-// You can use the "PartialMatch" operation when you want the pattern
-// to match any substring of the text.
-//
-// Example: simple search for a string:
-// pcrecpp::RE("ell").PartialMatch("hello");
-//
-// Example: find first number in a string:
-// int number;
-// pcrecpp::RE re("(\\d+)");
-// re.PartialMatch("x*100 + 20", &number);
-// assert(number == 100);
-//
-// -----------------------------------------------------------------------
-// UTF-8 AND THE MATCHING INTERFACE:
-//
-// By default, pattern and text are plain text, one byte per character.
-// The UTF8 flag, passed to the constructor, causes both pattern
-// and string to be treated as UTF-8 text, still a byte stream but
-// potentially multiple bytes per character. In practice, the text
-// is likelier to be UTF-8 than the pattern, but the match returned
-// may depend on the UTF8 flag, so always use it when matching
-// UTF8 text. E.g., "." will match one byte normally but with UTF8
-// set may match up to three bytes of a multi-byte character.
-//
-// Example:
-// pcrecpp::RE_Options options;
-// options.set_utf8();
-// pcrecpp::RE re(utf8_pattern, options);
-// re.FullMatch(utf8_string);
-//
-// Example: using the convenience function UTF8():
-// pcrecpp::RE re(utf8_pattern, pcrecpp::UTF8());
-// re.FullMatch(utf8_string);
-//
-// NOTE: The UTF8 option is ignored if pcre was not configured with the
-// --enable-utf8 flag.
-//
-// -----------------------------------------------------------------------
-// PASSING MODIFIERS TO THE REGULAR EXPRESSION ENGINE
-//
-// PCRE defines some modifiers to change the behavior of the regular
-// expression engine.
-// The C++ wrapper defines an auxiliary class, RE_Options, as a vehicle
-// to pass such modifiers to a RE class.
-//
-// Currently, the following modifiers are supported
-//
-// modifier description Perl corresponding
-//
-// PCRE_CASELESS case insensitive match /i
-// PCRE_MULTILINE multiple lines match /m
-// PCRE_DOTALL dot matches newlines /s
-// PCRE_DOLLAR_ENDONLY $ matches only at end N/A
-// PCRE_EXTRA strict escape parsing N/A
-// PCRE_EXTENDED ignore whitespaces /x
-// PCRE_UTF8 handles UTF8 chars built-in
-// PCRE_UNGREEDY reverses * and *? N/A
-// PCRE_NO_AUTO_CAPTURE disables matching parens N/A (*)
-//
-// (For a full account on how each modifier works, please check the
-// PCRE API reference manual).
-//
-// (*) Both Perl and PCRE allow non matching parentheses by means of the
-// "?:" modifier within the pattern itself. e.g. (?:ab|cd) does not
-// capture, while (ab|cd) does.
-//
-// For each modifier, there are two member functions whose name is made
-// out of the modifier in lowercase, without the "PCRE_" prefix. For
-// instance, PCRE_CASELESS is handled by
-// bool caseless(),
-// which returns true if the modifier is set, and
-// RE_Options & set_caseless(bool),
-// which sets or unsets the modifier.
-//
-// Moreover, PCRE_EXTRA_MATCH_LIMIT can be accessed through the
-// set_match_limit() and match_limit() member functions.
-// Setting match_limit to a non-zero value will limit the executation of
-// pcre to keep it from doing bad things like blowing the stack or taking
-// an eternity to return a result. A value of 5000 is good enough to stop
-// stack blowup in a 2MB thread stack. Setting match_limit to zero will
-// disable match limiting. Alternately, you can set match_limit_recursion()
-// which uses PCRE_EXTRA_MATCH_LIMIT_RECURSION to limit how much pcre
-// recurses. match_limit() caps the number of matches pcre does;
-// match_limit_recrusion() caps the depth of recursion.
-//
-// Normally, to pass one or more modifiers to a RE class, you declare
-// a RE_Options object, set the appropriate options, and pass this
-// object to a RE constructor. Example:
-//
-// RE_options opt;
-// opt.set_caseless(true);
-//
-// if (RE("HELLO", opt).PartialMatch("hello world")) ...
-//
-// RE_options has two constructors. The default constructor takes no
-// arguments and creates a set of flags that are off by default.
-//
-// The optional parameter 'option_flags' is to facilitate transfer
-// of legacy code from C programs. This lets you do
-// RE(pattern, RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).PartialMatch(str);
-//
-// But new code is better off doing
-// RE(pattern,
-// RE_Options().set_caseless(true).set_multiline(true)).PartialMatch(str);
-// (See below)
-//
-// If you are going to pass one of the most used modifiers, there are some
-// convenience functions that return a RE_Options class with the
-// appropriate modifier already set:
-// CASELESS(), UTF8(), MULTILINE(), DOTALL(), EXTENDED()
-//
-// If you need to set several options at once, and you don't want to go
-// through the pains of declaring a RE_Options object and setting several
-// options, there is a parallel method that give you such ability on the
-// fly. You can concatenate several set_xxxxx member functions, since each
-// of them returns a reference to its class object. e.g.: to pass
-// PCRE_CASELESS, PCRE_EXTENDED, and PCRE_MULTILINE to a RE with one
-// statement, you may write
-//
-// RE(" ^ xyz \\s+ .* blah$", RE_Options()
-// .set_caseless(true)
-// .set_extended(true)
-// .set_multiline(true)).PartialMatch(sometext);
-//
-// -----------------------------------------------------------------------
-// SCANNING TEXT INCREMENTALLY
-//
-// The "Consume" operation may be useful if you want to repeatedly
-// match regular expressions at the front of a string and skip over
-// them as they match. This requires use of the "StringPiece" type,
-// which represents a sub-range of a real string. Like RE, StringPiece
-// is defined in the pcrecpp namespace.
-//
-// Example: read lines of the form "var = value" from a string.
-// string contents = ...; // Fill string somehow
-// pcrecpp::StringPiece input(contents); // Wrap in a StringPiece
-//
-// string var;
-// int value;
-// pcrecpp::RE re("(\\w+) = (\\d+)\n");
-// while (re.Consume(&input, &var, &value)) {
-// ...;
-// }
-//
-// Each successful call to "Consume" will set "var/value", and also
-// advance "input" so it points past the matched text.
-//
-// The "FindAndConsume" operation is similar to "Consume" but does not
-// anchor your match at the beginning of the string. For example, you
-// could extract all words from a string by repeatedly calling
-// pcrecpp::RE("(\\w+)").FindAndConsume(&input, &word)
-//
-// -----------------------------------------------------------------------
-// PARSING HEX/OCTAL/C-RADIX NUMBERS
-//
-// By default, if you pass a pointer to a numeric value, the
-// corresponding text is interpreted as a base-10 number. You can
-// instead wrap the pointer with a call to one of the operators Hex(),
-// Octal(), or CRadix() to interpret the text in another base. The
-// CRadix operator interprets C-style "0" (base-8) and "0x" (base-16)
-// prefixes, but defaults to base-10.
-//
-// Example:
-// int a, b, c, d;
-// pcrecpp::RE re("(.*) (.*) (.*) (.*)");
-// re.FullMatch("100 40 0100 0x40",
-// pcrecpp::Octal(&a), pcrecpp::Hex(&b),
-// pcrecpp::CRadix(&c), pcrecpp::CRadix(&d));
-// will leave 64 in a, b, c, and d.
-//
-// -----------------------------------------------------------------------
-// REPLACING PARTS OF STRINGS
-//
-// You can replace the first match of "pattern" in "str" with
-// "rewrite". Within "rewrite", backslash-escaped digits (\1 to \9)
-// can be used to insert text matching corresponding parenthesized
-// group from the pattern. \0 in "rewrite" refers to the entire
-// matching text. E.g.,
-//
-// string s = "yabba dabba doo";
-// pcrecpp::RE("b+").Replace("d", &s);
-//
-// will leave "s" containing "yada dabba doo". The result is true if
-// the pattern matches and a replacement occurs, or false otherwise.
-//
-// GlobalReplace() is like Replace(), except that it replaces all
-// occurrences of the pattern in the string with the rewrite.
-// Replacements are not subject to re-matching. E.g.,
-//
-// string s = "yabba dabba doo";
-// pcrecpp::RE("b+").GlobalReplace("d", &s);
-//
-// will leave "s" containing "yada dada doo". It returns the number
-// of replacements made.
-//
-// Extract() is like Replace(), except that if the pattern matches,
-// "rewrite" is copied into "out" (an additional argument) with
-// substitutions. The non-matching portions of "text" are ignored.
-// Returns true iff a match occurred and the extraction happened
-// successfully. If no match occurs, the string is left unaffected.
-
-
-#include <string>
-#include <pcrecpparg.h> // defines the Arg class
-// These aren't technically needed here, but we include them
-// anyway so folks who include pcrecpp.h don't have to include
-// all these other header files as well.
-#include <pcre.h>
-#include <pcre_stringpiece.h>
-
-namespace pcrecpp {
-
-#define PCRE_SET_OR_CLEAR(b, o) \
- if (b) all_options_ |= (o); else all_options_ &= ~(o); \
- return *this
-
-#define PCRE_IS_SET(o) \
- (all_options_ & o) == o
-
-// We convert user-passed pointers into special Arg objects
-extern Arg no_arg;
-
-/***** Compiling regular expressions: the RE class *****/
-
-// RE_Options allow you to set options to be passed along to pcre,
-// along with other options we put on top of pcre.
-// Only 9 modifiers, plus match_limit and match_limit_recursion,
-// are supported now.
-class RE_Options {
- public:
- // constructor
- RE_Options() : match_limit_(0), match_limit_recursion_(0), all_options_(0) {}
-
- // alternative constructor.
- // To facilitate transfer of legacy code from C programs
- //
- // This lets you do
- // RE(pattern, RE_Options(PCRE_CASELESS|PCRE_MULTILINE)).PartialMatch(str);
- // But new code is better off doing
- // RE(pattern,
- // RE_Options().set_caseless(true).set_multiline(true)).PartialMatch(str);
- RE_Options(int option_flags) : match_limit_(0), match_limit_recursion_(0),
- all_options_(option_flags) {}
- // we're fine with the default destructor, copy constructor, etc.
-
- // accessors and mutators
- int match_limit() const { return match_limit_; };
- RE_Options &set_match_limit(int limit) {
- match_limit_ = limit;
- return *this;
- }
-
- int match_limit_recursion() const { return match_limit_recursion_; };
- RE_Options &set_match_limit_recursion(int limit) {
- match_limit_recursion_ = limit;
- return *this;
- }
-
- bool caseless() const {
- return PCRE_IS_SET(PCRE_CASELESS);
- }
- RE_Options &set_caseless(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_CASELESS);
- }
-
- bool multiline() const {
- return PCRE_IS_SET(PCRE_MULTILINE);
- }
- RE_Options &set_multiline(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_MULTILINE);
- }
-
- bool dotall() const {
- return PCRE_IS_SET(PCRE_DOTALL);
- }
- RE_Options &set_dotall(bool x) {
- PCRE_SET_OR_CLEAR(x,PCRE_DOTALL);
- }
-
- bool extended() const {
- return PCRE_IS_SET(PCRE_EXTENDED);
- }
- RE_Options &set_extended(bool x) {
- PCRE_SET_OR_CLEAR(x,PCRE_EXTENDED);
- }
-
- bool dollar_endonly() const {
- return PCRE_IS_SET(PCRE_DOLLAR_ENDONLY);
- }
- RE_Options &set_dollar_endonly(bool x) {
- PCRE_SET_OR_CLEAR(x,PCRE_DOLLAR_ENDONLY);
- }
-
- bool extra() const {
- return PCRE_IS_SET( PCRE_EXTRA);
- }
- RE_Options &set_extra(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_EXTRA);
- }
-
- bool ungreedy() const {
- return PCRE_IS_SET(PCRE_UNGREEDY);
- }
- RE_Options &set_ungreedy(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_UNGREEDY);
- }
-
- bool utf8() const {
- return PCRE_IS_SET(PCRE_UTF8);
- }
- RE_Options &set_utf8(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_UTF8);
- }
-
- bool no_auto_capture() const {
- return PCRE_IS_SET(PCRE_NO_AUTO_CAPTURE);
- }
- RE_Options &set_no_auto_capture(bool x) {
- PCRE_SET_OR_CLEAR(x, PCRE_NO_AUTO_CAPTURE);
- }
-
- RE_Options &set_all_options(int opt) {
- all_options_ = opt;
- return *this;
- }
- int all_options() const {
- return all_options_ ;
- }
-
- // TODO: add other pcre flags
-
- private:
- int match_limit_;
- int match_limit_recursion_;
- int all_options_;
-};
-
-// These functions return some common RE_Options
-static inline RE_Options UTF8() {
- return RE_Options().set_utf8(true);
-}
-
-static inline RE_Options CASELESS() {
- return RE_Options().set_caseless(true);
-}
-static inline RE_Options MULTILINE() {
- return RE_Options().set_multiline(true);
-}
-
-static inline RE_Options DOTALL() {
- return RE_Options().set_dotall(true);
-}
-
-static inline RE_Options EXTENDED() {
- return RE_Options().set_extended(true);
-}
-
-// Interface for regular expression matching. Also corresponds to a
-// pre-compiled regular expression. An "RE" object is safe for
-// concurrent use by multiple threads.
-class RE {
- public:
- // We provide implicit conversions from strings so that users can
- // pass in a string or a "const char*" wherever an "RE" is expected.
- RE(const char* pat) { Init(pat, NULL); }
- RE(const char *pat, const RE_Options& option) { Init(pat, &option); }
- RE(const string& pat) { Init(pat, NULL); }
- RE(const string& pat, const RE_Options& option) { Init(pat, &option); }
-
- // Copy constructor & assignment - note that these are expensive
- // because they recompile the expression.
- RE(const RE& re) { Init(re.pattern_, &re.options_); }
- const RE& operator=(const RE& re) {
- if (this != &re) {
- Cleanup();
-
- // This is the code that originally came from Google
- // Init(re.pattern_.c_str(), &re.options_);
-
- // This is the replacement from Ari Pollak
- Init(re.pattern_, &re.options_);
- }
- return *this;
- }
-
-
- ~RE();
-
- // The string specification for this RE. E.g.
- // RE re("ab*c?d+");
- // re.pattern(); // "ab*c?d+"
- const string& pattern() const { return pattern_; }
-
- // If RE could not be created properly, returns an error string.
- // Else returns the empty string.
- const string& error() const { return *error_; }
-
- /***** The useful part: the matching interface *****/
-
- // This is provided so one can do pattern.ReplaceAll() just as
- // easily as ReplaceAll(pattern-text, ....)
-
- bool FullMatch(const StringPiece& text,
- const Arg& ptr1 = no_arg,
- const Arg& ptr2 = no_arg,
- const Arg& ptr3 = no_arg,
- const Arg& ptr4 = no_arg,
- const Arg& ptr5 = no_arg,
- const Arg& ptr6 = no_arg,
- const Arg& ptr7 = no_arg,
- const Arg& ptr8 = no_arg,
- const Arg& ptr9 = no_arg,
- const Arg& ptr10 = no_arg,
- const Arg& ptr11 = no_arg,
- const Arg& ptr12 = no_arg,
- const Arg& ptr13 = no_arg,
- const Arg& ptr14 = no_arg,
- const Arg& ptr15 = no_arg,
- const Arg& ptr16 = no_arg) const;
-
- bool PartialMatch(const StringPiece& text,
- const Arg& ptr1 = no_arg,
- const Arg& ptr2 = no_arg,
- const Arg& ptr3 = no_arg,
- const Arg& ptr4 = no_arg,
- const Arg& ptr5 = no_arg,
- const Arg& ptr6 = no_arg,
- const Arg& ptr7 = no_arg,
- const Arg& ptr8 = no_arg,
- const Arg& ptr9 = no_arg,
- const Arg& ptr10 = no_arg,
- const Arg& ptr11 = no_arg,
- const Arg& ptr12 = no_arg,
- const Arg& ptr13 = no_arg,
- const Arg& ptr14 = no_arg,
- const Arg& ptr15 = no_arg,
- const Arg& ptr16 = no_arg) const;
-
- bool Consume(StringPiece* input,
- const Arg& ptr1 = no_arg,
- const Arg& ptr2 = no_arg,
- const Arg& ptr3 = no_arg,
- const Arg& ptr4 = no_arg,
- const Arg& ptr5 = no_arg,
- const Arg& ptr6 = no_arg,
- const Arg& ptr7 = no_arg,
- const Arg& ptr8 = no_arg,
- const Arg& ptr9 = no_arg,
- const Arg& ptr10 = no_arg,
- const Arg& ptr11 = no_arg,
- const Arg& ptr12 = no_arg,
- const Arg& ptr13 = no_arg,
- const Arg& ptr14 = no_arg,
- const Arg& ptr15 = no_arg,
- const Arg& ptr16 = no_arg) const;
-
- bool FindAndConsume(StringPiece* input,
- const Arg& ptr1 = no_arg,
- const Arg& ptr2 = no_arg,
- const Arg& ptr3 = no_arg,
- const Arg& ptr4 = no_arg,
- const Arg& ptr5 = no_arg,
- const Arg& ptr6 = no_arg,
- const Arg& ptr7 = no_arg,
- const Arg& ptr8 = no_arg,
- const Arg& ptr9 = no_arg,
- const Arg& ptr10 = no_arg,
- const Arg& ptr11 = no_arg,
- const Arg& ptr12 = no_arg,
- const Arg& ptr13 = no_arg,
- const Arg& ptr14 = no_arg,
- const Arg& ptr15 = no_arg,
- const Arg& ptr16 = no_arg) const;
-
- bool Replace(const StringPiece& rewrite,
- string *str) const;
-
- int GlobalReplace(const StringPiece& rewrite,
- string *str) const;
-
- bool Extract(const StringPiece &rewrite,
- const StringPiece &text,
- string *out) const;
-
- // Escapes all potentially meaningful regexp characters in
- // 'unquoted'. The returned string, used as a regular expression,
- // will exactly match the original string. For example,
- // 1.5-2.0?
- // may become:
- // 1\.5\-2\.0\?
- static string QuoteMeta(const StringPiece& unquoted);
-
-
- /***** Generic matching interface *****/
-
- // Type of match (TODO: Should be restructured as part of RE_Options)
- enum Anchor {
- UNANCHORED, // No anchoring
- ANCHOR_START, // Anchor at start only
- ANCHOR_BOTH // Anchor at start and end
- };
-
- // General matching routine. Stores the length of the match in
- // "*consumed" if successful.
- bool DoMatch(const StringPiece& text,
- Anchor anchor,
- int* consumed,
- const Arg* const* args, int n) const;
-
- // Return the number of capturing subpatterns, or -1 if the
- // regexp wasn't valid on construction.
- int NumberOfCapturingGroups() const;
-
- private:
-
- void Init(const string& pattern, const RE_Options* options);
- void Cleanup();
-
- // Match against "text", filling in "vec" (up to "vecsize" * 2/3) with
- // pairs of integers for the beginning and end positions of matched
- // text. The first pair corresponds to the entire matched text;
- // subsequent pairs correspond, in order, to parentheses-captured
- // matches. Returns the number of pairs (one more than the number of
- // the last subpattern with a match) if matching was successful
- // and zero if the match failed.
- // I.e. for RE("(foo)|(bar)|(baz)") it will return 2, 3, and 4 when matching
- // against "foo", "bar", and "baz" respectively.
- // When matching RE("(foo)|hello") against "hello", it will return 1.
- // But the values for all subpattern are filled in into "vec".
- int TryMatch(const StringPiece& text,
- int startpos,
- Anchor anchor,
- int *vec,
- int vecsize) const;
-
- // Append the "rewrite" string, with backslash subsitutions from "text"
- // and "vec", to string "out".
- bool Rewrite(string *out,
- const StringPiece& rewrite,
- const StringPiece& text,
- int *vec,
- int veclen) const;
-
- // internal implementation for DoMatch
- bool DoMatchImpl(const StringPiece& text,
- Anchor anchor,
- int* consumed,
- const Arg* const args[],
- int n,
- int* vec,
- int vecsize) const;
-
- // Compile the regexp for the specified anchoring mode
- pcre* Compile(Anchor anchor);
-
- string pattern_;
- RE_Options options_;
- pcre* re_full_; // For full matches
- pcre* re_partial_; // For partial matches
- const string* error_; // Error indicator (or points to empty string)
-};
-
-} // namespace pcrecpp
-
-#endif /* _PCRECPP_H */
diff --git a/ext/pcre/pcrelib/pcrecpp_unittest.cc b/ext/pcre/pcrelib/pcrecpp_unittest.cc
deleted file mode 100644
index 858728cd4e..0000000000
--- a/ext/pcre/pcrelib/pcrecpp_unittest.cc
+++ /dev/null
@@ -1,1227 +0,0 @@
-// -*- coding: utf-8 -*-
-//
-// Copyright (c) 2005 - 2006, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-//
-// TODO: Test extractions for PartialMatch/Consume
-
-#include <stdio.h>
-#include <cassert>
-#include <vector>
-#include "config.h"
-#include "pcrecpp.h"
-
-using pcrecpp::StringPiece;
-using pcrecpp::RE;
-using pcrecpp::RE_Options;
-using pcrecpp::Hex;
-using pcrecpp::Octal;
-using pcrecpp::CRadix;
-
-static bool VERBOSE_TEST = false;
-
-// CHECK dies with a fatal error if condition is not true. It is *not*
-// controlled by NDEBUG, so the check will be executed regardless of
-// compilation mode. Therefore, it is safe to do things like:
-// CHECK_EQ(fp->Write(x), 4)
-#define CHECK(condition) do { \
- if (!(condition)) { \
- fprintf(stderr, "%s:%d: Check failed: %s\n", \
- __FILE__, __LINE__, #condition); \
- exit(1); \
- } \
-} while (0)
-
-#define CHECK_EQ(a, b) CHECK(a == b)
-
-static void Timing1(int num_iters) {
- // Same pattern lots of times
- RE pattern("ruby:\\d+");
- StringPiece p("ruby:1234");
- for (int j = num_iters; j > 0; j--) {
- CHECK(pattern.FullMatch(p));
- }
-}
-
-static void Timing2(int num_iters) {
- // Same pattern lots of times
- RE pattern("ruby:(\\d+)");
- int i;
- for (int j = num_iters; j > 0; j--) {
- CHECK(pattern.FullMatch("ruby:1234", &i));
- CHECK_EQ(i, 1234);
- }
-}
-
-static void Timing3(int num_iters) {
- string text_string;
- for (int j = num_iters; j > 0; j--) {
- text_string += "this is another line\n";
- }
-
- RE line_matcher(".*\n");
- string line;
- StringPiece text(text_string);
- int counter = 0;
- while (line_matcher.Consume(&text)) {
- counter++;
- }
- printf("Matched %d lines\n", counter);
-}
-
-#if 0 // uncomment this if you have a way of defining VirtualProcessSize()
-
-static void LeakTest() {
- // Check for memory leaks
- unsigned long long initial_size = 0;
- for (int i = 0; i < 100000; i++) {
- if (i == 50000) {
- initial_size = VirtualProcessSize();
- printf("Size after 50000: %llu\n", initial_size);
- }
- char buf[100];
- snprintf(buf, sizeof(buf), "pat%09d", i);
- RE newre(buf);
- }
- uint64 final_size = VirtualProcessSize();
- printf("Size after 100000: %llu\n", final_size);
- const double growth = double(final_size - initial_size) / final_size;
- printf("Growth: %0.2f%%", growth * 100);
- CHECK(growth < 0.02); // Allow < 2% growth
-}
-
-#endif
-
-static void RadixTests() {
- printf("Testing hex\n");
-
-#define CHECK_HEX(type, value) \
- do { \
- type v; \
- CHECK(RE("([0-9a-fA-F]+)[uUlL]*").FullMatch(#value, Hex(&v))); \
- CHECK_EQ(v, 0x ## value); \
- CHECK(RE("([0-9a-fA-FxX]+)[uUlL]*").FullMatch("0x" #value, CRadix(&v))); \
- CHECK_EQ(v, 0x ## value); \
- } while(0)
-
- CHECK_HEX(short, 2bad);
- CHECK_HEX(unsigned short, 2badU);
- CHECK_HEX(int, dead);
- CHECK_HEX(unsigned int, deadU);
- CHECK_HEX(long, 7eadbeefL);
- CHECK_HEX(unsigned long, deadbeefUL);
-#ifdef HAVE_LONG_LONG
- CHECK_HEX(long long, 12345678deadbeefLL);
-#endif
-#ifdef HAVE_UNSIGNED_LONG_LONG
- CHECK_HEX(unsigned long long, cafebabedeadbeefULL);
-#endif
-
-#undef CHECK_HEX
-
- printf("Testing octal\n");
-
-#define CHECK_OCTAL(type, value) \
- do { \
- type v; \
- CHECK(RE("([0-7]+)[uUlL]*").FullMatch(#value, Octal(&v))); \
- CHECK_EQ(v, 0 ## value); \
- CHECK(RE("([0-9a-fA-FxX]+)[uUlL]*").FullMatch("0" #value, CRadix(&v))); \
- CHECK_EQ(v, 0 ## value); \
- } while(0)
-
- CHECK_OCTAL(short, 77777);
- CHECK_OCTAL(unsigned short, 177777U);
- CHECK_OCTAL(int, 17777777777);
- CHECK_OCTAL(unsigned int, 37777777777U);
- CHECK_OCTAL(long, 17777777777L);
- CHECK_OCTAL(unsigned long, 37777777777UL);
-#ifdef HAVE_LONG_LONG
- CHECK_OCTAL(long long, 777777777777777777777LL);
-#endif
-#ifdef HAVE_UNSIGNED_LONG_LONG
- CHECK_OCTAL(unsigned long long, 1777777777777777777777ULL);
-#endif
-
-#undef CHECK_OCTAL
-
- printf("Testing decimal\n");
-
-#define CHECK_DECIMAL(type, value) \
- do { \
- type v; \
- CHECK(RE("(-?[0-9]+)[uUlL]*").FullMatch(#value, &v)); \
- CHECK_EQ(v, value); \
- CHECK(RE("(-?[0-9a-fA-FxX]+)[uUlL]*").FullMatch(#value, CRadix(&v))); \
- CHECK_EQ(v, value); \
- } while(0)
-
- CHECK_DECIMAL(short, -1);
- CHECK_DECIMAL(unsigned short, 9999);
- CHECK_DECIMAL(int, -1000);
- CHECK_DECIMAL(unsigned int, 12345U);
- CHECK_DECIMAL(long, -10000000L);
- CHECK_DECIMAL(unsigned long, 3083324652U);
-#ifdef HAVE_LONG_LONG
- CHECK_DECIMAL(long long, -100000000000000LL);
-#endif
-#ifdef HAVE_UNSIGNED_LONG_LONG
- CHECK_DECIMAL(unsigned long long, 1234567890987654321ULL);
-#endif
-
-#undef CHECK_DECIMAL
-
-}
-
-static void TestReplace() {
- printf("Testing Replace\n");
-
- struct ReplaceTest {
- const char *regexp;
- const char *rewrite;
- const char *original;
- const char *single;
- const char *global;
- };
- static const ReplaceTest tests[] = {
- { "(qu|[b-df-hj-np-tv-z]*)([a-z]+)",
- "\\2\\1ay",
- "the quick brown fox jumps over the lazy dogs.",
- "ethay quick brown fox jumps over the lazy dogs.",
- "ethay ickquay ownbray oxfay umpsjay overay ethay azylay ogsday." },
- { "\\w+",
- "\\0-NOSPAM",
- "paul.haahr@google.com",
- "paul-NOSPAM.haahr@google.com",
- "paul-NOSPAM.haahr-NOSPAM@google-NOSPAM.com-NOSPAM" },
- { "^",
- "(START)",
- "foo",
- "(START)foo",
- "(START)foo" },
- { "^",
- "(START)",
- "",
- "(START)",
- "(START)" },
- { "$",
- "(END)",
- "",
- "(END)",
- "(END)" },
- { "b",
- "bb",
- "ababababab",
- "abbabababab",
- "abbabbabbabbabb" },
- { "b",
- "bb",
- "bbbbbb",
- "bbbbbbb",
- "bbbbbbbbbbbb" },
- { "b+",
- "bb",
- "bbbbbb",
- "bb",
- "bb" },
- { "b*",
- "bb",
- "bbbbbb",
- "bb",
- "bb" },
- { "b*",
- "bb",
- "aaaaa",
- "bbaaaaa",
- "bbabbabbabbabbabb" },
- { "b*",
- "bb",
- "aa\naa\n",
- "bbaa\naa\n",
- "bbabbabb\nbbabbabb\nbb" },
- { "b*",
- "bb",
- "aa\raa\r",
- "bbaa\raa\r",
- "bbabbabb\rbbabbabb\rbb" },
- { "b*",
- "bb",
- "aa\r\naa\r\n",
- "bbaa\r\naa\r\n",
- "bbabbabb\r\nbbabbabb\r\nbb" },
-#ifdef SUPPORT_UTF8
- { "b*",
- "bb",
- "\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8", // utf8
- "bb\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8",
- "bb\xE3\x83\x9B""bb""\xE3\x83\xBC""bb""\xE3\x83\xA0""bb""\xE3\x81\xB8""bb" },
- { "b*",
- "bb",
- "\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n", // utf8
- "bb\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n",
- ("bb\xE3\x83\x9B""bb\r\nbb""\xE3\x83\xBC""bb\rbb""\xE3\x83\xA0"
- "bb\nbb""\xE3\x81\xB8""bb\r\nbb") },
-#endif
- { "", NULL, NULL, NULL, NULL }
- };
-
-#ifdef SUPPORT_UTF8
- const bool support_utf8 = true;
-#else
- const bool support_utf8 = false;
-#endif
-
- for (const ReplaceTest *t = tests; t->original != NULL; ++t) {
- RE re(t->regexp, RE_Options(PCRE_NEWLINE_CRLF).set_utf8(support_utf8));
- assert(re.error().empty());
- string one(t->original);
- CHECK(re.Replace(t->rewrite, &one));
- CHECK_EQ(one, t->single);
- string all(t->original);
- CHECK(re.GlobalReplace(t->rewrite, &all) > 0);
- CHECK_EQ(all, t->global);
- }
-
- // One final test: test \r\n replacement when we're not in CRLF mode
- {
- RE re("b*", RE_Options(PCRE_NEWLINE_CR).set_utf8(support_utf8));
- assert(re.error().empty());
- string all("aa\r\naa\r\n");
- CHECK(re.GlobalReplace("bb", &all) > 0);
- CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb"));
- }
- {
- RE re("b*", RE_Options(PCRE_NEWLINE_LF).set_utf8(support_utf8));
- assert(re.error().empty());
- string all("aa\r\naa\r\n");
- CHECK(re.GlobalReplace("bb", &all) > 0);
- CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb"));
- }
- // TODO: test what happens when no PCRE_NEWLINE_* flag is set.
- // Alas, the answer depends on how pcre was compiled.
-}
-
-static void TestExtract() {
- printf("Testing Extract\n");
-
- string s;
-
- CHECK(RE("(.*)@([^.]*)").Extract("\\2!\\1", "boris@kremvax.ru", &s));
- CHECK_EQ(s, "kremvax!boris");
-
- // check the RE interface as well
- CHECK(RE(".*").Extract("'\\0'", "foo", &s));
- CHECK_EQ(s, "'foo'");
- CHECK(!RE("bar").Extract("'\\0'", "baz", &s));
- CHECK_EQ(s, "'foo'");
-}
-
-static void TestConsume() {
- printf("Testing Consume\n");
-
- string word;
-
- string s(" aaa b!@#$@#$cccc");
- StringPiece input(s);
-
- RE r("\\s*(\\w+)"); // matches a word, possibly proceeded by whitespace
- CHECK(r.Consume(&input, &word));
- CHECK_EQ(word, "aaa");
- CHECK(r.Consume(&input, &word));
- CHECK_EQ(word, "b");
- CHECK(! r.Consume(&input, &word));
-}
-
-static void TestFindAndConsume() {
- printf("Testing FindAndConsume\n");
-
- string word;
-
- string s(" aaa b!@#$@#$cccc");
- StringPiece input(s);
-
- RE r("(\\w+)"); // matches a word
- CHECK(r.FindAndConsume(&input, &word));
- CHECK_EQ(word, "aaa");
- CHECK(r.FindAndConsume(&input, &word));
- CHECK_EQ(word, "b");
- CHECK(r.FindAndConsume(&input, &word));
- CHECK_EQ(word, "cccc");
- CHECK(! r.FindAndConsume(&input, &word));
-}
-
-static void TestMatchNumberPeculiarity() {
- printf("Testing match-number peculiaraity\n");
-
- string word1;
- string word2;
- string word3;
-
- RE r("(foo)|(bar)|(baz)");
- CHECK(r.PartialMatch("foo", &word1, &word2, &word3));
- CHECK_EQ(word1, "foo");
- CHECK_EQ(word2, "");
- CHECK_EQ(word3, "");
- CHECK(r.PartialMatch("bar", &word1, &word2, &word3));
- CHECK_EQ(word1, "");
- CHECK_EQ(word2, "bar");
- CHECK_EQ(word3, "");
- CHECK(r.PartialMatch("baz", &word1, &word2, &word3));
- CHECK_EQ(word1, "");
- CHECK_EQ(word2, "");
- CHECK_EQ(word3, "baz");
- CHECK(!r.PartialMatch("f", &word1, &word2, &word3));
-
- string a;
- CHECK(RE("(foo)|hello").FullMatch("hello", &a));
- CHECK_EQ(a, "");
-}
-
-static void TestRecursion() {
- printf("Testing recursion\n");
-
- // Get one string that passes (sometimes), one that never does.
- string text_good("abcdefghijk");
- string text_bad("acdefghijkl");
-
- // According to pcretest, matching text_good against (\w+)*b
- // requires match_limit of at least 8192, and match_recursion_limit
- // of at least 37.
-
- RE_Options options_ml;
- options_ml.set_match_limit(8192);
- RE re("(\\w+)*b", options_ml);
- CHECK(re.PartialMatch(text_good) == true);
- CHECK(re.PartialMatch(text_bad) == false);
- CHECK(re.FullMatch(text_good) == false);
- CHECK(re.FullMatch(text_bad) == false);
-
- options_ml.set_match_limit(1024);
- RE re2("(\\w+)*b", options_ml);
- CHECK(re2.PartialMatch(text_good) == false); // because of match_limit
- CHECK(re2.PartialMatch(text_bad) == false);
- CHECK(re2.FullMatch(text_good) == false);
- CHECK(re2.FullMatch(text_bad) == false);
-
- RE_Options options_mlr;
- options_mlr.set_match_limit_recursion(50);
- RE re3("(\\w+)*b", options_mlr);
- CHECK(re3.PartialMatch(text_good) == true);
- CHECK(re3.PartialMatch(text_bad) == false);
- CHECK(re3.FullMatch(text_good) == false);
- CHECK(re3.FullMatch(text_bad) == false);
-
- options_mlr.set_match_limit_recursion(10);
- RE re4("(\\w+)*b", options_mlr);
- CHECK(re4.PartialMatch(text_good) == false);
- CHECK(re4.PartialMatch(text_bad) == false);
- CHECK(re4.FullMatch(text_good) == false);
- CHECK(re4.FullMatch(text_bad) == false);
-}
-
-// A meta-quoted string, interpreted as a pattern, should always match
-// the original unquoted string.
-static void TestQuoteMeta(string unquoted, RE_Options options = RE_Options()) {
- string quoted = RE::QuoteMeta(unquoted);
- RE re(quoted, options);
- CHECK(re.FullMatch(unquoted));
-}
-
-// A string containing meaningful regexp characters, which is then meta-
-// quoted, should not generally match a string the unquoted string does.
-static void NegativeTestQuoteMeta(string unquoted, string should_not_match,
- RE_Options options = RE_Options()) {
- string quoted = RE::QuoteMeta(unquoted);
- RE re(quoted, options);
- CHECK(!re.FullMatch(should_not_match));
-}
-
-// Tests that quoted meta characters match their original strings,
-// and that a few things that shouldn't match indeed do not.
-static void TestQuotaMetaSimple() {
- TestQuoteMeta("foo");
- TestQuoteMeta("foo.bar");
- TestQuoteMeta("foo\\.bar");
- TestQuoteMeta("[1-9]");
- TestQuoteMeta("1.5-2.0?");
- TestQuoteMeta("\\d");
- TestQuoteMeta("Who doesn't like ice cream?");
- TestQuoteMeta("((a|b)c?d*e+[f-h]i)");
- TestQuoteMeta("((?!)xxx).*yyy");
- TestQuoteMeta("([");
-}
-
-static void TestQuoteMetaSimpleNegative() {
- NegativeTestQuoteMeta("foo", "bar");
- NegativeTestQuoteMeta("...", "bar");
- NegativeTestQuoteMeta("\\.", ".");
- NegativeTestQuoteMeta("\\.", "..");
- NegativeTestQuoteMeta("(a)", "a");
- NegativeTestQuoteMeta("(a|b)", "a");
- NegativeTestQuoteMeta("(a|b)", "(a)");
- NegativeTestQuoteMeta("(a|b)", "a|b");
- NegativeTestQuoteMeta("[0-9]", "0");
- NegativeTestQuoteMeta("[0-9]", "0-9");
- NegativeTestQuoteMeta("[0-9]", "[9]");
- NegativeTestQuoteMeta("((?!)xxx)", "xxx");
-}
-
-static void TestQuoteMetaLatin1() {
- TestQuoteMeta("3\xb2 = 9");
-}
-
-static void TestQuoteMetaUtf8() {
-#ifdef SUPPORT_UTF8
- TestQuoteMeta("Pl\xc3\xa1\x63ido Domingo", pcrecpp::UTF8());
- TestQuoteMeta("xyz", pcrecpp::UTF8()); // No fancy utf8
- TestQuoteMeta("\xc2\xb0", pcrecpp::UTF8()); // 2-byte utf8 (degree symbol)
- TestQuoteMeta("27\xc2\xb0 degrees", pcrecpp::UTF8()); // As a middle character
- TestQuoteMeta("\xe2\x80\xb3", pcrecpp::UTF8()); // 3-byte utf8 (double prime)
- TestQuoteMeta("\xf0\x9d\x85\x9f", pcrecpp::UTF8()); // 4-byte utf8 (music note)
- TestQuoteMeta("27\xc2\xb0"); // Interpreted as Latin-1, but should still work
- NegativeTestQuoteMeta("27\xc2\xb0", // 2-byte utf (degree symbol)
- "27\\\xc2\\\xb0",
- pcrecpp::UTF8());
-#endif
-}
-
-static void TestQuoteMetaAll() {
- printf("Testing QuoteMeta\n");
- TestQuotaMetaSimple();
- TestQuoteMetaSimpleNegative();
- TestQuoteMetaLatin1();
- TestQuoteMetaUtf8();
-}
-
-//
-// Options tests contributed by
-// Giuseppe Maxia, CTO, Stardata s.r.l.
-// July 2005
-//
-static void GetOneOptionResult(
- const char *option_name,
- const char *regex,
- const char *str,
- RE_Options options,
- bool full,
- string expected) {
-
- printf("Testing Option <%s>\n", option_name);
- if(VERBOSE_TEST)
- printf("/%s/ finds \"%s\" within \"%s\" \n",
- regex,
- expected.c_str(),
- str);
- string captured("");
- if (full)
- RE(regex,options).FullMatch(str, &captured);
- else
- RE(regex,options).PartialMatch(str, &captured);
- CHECK_EQ(captured, expected);
-}
-
-static void TestOneOption(
- const char *option_name,
- const char *regex,
- const char *str,
- RE_Options options,
- bool full,
- bool assertive = true) {
-
- printf("Testing Option <%s>\n", option_name);
- if (VERBOSE_TEST)
- printf("'%s' %s /%s/ \n",
- str,
- (assertive? "matches" : "doesn't match"),
- regex);
- if (assertive) {
- if (full)
- CHECK(RE(regex,options).FullMatch(str));
- else
- CHECK(RE(regex,options).PartialMatch(str));
- } else {
- if (full)
- CHECK(!RE(regex,options).FullMatch(str));
- else
- CHECK(!RE(regex,options).PartialMatch(str));
- }
-}
-
-static void Test_CASELESS() {
- RE_Options options;
- RE_Options options2;
-
- options.set_caseless(true);
- TestOneOption("CASELESS (class)", "HELLO", "hello", options, false);
- TestOneOption("CASELESS (class2)", "HELLO", "hello", options2.set_caseless(true), false);
- TestOneOption("CASELESS (class)", "^[A-Z]+$", "Hello", options, false);
-
- TestOneOption("CASELESS (function)", "HELLO", "hello", pcrecpp::CASELESS(), false);
- TestOneOption("CASELESS (function)", "^[A-Z]+$", "Hello", pcrecpp::CASELESS(), false);
- options.set_caseless(false);
- TestOneOption("no CASELESS", "HELLO", "hello", options, false, false);
-}
-
-static void Test_MULTILINE() {
- RE_Options options;
- RE_Options options2;
- const char *str = "HELLO\n" "cruel\n" "world\n";
-
- options.set_multiline(true);
- TestOneOption("MULTILINE (class)", "^cruel$", str, options, false);
- TestOneOption("MULTILINE (class2)", "^cruel$", str, options2.set_multiline(true), false);
- TestOneOption("MULTILINE (function)", "^cruel$", str, pcrecpp::MULTILINE(), false);
- options.set_multiline(false);
- TestOneOption("no MULTILINE", "^cruel$", str, options, false, false);
-}
-
-static void Test_DOTALL() {
- RE_Options options;
- RE_Options options2;
- const char *str = "HELLO\n" "cruel\n" "world";
-
- options.set_dotall(true);
- TestOneOption("DOTALL (class)", "HELLO.*world", str, options, true);
- TestOneOption("DOTALL (class2)", "HELLO.*world", str, options2.set_dotall(true), true);
- TestOneOption("DOTALL (function)", "HELLO.*world", str, pcrecpp::DOTALL(), true);
- options.set_dotall(false);
- TestOneOption("no DOTALL", "HELLO.*world", str, options, true, false);
-}
-
-static void Test_DOLLAR_ENDONLY() {
- RE_Options options;
- RE_Options options2;
- const char *str = "HELLO world\n";
-
- TestOneOption("no DOLLAR_ENDONLY", "world$", str, options, false);
- options.set_dollar_endonly(true);
- TestOneOption("DOLLAR_ENDONLY 1", "world$", str, options, false, false);
- TestOneOption("DOLLAR_ENDONLY 2", "world$", str, options2.set_dollar_endonly(true), false, false);
-}
-
-static void Test_EXTRA() {
- RE_Options options;
- const char *str = "HELLO";
-
- options.set_extra(true);
- TestOneOption("EXTRA 1", "\\HELL\\O", str, options, true, false );
- TestOneOption("EXTRA 2", "\\HELL\\O", str, RE_Options().set_extra(true), true, false );
- options.set_extra(false);
- TestOneOption("no EXTRA", "\\HELL\\O", str, options, true );
-}
-
-static void Test_EXTENDED() {
- RE_Options options;
- RE_Options options2;
- const char *str = "HELLO world";
-
- options.set_extended(true);
- TestOneOption("EXTENDED (class)", "HELLO world", str, options, false, false);
- TestOneOption("EXTENDED (class2)", "HELLO world", str, options2.set_extended(true), false, false);
- TestOneOption("EXTENDED (class)",
- "^ HE L{2} O "
- "\\s+ "
- "\\w+ $ ",
- str,
- options,
- false);
-
- TestOneOption("EXTENDED (function)", "HELLO world", str, pcrecpp::EXTENDED(), false, false);
- TestOneOption("EXTENDED (function)",
- "^ HE L{2} O "
- "\\s+ "
- "\\w+ $ ",
- str,
- pcrecpp::EXTENDED(),
- false);
-
- options.set_extended(false);
- TestOneOption("no EXTENDED", "HELLO world", str, options, false);
-}
-
-static void Test_NO_AUTO_CAPTURE() {
- RE_Options options;
- const char *str = "HELLO world";
- string captured;
-
- printf("Testing Option <no NO_AUTO_CAPTURE>\n");
- if (VERBOSE_TEST)
- printf("parentheses capture text\n");
- RE re("(world|universe)$", options);
- CHECK(re.Extract("\\1", str , &captured));
- CHECK_EQ(captured, "world");
- options.set_no_auto_capture(true);
- printf("testing Option <NO_AUTO_CAPTURE>\n");
- if (VERBOSE_TEST)
- printf("parentheses do not capture text\n");
- re.Extract("\\1",str, &captured );
- CHECK_EQ(captured, "world");
-}
-
-static void Test_UNGREEDY() {
- RE_Options options;
- const char *str = "HELLO, 'this' is the 'world'";
-
- options.set_ungreedy(true);
- GetOneOptionResult("UNGREEDY 1", "('.*')", str, options, false, "'this'" );
- GetOneOptionResult("UNGREEDY 2", "('.*')", str, RE_Options().set_ungreedy(true), false, "'this'" );
- GetOneOptionResult("UNGREEDY", "('.*?')", str, options, false, "'this' is the 'world'" );
-
- options.set_ungreedy(false);
- GetOneOptionResult("no UNGREEDY", "('.*')", str, options, false, "'this' is the 'world'" );
- GetOneOptionResult("no UNGREEDY", "('.*?')", str, options, false, "'this'" );
-}
-
-static void Test_all_options() {
- const char *str = "HELLO\n" "cruel\n" "world";
- RE_Options options;
- options.set_all_options(PCRE_CASELESS | PCRE_DOTALL);
-
- TestOneOption("all_options (CASELESS|DOTALL)", "^hello.*WORLD", str , options, false);
- options.set_all_options(0);
- TestOneOption("all_options (0)", "^hello.*WORLD", str , options, false, false);
- options.set_all_options(PCRE_MULTILINE | PCRE_EXTENDED);
-
- TestOneOption("all_options (MULTILINE|EXTENDED)", " ^ c r u e l $ ", str, options, false);
- TestOneOption("all_options (MULTILINE|EXTENDED) with constructor",
- " ^ c r u e l $ ",
- str,
- RE_Options(PCRE_MULTILINE | PCRE_EXTENDED),
- false);
-
- TestOneOption("all_options (MULTILINE|EXTENDED) with concatenation",
- " ^ c r u e l $ ",
- str,
- RE_Options()
- .set_multiline(true)
- .set_extended(true),
- false);
-
- options.set_all_options(0);
- TestOneOption("all_options (0)", "^ c r u e l $", str, options, false, false);
-
-}
-
-static void TestOptions() {
- printf("Testing Options\n");
- Test_CASELESS();
- Test_MULTILINE();
- Test_DOTALL();
- Test_DOLLAR_ENDONLY();
- Test_EXTENDED();
- Test_NO_AUTO_CAPTURE();
- Test_UNGREEDY();
- Test_EXTRA();
- Test_all_options();
-}
-
-static void TestConstructors() {
- printf("Testing constructors\n");
-
- RE_Options options;
- options.set_dotall(true);
- const char *str = "HELLO\n" "cruel\n" "world";
-
- RE orig("HELLO.*world", options);
- CHECK(orig.FullMatch(str));
-
- RE copy1(orig);
- CHECK(copy1.FullMatch(str));
-
- RE copy2("not a match");
- CHECK(!copy2.FullMatch(str));
- copy2 = copy1;
- CHECK(copy2.FullMatch(str));
- copy2 = orig;
- CHECK(copy2.FullMatch(str));
-
- // Make sure when we assign to ourselves, nothing bad happens
- orig = orig;
- copy1 = copy1;
- copy2 = copy2;
- CHECK(orig.FullMatch(str));
- CHECK(copy1.FullMatch(str));
- CHECK(copy2.FullMatch(str));
-}
-
-int main(int argc, char** argv) {
- // Treat any flag as --help
- if (argc > 1 && argv[1][0] == '-') {
- printf("Usage: %s [timing1|timing2|timing3 num-iters]\n"
- " If 'timingX ###' is specified, run the given timing test\n"
- " with the given number of iterations, rather than running\n"
- " the default corectness test.\n", argv[0]);
- return 0;
- }
-
- if (argc > 1) {
- if ( argc == 2 || atoi(argv[2]) == 0) {
- printf("timing mode needs a num-iters argument\n");
- return 1;
- }
- if (!strcmp(argv[1], "timing1"))
- Timing1(atoi(argv[2]));
- else if (!strcmp(argv[1], "timing2"))
- Timing2(atoi(argv[2]));
- else if (!strcmp(argv[1], "timing3"))
- Timing3(atoi(argv[2]));
- else
- printf("Unknown argument '%s'\n", argv[1]);
- return 0;
- }
-
- printf("Testing FullMatch\n");
-
- int i;
- string s;
-
- /***** FullMatch with no args *****/
-
- CHECK(RE("h.*o").FullMatch("hello"));
- CHECK(!RE("h.*o").FullMatch("othello"));
- CHECK(!RE("h.*o").FullMatch("hello!"));
-
- /***** FullMatch with args *****/
-
- // Zero-arg
- CHECK(RE("\\d+").FullMatch("1001"));
-
- // Single-arg
- CHECK(RE("(\\d+)").FullMatch("1001", &i));
- CHECK_EQ(i, 1001);
- CHECK(RE("(-?\\d+)").FullMatch("-123", &i));
- CHECK_EQ(i, -123);
- CHECK(!RE("()\\d+").FullMatch("10", &i));
- CHECK(!RE("(\\d+)").FullMatch("1234567890123456789012345678901234567890",
- &i));
-
- // Digits surrounding integer-arg
- CHECK(RE("1(\\d*)4").FullMatch("1234", &i));
- CHECK_EQ(i, 23);
- CHECK(RE("(\\d)\\d+").FullMatch("1234", &i));
- CHECK_EQ(i, 1);
- CHECK(RE("(-\\d)\\d+").FullMatch("-1234", &i));
- CHECK_EQ(i, -1);
- CHECK(RE("(\\d)").PartialMatch("1234", &i));
- CHECK_EQ(i, 1);
- CHECK(RE("(-\\d)").PartialMatch("-1234", &i));
- CHECK_EQ(i, -1);
-
- // String-arg
- CHECK(RE("h(.*)o").FullMatch("hello", &s));
- CHECK_EQ(s, string("ell"));
-
- // StringPiece-arg
- StringPiece sp;
- CHECK(RE("(\\w+):(\\d+)").FullMatch("ruby:1234", &sp, &i));
- CHECK_EQ(sp.size(), 4);
- CHECK(memcmp(sp.data(), "ruby", 4) == 0);
- CHECK_EQ(i, 1234);
-
- // Multi-arg
- CHECK(RE("(\\w+):(\\d+)").FullMatch("ruby:1234", &s, &i));
- CHECK_EQ(s, string("ruby"));
- CHECK_EQ(i, 1234);
-
- // Ignored arg
- CHECK(RE("(\\w+)(:)(\\d+)").FullMatch("ruby:1234", &s, (void*)NULL, &i));
- CHECK_EQ(s, string("ruby"));
- CHECK_EQ(i, 1234);
-
- // Type tests
- {
- char c;
- CHECK(RE("(H)ello").FullMatch("Hello", &c));
- CHECK_EQ(c, 'H');
- }
- {
- unsigned char c;
- CHECK(RE("(H)ello").FullMatch("Hello", &c));
- CHECK_EQ(c, static_cast<unsigned char>('H'));
- }
- {
- short v;
- CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
- CHECK(RE("(-?\\d+)").FullMatch("-100", &v)); CHECK_EQ(v, -100);
- CHECK(RE("(-?\\d+)").FullMatch("32767", &v)); CHECK_EQ(v, 32767);
- CHECK(RE("(-?\\d+)").FullMatch("-32768", &v)); CHECK_EQ(v, -32768);
- CHECK(!RE("(-?\\d+)").FullMatch("-32769", &v));
- CHECK(!RE("(-?\\d+)").FullMatch("32768", &v));
- }
- {
- unsigned short v;
- CHECK(RE("(\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
- CHECK(RE("(\\d+)").FullMatch("32767", &v)); CHECK_EQ(v, 32767);
- CHECK(RE("(\\d+)").FullMatch("65535", &v)); CHECK_EQ(v, 65535);
- CHECK(!RE("(\\d+)").FullMatch("65536", &v));
- }
- {
- int v;
- static const int max_value = 0x7fffffff;
- static const int min_value = -max_value - 1;
- CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
- CHECK(RE("(-?\\d+)").FullMatch("-100", &v)); CHECK_EQ(v, -100);
- CHECK(RE("(-?\\d+)").FullMatch("2147483647", &v)); CHECK_EQ(v, max_value);
- CHECK(RE("(-?\\d+)").FullMatch("-2147483648", &v)); CHECK_EQ(v, min_value);
- CHECK(!RE("(-?\\d+)").FullMatch("-2147483649", &v));
- CHECK(!RE("(-?\\d+)").FullMatch("2147483648", &v));
- }
- {
- unsigned int v;
- static const unsigned int max_value = 0xfffffffful;
- CHECK(RE("(\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
- CHECK(RE("(\\d+)").FullMatch("4294967295", &v)); CHECK_EQ(v, max_value);
- CHECK(!RE("(\\d+)").FullMatch("4294967296", &v));
- }
-#ifdef HAVE_LONG_LONG
- {
- long long v;
- static const long long max_value = 0x7fffffffffffffffLL;
- static const long long min_value = -max_value - 1;
- char buf[32];
-
- CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
- CHECK(RE("(-?\\d+)").FullMatch("-100",&v)); CHECK_EQ(v, -100);
-
- snprintf(buf, sizeof(buf), "%lld", max_value);
- CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
-
- snprintf(buf, sizeof(buf), "%lld", min_value);
- CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, min_value);
-
- snprintf(buf, sizeof(buf), "%lld", max_value);
- assert(buf[strlen(buf)-1] != '9');
- buf[strlen(buf)-1]++;
- CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
-
- snprintf(buf, sizeof(buf), "%lld", min_value);
- assert(buf[strlen(buf)-1] != '9');
- buf[strlen(buf)-1]++;
- CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
- }
-#endif
-#if defined HAVE_UNSIGNED_LONG_LONG && defined HAVE_LONG_LONG
- {
- unsigned long long v;
- long long v2;
- static const unsigned long long max_value = 0xffffffffffffffffULL;
- char buf[32];
-
- CHECK(RE("(-?\\d+)").FullMatch("100",&v)); CHECK_EQ(v, 100);
- CHECK(RE("(-?\\d+)").FullMatch("-100",&v2)); CHECK_EQ(v2, -100);
-
- snprintf(buf, sizeof(buf), "%llu", max_value);
- CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
-
- assert(buf[strlen(buf)-1] != '9');
- buf[strlen(buf)-1]++;
- CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
- }
-#endif
- {
- float v;
- CHECK(RE("(.*)").FullMatch("100", &v));
- CHECK(RE("(.*)").FullMatch("-100.", &v));
- CHECK(RE("(.*)").FullMatch("1e23", &v));
- }
- {
- double v;
- CHECK(RE("(.*)").FullMatch("100", &v));
- CHECK(RE("(.*)").FullMatch("-100.", &v));
- CHECK(RE("(.*)").FullMatch("1e23", &v));
- }
-
- // Check that matching is fully anchored
- CHECK(!RE("(\\d+)").FullMatch("x1001", &i));
- CHECK(!RE("(\\d+)").FullMatch("1001x", &i));
- CHECK(RE("x(\\d+)").FullMatch("x1001", &i)); CHECK_EQ(i, 1001);
- CHECK(RE("(\\d+)x").FullMatch("1001x", &i)); CHECK_EQ(i, 1001);
-
- // Braces
- CHECK(RE("[0-9a-f+.-]{5,}").FullMatch("0abcd"));
- CHECK(RE("[0-9a-f+.-]{5,}").FullMatch("0abcde"));
- CHECK(!RE("[0-9a-f+.-]{5,}").FullMatch("0abc"));
-
- // Complicated RE
- CHECK(RE("foo|bar|[A-Z]").FullMatch("foo"));
- CHECK(RE("foo|bar|[A-Z]").FullMatch("bar"));
- CHECK(RE("foo|bar|[A-Z]").FullMatch("X"));
- CHECK(!RE("foo|bar|[A-Z]").FullMatch("XY"));
-
- // Check full-match handling (needs '$' tacked on internally)
- CHECK(RE("fo|foo").FullMatch("fo"));
- CHECK(RE("fo|foo").FullMatch("foo"));
- CHECK(RE("fo|foo$").FullMatch("fo"));
- CHECK(RE("fo|foo$").FullMatch("foo"));
- CHECK(RE("foo$").FullMatch("foo"));
- CHECK(!RE("foo\\$").FullMatch("foo$bar"));
- CHECK(!RE("fo|bar").FullMatch("fox"));
-
- // Uncomment the following if we change the handling of '$' to
- // prevent it from matching a trailing newline
- if (false) {
- // Check that we don't get bitten by pcre's special handling of a
- // '\n' at the end of the string matching '$'
- CHECK(!RE("foo$").PartialMatch("foo\n"));
- }
-
- // Number of args
- int a[16];
- CHECK(RE("").FullMatch(""));
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d){1}").FullMatch("1",
- &a[0]));
- CHECK_EQ(a[0], 1);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)").FullMatch("12",
- &a[0], &a[1]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)").FullMatch("123",
- &a[0], &a[1], &a[2]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)(\\d)").FullMatch("1234",
- &a[0], &a[1], &a[2], &a[3]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
- CHECK_EQ(a[3], 4);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)(\\d)(\\d)").FullMatch("12345",
- &a[0], &a[1], &a[2],
- &a[3], &a[4]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
- CHECK_EQ(a[3], 4);
- CHECK_EQ(a[4], 5);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)").FullMatch("123456",
- &a[0], &a[1], &a[2],
- &a[3], &a[4], &a[5]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
- CHECK_EQ(a[3], 4);
- CHECK_EQ(a[4], 5);
- CHECK_EQ(a[5], 6);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)").FullMatch("1234567",
- &a[0], &a[1], &a[2], &a[3],
- &a[4], &a[5], &a[6]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
- CHECK_EQ(a[3], 4);
- CHECK_EQ(a[4], 5);
- CHECK_EQ(a[5], 6);
- CHECK_EQ(a[6], 7);
-
- memset(a, 0, sizeof(0));
- CHECK(RE("(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)"
- "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)").FullMatch(
- "1234567890123456",
- &a[0], &a[1], &a[2], &a[3],
- &a[4], &a[5], &a[6], &a[7],
- &a[8], &a[9], &a[10], &a[11],
- &a[12], &a[13], &a[14], &a[15]));
- CHECK_EQ(a[0], 1);
- CHECK_EQ(a[1], 2);
- CHECK_EQ(a[2], 3);
- CHECK_EQ(a[3], 4);
- CHECK_EQ(a[4], 5);
- CHECK_EQ(a[5], 6);
- CHECK_EQ(a[6], 7);
- CHECK_EQ(a[7], 8);
- CHECK_EQ(a[8], 9);
- CHECK_EQ(a[9], 0);
- CHECK_EQ(a[10], 1);
- CHECK_EQ(a[11], 2);
- CHECK_EQ(a[12], 3);
- CHECK_EQ(a[13], 4);
- CHECK_EQ(a[14], 5);
- CHECK_EQ(a[15], 6);
-
- /***** PartialMatch *****/
-
- printf("Testing PartialMatch\n");
-
- CHECK(RE("h.*o").PartialMatch("hello"));
- CHECK(RE("h.*o").PartialMatch("othello"));
- CHECK(RE("h.*o").PartialMatch("hello!"));
- CHECK(RE("((((((((((((((((((((x))))))))))))))))))))").PartialMatch("x"));
-
- /***** other tests *****/
-
- RadixTests();
- TestReplace();
- TestExtract();
- TestConsume();
- TestFindAndConsume();
- TestQuoteMetaAll();
- TestMatchNumberPeculiarity();
-
- // Check the pattern() accessor
- {
- const string kPattern = "http://([^/]+)/.*";
- const RE re(kPattern);
- CHECK_EQ(kPattern, re.pattern());
- }
-
- // Check RE error field.
- {
- RE re("foo");
- CHECK(re.error().empty()); // Must have no error
- }
-
-#ifdef SUPPORT_UTF8
- // Check UTF-8 handling
- {
- printf("Testing UTF-8 handling\n");
-
- // Three Japanese characters (nihongo)
- const char utf8_string[] = {
- 0xe6, 0x97, 0xa5, // 65e5
- 0xe6, 0x9c, 0xac, // 627c
- 0xe8, 0xaa, 0x9e, // 8a9e
- 0
- };
- const char utf8_pattern[] = {
- '.',
- 0xe6, 0x9c, 0xac, // 627c
- '.',
- 0
- };
-
- // Both should match in either mode, bytes or UTF-8
- RE re_test1(".........");
- CHECK(re_test1.FullMatch(utf8_string));
- RE re_test2("...", pcrecpp::UTF8());
- CHECK(re_test2.FullMatch(utf8_string));
-
- // Check that '.' matches one byte or UTF-8 character
- // according to the mode.
- string ss;
- RE re_test3("(.)");
- CHECK(re_test3.PartialMatch(utf8_string, &ss));
- CHECK_EQ(ss, string("\xe6"));
- RE re_test4("(.)", pcrecpp::UTF8());
- CHECK(re_test4.PartialMatch(utf8_string, &ss));
- CHECK_EQ(ss, string("\xe6\x97\xa5"));
-
- // Check that string matches itself in either mode
- RE re_test5(utf8_string);
- CHECK(re_test5.FullMatch(utf8_string));
- RE re_test6(utf8_string, pcrecpp::UTF8());
- CHECK(re_test6.FullMatch(utf8_string));
-
- // Check that pattern matches string only in UTF8 mode
- RE re_test7(utf8_pattern);
- CHECK(!re_test7.FullMatch(utf8_string));
- RE re_test8(utf8_pattern, pcrecpp::UTF8());
- CHECK(re_test8.FullMatch(utf8_string));
- }
-
- // Check that ungreedy, UTF8 regular expressions don't match when they
- // oughtn't -- see bug 82246.
- {
- // This code always worked.
- const char* pattern = "\\w+X";
- const string target = "a aX";
- RE match_sentence(pattern);
- RE match_sentence_re(pattern, pcrecpp::UTF8());
-
- CHECK(!match_sentence.FullMatch(target));
- CHECK(!match_sentence_re.FullMatch(target));
- }
-
- {
- const char* pattern = "(?U)\\w+X";
- const string target = "a aX";
- RE match_sentence(pattern);
- RE match_sentence_re(pattern, pcrecpp::UTF8());
-
- CHECK(!match_sentence.FullMatch(target));
- CHECK(!match_sentence_re.FullMatch(target));
- }
-#endif /* def SUPPORT_UTF8 */
-
- printf("Testing error reporting\n");
-
- { RE re("a\\1"); CHECK(!re.error().empty()); }
- {
- RE re("a[x");
- CHECK(!re.error().empty());
- }
- {
- RE re("a[z-a]");
- CHECK(!re.error().empty());
- }
- {
- RE re("a[[:foobar:]]");
- CHECK(!re.error().empty());
- }
- {
- RE re("a(b");
- CHECK(!re.error().empty());
- }
- {
- RE re("a\\");
- CHECK(!re.error().empty());
- }
-
- // Test that recursion is stopped
- TestRecursion();
-
- // Test Options
- if (getenv("VERBOSE_TEST") != NULL)
- VERBOSE_TEST = true;
- TestOptions();
-
- // Test the constructors
- TestConstructors();
-
- // Done
- printf("OK\n");
-
- return 0;
-}
diff --git a/ext/pcre/pcrelib/pcrecpparg.h b/ext/pcre/pcrelib/pcrecpparg.h
deleted file mode 100644
index 323dde58e5..0000000000
--- a/ext/pcre/pcrelib/pcrecpparg.h
+++ /dev/null
@@ -1,171 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: Sanjay Ghemawat
-
-#ifndef _PCRECPPARG_H
-#define _PCRECPPARG_H
-
-#include <stdlib.h> // for NULL
-#include <string>
-
-namespace pcrecpp {
-
-class StringPiece;
-
-// Hex/Octal/Binary?
-
-// Special class for parsing into objects that define a ParseFrom() method
-template <class T>
-class _RE_MatchObject {
- public:
- static inline bool Parse(const char* str, int n, void* dest) {
- T* object = reinterpret_cast<T*>(dest);
- return object->ParseFrom(str, n);
- }
-};
-
-class Arg {
- public:
- // Empty constructor so we can declare arrays of Arg
- Arg();
-
- // Constructor specially designed for NULL arguments
- Arg(void*);
-
- typedef bool (*Parser)(const char* str, int n, void* dest);
-
-// Type-specific parsers
-#define PCRE_MAKE_PARSER(type,name) \
- Arg(type* p) : arg_(p), parser_(name) { } \
- Arg(type* p, Parser parser) : arg_(p), parser_(parser) { }
-
-
- PCRE_MAKE_PARSER(char, parse_char);
- PCRE_MAKE_PARSER(unsigned char, parse_uchar);
- PCRE_MAKE_PARSER(short, parse_short);
- PCRE_MAKE_PARSER(unsigned short, parse_ushort);
- PCRE_MAKE_PARSER(int, parse_int);
- PCRE_MAKE_PARSER(unsigned int, parse_uint);
- PCRE_MAKE_PARSER(long, parse_long);
- PCRE_MAKE_PARSER(unsigned long, parse_ulong);
-#if 1
- PCRE_MAKE_PARSER(long long, parse_longlong);
-#endif
-#if 1
- PCRE_MAKE_PARSER(unsigned long long, parse_ulonglong);
-#endif
- PCRE_MAKE_PARSER(float, parse_float);
- PCRE_MAKE_PARSER(double, parse_double);
- PCRE_MAKE_PARSER(std::string, parse_string);
- PCRE_MAKE_PARSER(StringPiece, parse_stringpiece);
-
-#undef PCRE_MAKE_PARSER
-
- // Generic constructor
- template <class T> Arg(T*, Parser parser);
- // Generic constructor template
- template <class T> Arg(T* p)
- : arg_(p), parser_(_RE_MatchObject<T>::Parse) {
- }
-
- // Parse the data
- bool Parse(const char* str, int n) const;
-
- private:
- void* arg_;
- Parser parser_;
-
- static bool parse_null (const char* str, int n, void* dest);
- static bool parse_char (const char* str, int n, void* dest);
- static bool parse_uchar (const char* str, int n, void* dest);
- static bool parse_float (const char* str, int n, void* dest);
- static bool parse_double (const char* str, int n, void* dest);
- static bool parse_string (const char* str, int n, void* dest);
- static bool parse_stringpiece (const char* str, int n, void* dest);
-
-#define PCRE_DECLARE_INTEGER_PARSER(name) \
- private: \
- static bool parse_ ## name(const char* str, int n, void* dest); \
- static bool parse_ ## name ## _radix( \
- const char* str, int n, void* dest, int radix); \
- public: \
- static bool parse_ ## name ## _hex(const char* str, int n, void* dest); \
- static bool parse_ ## name ## _octal(const char* str, int n, void* dest); \
- static bool parse_ ## name ## _cradix(const char* str, int n, void* dest)
-
- PCRE_DECLARE_INTEGER_PARSER(short);
- PCRE_DECLARE_INTEGER_PARSER(ushort);
- PCRE_DECLARE_INTEGER_PARSER(int);
- PCRE_DECLARE_INTEGER_PARSER(uint);
- PCRE_DECLARE_INTEGER_PARSER(long);
- PCRE_DECLARE_INTEGER_PARSER(ulong);
- PCRE_DECLARE_INTEGER_PARSER(longlong);
- PCRE_DECLARE_INTEGER_PARSER(ulonglong);
-
-#undef PCRE_DECLARE_INTEGER_PARSER
-};
-
-inline Arg::Arg() : arg_(NULL), parser_(parse_null) { }
-inline Arg::Arg(void* p) : arg_(p), parser_(parse_null) { }
-
-inline bool Arg::Parse(const char* str, int n) const {
- return (*parser_)(str, n, arg_);
-}
-
-// This part of the parser, appropriate only for ints, deals with bases
-#define MAKE_INTEGER_PARSER(type, name) \
- inline Arg Hex(type* ptr) { \
- return Arg(ptr, Arg::parse_ ## name ## _hex); } \
- inline Arg Octal(type* ptr) { \
- return Arg(ptr, Arg::parse_ ## name ## _octal); } \
- inline Arg CRadix(type* ptr) { \
- return Arg(ptr, Arg::parse_ ## name ## _cradix); }
-
-MAKE_INTEGER_PARSER(short, short);
-MAKE_INTEGER_PARSER(unsigned short, ushort);
-MAKE_INTEGER_PARSER(int, int);
-MAKE_INTEGER_PARSER(unsigned int, uint);
-MAKE_INTEGER_PARSER(long, long);
-MAKE_INTEGER_PARSER(unsigned long, ulong);
-#if 1
-MAKE_INTEGER_PARSER(long long, longlong);
-#endif
-#if 1
-MAKE_INTEGER_PARSER(unsigned long long, ulonglong);
-#endif
-
-#undef PCRE_IS_SET
-#undef PCRE_SET_OR_CLEAR
-#undef MAKE_INTEGER_PARSER
-
-} // namespace pcrecpp
-
-
-#endif /* _PCRECPPARG_H */
diff --git a/ext/pcre/pcrelib/pcredemo.c b/ext/pcre/pcrelib/pcredemo.c
index 8b06a9ce63..3647568766 100644
--- a/ext/pcre/pcrelib/pcredemo.c
+++ b/ext/pcre/pcrelib/pcredemo.c
@@ -4,17 +4,27 @@
/* This is a demonstration program to illustrate the most straightforward ways
of calling the PCRE regular expression library from a C program. See the
-pcresample documentation for a short discussion.
+pcresample documentation for a short discussion ("man pcresample" if you have
+the PCRE man pages installed).
+
+In Unix-like environments, compile this program thuswise:
-Compile thuswise:
gcc -Wall pcredemo.c -I/usr/local/include -L/usr/local/lib \
-R/usr/local/lib -lpcre
Replace "/usr/local/include" and "/usr/local/lib" with wherever the include and
-library files for PCRE are installed on your system. Only some operating
+library files for PCRE are installed on your system. You don't need -I and -L
+if PCRE is installed in the standard system libraries. Only some operating
systems (e.g. Solaris) use the -R option.
-*/
+Building under Windows:
+
+If you want to statically link this program against a non-dll .a file, you must
+define PCRE_STATIC before including pcre.h, otherwise the pcre_malloc() and
+pcre_free() exported functions will be declared __declspec(dllimport), with
+unwanted results. So in this environment, uncomment the following line. */
+
+/* #define PCRE_STATIC */
#include <stdio.h>
#include <string.h>
@@ -128,8 +138,8 @@ printf("\nMatch succeeded at offset %d\n", ovector[0]);
/*************************************************************************
* We have found the first match within the subject string. If the output *
-* vector wasn't big enough, set its size to the maximum. Then output any *
-* substrings that were captured. *
+* vector wasn't big enough, say so. Then output any substrings that were *
+* captured. *
*************************************************************************/
/* The output vector wasn't big enough */
@@ -154,7 +164,7 @@ for (i = 0; i < rc; i++)
/**************************************************************************
* That concludes the basic part of this demonstration program. We have *
* compiled a pattern, and performed a single match. The code that follows *
-* first shows how to access named substrings, and then how to code for *
+* shows first how to access named substrings, and then how to code for *
* repeated matches on the same subject. *
**************************************************************************/
diff --git a/ext/pcre/pcrelib/pcregrep.c b/ext/pcre/pcrelib/pcregrep.c
deleted file mode 100644
index 0e57e56514..0000000000
--- a/ext/pcre/pcrelib/pcregrep.c
+++ /dev/null
@@ -1,1993 +0,0 @@
-/*************************************************
-* pcregrep program *
-*************************************************/
-
-/* This is a grep program that uses the PCRE regular expression library to do
-its pattern matching. On a Unix or Win32 system it can recurse into
-directories.
-
- Copyright (c) 1997-2006 University of Cambridge
-
------------------------------------------------------------------------------
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- * Neither the name of the University of Cambridge nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
-*/
-
-#include <ctype.h>
-#include <locale.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "pcre.h"
-
-#define FALSE 0
-#define TRUE 1
-
-typedef int BOOL;
-
-#define VERSION "4.4 29-Nov-2006"
-#define MAX_PATTERN_COUNT 100
-
-#if BUFSIZ > 8192
-#define MBUFTHIRD BUFSIZ
-#else
-#define MBUFTHIRD 8192
-#endif
-
-/* Values for the "filenames" variable, which specifies options for file name
-output. The order is important; it is assumed that a file name is wanted for
-all values greater than FN_DEFAULT. */
-
-enum { FN_NONE, FN_DEFAULT, FN_ONLY, FN_NOMATCH_ONLY, FN_FORCE };
-
-/* Actions for the -d and -D options */
-
-enum { dee_READ, dee_SKIP, dee_RECURSE };
-enum { DEE_READ, DEE_SKIP };
-
-/* Actions for special processing options (flag bits) */
-
-#define PO_WORD_MATCH 0x0001
-#define PO_LINE_MATCH 0x0002
-#define PO_FIXED_STRINGS 0x0004
-
-/* Line ending types */
-
-enum { EL_LF, EL_CR, EL_CRLF, EL_ANY };
-
-
-
-/*************************************************
-* Global variables *
-*************************************************/
-
-/* Jeffrey Friedl has some debugging requirements that are not part of the
-regular code. */
-
-#ifdef JFRIEDL_DEBUG
-static int S_arg = -1;
-static unsigned int jfriedl_XR = 0; /* repeat regex attempt this many times */
-static unsigned int jfriedl_XT = 0; /* replicate text this many times */
-static const char *jfriedl_prefix = "";
-static const char *jfriedl_postfix = "";
-#endif
-
-static int endlinetype;
-
-static char *colour_string = (char *)"1;31";
-static char *colour_option = NULL;
-static char *dee_option = NULL;
-static char *DEE_option = NULL;
-static char *newline = NULL;
-static char *pattern_filename = NULL;
-static char *stdin_name = (char *)"(standard input)";
-static char *locale = NULL;
-
-static const unsigned char *pcretables = NULL;
-
-static int pattern_count = 0;
-static pcre **pattern_list;
-static pcre_extra **hints_list;
-
-static char *include_pattern = NULL;
-static char *exclude_pattern = NULL;
-
-static pcre *include_compiled = NULL;
-static pcre *exclude_compiled = NULL;
-
-static int after_context = 0;
-static int before_context = 0;
-static int both_context = 0;
-static int dee_action = dee_READ;
-static int DEE_action = DEE_READ;
-static int error_count = 0;
-static int filenames = FN_DEFAULT;
-static int process_options = 0;
-
-static BOOL count_only = FALSE;
-static BOOL do_colour = FALSE;
-static BOOL hyphenpending = FALSE;
-static BOOL invert = FALSE;
-static BOOL multiline = FALSE;
-static BOOL number = FALSE;
-static BOOL only_matching = FALSE;
-static BOOL quiet = FALSE;
-static BOOL silent = FALSE;
-static BOOL utf8 = FALSE;
-
-/* Structure for options and list of them */
-
-enum { OP_NODATA, OP_STRING, OP_OP_STRING, OP_NUMBER, OP_OP_NUMBER,
- OP_PATLIST };
-
-typedef struct option_item {
- int type;
- int one_char;
- void *dataptr;
- const char *long_name;
- const char *help_text;
-} option_item;
-
-/* Options without a single-letter equivalent get a negative value. This can be
-used to identify them. */
-
-#define N_COLOUR (-1)
-#define N_EXCLUDE (-2)
-#define N_HELP (-3)
-#define N_INCLUDE (-4)
-#define N_LABEL (-5)
-#define N_LOCALE (-6)
-#define N_NULL (-7)
-
-static option_item optionlist[] = {
- { OP_NODATA, N_NULL, NULL, "", " terminate options" },
- { OP_NODATA, N_HELP, NULL, "help", "display this help and exit" },
- { OP_NUMBER, 'A', &after_context, "after-context=number", "set number of following context lines" },
- { OP_NUMBER, 'B', &before_context, "before-context=number", "set number of prior context lines" },
- { OP_OP_STRING, N_COLOUR, &colour_option, "color=option", "matched text color option" },
- { OP_NUMBER, 'C', &both_context, "context=number", "set number of context lines, before & after" },
- { OP_NODATA, 'c', NULL, "count", "print only a count of matching lines per FILE" },
- { OP_OP_STRING, N_COLOUR, &colour_option, "colour=option", "matched text colour option" },
- { OP_STRING, 'D', &DEE_option, "devices=action","how to handle devices, FIFOs, and sockets" },
- { OP_STRING, 'd', &dee_option, "directories=action", "how to handle directories" },
- { OP_PATLIST, 'e', NULL, "regex(p)", "specify pattern (may be used more than once)" },
- { OP_NODATA, 'F', NULL, "fixed_strings", "patterns are sets of newline-separated strings" },
- { OP_STRING, 'f', &pattern_filename, "file=path", "read patterns from file" },
- { OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" },
- { OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" },
- { OP_NODATA, 'i', NULL, "ignore-case", "ignore case distinctions" },
- { OP_NODATA, 'l', NULL, "files-with-matches", "print only FILE names containing matches" },
- { OP_NODATA, 'L', NULL, "files-without-match","print only FILE names not containing matches" },
- { OP_STRING, N_LABEL, &stdin_name, "label=name", "set name for standard input" },
- { OP_STRING, N_LOCALE, &locale, "locale=locale", "use the named locale" },
- { OP_NODATA, 'M', NULL, "multiline", "run in multiline mode" },
- { OP_STRING, 'N', &newline, "newline=type", "specify newline type (CR, LR, CRLF)" },
- { OP_NODATA, 'n', NULL, "line-number", "print line number with output lines" },
- { OP_NODATA, 'o', NULL, "only-matching", "show only the part of the line that matched" },
- { OP_NODATA, 'q', NULL, "quiet", "suppress output, just set return code" },
- { OP_NODATA, 'r', NULL, "recursive", "recursively scan sub-directories" },
- { OP_STRING, N_EXCLUDE,&exclude_pattern, "exclude=pattern","exclude matching files when recursing" },
- { OP_STRING, N_INCLUDE,&include_pattern, "include=pattern","include matching files when recursing" },
-#ifdef JFRIEDL_DEBUG
- { OP_OP_NUMBER, 'S', &S_arg, "jeffS", "replace matched (sub)string with X" },
-#endif
- { OP_NODATA, 's', NULL, "no-messages", "suppress error messages" },
- { OP_NODATA, 'u', NULL, "utf-8", "use UTF-8 mode" },
- { OP_NODATA, 'V', NULL, "version", "print version information and exit" },
- { OP_NODATA, 'v', NULL, "invert-match", "select non-matching lines" },
- { OP_NODATA, 'w', NULL, "word-regex(p)", "force patterns to match only as words" },
- { OP_NODATA, 'x', NULL, "line-regex(p)", "force patterns to match only whole lines" },
- { OP_NODATA, 0, NULL, NULL, NULL }
-};
-
-/* Tables for prefixing and suffixing patterns, according to the -w, -x, and -F
-options. These set the 1, 2, and 4 bits in process_options, respectively. Note
-that the combination of -w and -x has the same effect as -x on its own, so we
-can treat them as the same. */
-
-static const char *prefix[] = {
- "", "\\b", "^(?:", "^(?:", "\\Q", "\\b\\Q", "^(?:\\Q", "^(?:\\Q" };
-
-static const char *suffix[] = {
- "", "\\b", ")$", ")$", "\\E", "\\E\\b", "\\E)$", "\\E)$" };
-
-/* UTF-8 tables - used only when the newline setting is "all". */
-
-const int utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
-
-const char utf8_table4[] = {
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
- 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };
-
-
-
-/*************************************************
-* OS-specific functions *
-*************************************************/
-
-/* These functions are defined so that they can be made system specific,
-although at present the only ones are for Unix, Win32, and for "no support". */
-
-
-/************* Directory scanning in Unix ***********/
-
-#if IS_UNIX
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-typedef DIR directory_type;
-
-static int
-isdirectory(char *filename)
-{
-struct stat statbuf;
-if (stat(filename, &statbuf) < 0)
- return 0; /* In the expectation that opening as a file will fail */
-return ((statbuf.st_mode & S_IFMT) == S_IFDIR)? '/' : 0;
-}
-
-static directory_type *
-opendirectory(char *filename)
-{
-return opendir(filename);
-}
-
-static char *
-readdirectory(directory_type *dir)
-{
-for (;;)
- {
- struct dirent *dent = readdir(dir);
- if (dent == NULL) return NULL;
- if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0)
- return dent->d_name;
- }
-return NULL; /* Keep compiler happy; never executed */
-}
-
-static void
-closedirectory(directory_type *dir)
-{
-closedir(dir);
-}
-
-
-/************* Test for regular file in Unix **********/
-
-static int
-isregfile(char *filename)
-{
-struct stat statbuf;
-if (stat(filename, &statbuf) < 0)
- return 1; /* In the expectation that opening as a file will fail */
-return (statbuf.st_mode & S_IFMT) == S_IFREG;
-}
-
-
-/************* Test stdout for being a terminal in Unix **********/
-
-static BOOL
-is_stdout_tty(void)
-{
-return isatty(fileno(stdout));
-}
-
-
-/************* Directory scanning in Win32 ***********/
-
-/* I (Philip Hazel) have no means of testing this code. It was contributed by
-Lionel Fourquaux. David Burgess added a patch to define INVALID_FILE_ATTRIBUTES
-when it did not exist. */
-
-
-#elif HAVE_WIN32API
-
-#ifndef STRICT
-# define STRICT
-#endif
-#ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#ifndef INVALID_FILE_ATTRIBUTES
-#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
-#endif
-
-#include <windows.h>
-
-typedef struct directory_type
-{
-HANDLE handle;
-BOOL first;
-WIN32_FIND_DATA data;
-} directory_type;
-
-int
-isdirectory(char *filename)
-{
-DWORD attr = GetFileAttributes(filename);
-if (attr == INVALID_FILE_ATTRIBUTES)
- return 0;
-return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) ? '/' : 0;
-}
-
-directory_type *
-opendirectory(char *filename)
-{
-size_t len;
-char *pattern;
-directory_type *dir;
-DWORD err;
-len = strlen(filename);
-pattern = (char *) malloc(len + 3);
-dir = (directory_type *) malloc(sizeof(*dir));
-if ((pattern == NULL) || (dir == NULL))
- {
- fprintf(stderr, "pcregrep: malloc failed\n");
- exit(2);
- }
-memcpy(pattern, filename, len);
-memcpy(&(pattern[len]), "\\*", 3);
-dir->handle = FindFirstFile(pattern, &(dir->data));
-if (dir->handle != INVALID_HANDLE_VALUE)
- {
- free(pattern);
- dir->first = TRUE;
- return dir;
- }
-err = GetLastError();
-free(pattern);
-free(dir);
-errno = (err == ERROR_ACCESS_DENIED) ? EACCES : ENOENT;
-return NULL;
-}
-
-char *
-readdirectory(directory_type *dir)
-{
-for (;;)
- {
- if (!dir->first)
- {
- if (!FindNextFile(dir->handle, &(dir->data)))
- return NULL;
- }
- else
- {
- dir->first = FALSE;
- }
- if (strcmp(dir->data.cFileName, ".") != 0 && strcmp(dir->data.cFileName, "..") != 0)
- return dir->data.cFileName;
- }
-#ifndef _MSC_VER
-return NULL; /* Keep compiler happy; never executed */
-#endif
-}
-
-void
-closedirectory(directory_type *dir)
-{
-FindClose(dir->handle);
-free(dir);
-}
-
-
-/************* Test for regular file in Win32 **********/
-
-/* I don't know how to do this, or if it can be done; assume all paths are
-regular if they are not directories. */
-
-int isregfile(char *filename)
-{
-return !isdirectory(filename)
-}
-
-
-/************* Test stdout for being a terminal in Win32 **********/
-
-/* I don't know how to do this; assume never */
-
-static BOOL
-is_stdout_tty(void)
-{
-FALSE;
-}
-
-
-/************* Directory scanning when we can't do it ***********/
-
-/* The type is void, and apart from isdirectory(), the functions do nothing. */
-
-#else
-
-typedef void directory_type;
-
-int isdirectory(char *filename) { return 0; }
-directory_type * opendirectory(char *filename) {}
-char *readdirectory(directory_type *dir) {}
-void closedirectory(directory_type *dir) {}
-
-
-/************* Test for regular when we can't do it **********/
-
-/* Assume all files are regular. */
-
-int isregfile(char *filename) { return 1; }
-
-
-/************* Test stdout for being a terminal when we can't do it **********/
-
-static BOOL
-is_stdout_tty(void)
-{
-return FALSE;
-}
-
-
-#endif
-
-
-
-#if ! HAVE_STRERROR
-/*************************************************
-* Provide strerror() for non-ANSI libraries *
-*************************************************/
-
-/* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
-in their libraries, but can provide the same facility by this simple
-alternative function. */
-
-extern int sys_nerr;
-extern char *sys_errlist[];
-
-char *
-strerror(int n)
-{
-if (n < 0 || n >= sys_nerr) return "unknown error number";
-return sys_errlist[n];
-}
-#endif /* HAVE_STRERROR */
-
-
-
-/*************************************************
-* Find end of line *
-*************************************************/
-
-/* The length of the endline sequence that is found is set via lenptr. This may
-be zero at the very end of the file if there is no line-ending sequence there.
-
-Arguments:
- p current position in line
- endptr end of available data
- lenptr where to put the length of the eol sequence
-
-Returns: pointer to the last byte of the line
-*/
-
-static char *
-end_of_line(char *p, char *endptr, int *lenptr)
-{
-switch(endlinetype)
- {
- default: /* Just in case */
- case EL_LF:
- while (p < endptr && *p != '\n') p++;
- if (p < endptr)
- {
- *lenptr = 1;
- return p + 1;
- }
- *lenptr = 0;
- return endptr;
-
- case EL_CR:
- while (p < endptr && *p != '\r') p++;
- if (p < endptr)
- {
- *lenptr = 1;
- return p + 1;
- }
- *lenptr = 0;
- return endptr;
-
- case EL_CRLF:
- for (;;)
- {
- while (p < endptr && *p != '\r') p++;
- if (++p >= endptr)
- {
- *lenptr = 0;
- return endptr;
- }
- if (*p == '\n')
- {
- *lenptr = 2;
- return p + 1;
- }
- }
- break;
-
- case EL_ANY:
- while (p < endptr)
- {
- int extra = 0;
- register int c = *((unsigned char *)p);
-
- if (utf8 && c >= 0xc0)
- {
- int gcii, gcss;
- extra = utf8_table4[c & 0x3f]; /* Number of additional bytes */
- gcss = 6*extra;
- c = (c & utf8_table3[extra]) << gcss;
- for (gcii = 1; gcii <= extra; gcii++)
- {
- gcss -= 6;
- c |= (p[gcii] & 0x3f) << gcss;
- }
- }
-
- p += 1 + extra;
-
- switch (c)
- {
- case 0x0a: /* LF */
- case 0x0b: /* VT */
- case 0x0c: /* FF */
- *lenptr = 1;
- return p;
-
- case 0x0d: /* CR */
- if (p < endptr && *p == 0x0a)
- {
- *lenptr = 2;
- p++;
- }
- else *lenptr = 1;
- return p;
-
- case 0x85: /* NEL */
- *lenptr = utf8? 2 : 1;
- return p;
-
- case 0x2028: /* LS */
- case 0x2029: /* PS */
- *lenptr = 3;
- return p;
-
- default:
- break;
- }
- } /* End of loop for ANY case */
-
- *lenptr = 0; /* Must have hit the end */
- return endptr;
- } /* End of overall switch */
-}
-
-
-
-/*************************************************
-* Find start of previous line *
-*************************************************/
-
-/* This is called when looking back for before lines to print.
-
-Arguments:
- p start of the subsequent line
- startptr start of available data
-
-Returns: pointer to the start of the previous line
-*/
-
-static char *
-previous_line(char *p, char *startptr)
-{
-switch(endlinetype)
- {
- default: /* Just in case */
- case EL_LF:
- p--;
- while (p > startptr && p[-1] != '\n') p--;
- return p;
-
- case EL_CR:
- p--;
- while (p > startptr && p[-1] != '\n') p--;
- return p;
-
- case EL_CRLF:
- for (;;)
- {
- p -= 2;
- while (p > startptr && p[-1] != '\n') p--;
- if (p <= startptr + 1 || p[-2] == '\r') return p;
- }
- return p; /* But control should never get here */
-
- case EL_ANY:
- if (*(--p) == '\n' && p > startptr && p[-1] == '\r') p--;
- if (utf8) while ((*p & 0xc0) == 0x80) p--;
-
- while (p > startptr)
- {
- register int c;
- char *pp = p - 1;
-
- if (utf8)
- {
- int extra = 0;
- while ((*pp & 0xc0) == 0x80) pp--;
- c = *((unsigned char *)pp);
- if (c >= 0xc0)
- {
- int gcii, gcss;
- extra = utf8_table4[c & 0x3f]; /* Number of additional bytes */
- gcss = 6*extra;
- c = (c & utf8_table3[extra]) << gcss;
- for (gcii = 1; gcii <= extra; gcii++)
- {
- gcss -= 6;
- c |= (pp[gcii] & 0x3f) << gcss;
- }
- }
- }
- else c = *((unsigned char *)pp);
-
- switch (c)
- {
- case 0x0a: /* LF */
- case 0x0b: /* VT */
- case 0x0c: /* FF */
- case 0x0d: /* CR */
- case 0x85: /* NEL */
- case 0x2028: /* LS */
- case 0x2029: /* PS */
- return p;
-
- default:
- break;
- }
-
- p = pp; /* Back one character */
- } /* End of loop for ANY case */
-
- return startptr; /* Hit start of data */
- } /* End of overall switch */
-}
-
-
-
-
-
-/*************************************************
-* Print the previous "after" lines *
-*************************************************/
-
-/* This is called if we are about to lose said lines because of buffer filling,
-and at the end of the file. The data in the line is written using fwrite() so
-that a binary zero does not terminate it.
-
-Arguments:
- lastmatchnumber the number of the last matching line, plus one
- lastmatchrestart where we restarted after the last match
- endptr end of available data
- printname filename for printing
-
-Returns: nothing
-*/
-
-static void do_after_lines(int lastmatchnumber, char *lastmatchrestart,
- char *endptr, char *printname)
-{
-if (after_context > 0 && lastmatchnumber > 0)
- {
- int count = 0;
- while (lastmatchrestart < endptr && count++ < after_context)
- {
- int ellength;
- char *pp = lastmatchrestart;
- if (printname != NULL) fprintf(stdout, "%s-", printname);
- if (number) fprintf(stdout, "%d-", lastmatchnumber++);
- pp = end_of_line(pp, endptr, &ellength);
- fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
- lastmatchrestart = pp;
- }
- hyphenpending = TRUE;
- }
-}
-
-
-
-/*************************************************
-* Grep an individual file *
-*************************************************/
-
-/* This is called from grep_or_recurse() below. It uses a buffer that is three
-times the value of MBUFTHIRD. The matching point is never allowed to stray into
-the top third of the buffer, thus keeping more of the file available for
-context printing or for multiline scanning. For large files, the pointer will
-be in the middle third most of the time, so the bottom third is available for
-"before" context printing.
-
-Arguments:
- in the fopened FILE stream
- printname the file name if it is to be printed for each match
- or NULL if the file name is not to be printed
- it cannot be NULL if filenames[_nomatch]_only is set
-
-Returns: 0 if there was at least one match
- 1 otherwise (no matches)
-*/
-
-static int
-pcregrep(FILE *in, char *printname)
-{
-int rc = 1;
-int linenumber = 1;
-int lastmatchnumber = 0;
-int count = 0;
-int offsets[99];
-char *lastmatchrestart = NULL;
-char buffer[3*MBUFTHIRD];
-char *ptr = buffer;
-char *endptr;
-size_t bufflength;
-BOOL endhyphenpending = FALSE;
-
-/* Do the first read into the start of the buffer and set up the pointer to
-end of what we have. */
-
-bufflength = fread(buffer, 1, 3*MBUFTHIRD, in);
-endptr = buffer + bufflength;
-
-/* Loop while the current pointer is not at the end of the file. For large
-files, endptr will be at the end of the buffer when we are in the middle of the
-file, but ptr will never get there, because as soon as it gets over 2/3 of the
-way, the buffer is shifted left and re-filled. */
-
-while (ptr < endptr)
- {
- int i, endlinelength;
- int mrc = 0;
- BOOL match = FALSE;
- char *t = ptr;
- size_t length, linelength;
-
- /* At this point, ptr is at the start of a line. We need to find the length
- of the subject string to pass to pcre_exec(). In multiline mode, it is the
- length remainder of the data in the buffer. Otherwise, it is the length of
- the next line. After matching, we always advance by the length of the next
- line. In multiline mode the PCRE_FIRSTLINE option is used for compiling, so
- that any match is constrained to be in the first line. */
-
- t = end_of_line(t, endptr, &endlinelength);
- linelength = t - ptr - endlinelength;
- length = multiline? endptr - ptr : linelength;
-
- /* Extra processing for Jeffrey Friedl's debugging. */
-
-#ifdef JFRIEDL_DEBUG
- if (jfriedl_XT || jfriedl_XR)
- {
- #include <sys/time.h>
- #include <time.h>
- struct timeval start_time, end_time;
- struct timezone dummy;
-
- if (jfriedl_XT)
- {
- unsigned long newlen = length * jfriedl_XT + strlen(jfriedl_prefix) + strlen(jfriedl_postfix);
- const char *orig = ptr;
- ptr = malloc(newlen + 1);
- if (!ptr) {
- printf("out of memory");
- exit(2);
- }
- endptr = ptr;
- strcpy(endptr, jfriedl_prefix); endptr += strlen(jfriedl_prefix);
- for (i = 0; i < jfriedl_XT; i++) {
- strncpy(endptr, orig, length);
- endptr += length;
- }
- strcpy(endptr, jfriedl_postfix); endptr += strlen(jfriedl_postfix);
- length = newlen;
- }
-
- if (gettimeofday(&start_time, &dummy) != 0)
- perror("bad gettimeofday");
-
-
- for (i = 0; i < jfriedl_XR; i++)
- match = (pcre_exec(pattern_list[0], hints_list[0], ptr, length, 0, 0, offsets, 99) >= 0);
-
- if (gettimeofday(&end_time, &dummy) != 0)
- perror("bad gettimeofday");
-
- double delta = ((end_time.tv_sec + (end_time.tv_usec / 1000000.0))
- -
- (start_time.tv_sec + (start_time.tv_usec / 1000000.0)));
-
- printf("%s TIMER[%.4f]\n", match ? "MATCH" : "FAIL", delta);
- return 0;
- }
-#endif
-
-
- /* Run through all the patterns until one matches. Note that we don't include
- the final newline in the subject string. */
-
- for (i = 0; i < pattern_count; i++)
- {
- mrc = pcre_exec(pattern_list[i], hints_list[i], ptr, length, 0, 0,
- offsets, 99);
- if (mrc >= 0) { match = TRUE; break; }
- if (mrc != PCRE_ERROR_NOMATCH)
- {
- fprintf(stderr, "pcregrep: pcre_exec() error %d while matching ", mrc);
- if (pattern_count > 1) fprintf(stderr, "pattern number %d to ", i+1);
- fprintf(stderr, "this line:\n");
- fwrite(ptr, 1, linelength, stderr); /* In case binary zero included */
- fprintf(stderr, "\n");
- if (error_count == 0 &&
- (mrc == PCRE_ERROR_MATCHLIMIT || mrc == PCRE_ERROR_RECURSIONLIMIT))
- {
- fprintf(stderr, "pcregrep: error %d means that a resource limit "
- "was exceeded\n", mrc);
- fprintf(stderr, "pcregrep: check your regex for nested unlimited loops\n");
- }
- if (error_count++ > 20)
- {
- fprintf(stderr, "pcregrep: too many errors - abandoned\n");
- exit(2);
- }
- match = invert; /* No more matching; don't show the line again */
- break;
- }
- }
-
- /* If it's a match or a not-match (as required), do what's wanted. */
-
- if (match != invert)
- {
- BOOL hyphenprinted = FALSE;
-
- /* We've failed if we want a file that doesn't have any matches. */
-
- if (filenames == FN_NOMATCH_ONLY) return 1;
-
- /* Just count if just counting is wanted. */
-
- if (count_only) count++;
-
- /* If all we want is a file name, there is no need to scan any more lines
- in the file. */
-
- else if (filenames == FN_ONLY)
- {
- fprintf(stdout, "%s\n", printname);
- return 0;
- }
-
- /* Likewise, if all we want is a yes/no answer. */
-
- else if (quiet) return 0;
-
- /* The --only-matching option prints just the substring that matched, and
- does not pring any context. */
-
- else if (only_matching)
- {
- if (printname != NULL) fprintf(stdout, "%s:", printname);
- if (number) fprintf(stdout, "%d:", linenumber);
- fwrite(ptr + offsets[0], 1, offsets[1] - offsets[0], stdout);
- fprintf(stdout, "\n");
- }
-
- /* This is the default case when none of the above options is set. We print
- the matching lines(s), possibly preceded and/or followed by other lines of
- context. */
-
- else
- {
- /* See if there is a requirement to print some "after" lines from a
- previous match. We never print any overlaps. */
-
- if (after_context > 0 && lastmatchnumber > 0)
- {
- int ellength;
- int linecount = 0;
- char *p = lastmatchrestart;
-
- while (p < ptr && linecount < after_context)
- {
- p = end_of_line(p, ptr, &ellength);
- linecount++;
- }
-
- /* It is important to advance lastmatchrestart during this printing so
- that it interacts correctly with any "before" printing below. Print
- each line's data using fwrite() in case there are binary zeroes. */
-
- while (lastmatchrestart < p)
- {
- char *pp = lastmatchrestart;
- if (printname != NULL) fprintf(stdout, "%s-", printname);
- if (number) fprintf(stdout, "%d-", lastmatchnumber++);
- pp = end_of_line(pp, endptr, &ellength);
- fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
- lastmatchrestart = pp;
- }
- if (lastmatchrestart != ptr) hyphenpending = TRUE;
- }
-
- /* If there were non-contiguous lines printed above, insert hyphens. */
-
- if (hyphenpending)
- {
- fprintf(stdout, "--\n");
- hyphenpending = FALSE;
- hyphenprinted = TRUE;
- }
-
- /* See if there is a requirement to print some "before" lines for this
- match. Again, don't print overlaps. */
-
- if (before_context > 0)
- {
- int linecount = 0;
- char *p = ptr;
-
- while (p > buffer && (lastmatchnumber == 0 || p > lastmatchrestart) &&
- linecount < before_context)
- {
- linecount++;
- p = previous_line(p, buffer);
- }
-
- if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted)
- fprintf(stdout, "--\n");
-
- while (p < ptr)
- {
- int ellength;
- char *pp = p;
- if (printname != NULL) fprintf(stdout, "%s-", printname);
- if (number) fprintf(stdout, "%d-", linenumber - linecount--);
- pp = end_of_line(pp, endptr, &ellength);
- fwrite(p, 1, pp - p, stdout);
- p = pp;
- }
- }
-
- /* Now print the matching line(s); ensure we set hyphenpending at the end
- of the file if any context lines are being output. */
-
- if (after_context > 0 || before_context > 0)
- endhyphenpending = TRUE;
-
- if (printname != NULL) fprintf(stdout, "%s:", printname);
- if (number) fprintf(stdout, "%d:", linenumber);
-
- /* In multiline mode, we want to print to the end of the line in which
- the end of the matched string is found, so we adjust linelength and the
- line number appropriately. Because the PCRE_FIRSTLINE option is set, the
- start of the match will always be before the first newline sequence. */
-
- if (multiline)
- {
- int ellength;
- char *endmatch = ptr + offsets[1];
- t = ptr;
- while (t < endmatch)
- {
- t = end_of_line(t, endptr, &ellength);
- if (t <= endmatch) linenumber++; else break;
- }
- endmatch = end_of_line(endmatch, endptr, &ellength);
- linelength = endmatch - ptr - ellength;
- }
-
- /*** NOTE: Use only fwrite() to output the data line, so that binary
- zeroes are treated as just another data character. */
-
- /* This extra option, for Jeffrey Friedl's debugging requirements,
- replaces the matched string, or a specific captured string if it exists,
- with X. When this happens, colouring is ignored. */
-
-#ifdef JFRIEDL_DEBUG
- if (S_arg >= 0 && S_arg < mrc)
- {
- int first = S_arg * 2;
- int last = first + 1;
- fwrite(ptr, 1, offsets[first], stdout);
- fprintf(stdout, "X");
- fwrite(ptr + offsets[last], 1, linelength - offsets[last], stdout);
- }
- else
-#endif
-
- /* We have to split the line(s) up if colouring. */
-
- if (do_colour)
- {
- fwrite(ptr, 1, offsets[0], stdout);
- fprintf(stdout, "%c[%sm", 0x1b, colour_string);
- fwrite(ptr + offsets[0], 1, offsets[1] - offsets[0], stdout);
- fprintf(stdout, "%c[00m", 0x1b);
- fwrite(ptr + offsets[1], 1, linelength - offsets[1], stdout);
- }
- else fwrite(ptr, 1, linelength + endlinelength, stdout);
- }
-
- /* End of doing what has to be done for a match */
-
- rc = 0; /* Had some success */
-
- /* Remember where the last match happened for after_context. We remember
- where we are about to restart, and that line's number. */
-
- lastmatchrestart = ptr + linelength + endlinelength;
- lastmatchnumber = linenumber + 1;
- }
-
- /* Advance to after the newline and increment the line number. */
-
- ptr += linelength + endlinelength;
- linenumber++;
-
- /* If we haven't yet reached the end of the file (the buffer is full), and
- the current point is in the top 1/3 of the buffer, slide the buffer down by
- 1/3 and refill it. Before we do this, if some unprinted "after" lines are
- about to be lost, print them. */
-
- if (bufflength >= sizeof(buffer) && ptr > buffer + 2*MBUFTHIRD)
- {
- if (after_context > 0 &&
- lastmatchnumber > 0 &&
- lastmatchrestart < buffer + MBUFTHIRD)
- {
- do_after_lines(lastmatchnumber, lastmatchrestart, endptr, printname);
- lastmatchnumber = 0;
- }
-
- /* Now do the shuffle */
-
- memmove(buffer, buffer + MBUFTHIRD, 2*MBUFTHIRD);
- ptr -= MBUFTHIRD;
- bufflength = 2*MBUFTHIRD + fread(buffer + 2*MBUFTHIRD, 1, MBUFTHIRD, in);
- endptr = buffer + bufflength;
-
- /* Adjust any last match point */
-
- if (lastmatchnumber > 0) lastmatchrestart -= MBUFTHIRD;
- }
- } /* Loop through the whole file */
-
-/* End of file; print final "after" lines if wanted; do_after_lines sets
-hyphenpending if it prints something. */
-
-if (!only_matching && !count_only)
- {
- do_after_lines(lastmatchnumber, lastmatchrestart, endptr, printname);
- hyphenpending |= endhyphenpending;
- }
-
-/* Print the file name if we are looking for those without matches and there
-were none. If we found a match, we won't have got this far. */
-
-if (filenames == FN_NOMATCH_ONLY)
- {
- fprintf(stdout, "%s\n", printname);
- return 0;
- }
-
-/* Print the match count if wanted */
-
-if (count_only)
- {
- if (printname != NULL) fprintf(stdout, "%s:", printname);
- fprintf(stdout, "%d\n", count);
- }
-
-return rc;
-}
-
-
-
-/*************************************************
-* Grep a file or recurse into a directory *
-*************************************************/
-
-/* Given a path name, if it's a directory, scan all the files if we are
-recursing; if it's a file, grep it.
-
-Arguments:
- pathname the path to investigate
- dir_recurse TRUE if recursing is wanted (-r or -drecurse)
- only_one_at_top TRUE if the path is the only one at toplevel
-
-Returns: 0 if there was at least one match
- 1 if there were no matches
- 2 there was some kind of error
-
-However, file opening failures are suppressed if "silent" is set.
-*/
-
-static int
-grep_or_recurse(char *pathname, BOOL dir_recurse, BOOL only_one_at_top)
-{
-int rc = 1;
-int sep;
-FILE *in;
-
-/* If the file name is "-" we scan stdin */
-
-if (strcmp(pathname, "-") == 0)
- {
- return pcregrep(stdin,
- (filenames > FN_DEFAULT || (filenames == FN_DEFAULT && !only_one_at_top))?
- stdin_name : NULL);
- }
-
-
-/* If the file is a directory, skip if skipping or if we are recursing, scan
-each file within it, subject to any include or exclude patterns that were set.
-The scanning code is localized so it can be made system-specific. */
-
-if ((sep = isdirectory(pathname)) != 0)
- {
- if (dee_action == dee_SKIP) return 1;
- if (dee_action == dee_RECURSE)
- {
- char buffer[1024];
- char *nextfile;
- directory_type *dir = opendirectory(pathname);
-
- if (dir == NULL)
- {
- if (!silent)
- fprintf(stderr, "pcregrep: Failed to open directory %s: %s\n", pathname,
- strerror(errno));
- return 2;
- }
-
- while ((nextfile = readdirectory(dir)) != NULL)
- {
- int frc, blen;
- sprintf(buffer, "%.512s%c%.128s", pathname, sep, nextfile);
- blen = strlen(buffer);
-
- if (exclude_compiled != NULL &&
- pcre_exec(exclude_compiled, NULL, buffer, blen, 0, 0, NULL, 0) >= 0)
- continue;
-
- if (include_compiled != NULL &&
- pcre_exec(include_compiled, NULL, buffer, blen, 0, 0, NULL, 0) < 0)
- continue;
-
- frc = grep_or_recurse(buffer, dir_recurse, FALSE);
- if (frc > 1) rc = frc;
- else if (frc == 0 && rc == 1) rc = 0;
- }
-
- closedirectory(dir);
- return rc;
- }
- }
-
-/* If the file is not a directory and not a regular file, skip it if that's
-been requested. */
-
-else if (!isregfile(pathname) && DEE_action == DEE_SKIP) return 1;
-
-/* Control reaches here if we have a regular file, or if we have a directory
-and recursion or skipping was not requested, or if we have anything else and
-skipping was not requested. The scan proceeds. If this is the first and only
-argument at top level, we don't show the file name, unless we are only showing
-the file name, or the filename was forced (-H). */
-
-in = fopen(pathname, "r");
-if (in == NULL)
- {
- if (!silent)
- fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pathname,
- strerror(errno));
- return 2;
- }
-
-rc = pcregrep(in, (filenames > FN_DEFAULT ||
- (filenames == FN_DEFAULT && !only_one_at_top))? pathname : NULL);
-
-fclose(in);
-return rc;
-}
-
-
-
-
-/*************************************************
-* Usage function *
-*************************************************/
-
-static int
-usage(int rc)
-{
-option_item *op;
-fprintf(stderr, "Usage: pcregrep [-");
-for (op = optionlist; op->one_char != 0; op++)
- {
- if (op->one_char > 0) fprintf(stderr, "%c", op->one_char);
- }
-fprintf(stderr, "] [long options] [pattern] [files]\n");
-fprintf(stderr, "Type `pcregrep --help' for more information.\n");
-return rc;
-}
-
-
-
-
-/*************************************************
-* Help function *
-*************************************************/
-
-static void
-help(void)
-{
-option_item *op;
-
-printf("Usage: pcregrep [OPTION]... [PATTERN] [FILE1 FILE2 ...]\n");
-printf("Search for PATTERN in each FILE or standard input.\n");
-printf("PATTERN must be present if neither -e nor -f is used.\n");
-printf("\"-\" can be used as a file name to mean STDIN.\n\n");
-printf("Example: pcregrep -i 'hello.*world' menu.h main.c\n\n");
-
-printf("Options:\n");
-
-for (op = optionlist; op->one_char != 0; op++)
- {
- int n;
- char s[4];
- if (op->one_char > 0) sprintf(s, "-%c,", op->one_char); else strcpy(s, " ");
- printf(" %s --%s%n", s, op->long_name, &n);
- n = 30 - n;
- if (n < 1) n = 1;
- printf("%.*s%s\n", n, " ", op->help_text);
- }
-
-printf("\nWhen reading patterns from a file instead of using a command line option,\n");
-printf("trailing white space is removed and blank lines are ignored.\n");
-printf("There is a maximum of %d patterns.\n", MAX_PATTERN_COUNT);
-
-printf("\nWith no FILEs, read standard input. If fewer than two FILEs given, assume -h.\n");
-printf("Exit status is 0 if any matches, 1 if no matches, and 2 if trouble.\n");
-}
-
-
-
-
-/*************************************************
-* Handle a single-letter, no data option *
-*************************************************/
-
-static int
-handle_option(int letter, int options)
-{
-switch(letter)
- {
- case N_HELP: help(); exit(0);
- case 'c': count_only = TRUE; break;
- case 'F': process_options |= PO_FIXED_STRINGS; break;
- case 'H': filenames = FN_FORCE; break;
- case 'h': filenames = FN_NONE; break;
- case 'i': options |= PCRE_CASELESS; break;
- case 'l': filenames = FN_ONLY; break;
- case 'L': filenames = FN_NOMATCH_ONLY; break;
- case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;
- case 'n': number = TRUE; break;
- case 'o': only_matching = TRUE; break;
- case 'q': quiet = TRUE; break;
- case 'r': dee_action = dee_RECURSE; break;
- case 's': silent = TRUE; break;
- case 'u': options |= PCRE_UTF8; utf8 = TRUE; break;
- case 'v': invert = TRUE; break;
- case 'w': process_options |= PO_WORD_MATCH; break;
- case 'x': process_options |= PO_LINE_MATCH; break;
-
- case 'V':
- fprintf(stderr, "pcregrep version %s using ", VERSION);
- fprintf(stderr, "PCRE version %s\n", pcre_version());
- exit(0);
- break;
-
- default:
- fprintf(stderr, "pcregrep: Unknown option -%c\n", letter);
- exit(usage(2));
- }
-
-return options;
-}
-
-
-
-
-/*************************************************
-* Construct printed ordinal *
-*************************************************/
-
-/* This turns a number into "1st", "3rd", etc. */
-
-static char *
-ordin(int n)
-{
-static char buffer[8];
-char *p = buffer;
-sprintf(p, "%d", n);
-while (*p != 0) p++;
-switch (n%10)
- {
- case 1: strcpy(p, "st"); break;
- case 2: strcpy(p, "nd"); break;
- case 3: strcpy(p, "rd"); break;
- default: strcpy(p, "th"); break;
- }
-return buffer;
-}
-
-
-
-/*************************************************
-* Compile a single pattern *
-*************************************************/
-
-/* When the -F option has been used, this is called for each substring.
-Otherwise it's called for each supplied pattern.
-
-Arguments:
- pattern the pattern string
- options the PCRE options
- filename the file name, or NULL for a command-line pattern
- count 0 if this is the only command line pattern, or
- number of the command line pattern, or
- linenumber for a pattern from a file
-
-Returns: TRUE on success, FALSE after an error
-*/
-
-static BOOL
-compile_single_pattern(char *pattern, int options, char *filename, int count)
-{
-char buffer[MBUFTHIRD + 16];
-const char *error;
-int errptr;
-
-if (pattern_count >= MAX_PATTERN_COUNT)
- {
- fprintf(stderr, "pcregrep: Too many %spatterns (max %d)\n",
- (filename == NULL)? "command-line " : "", MAX_PATTERN_COUNT);
- return FALSE;
- }
-
-sprintf(buffer, "%s%.*s%s", prefix[process_options], MBUFTHIRD, pattern,
- suffix[process_options]);
-pattern_list[pattern_count] =
- pcre_compile(buffer, options, &error, &errptr, pcretables);
-if (pattern_list[pattern_count++] != NULL) return TRUE;
-
-/* Handle compile errors */
-
-errptr -= (int)strlen(prefix[process_options]);
-if (errptr > (int)strlen(pattern)) errptr = (int)strlen(pattern);
-
-if (filename == NULL)
- {
- if (count == 0)
- fprintf(stderr, "pcregrep: Error in command-line regex "
- "at offset %d: %s\n", errptr, error);
- else
- fprintf(stderr, "pcregrep: Error in %s command-line regex "
- "at offset %d: %s\n", ordin(count), errptr, error);
- }
-else
- {
- fprintf(stderr, "pcregrep: Error in regex in line %d of %s "
- "at offset %d: %s\n", count, filename, errptr, error);
- }
-
-return FALSE;
-}
-
-
-
-/*************************************************
-* Compile one supplied pattern *
-*************************************************/
-
-/* When the -F option has been used, each string may be a list of strings,
-separated by line breaks. They will be matched literally.
-
-Arguments:
- pattern the pattern string
- options the PCRE options
- filename the file name, or NULL for a command-line pattern
- count 0 if this is the only command line pattern, or
- number of the command line pattern, or
- linenumber for a pattern from a file
-
-Returns: TRUE on success, FALSE after an error
-*/
-
-static BOOL
-compile_pattern(char *pattern, int options, char *filename, int count)
-{
-if ((process_options & PO_FIXED_STRINGS) != 0)
- {
- char *eop = pattern + strlen(pattern);
- char buffer[MBUFTHIRD];
- for(;;)
- {
- int ellength;
- char *p = end_of_line(pattern, eop, &ellength);
- if (ellength == 0)
- return compile_single_pattern(pattern, options, filename, count);
- sprintf(buffer, "%.*s", p - pattern - ellength, pattern);
- pattern = p;
- if (!compile_single_pattern(buffer, options, filename, count))
- return FALSE;
- }
- }
-else return compile_single_pattern(pattern, options, filename, count);
-}
-
-
-
-/*************************************************
-* Main program *
-*************************************************/
-
-/* Returns 0 if something matched, 1 if nothing matched, 2 after an error. */
-
-int
-main(int argc, char **argv)
-{
-int i, j;
-int rc = 1;
-int pcre_options = 0;
-int cmd_pattern_count = 0;
-int errptr;
-BOOL only_one_at_top;
-char *patterns[MAX_PATTERN_COUNT];
-const char *locale_from = "--locale";
-const char *error;
-
-/* Set the default line ending value from the default in the PCRE library;
-"lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf".
-*/
-
-(void)pcre_config(PCRE_CONFIG_NEWLINE, &i);
-switch(i)
- {
- default: newline = (char *)"lf"; break;
- case '\r': newline = (char *)"cr"; break;
- case ('\r' << 8) | '\n': newline = (char *)"crlf"; break;
- case -1: newline = (char *)"any"; break;
- }
-
-/* Process the options */
-
-for (i = 1; i < argc; i++)
- {
- option_item *op = NULL;
- char *option_data = (char *)""; /* default to keep compiler happy */
- BOOL longop;
- BOOL longopwasequals = FALSE;
-
- if (argv[i][0] != '-') break;
-
- /* If we hit an argument that is just "-", it may be a reference to STDIN,
- but only if we have previously had -e or -f to define the patterns. */
-
- if (argv[i][1] == 0)
- {
- if (pattern_filename != NULL || pattern_count > 0) break;
- else exit(usage(2));
- }
-
- /* Handle a long name option, or -- to terminate the options */
-
- if (argv[i][1] == '-')
- {
- char *arg = argv[i] + 2;
- char *argequals = strchr(arg, '=');
-
- if (*arg == 0) /* -- terminates options */
- {
- i++;
- break; /* out of the options-handling loop */
- }
-
- longop = TRUE;
-
- /* Some long options have data that follows after =, for example file=name.
- Some options have variations in the long name spelling: specifically, we
- allow "regexp" because GNU grep allows it, though I personally go along
- with Jeffrey Friedl and Larry Wall in preferring "regex" without the "p".
- These options are entered in the table as "regex(p)". No option is in both
- these categories, fortunately. */
-
- for (op = optionlist; op->one_char != 0; op++)
- {
- char *opbra = strchr(op->long_name, '(');
- char *equals = strchr(op->long_name, '=');
- if (opbra == NULL) /* Not a (p) case */
- {
- if (equals == NULL) /* Not thing=data case */
- {
- if (strcmp(arg, op->long_name) == 0) break;
- }
- else /* Special case xxx=data */
- {
- int oplen = equals - op->long_name;
- int arglen = (argequals == NULL)? strlen(arg) : argequals - arg;
- if (oplen == arglen && strncmp(arg, op->long_name, oplen) == 0)
- {
- option_data = arg + arglen;
- if (*option_data == '=')
- {
- option_data++;
- longopwasequals = TRUE;
- }
- break;
- }
- }
- }
- else /* Special case xxxx(p) */
- {
- char buff1[24];
- char buff2[24];
- int baselen = opbra - op->long_name;
- sprintf(buff1, "%.*s", baselen, op->long_name);
- sprintf(buff2, "%s%.*s", buff1, strlen(op->long_name) - baselen - 2,
- opbra + 1);
- if (strcmp(arg, buff1) == 0 || strcmp(arg, buff2) == 0)
- break;
- }
- }
-
- if (op->one_char == 0)
- {
- fprintf(stderr, "pcregrep: Unknown option %s\n", argv[i]);
- exit(usage(2));
- }
- }
-
-
- /* Jeffrey Friedl's debugging harness uses these additional options which
- are not in the right form for putting in the option table because they use
- only one hyphen, yet are more than one character long. By putting them
- separately here, they will not get displayed as part of the help() output,
- but I don't think Jeffrey will care about that. */
-
-#ifdef JFRIEDL_DEBUG
- else if (strcmp(argv[i], "-pre") == 0) {
- jfriedl_prefix = argv[++i];
- continue;
- } else if (strcmp(argv[i], "-post") == 0) {
- jfriedl_postfix = argv[++i];
- continue;
- } else if (strcmp(argv[i], "-XT") == 0) {
- sscanf(argv[++i], "%d", &jfriedl_XT);
- continue;
- } else if (strcmp(argv[i], "-XR") == 0) {
- sscanf(argv[++i], "%d", &jfriedl_XR);
- continue;
- }
-#endif
-
-
- /* One-char options; many that have no data may be in a single argument; we
- continue till we hit the last one or one that needs data. */
-
- else
- {
- char *s = argv[i] + 1;
- longop = FALSE;
- while (*s != 0)
- {
- for (op = optionlist; op->one_char != 0; op++)
- { if (*s == op->one_char) break; }
- if (op->one_char == 0)
- {
- fprintf(stderr, "pcregrep: Unknown option letter '%c' in \"%s\"\n",
- *s, argv[i]);
- exit(usage(2));
- }
- if (op->type != OP_NODATA || s[1] == 0)
- {
- option_data = s+1;
- break;
- }
- pcre_options = handle_option(*s++, pcre_options);
- }
- }
-
- /* At this point we should have op pointing to a matched option. If the type
- is NO_DATA, it means that there is no data, and the option might set
- something in the PCRE options. */
-
- if (op->type == OP_NODATA)
- {
- pcre_options = handle_option(op->one_char, pcre_options);
- continue;
- }
-
- /* If the option type is OP_OP_STRING or OP_OP_NUMBER, it's an option that
- either has a value or defaults to something. It cannot have data in a
- separate item. At the moment, the only such options are "colo(u)r" and
- Jeffrey Friedl's special -S debugging option. */
-
- if (*option_data == 0 &&
- (op->type == OP_OP_STRING || op->type == OP_OP_NUMBER))
- {
- switch (op->one_char)
- {
- case N_COLOUR:
- colour_option = (char *)"auto";
- break;
-#ifdef JFRIEDL_DEBUG
- case 'S':
- S_arg = 0;
- break;
-#endif
- }
- continue;
- }
-
- /* Otherwise, find the data string for the option. */
-
- if (*option_data == 0)
- {
- if (i >= argc - 1 || longopwasequals)
- {
- fprintf(stderr, "pcregrep: Data missing after %s\n", argv[i]);
- exit(usage(2));
- }
- option_data = argv[++i];
- }
-
- /* If the option type is OP_PATLIST, it's the -e option, which can be called
- multiple times to create a list of patterns. */
-
- if (op->type == OP_PATLIST)
- {
- if (cmd_pattern_count >= MAX_PATTERN_COUNT)
- {
- fprintf(stderr, "pcregrep: Too many command-line patterns (max %d)\n",
- MAX_PATTERN_COUNT);
- return 2;
- }
- patterns[cmd_pattern_count++] = option_data;
- }
-
- /* Otherwise, deal with single string or numeric data values. */
-
- else if (op->type != OP_NUMBER && op->type != OP_OP_NUMBER)
- {
- *((char **)op->dataptr) = option_data;
- }
- else
- {
- char *endptr;
- int n = strtoul(option_data, &endptr, 10);
- if (*endptr != 0)
- {
- if (longop)
- {
- char *equals = strchr(op->long_name, '=');
- int nlen = (equals == NULL)? (int)strlen(op->long_name) :
- equals - op->long_name;
- fprintf(stderr, "pcregrep: Malformed number \"%s\" after --%.*s\n",
- option_data, nlen, op->long_name);
- }
- else
- fprintf(stderr, "pcregrep: Malformed number \"%s\" after -%c\n",
- option_data, op->one_char);
- exit(usage(2));
- }
- *((int *)op->dataptr) = n;
- }
- }
-
-/* Options have been decoded. If -C was used, its value is used as a default
-for -A and -B. */
-
-if (both_context > 0)
- {
- if (after_context == 0) after_context = both_context;
- if (before_context == 0) before_context = both_context;
- }
-
-/* If a locale has not been provided as an option, see if the LC_CTYPE or
-LC_ALL environment variable is set, and if so, use it. */
-
-if (locale == NULL)
- {
- locale = getenv("LC_ALL");
- locale_from = "LCC_ALL";
- }
-
-if (locale == NULL)
- {
- locale = getenv("LC_CTYPE");
- locale_from = "LC_CTYPE";
- }
-
-/* If a locale has been provided, set it, and generate the tables the PCRE
-needs. Otherwise, pcretables==NULL, which causes the use of default tables. */
-
-if (locale != NULL)
- {
- if (setlocale(LC_CTYPE, locale) == NULL)
- {
- fprintf(stderr, "pcregrep: Failed to set locale %s (obtained from %s)\n",
- locale, locale_from);
- return 2;
- }
- pcretables = pcre_maketables();
- }
-
-/* Sort out colouring */
-
-if (colour_option != NULL && strcmp(colour_option, "never") != 0)
- {
- if (strcmp(colour_option, "always") == 0) do_colour = TRUE;
- else if (strcmp(colour_option, "auto") == 0) do_colour = is_stdout_tty();
- else
- {
- fprintf(stderr, "pcregrep: Unknown colour setting \"%s\"\n",
- colour_option);
- return 2;
- }
- if (do_colour)
- {
- char *cs = getenv("PCREGREP_COLOUR");
- if (cs == NULL) cs = getenv("PCREGREP_COLOR");
- if (cs != NULL) colour_string = cs;
- }
- }
-
-/* Interpret the newline type; the default settings are Unix-like. */
-
-if (strcmp(newline, "cr") == 0 || strcmp(newline, "CR") == 0)
- {
- pcre_options |= PCRE_NEWLINE_CR;
- endlinetype = EL_CR;
- }
-else if (strcmp(newline, "lf") == 0 || strcmp(newline, "LF") == 0)
- {
- pcre_options |= PCRE_NEWLINE_LF;
- endlinetype = EL_LF;
- }
-else if (strcmp(newline, "crlf") == 0 || strcmp(newline, "CRLF") == 0)
- {
- pcre_options |= PCRE_NEWLINE_CRLF;
- endlinetype = EL_CRLF;
- }
-else if (strcmp(newline, "any") == 0 || strcmp(newline, "ANY") == 0)
- {
- pcre_options |= PCRE_NEWLINE_ANY;
- endlinetype = EL_ANY;
- }
-else
- {
- fprintf(stderr, "pcregrep: Invalid newline specifier \"%s\"\n", newline);
- return 2;
- }
-
-/* Interpret the text values for -d and -D */
-
-if (dee_option != NULL)
- {
- if (strcmp(dee_option, "read") == 0) dee_action = dee_READ;
- else if (strcmp(dee_option, "recurse") == 0) dee_action = dee_RECURSE;
- else if (strcmp(dee_option, "skip") == 0) dee_action = dee_SKIP;
- else
- {
- fprintf(stderr, "pcregrep: Invalid value \"%s\" for -d\n", dee_option);
- return 2;
- }
- }
-
-if (DEE_option != NULL)
- {
- if (strcmp(DEE_option, "read") == 0) DEE_action = DEE_READ;
- else if (strcmp(DEE_option, "skip") == 0) DEE_action = DEE_SKIP;
- else
- {
- fprintf(stderr, "pcregrep: Invalid value \"%s\" for -D\n", DEE_option);
- return 2;
- }
- }
-
-/* Check the values for Jeffrey Friedl's debugging options. */
-
-#ifdef JFRIEDL_DEBUG
-if (S_arg > 9)
- {
- fprintf(stderr, "pcregrep: bad value for -S option\n");
- return 2;
- }
-if (jfriedl_XT != 0 || jfriedl_XR != 0)
- {
- if (jfriedl_XT == 0) jfriedl_XT = 1;
- if (jfriedl_XR == 0) jfriedl_XR = 1;
- }
-#endif
-
-/* Get memory to store the pattern and hints lists. */
-
-pattern_list = (pcre **)malloc(MAX_PATTERN_COUNT * sizeof(pcre *));
-hints_list = (pcre_extra **)malloc(MAX_PATTERN_COUNT * sizeof(pcre_extra *));
-
-if (pattern_list == NULL || hints_list == NULL)
- {
- fprintf(stderr, "pcregrep: malloc failed\n");
- return 2;
- }
-
-/* If no patterns were provided by -e, and there is no file provided by -f,
-the first argument is the one and only pattern, and it must exist. */
-
-if (cmd_pattern_count == 0 && pattern_filename == NULL)
- {
- if (i >= argc) return usage(2);
- patterns[cmd_pattern_count++] = argv[i++];
- }
-
-/* Compile the patterns that were provided on the command line, either by
-multiple uses of -e or as a single unkeyed pattern. */
-
-for (j = 0; j < cmd_pattern_count; j++)
- {
- if (!compile_pattern(patterns[j], pcre_options, NULL,
- (j == 0 && cmd_pattern_count == 1)? 0 : j + 1))
- return 2;
- }
-
-/* Compile the regular expressions that are provided in a file. */
-
-if (pattern_filename != NULL)
- {
- int linenumber = 0;
- FILE *f;
- char *filename;
- char buffer[MBUFTHIRD];
-
- if (strcmp(pattern_filename, "-") == 0)
- {
- f = stdin;
- filename = stdin_name;
- }
- else
- {
- f = fopen(pattern_filename, "r");
- if (f == NULL)
- {
- fprintf(stderr, "pcregrep: Failed to open %s: %s\n", pattern_filename,
- strerror(errno));
- return 2;
- }
- filename = pattern_filename;
- }
-
- while (fgets(buffer, MBUFTHIRD, f) != NULL)
- {
- char *s = buffer + (int)strlen(buffer);
- while (s > buffer && isspace((unsigned char)(s[-1]))) s--;
- *s = 0;
- linenumber++;
- if (buffer[0] == 0) continue; /* Skip blank lines */
- if (!compile_pattern(buffer, pcre_options, filename, linenumber))
- return 2;
- }
-
- if (f != stdin) fclose(f);
- }
-
-/* Study the regular expressions, as we will be running them many times */
-
-for (j = 0; j < pattern_count; j++)
- {
- hints_list[j] = pcre_study(pattern_list[j], 0, &error);
- if (error != NULL)
- {
- char s[16];
- if (pattern_count == 1) s[0] = 0; else sprintf(s, " number %d", j);
- fprintf(stderr, "pcregrep: Error while studying regex%s: %s\n", s, error);
- return 2;
- }
- }
-
-/* If there are include or exclude patterns, compile them. */
-
-if (exclude_pattern != NULL)
- {
- exclude_compiled = pcre_compile(exclude_pattern, 0, &error, &errptr,
- pcretables);
- if (exclude_compiled == NULL)
- {
- fprintf(stderr, "pcregrep: Error in 'exclude' regex at offset %d: %s\n",
- errptr, error);
- return 2;
- }
- }
-
-if (include_pattern != NULL)
- {
- include_compiled = pcre_compile(include_pattern, 0, &error, &errptr,
- pcretables);
- if (include_compiled == NULL)
- {
- fprintf(stderr, "pcregrep: Error in 'include' regex at offset %d: %s\n",
- errptr, error);
- return 2;
- }
- }
-
-/* If there are no further arguments, do the business on stdin and exit. */
-
-if (i >= argc)
- return pcregrep(stdin, (filenames > FN_DEFAULT)? stdin_name : NULL);
-
-/* Otherwise, work through the remaining arguments as files or directories.
-Pass in the fact that there is only one argument at top level - this suppresses
-the file name if the argument is not a directory and filenames are not
-otherwise forced. */
-
-only_one_at_top = i == argc - 1; /* Catch initial value of i */
-
-for (; i < argc; i++)
- {
- int frc = grep_or_recurse(argv[i], dee_action == dee_RECURSE,
- only_one_at_top);
- if (frc > 1) rc = frc;
- else if (frc == 0 && rc == 1) rc = 0;
- }
-
-return rc;
-}
-
-/* End of pcregrep */
diff --git a/ext/pcre/pcrelib/pcreposix.c b/ext/pcre/pcrelib/pcreposix.c
index 31c7a31ab3..53ea6c7231 100644
--- a/ext/pcre/pcrelib/pcreposix.c
+++ b/ext/pcre/pcrelib/pcreposix.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -42,10 +42,22 @@ POSSIBILITY OF SUCH DAMAGE.
functions. */
+#include "config.h"
+
+
+/* Ensure that the PCREPOSIX_EXP_xxx macros are set appropriately for
+compiling these functions. This must come before including pcreposix.h, where
+they are set for an application (using these functions) if they have not
+previously been set. */
+
+#if defined(_WIN32) && !defined(PCRE_STATIC)
+# define PCREPOSIX_EXP_DECL extern __declspec(dllexport)
+# define PCREPOSIX_EXP_DEFN __declspec(dllexport)
+#endif
+
+#include "pcre.h"
#include "pcre_internal.h"
#include "pcreposix.h"
-#include "stdlib.h"
-
/* Table to translate PCRE compile time error codes into POSIX error codes. */
@@ -80,7 +92,7 @@ static const int eint[] = {
REG_BADPAT, /* malformed number or name after (?( */
REG_BADPAT, /* conditional group contains more than two branches */
REG_BADPAT, /* assertion expected after (?( */
- REG_BADPAT, /* (?R or (?digits must be followed by ) */
+ REG_BADPAT, /* (?R or (?[+-]digits must be followed by ) */
REG_ECTYPE, /* unknown POSIX class name */
REG_BADPAT, /* POSIX collating elements are not supported */
REG_INVARG, /* this version of PCRE is not compiled with PCRE_UTF8 support */
@@ -108,7 +120,12 @@ static const int eint[] = {
REG_BADPAT, /* DEFINE group contains more than one branch */
REG_BADPAT, /* repeating a DEFINE group is not allowed */
REG_INVARG, /* inconsistent NEWLINE options */
- REG_BADPAT /* \g is not followed followed by an (optionally braced) non-zero number */
+ REG_BADPAT, /* \g is not followed followed by an (optionally braced) non-zero number */
+ REG_BADPAT, /* (?+ or (?- must be followed by a non-zero number */
+ REG_BADPAT, /* number is too big */
+ REG_BADPAT, /* subpattern name expected */
+ REG_BADPAT, /* digit expected after (?+ */
+ REG_BADPAT /* ] is an invalid data character in JavaScript compatibility mode */
};
/* Table of texts corresponding to POSIX error codes */
@@ -141,7 +158,7 @@ static const char *const pstring[] = {
* Translate error code to string *
*************************************************/
-PCRE_DATA_SCOPE size_t
+PCREPOSIX_EXP_DEFN size_t
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
const char *message, *addmessage;
@@ -176,7 +193,7 @@ return length + addlength;
* Free store held by a regex *
*************************************************/
-PCRE_DATA_SCOPE void
+PCREPOSIX_EXP_DEFN void
regfree(regex_t *preg)
{
(pcre_free)(preg->re_pcre);
@@ -199,7 +216,7 @@ Returns: 0 on success
various non-zero codes on failure
*/
-PCRE_DATA_SCOPE int
+PCREPOSIX_EXP_DEFN int
regcomp(regex_t *preg, const char *pattern, int cflags)
{
const char *errorptr;
@@ -241,11 +258,11 @@ If REG_NOSUB was specified at compile time, the PCRE_NO_AUTO_CAPTURE flag will
be set. When this is the case, the nmatch and pmatch arguments are ignored, and
the only result is yes/no/error. */
-PCRE_DATA_SCOPE int
+PCREPOSIX_EXP_DEFN int
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
-int rc;
+int rc, so, eo;
int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
@@ -278,7 +295,23 @@ else if (nmatch > 0)
}
}
-rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
+/* REG_STARTEND is a BSD extension, to allow for non-NUL-terminated strings.
+The man page from OS X says "REG_STARTEND affects only the location of the
+string, not how it is matched". That is why the "so" value is used to bump the
+start location rather than being passed as a PCRE "starting offset". */
+
+if ((eflags & REG_STARTEND) != 0)
+ {
+ so = pmatch[0].rm_so;
+ eo = pmatch[0].rm_eo;
+ }
+else
+ {
+ so = 0;
+ eo = strlen(string);
+ }
+
+rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so),
0, options, ovector, nmatch * 3);
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
diff --git a/ext/pcre/pcrelib/pcreposix.h b/ext/pcre/pcrelib/pcreposix.h
index 31ee03749c..a73ad261de 100644
--- a/ext/pcre/pcrelib/pcreposix.h
+++ b/ext/pcre/pcrelib/pcreposix.h
@@ -9,7 +9,7 @@
Compatible Regular Expression library. It defines the things POSIX says should
be there. I hope.
- Copyright (c) 1997-2006 University of Cambridge
+ Copyright (c) 1997-2008 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -59,6 +59,7 @@ extern "C" {
#define REG_DOTALL 0x0010 /* NOT defined by POSIX. */
#define REG_NOSUB 0x0020
#define REG_UTF8 0x0040 /* NOT defined by POSIX. */
+#define REG_STARTEND 0x0080 /* BSD feature: pass subject string by so,eo */
/* This is not used by PCRE, but by defining it we make it easier
to slot PCRE into existing programs that make POSIX calls. */
@@ -105,40 +106,35 @@ typedef struct {
regoff_t rm_eo;
} regmatch_t;
-/* Win32 uses DLL by default; it needs special stuff for exported functions
-when building PCRE. */
+/* When an application links to a PCRE DLL in Windows, the symbols that are
+imported have to be identified as such. When building PCRE, the appropriate
+export settings are needed, and are set in pcreposix.c before including this
+file. */
-#ifndef PCRE_DATA_SCOPE
-#ifdef _WIN32
-# ifdef PCRE_DEFINITION
-# ifdef DLL_EXPORT
-# define PCRE_DATA_SCOPE __declspec(dllexport)
-# endif
-# else
-# ifndef PCRE_STATIC
-# define PCRE_DATA_SCOPE extern __declspec(dllimport)
-# endif
-# endif
-#endif
+#if defined(_WIN32) && !defined(PCRE_STATIC) && !defined(PCREPOSIX_EXP_DECL)
+# define PCREPOSIX_EXP_DECL extern __declspec(dllimport)
+# define PCREPOSIX_EXP_DEFN __declspec(dllimport)
#endif
-/* Otherwise, we use the standard "extern". */
+/* By default, we use the standard "extern" declarations. */
-#ifndef PCRE_DATA_SCOPE
+#ifndef PCREPOSIX_EXP_DECL
# ifdef __cplusplus
-# define PCRE_DATA_SCOPE extern "C"
+# define PCREPOSIX_EXP_DECL extern "C"
+# define PCREPOSIX_EXP_DEFN extern "C"
# else
-# define PCRE_DATA_SCOPE extern
+# define PCREPOSIX_EXP_DECL extern
+# define PCREPOSIX_EXP_DEFN extern
# endif
#endif
/* The functions */
-PCRE_DATA_SCOPE int regcomp(regex_t *, const char *, int);
-PCRE_DATA_SCOPE int regexec(const regex_t *, const char *, size_t,
- regmatch_t *, int);
-PCRE_DATA_SCOPE size_t regerror(int, const regex_t *, char *, size_t);
-PCRE_DATA_SCOPE void regfree(regex_t *);
+PCREPOSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
+PCREPOSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t,
+ regmatch_t *, int);
+PCREPOSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
+PCREPOSIX_EXP_DECL void regfree(regex_t *);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/ext/pcre/pcrelib/pcretest.c b/ext/pcre/pcrelib/pcretest.c
deleted file mode 100644
index d5249fa18f..0000000000
--- a/ext/pcre/pcrelib/pcretest.c
+++ /dev/null
@@ -1,2305 +0,0 @@
-/*************************************************
-* PCRE testing program *
-*************************************************/
-
-/* This program was hacked up as a tester for PCRE. I really should have
-written it more tidily in the first place. Will I ever learn? It has grown and
-been extended and consequently is now rather, er, *very* untidy in places.
-
------------------------------------------------------------------------------
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- * Neither the name of the University of Cambridge nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
-*/
-
-
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <locale.h>
-#include <errno.h>
-
-
-/* A number of things vary for Windows builds. Originally, pcretest opened its
-input and output without "b"; then I was told that "b" was needed in some
-environments, so it was added for release 5.0 to both the input and output. (It
-makes no difference on Unix-like systems.) Later I was told that it is wrong
-for the input on Windows. I've now abstracted the modes into two macros that
-are set here, to make it easier to fiddle with them, and removed "b" from the
-input mode under Windows. */
-
-#if defined(_WIN32) || defined(WIN32)
-#include <io.h> /* For _setmode() */
-#include <fcntl.h> /* For _O_BINARY */
-#define INPUT_MODE "r"
-#define OUTPUT_MODE "wb"
-
-#else
-#include <sys/time.h> /* These two includes are needed */
-#include <sys/resource.h> /* for setrlimit(). */
-#define INPUT_MODE "rb"
-#define OUTPUT_MODE "wb"
-#endif
-
-
-#define PCRE_SPY /* For Win32 build, import data, not export */
-
-/* We include pcre_internal.h because we need the internal info for displaying
-the results of pcre_study() and we also need to know about the internal
-macros, structures, and other internal data values; pcretest has "inside
-information" compared to a program that strictly follows the PCRE API. */
-
-#include "pcre_internal.h"
-
-/* We need access to the data tables that PCRE uses. So as not to have to keep
-two copies, we include the source file here, changing the names of the external
-symbols to prevent clashes. */
-
-#define _pcre_utf8_table1 utf8_table1
-#define _pcre_utf8_table1_size utf8_table1_size
-#define _pcre_utf8_table2 utf8_table2
-#define _pcre_utf8_table3 utf8_table3
-#define _pcre_utf8_table4 utf8_table4
-#define _pcre_utt utt
-#define _pcre_utt_size utt_size
-#define _pcre_OP_lengths OP_lengths
-
-#include "pcre_tables.c"
-
-/* We also need the pcre_printint() function for printing out compiled
-patterns. This function is in a separate file so that it can be included in
-pcre_compile.c when that module is compiled with debugging enabled.
-
-The definition of the macro PRINTABLE, which determines whether to print an
-output character as-is or as a hex value when showing compiled patterns, is
-contained in this file. We uses it here also, in cases when the locale has not
-been explicitly changed, so as to get consistent output from systems that
-differ in their output from isprint() even in the "C" locale. */
-
-#include "pcre_printint.src"
-
-#define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))
-
-
-/* It is possible to compile this test program without including support for
-testing the POSIX interface, though this is not available via the standard
-Makefile. */
-
-#if !defined NOPOSIX
-#include "pcreposix.h"
-#endif
-
-/* It is also possible, for the benefit of the version imported into Exim, to
-build pcretest without support for UTF8 (define NOUTF8), without the interface
-to the DFA matcher (NODFA), and without the doublecheck of the old "info"
-function (define NOINFOCHECK). */
-
-
-/* Other parameters */
-
-#ifndef CLOCKS_PER_SEC
-#ifdef CLK_TCK
-#define CLOCKS_PER_SEC CLK_TCK
-#else
-#define CLOCKS_PER_SEC 100
-#endif
-#endif
-
-/* This is the default loop count for timing. */
-
-#define LOOPREPEAT 500000
-
-/* Static variables */
-
-static FILE *outfile;
-static int log_store = 0;
-static int callout_count;
-static int callout_extra;
-static int callout_fail_count;
-static int callout_fail_id;
-static int first_callout;
-static int locale_set = 0;
-static int show_malloc;
-static int use_utf8;
-static size_t gotten_store;
-
-/* The buffers grow automatically if very long input lines are encountered. */
-
-static int buffer_size = 50000;
-static uschar *buffer = NULL;
-static uschar *dbuffer = NULL;
-static uschar *pbuffer = NULL;
-
-
-
-/*************************************************
-* Read or extend an input line *
-*************************************************/
-
-/* Input lines are read into buffer, but both patterns and data lines can be
-continued over multiple input lines. In addition, if the buffer fills up, we
-want to automatically expand it so as to be able to handle extremely large
-lines that are needed for certain stress tests. When the input buffer is
-expanded, the other two buffers must also be expanded likewise, and the
-contents of pbuffer, which are a copy of the input for callouts, must be
-preserved (for when expansion happens for a data line). This is not the most
-optimal way of handling this, but hey, this is just a test program!
-
-Arguments:
- f the file to read
- start where in buffer to start (this *must* be within buffer)
-
-Returns: pointer to the start of new data
- could be a copy of start, or could be moved
- NULL if no data read and EOF reached
-*/
-
-static uschar *
-extend_inputline(FILE *f, uschar *start)
-{
-uschar *here = start;
-
-for (;;)
- {
- int rlen = buffer_size - (here - buffer);
-
- if (rlen > 1000)
- {
- int dlen;
- if (fgets((char *)here, rlen, f) == NULL)
- return (here == start)? NULL : start;
- dlen = (int)strlen((char *)here);
- if (dlen > 0 && here[dlen - 1] == '\n') return start;
- here += dlen;
- }
-
- else
- {
- int new_buffer_size = 2*buffer_size;
- uschar *new_buffer = (unsigned char *)malloc(new_buffer_size);
- uschar *new_dbuffer = (unsigned char *)malloc(new_buffer_size);
- uschar *new_pbuffer = (unsigned char *)malloc(new_buffer_size);
-
- if (new_buffer == NULL || new_dbuffer == NULL || new_pbuffer == NULL)
- {
- fprintf(stderr, "pcretest: malloc(%d) failed\n", new_buffer_size);
- exit(1);
- }
-
- memcpy(new_buffer, buffer, buffer_size);
- memcpy(new_pbuffer, pbuffer, buffer_size);
-
- buffer_size = new_buffer_size;
-
- start = new_buffer + (start - buffer);
- here = new_buffer + (here - buffer);
-
- free(buffer);
- free(dbuffer);
- free(pbuffer);
-
- buffer = new_buffer;
- dbuffer = new_dbuffer;
- pbuffer = new_pbuffer;
- }
- }
-
-return NULL; /* Control never gets here */
-}
-
-
-
-
-
-
-
-/*************************************************
-* Read number from string *
-*************************************************/
-
-/* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess
-around with conditional compilation, just do the job by hand. It is only used
-for unpicking arguments, so just keep it simple.
-
-Arguments:
- str string to be converted
- endptr where to put the end pointer
-
-Returns: the unsigned long
-*/
-
-static int
-get_value(unsigned char *str, unsigned char **endptr)
-{
-int result = 0;
-while(*str != 0 && isspace(*str)) str++;
-while (isdigit(*str)) result = result * 10 + (int)(*str++ - '0');
-*endptr = str;
-return(result);
-}
-
-
-
-
-/*************************************************
-* Convert UTF-8 string to value *
-*************************************************/
-
-/* This function takes one or more bytes that represents a UTF-8 character,
-and returns the value of the character.
-
-Argument:
- utf8bytes a pointer to the byte vector
- vptr a pointer to an int to receive the value
-
-Returns: > 0 => the number of bytes consumed
- -6 to 0 => malformed UTF-8 character at offset = (-return)
-*/
-
-#if !defined NOUTF8
-
-static int
-utf82ord(unsigned char *utf8bytes, int *vptr)
-{
-int c = *utf8bytes++;
-int d = c;
-int i, j, s;
-
-for (i = -1; i < 6; i++) /* i is number of additional bytes */
- {
- if ((d & 0x80) == 0) break;
- d <<= 1;
- }
-
-if (i == -1) { *vptr = c; return 1; } /* ascii character */
-if (i == 0 || i == 6) return 0; /* invalid UTF-8 */
-
-/* i now has a value in the range 1-5 */
-
-s = 6*i;
-d = (c & utf8_table3[i]) << s;
-
-for (j = 0; j < i; j++)
- {
- c = *utf8bytes++;
- if ((c & 0xc0) != 0x80) return -(j+1);
- s -= 6;
- d |= (c & 0x3f) << s;
- }
-
-/* Check that encoding was the correct unique one */
-
-for (j = 0; j < utf8_table1_size; j++)
- if (d <= utf8_table1[j]) break;
-if (j != i) return -(i+1);
-
-/* Valid value */
-
-*vptr = d;
-return i+1;
-}
-
-#endif
-
-
-
-/*************************************************
-* Convert character value to UTF-8 *
-*************************************************/
-
-/* This function takes an integer value in the range 0 - 0x7fffffff
-and encodes it as a UTF-8 character in 0 to 6 bytes.
-
-Arguments:
- cvalue the character value
- utf8bytes pointer to buffer for result - at least 6 bytes long
-
-Returns: number of characters placed in the buffer
-*/
-
-#if !defined NOUTF8
-
-static int
-ord2utf8(int cvalue, uschar *utf8bytes)
-{
-register int i, j;
-for (i = 0; i < utf8_table1_size; i++)
- if (cvalue <= utf8_table1[i]) break;
-utf8bytes += i;
-for (j = i; j > 0; j--)
- {
- *utf8bytes-- = 0x80 | (cvalue & 0x3f);
- cvalue >>= 6;
- }
-*utf8bytes = utf8_table2[i] | cvalue;
-return i + 1;
-}
-
-#endif
-
-
-
-/*************************************************
-* Print character string *
-*************************************************/
-
-/* Character string printing function. Must handle UTF-8 strings in utf8
-mode. Yields number of characters printed. If handed a NULL file, just counts
-chars without printing. */
-
-static int pchars(unsigned char *p, int length, FILE *f)
-{
-int c = 0;
-int yield = 0;
-
-while (length-- > 0)
- {
-#if !defined NOUTF8
- if (use_utf8)
- {
- int rc = utf82ord(p, &c);
-
- if (rc > 0 && rc <= length + 1) /* Mustn't run over the end */
- {
- length -= rc - 1;
- p += rc;
- if (PRINTHEX(c))
- {
- if (f != NULL) fprintf(f, "%c", c);
- yield++;
- }
- else
- {
- int n = 4;
- if (f != NULL) fprintf(f, "\\x{%02x}", c);
- yield += (n <= 0x000000ff)? 2 :
- (n <= 0x00000fff)? 3 :
- (n <= 0x0000ffff)? 4 :
- (n <= 0x000fffff)? 5 : 6;
- }
- continue;
- }
- }
-#endif
-
- /* Not UTF-8, or malformed UTF-8 */
-
- c = *p++;
- if (PRINTHEX(c))
- {
- if (f != NULL) fprintf(f, "%c", c);
- yield++;
- }
- else
- {
- if (f != NULL) fprintf(f, "\\x%02x", c);
- yield += 4;
- }
- }
-
-return yield;
-}
-
-
-
-/*************************************************
-* Callout function *
-*************************************************/
-
-/* Called from PCRE as a result of the (?C) item. We print out where we are in
-the match. Yield zero unless more callouts than the fail count, or the callout
-data is not zero. */
-
-static int callout(pcre_callout_block *cb)
-{
-FILE *f = (first_callout | callout_extra)? outfile : NULL;
-int i, pre_start, post_start, subject_length;
-
-if (callout_extra)
- {
- fprintf(f, "Callout %d: last capture = %d\n",
- cb->callout_number, cb->capture_last);
-
- for (i = 0; i < cb->capture_top * 2; i += 2)
- {
- if (cb->offset_vector[i] < 0)
- fprintf(f, "%2d: <unset>\n", i/2);
- else
- {
- fprintf(f, "%2d: ", i/2);
- (void)pchars((unsigned char *)cb->subject + cb->offset_vector[i],
- cb->offset_vector[i+1] - cb->offset_vector[i], f);
- fprintf(f, "\n");
- }
- }
- }
-
-/* Re-print the subject in canonical form, the first time or if giving full
-datails. On subsequent calls in the same match, we use pchars just to find the
-printed lengths of the substrings. */
-
-if (f != NULL) fprintf(f, "--->");
-
-pre_start = pchars((unsigned char *)cb->subject, cb->start_match, f);
-post_start = pchars((unsigned char *)(cb->subject + cb->start_match),
- cb->current_position - cb->start_match, f);
-
-subject_length = pchars((unsigned char *)cb->subject, cb->subject_length, NULL);
-
-(void)pchars((unsigned char *)(cb->subject + cb->current_position),
- cb->subject_length - cb->current_position, f);
-
-if (f != NULL) fprintf(f, "\n");
-
-/* Always print appropriate indicators, with callout number if not already
-shown. For automatic callouts, show the pattern offset. */
-
-if (cb->callout_number == 255)
- {
- fprintf(outfile, "%+3d ", cb->pattern_position);
- if (cb->pattern_position > 99) fprintf(outfile, "\n ");
- }
-else
- {
- if (callout_extra) fprintf(outfile, " ");
- else fprintf(outfile, "%3d ", cb->callout_number);
- }
-
-for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
-fprintf(outfile, "^");
-
-if (post_start > 0)
- {
- for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
- fprintf(outfile, "^");
- }
-
-for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
- fprintf(outfile, " ");
-
-fprintf(outfile, "%.*s", (cb->next_item_length == 0)? 1 : cb->next_item_length,
- pbuffer + cb->pattern_position);
-
-fprintf(outfile, "\n");
-first_callout = 0;
-
-if (cb->callout_data != NULL)
- {
- int callout_data = *((int *)(cb->callout_data));
- if (callout_data != 0)
- {
- fprintf(outfile, "Callout data = %d\n", callout_data);
- return callout_data;
- }
- }
-
-return (cb->callout_number != callout_fail_id)? 0 :
- (++callout_count >= callout_fail_count)? 1 : 0;
-}
-
-
-/*************************************************
-* Local malloc functions *
-*************************************************/
-
-/* Alternative malloc function, to test functionality and show the size of the
-compiled re. */
-
-static void *new_malloc(size_t size)
-{
-void *block = malloc(size);
-gotten_store = size;
-if (show_malloc)
- fprintf(outfile, "malloc %3d %p\n", (int)size, block);
-return block;
-}
-
-static void new_free(void *block)
-{
-if (show_malloc)
- fprintf(outfile, "free %p\n", block);
-free(block);
-}
-
-
-/* For recursion malloc/free, to test stacking calls */
-
-static void *stack_malloc(size_t size)
-{
-void *block = malloc(size);
-if (show_malloc)
- fprintf(outfile, "stack_malloc %3d %p\n", (int)size, block);
-return block;
-}
-
-static void stack_free(void *block)
-{
-if (show_malloc)
- fprintf(outfile, "stack_free %p\n", block);
-free(block);
-}
-
-
-/*************************************************
-* Call pcre_fullinfo() *
-*************************************************/
-
-/* Get one piece of information from the pcre_fullinfo() function */
-
-static void new_info(pcre *re, pcre_extra *study, int option, void *ptr)
-{
-int rc;
-if ((rc = pcre_fullinfo(re, study, option, ptr)) < 0)
- fprintf(outfile, "Error %d from pcre_fullinfo(%d)\n", rc, option);
-}
-
-
-
-/*************************************************
-* Byte flipping function *
-*************************************************/
-
-static unsigned long int
-byteflip(unsigned long int value, int n)
-{
-if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);
-return ((value & 0x000000ff) << 24) |
- ((value & 0x0000ff00) << 8) |
- ((value & 0x00ff0000) >> 8) |
- ((value & 0xff000000) >> 24);
-}
-
-
-
-
-/*************************************************
-* Check match or recursion limit *
-*************************************************/
-
-static int
-check_match_limit(pcre *re, pcre_extra *extra, uschar *bptr, int len,
- int start_offset, int options, int *use_offsets, int use_size_offsets,
- int flag, unsigned long int *limit, int errnumber, const char *msg)
-{
-int count;
-int min = 0;
-int mid = 64;
-int max = -1;
-
-extra->flags |= flag;
-
-for (;;)
- {
- *limit = mid;
-
- count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options,
- use_offsets, use_size_offsets);
-
- if (count == errnumber)
- {
- /* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */
- min = mid;
- mid = (mid == max - 1)? max : (max > 0)? (min + max)/2 : mid*2;
- }
-
- else if (count >= 0 || count == PCRE_ERROR_NOMATCH ||
- count == PCRE_ERROR_PARTIAL)
- {
- if (mid == min + 1)
- {
- fprintf(outfile, "Minimum %s limit = %d\n", msg, mid);
- break;
- }
- /* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */
- max = mid;
- mid = (min + mid)/2;
- }
- else break; /* Some other error */
- }
-
-extra->flags &= ~flag;
-return count;
-}
-
-
-
-/*************************************************
-* Check newline indicator *
-*************************************************/
-
-/* This is used both at compile and run-time to check for <xxx> escapes, where
-xxx is LF, CR, CRLF, or ANY. Print a message and return 0 if there is no match.
-
-Arguments:
- p points after the leading '<'
- f file for error message
-
-Returns: appropriate PCRE_NEWLINE_xxx flags, or 0
-*/
-
-static int
-check_newline(uschar *p, FILE *f)
-{
-if (strncmp((char *)p, "cr>", 3) == 0) return PCRE_NEWLINE_CR;
-if (strncmp((char *)p, "lf>", 3) == 0) return PCRE_NEWLINE_LF;
-if (strncmp((char *)p, "crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;
-if (strncmp((char *)p, "any>", 4) == 0) return PCRE_NEWLINE_ANY;
-fprintf(f, "Unknown newline type at: <%s\n", p);
-return 0;
-}
-
-
-
-/*************************************************
-* Usage function *
-*************************************************/
-
-static void
-usage(void)
-{
-printf("Usage: pcretest [options] [<input> [<output>]]\n");
-printf(" -b show compiled code (bytecode)\n");
-printf(" -C show PCRE compile-time options and exit\n");
-printf(" -d debug: show compiled code and information (-b and -i)\n");
-#if !defined NODFA
-printf(" -dfa force DFA matching for all subjects\n");
-#endif
-printf(" -help show usage information\n");
-printf(" -i show information about compiled patterns\n"
- " -m output memory used information\n"
- " -o <n> set size of offsets vector to <n>\n");
-#if !defined NOPOSIX
-printf(" -p use POSIX interface\n");
-#endif
-printf(" -q quiet: do not output PCRE version number at start\n");
-printf(" -S <n> set stack size to <n> megabytes\n");
-printf(" -s output store (memory) used information\n"
- " -t time compilation and execution\n");
-printf(" -t <n> time compilation and execution, repeating <n> times\n");
-printf(" -tm time execution (matching) only\n");
-printf(" -tm <n> time execution (matching) only, repeating <n> times\n");
-}
-
-
-
-/*************************************************
-* Main Program *
-*************************************************/
-
-/* Read lines from named file or stdin and write to named file or stdout; lines
-consist of a regular expression, in delimiters and optionally followed by
-options, followed by a set of test data, terminated by an empty line. */
-
-int main(int argc, char **argv)
-{
-FILE *infile = stdin;
-int options = 0;
-int study_options = 0;
-int op = 1;
-int timeit = 0;
-int timeitm = 0;
-int showinfo = 0;
-int showstore = 0;
-int quiet = 0;
-int size_offsets = 45;
-int size_offsets_max;
-int *offsets = NULL;
-#if !defined NOPOSIX
-int posix = 0;
-#endif
-int debug = 0;
-int done = 0;
-int all_use_dfa = 0;
-int yield = 0;
-int stack_size;
-
-/* These vectors store, end-to-end, a list of captured substring names. Assume
-that 1024 is plenty long enough for the few names we'll be testing. */
-
-uschar copynames[1024];
-uschar getnames[1024];
-
-uschar *copynamesptr;
-uschar *getnamesptr;
-
-/* Get buffers from malloc() so that Electric Fence will check their misuse
-when I am debugging. They grow automatically when very long lines are read. */
-
-buffer = (unsigned char *)malloc(buffer_size);
-dbuffer = (unsigned char *)malloc(buffer_size);
-pbuffer = (unsigned char *)malloc(buffer_size);
-
-/* The outfile variable is static so that new_malloc can use it. */
-
-outfile = stdout;
-
-/* The following _setmode() stuff is some Windows magic that tells its runtime
-library to translate CRLF into a single LF character. At least, that's what
-I've been told: never having used Windows I take this all on trust. Originally
-it set 0x8000, but then I was advised that _O_BINARY was better. */
-
-#if defined(_WIN32) || defined(WIN32)
-_setmode( _fileno( stdout ), _O_BINARY );
-#endif
-
-/* Scan options */
-
-while (argc > 1 && argv[op][0] == '-')
- {
- unsigned char *endptr;
-
- if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)
- showstore = 1;
- else if (strcmp(argv[op], "-q") == 0) quiet = 1;
- else if (strcmp(argv[op], "-b") == 0) debug = 1;
- else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
- else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
-#if !defined NODFA
- else if (strcmp(argv[op], "-dfa") == 0) all_use_dfa = 1;
-#endif
- else if (strcmp(argv[op], "-o") == 0 && argc > 2 &&
- ((size_offsets = get_value((unsigned char *)argv[op+1], &endptr)),
- *endptr == 0))
- {
- op++;
- argc--;
- }
- else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)
- {
- int both = argv[op][2] == 0;
- int temp;
- if (argc > 2 && (temp = get_value((unsigned char *)argv[op+1], &endptr),
- *endptr == 0))
- {
- timeitm = temp;
- op++;
- argc--;
- }
- else timeitm = LOOPREPEAT;
- if (both) timeit = timeitm;
- }
- else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&
- ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
- *endptr == 0))
- {
-#if defined(_WIN32) || defined(WIN32)
- printf("PCRE: -S not supported on this OS\n");
- exit(1);
-#else
- int rc;
- struct rlimit rlim;
- getrlimit(RLIMIT_STACK, &rlim);
- rlim.rlim_cur = stack_size * 1024 * 1024;
- rc = setrlimit(RLIMIT_STACK, &rlim);
- if (rc != 0)
- {
- printf("PCRE: setrlimit() failed with error %d\n", rc);
- exit(1);
- }
- op++;
- argc--;
-#endif
- }
-#if !defined NOPOSIX
- else if (strcmp(argv[op], "-p") == 0) posix = 1;
-#endif
- else if (strcmp(argv[op], "-C") == 0)
- {
- int rc;
- printf("PCRE version %s\n", pcre_version());
- printf("Compiled with\n");
- (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
- printf(" %sUTF-8 support\n", rc? "" : "No ");
- (void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
- printf(" %sUnicode properties support\n", rc? "" : "No ");
- (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
- printf(" Newline sequence is %s\n", (rc == '\r')? "CR" :
- (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :
- (rc == -1)? "ANY" : "???");
- (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc);
- printf(" Internal link size = %d\n", rc);
- (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
- printf(" POSIX malloc threshold = %d\n", rc);
- (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc);
- printf(" Default match limit = %d\n", rc);
- (void)pcre_config(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &rc);
- printf(" Default recursion depth limit = %d\n", rc);
- (void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc);
- printf(" Match recursion uses %s\n", rc? "stack" : "heap");
- exit(0);
- }
- else if (strcmp(argv[op], "-help") == 0 ||
- strcmp(argv[op], "--help") == 0)
- {
- usage();
- goto EXIT;
- }
- else
- {
- printf("** Unknown or malformed option %s\n", argv[op]);
- usage();
- yield = 1;
- goto EXIT;
- }
- op++;
- argc--;
- }
-
-/* Get the store for the offsets vector, and remember what it was */
-
-size_offsets_max = size_offsets;
-offsets = (int *)malloc(size_offsets_max * sizeof(int));
-if (offsets == NULL)
- {
- printf("** Failed to get %d bytes of memory for offsets vector\n",
- size_offsets_max * sizeof(int));
- yield = 1;
- goto EXIT;
- }
-
-/* Sort out the input and output files */
-
-if (argc > 1)
- {
- infile = fopen(argv[op], INPUT_MODE);
- if (infile == NULL)
- {
- printf("** Failed to open %s\n", argv[op]);
- yield = 1;
- goto EXIT;
- }
- }
-
-if (argc > 2)
- {
- outfile = fopen(argv[op+1], OUTPUT_MODE);
- if (outfile == NULL)
- {
- printf("** Failed to open %s\n", argv[op+1]);
- yield = 1;
- goto EXIT;
- }
- }
-
-/* Set alternative malloc function */
-
-pcre_malloc = new_malloc;
-pcre_free = new_free;
-pcre_stack_malloc = stack_malloc;
-pcre_stack_free = stack_free;
-
-/* Heading line unless quiet, then prompt for first regex if stdin */
-
-if (!quiet) fprintf(outfile, "PCRE version %s\n\n", pcre_version());
-
-/* Main loop */
-
-while (!done)
- {
- pcre *re = NULL;
- pcre_extra *extra = NULL;
-
-#if !defined NOPOSIX /* There are still compilers that require no indent */
- regex_t preg;
- int do_posix = 0;
-#endif
-
- const char *error;
- unsigned char *p, *pp, *ppp;
- unsigned char *to_file = NULL;
- const unsigned char *tables = NULL;
- unsigned long int true_size, true_study_size = 0;
- size_t size, regex_gotten_store;
- int do_study = 0;
- int do_debug = debug;
- int do_G = 0;
- int do_g = 0;
- int do_showinfo = showinfo;
- int do_showrest = 0;
- int do_flip = 0;
- int erroroffset, len, delimiter, poffset;
-
- use_utf8 = 0;
-
- if (infile == stdin) printf(" re> ");
- if (extend_inputline(infile, buffer) == NULL) break;
- if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
- fflush(outfile);
-
- p = buffer;
- while (isspace(*p)) p++;
- if (*p == 0) continue;
-
- /* See if the pattern is to be loaded pre-compiled from a file. */
-
- if (*p == '<' && strchr((char *)(p+1), '<') == NULL)
- {
- unsigned long int magic, get_options;
- uschar sbuf[8];
- FILE *f;
-
- p++;
- pp = p + (int)strlen((char *)p);
- while (isspace(pp[-1])) pp--;
- *pp = 0;
-
- f = fopen((char *)p, "rb");
- if (f == NULL)
- {
- fprintf(outfile, "Failed to open %s: %s\n", p, strerror(errno));
- continue;
- }
-
- if (fread(sbuf, 1, 8, f) != 8) goto FAIL_READ;
-
- true_size =
- (sbuf[0] << 24) | (sbuf[1] << 16) | (sbuf[2] << 8) | sbuf[3];
- true_study_size =
- (sbuf[4] << 24) | (sbuf[5] << 16) | (sbuf[6] << 8) | sbuf[7];
-
- re = (real_pcre *)new_malloc(true_size);
- regex_gotten_store = gotten_store;
-
- if (fread(re, 1, true_size, f) != true_size) goto FAIL_READ;
-
- magic = ((real_pcre *)re)->magic_number;
- if (magic != MAGIC_NUMBER)
- {
- if (byteflip(magic, sizeof(magic)) == MAGIC_NUMBER)
- {
- do_flip = 1;
- }
- else
- {
- fprintf(outfile, "Data in %s is not a compiled PCRE regex\n", p);
- fclose(f);
- continue;
- }
- }
-
- fprintf(outfile, "Compiled regex%s loaded from %s\n",
- do_flip? " (byte-inverted)" : "", p);
-
- /* Need to know if UTF-8 for printing data strings */
-
- new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
- use_utf8 = (get_options & PCRE_UTF8) != 0;
-
- /* Now see if there is any following study data */
-
- if (true_study_size != 0)
- {
- pcre_study_data *psd;
-
- extra = (pcre_extra *)new_malloc(sizeof(pcre_extra) + true_study_size);
- extra->flags = PCRE_EXTRA_STUDY_DATA;
-
- psd = (pcre_study_data *)(((char *)extra) + sizeof(pcre_extra));
- extra->study_data = psd;
-
- if (fread(psd, 1, true_study_size, f) != true_study_size)
- {
- FAIL_READ:
- fprintf(outfile, "Failed to read data from %s\n", p);
- if (extra != NULL) new_free(extra);
- if (re != NULL) new_free(re);
- fclose(f);
- continue;
- }
- fprintf(outfile, "Study data loaded from %s\n", p);
- do_study = 1; /* To get the data output if requested */
- }
- else fprintf(outfile, "No study data\n");
-
- fclose(f);
- goto SHOW_INFO;
- }
-
- /* In-line pattern (the usual case). Get the delimiter and seek the end of
- the pattern; if is isn't complete, read more. */
-
- delimiter = *p++;
-
- if (isalnum(delimiter) || delimiter == '\\')
- {
- fprintf(outfile, "** Delimiter must not be alphameric or \\\n");
- goto SKIP_DATA;
- }
-
- pp = p;
- poffset = p - buffer;
-
- for(;;)
- {
- while (*pp != 0)
- {
- if (*pp == '\\' && pp[1] != 0) pp++;
- else if (*pp == delimiter) break;
- pp++;
- }
- if (*pp != 0) break;
- if (infile == stdin) printf(" > ");
- if ((pp = extend_inputline(infile, pp)) == NULL)
- {
- fprintf(outfile, "** Unexpected EOF\n");
- done = 1;
- goto CONTINUE;
- }
- if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
- }
-
- /* The buffer may have moved while being extended; reset the start of data
- pointer to the correct relative point in the buffer. */
-
- p = buffer + poffset;
-
- /* If the first character after the delimiter is backslash, make
- the pattern end with backslash. This is purely to provide a way
- of testing for the error message when a pattern ends with backslash. */
-
- if (pp[1] == '\\') *pp++ = '\\';
-
- /* Terminate the pattern at the delimiter, and save a copy of the pattern
- for callouts. */
-
- *pp++ = 0;
- strcpy((char *)pbuffer, (char *)p);
-
- /* Look for options after final delimiter */
-
- options = 0;
- study_options = 0;
- log_store = showstore; /* default from command line */
-
- while (*pp != 0)
- {
- switch (*pp++)
- {
- case 'f': options |= PCRE_FIRSTLINE; break;
- case 'g': do_g = 1; break;
- case 'i': options |= PCRE_CASELESS; break;
- case 'm': options |= PCRE_MULTILINE; break;
- case 's': options |= PCRE_DOTALL; break;
- case 'x': options |= PCRE_EXTENDED; break;
-
- case '+': do_showrest = 1; break;
- case 'A': options |= PCRE_ANCHORED; break;
- case 'B': do_debug = 1; break;
- case 'C': options |= PCRE_AUTO_CALLOUT; break;
- case 'D': do_debug = do_showinfo = 1; break;
- case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
- case 'F': do_flip = 1; break;
- case 'G': do_G = 1; break;
- case 'I': do_showinfo = 1; break;
- case 'J': options |= PCRE_DUPNAMES; break;
- case 'M': log_store = 1; break;
- case 'N': options |= PCRE_NO_AUTO_CAPTURE; break;
-
-#if !defined NOPOSIX
- case 'P': do_posix = 1; break;
-#endif
-
- case 'S': do_study = 1; break;
- case 'U': options |= PCRE_UNGREEDY; break;
- case 'X': options |= PCRE_EXTRA; break;
- case '8': options |= PCRE_UTF8; use_utf8 = 1; break;
- case '?': options |= PCRE_NO_UTF8_CHECK; break;
-
- case 'L':
- ppp = pp;
- /* The '\r' test here is so that it works on Windows. */
- /* The '0' test is just in case this is an unterminated line. */
- while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
- *ppp = 0;
- if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
- {
- fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
- goto SKIP_DATA;
- }
- locale_set = 1;
- tables = pcre_maketables();
- pp = ppp;
- break;
-
- case '>':
- to_file = pp;
- while (*pp != 0) pp++;
- while (isspace(pp[-1])) pp--;
- *pp = 0;
- break;
-
- case '<':
- {
- int x = check_newline(pp, outfile);
- if (x == 0) goto SKIP_DATA;
- options |= x;
- while (*pp++ != '>');
- }
- break;
-
- case '\r': /* So that it works in Windows */
- case '\n':
- case ' ':
- break;
-
- default:
- fprintf(outfile, "** Unknown option '%c'\n", pp[-1]);
- goto SKIP_DATA;
- }
- }
-
- /* Handle compiling via the POSIX interface, which doesn't support the
- timing, showing, or debugging options, nor the ability to pass over
- local character tables. */
-
-#if !defined NOPOSIX
- if (posix || do_posix)
- {
- int rc;
- int cflags = 0;
-
- if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE;
- if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE;
- if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL;
- if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB;
- if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8;
-
- rc = regcomp(&preg, (char *)p, cflags);
-
- /* Compilation failed; go back for another re, skipping to blank line
- if non-interactive. */
-
- if (rc != 0)
- {
- (void)regerror(rc, &preg, (char *)buffer, buffer_size);
- fprintf(outfile, "Failed: POSIX code %d: %s\n", rc, buffer);
- goto SKIP_DATA;
- }
- }
-
- /* Handle compiling via the native interface */
-
- else
-#endif /* !defined NOPOSIX */
-
- {
- if (timeit > 0)
- {
- register int i;
- clock_t time_taken;
- clock_t start_time = clock();
- for (i = 0; i < timeit; i++)
- {
- re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
- if (re != NULL) free(re);
- }
- time_taken = clock() - start_time;
- fprintf(outfile, "Compile time %.4f milliseconds\n",
- (((double)time_taken * 1000.0) / (double)timeit) /
- (double)CLOCKS_PER_SEC);
- }
-
- re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
-
- /* Compilation failed; go back for another re, skipping to blank line
- if non-interactive. */
-
- if (re == NULL)
- {
- fprintf(outfile, "Failed: %s at offset %d\n", error, erroroffset);
- SKIP_DATA:
- if (infile != stdin)
- {
- for (;;)
- {
- if (extend_inputline(infile, buffer) == NULL)
- {
- done = 1;
- goto CONTINUE;
- }
- len = (int)strlen((char *)buffer);
- while (len > 0 && isspace(buffer[len-1])) len--;
- if (len == 0) break;
- }
- fprintf(outfile, "\n");
- }
- goto CONTINUE;
- }
-
- /* Compilation succeeded; print data if required. There are now two
- info-returning functions. The old one has a limited interface and
- returns only limited data. Check that it agrees with the newer one. */
-
- if (log_store)
- fprintf(outfile, "Memory allocation (code space): %d\n",
- (int)(gotten_store -
- sizeof(real_pcre) -
- ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size));
-
- /* Extract the size for possible writing before possibly flipping it,
- and remember the store that was got. */
-
- true_size = ((real_pcre *)re)->size;
- regex_gotten_store = gotten_store;
-
- /* If /S was present, study the regexp to generate additional info to
- help with the matching. */
-
- if (do_study)
- {
- if (timeit > 0)
- {
- register int i;
- clock_t time_taken;
- clock_t start_time = clock();
- for (i = 0; i < timeit; i++)
- extra = pcre_study(re, study_options, &error);
- time_taken = clock() - start_time;
- if (extra != NULL) free(extra);
- fprintf(outfile, " Study time %.4f milliseconds\n",
- (((double)time_taken * 1000.0) / (double)timeit) /
- (double)CLOCKS_PER_SEC);
- }
- extra = pcre_study(re, study_options, &error);
- if (error != NULL)
- fprintf(outfile, "Failed to study: %s\n", error);
- else if (extra != NULL)
- true_study_size = ((pcre_study_data *)(extra->study_data))->size;
- }
-
- /* If the 'F' option was present, we flip the bytes of all the integer
- fields in the regex data block and the study block. This is to make it
- possible to test PCRE's handling of byte-flipped patterns, e.g. those
- compiled on a different architecture. */
-
- if (do_flip)
- {
- real_pcre *rre = (real_pcre *)re;
- rre->magic_number = byteflip(rre->magic_number, sizeof(rre->magic_number));
- rre->size = byteflip(rre->size, sizeof(rre->size));
- rre->options = byteflip(rre->options, sizeof(rre->options));
- rre->top_bracket = byteflip(rre->top_bracket, sizeof(rre->top_bracket));
- rre->top_backref = byteflip(rre->top_backref, sizeof(rre->top_backref));
- rre->first_byte = byteflip(rre->first_byte, sizeof(rre->first_byte));
- rre->req_byte = byteflip(rre->req_byte, sizeof(rre->req_byte));
- rre->name_table_offset = byteflip(rre->name_table_offset,
- sizeof(rre->name_table_offset));
- rre->name_entry_size = byteflip(rre->name_entry_size,
- sizeof(rre->name_entry_size));
- rre->name_count = byteflip(rre->name_count, sizeof(rre->name_count));
-
- if (extra != NULL)
- {
- pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
- rsd->size = byteflip(rsd->size, sizeof(rsd->size));
- rsd->options = byteflip(rsd->options, sizeof(rsd->options));
- }
- }
-
- /* Extract information from the compiled data if required */
-
- SHOW_INFO:
-
- if (do_debug)
- {
- fprintf(outfile, "------------------------------------------------------------------\n");
- pcre_printint(re, outfile);
- }
-
- if (do_showinfo)
- {
- unsigned long int get_options, all_options;
-#if !defined NOINFOCHECK
- int old_first_char, old_options, old_count;
-#endif
- int count, backrefmax, first_char, need_char;
- int nameentrysize, namecount;
- const uschar *nametable;
-
- new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
- new_info(re, NULL, PCRE_INFO_SIZE, &size);
- new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
- new_info(re, NULL, PCRE_INFO_BACKREFMAX, &backrefmax);
- new_info(re, NULL, PCRE_INFO_FIRSTBYTE, &first_char);
- new_info(re, NULL, PCRE_INFO_LASTLITERAL, &need_char);
- new_info(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &nameentrysize);
- new_info(re, NULL, PCRE_INFO_NAMECOUNT, &namecount);
- new_info(re, NULL, PCRE_INFO_NAMETABLE, (void *)&nametable);
-
-#if !defined NOINFOCHECK
- old_count = pcre_info(re, &old_options, &old_first_char);
- if (count < 0) fprintf(outfile,
- "Error %d from pcre_info()\n", count);
- else
- {
- if (old_count != count) fprintf(outfile,
- "Count disagreement: pcre_fullinfo=%d pcre_info=%d\n", count,
- old_count);
-
- if (old_first_char != first_char) fprintf(outfile,
- "First char disagreement: pcre_fullinfo=%d pcre_info=%d\n",
- first_char, old_first_char);
-
- if (old_options != (int)get_options) fprintf(outfile,
- "Options disagreement: pcre_fullinfo=%ld pcre_info=%d\n",
- get_options, old_options);
- }
-#endif
-
- if (size != regex_gotten_store) fprintf(outfile,
- "Size disagreement: pcre_fullinfo=%d call to malloc for %d\n",
- (int)size, (int)regex_gotten_store);
-
- fprintf(outfile, "Capturing subpattern count = %d\n", count);
- if (backrefmax > 0)
- fprintf(outfile, "Max back reference = %d\n", backrefmax);
-
- if (namecount > 0)
- {
- fprintf(outfile, "Named capturing subpatterns:\n");
- while (namecount-- > 0)
- {
- fprintf(outfile, " %s %*s%3d\n", nametable + 2,
- nameentrysize - 3 - (int)strlen((char *)nametable + 2), "",
- GET2(nametable, 0));
- nametable += nameentrysize;
- }
- }
-
- /* The NOPARTIAL bit is a private bit in the options, so we have
- to fish it out via out back door */
-
- all_options = ((real_pcre *)re)->options;
- if (do_flip)
- {
- all_options = byteflip(all_options, sizeof(all_options));
- }
-
- if ((all_options & PCRE_NOPARTIAL) != 0)
- fprintf(outfile, "Partial matching not supported\n");
-
- if (get_options == 0) fprintf(outfile, "No options\n");
- else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
- ((get_options & PCRE_ANCHORED) != 0)? " anchored" : "",
- ((get_options & PCRE_CASELESS) != 0)? " caseless" : "",
- ((get_options & PCRE_EXTENDED) != 0)? " extended" : "",
- ((get_options & PCRE_MULTILINE) != 0)? " multiline" : "",
- ((get_options & PCRE_FIRSTLINE) != 0)? " firstline" : "",
- ((get_options & PCRE_DOTALL) != 0)? " dotall" : "",
- ((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
- ((get_options & PCRE_EXTRA) != 0)? " extra" : "",
- ((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "",
- ((get_options & PCRE_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "",
- ((get_options & PCRE_UTF8) != 0)? " utf8" : "",
- ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
- ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
-
- switch (get_options & PCRE_NEWLINE_BITS)
- {
- case PCRE_NEWLINE_CR:
- fprintf(outfile, "Forced newline sequence: CR\n");
- break;
-
- case PCRE_NEWLINE_LF:
- fprintf(outfile, "Forced newline sequence: LF\n");
- break;
-
- case PCRE_NEWLINE_CRLF:
- fprintf(outfile, "Forced newline sequence: CRLF\n");
- break;
-
- case PCRE_NEWLINE_ANY:
- fprintf(outfile, "Forced newline sequence: ANY\n");
- break;
-
- default:
- break;
- }
-
- if (first_char == -1)
- {
- fprintf(outfile, "First char at start or follows newline\n");
- }
- else if (first_char < 0)
- {
- fprintf(outfile, "No first char\n");
- }
- else
- {
- int ch = first_char & 255;
- const char *caseless = ((first_char & REQ_CASELESS) == 0)?
- "" : " (caseless)";
- if (PRINTHEX(ch))
- fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);
- else
- fprintf(outfile, "First char = %d%s\n", ch, caseless);
- }
-
- if (need_char < 0)
- {
- fprintf(outfile, "No need char\n");
- }
- else
- {
- int ch = need_char & 255;
- const char *caseless = ((need_char & REQ_CASELESS) == 0)?
- "" : " (caseless)";
- if (PRINTHEX(ch))
- fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);
- else
- fprintf(outfile, "Need char = %d%s\n", ch, caseless);
- }
-
- /* Don't output study size; at present it is in any case a fixed
- value, but it varies, depending on the computer architecture, and
- so messes up the test suite. (And with the /F option, it might be
- flipped.) */
-
- if (do_study)
- {
- if (extra == NULL)
- fprintf(outfile, "Study returned NULL\n");
- else
- {
- uschar *start_bits = NULL;
- new_info(re, extra, PCRE_INFO_FIRSTTABLE, &start_bits);
-
- if (start_bits == NULL)
- fprintf(outfile, "No starting byte set\n");
- else
- {
- int i;
- int c = 24;
- fprintf(outfile, "Starting byte set: ");
- for (i = 0; i < 256; i++)
- {
- if ((start_bits[i/8] & (1<<(i&7))) != 0)
- {
- if (c > 75)
- {
- fprintf(outfile, "\n ");
- c = 2;
- }
- if (PRINTHEX(i) && i != ' ')
- {
- fprintf(outfile, "%c ", i);
- c += 2;
- }
- else
- {
- fprintf(outfile, "\\x%02x ", i);
- c += 5;
- }
- }
- }
- fprintf(outfile, "\n");
- }
- }
- }
- }
-
- /* If the '>' option was present, we write out the regex to a file, and
- that is all. The first 8 bytes of the file are the regex length and then
- the study length, in big-endian order. */
-
- if (to_file != NULL)
- {
- FILE *f = fopen((char *)to_file, "wb");
- if (f == NULL)
- {
- fprintf(outfile, "Unable to open %s: %s\n", to_file, strerror(errno));
- }
- else
- {
- uschar sbuf[8];
- sbuf[0] = (true_size >> 24) & 255;
- sbuf[1] = (true_size >> 16) & 255;
- sbuf[2] = (true_size >> 8) & 255;
- sbuf[3] = (true_size) & 255;
-
- sbuf[4] = (true_study_size >> 24) & 255;
- sbuf[5] = (true_study_size >> 16) & 255;
- sbuf[6] = (true_study_size >> 8) & 255;
- sbuf[7] = (true_study_size) & 255;
-
- if (fwrite(sbuf, 1, 8, f) < 8 ||
- fwrite(re, 1, true_size, f) < true_size)
- {
- fprintf(outfile, "Write error on %s: %s\n", to_file, strerror(errno));
- }
- else
- {
- fprintf(outfile, "Compiled regex written to %s\n", to_file);
- if (extra != NULL)
- {
- if (fwrite(extra->study_data, 1, true_study_size, f) <
- true_study_size)
- {
- fprintf(outfile, "Write error on %s: %s\n", to_file,
- strerror(errno));
- }
- else fprintf(outfile, "Study data written to %s\n", to_file);
-
- }
- }
- fclose(f);
- }
-
- new_free(re);
- if (extra != NULL) new_free(extra);
- if (tables != NULL) new_free((void *)tables);
- continue; /* With next regex */
- }
- } /* End of non-POSIX compile */
-
- /* Read data lines and test them */
-
- for (;;)
- {
- uschar *q;
- uschar *bptr = dbuffer;
- int *use_offsets = offsets;
- int use_size_offsets = size_offsets;
- int callout_data = 0;
- int callout_data_set = 0;
- int count, c;
- int copystrings = 0;
- int find_match_limit = 0;
- int getstrings = 0;
- int getlist = 0;
- int gmatched = 0;
- int start_offset = 0;
- int g_notempty = 0;
- int use_dfa = 0;
-
- options = 0;
-
- *copynames = 0;
- *getnames = 0;
-
- copynamesptr = copynames;
- getnamesptr = getnames;
-
- pcre_callout = callout;
- first_callout = 1;
- callout_extra = 0;
- callout_count = 0;
- callout_fail_count = 999999;
- callout_fail_id = -1;
- show_malloc = 0;
-
- if (extra != NULL) extra->flags &=
- ~(PCRE_EXTRA_MATCH_LIMIT|PCRE_EXTRA_MATCH_LIMIT_RECURSION);
-
- len = 0;
- for (;;)
- {
- if (infile == stdin) printf("data> ");
- if (extend_inputline(infile, buffer + len) == NULL)
- {
- if (len > 0) break;
- done = 1;
- goto CONTINUE;
- }
- if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
- len = (int)strlen((char *)buffer);
- if (buffer[len-1] == '\n') break;
- }
-
- while (len > 0 && isspace(buffer[len-1])) len--;
- buffer[len] = 0;
- if (len == 0) break;
-
- p = buffer;
- while (isspace(*p)) p++;
-
- q = dbuffer;
- while ((c = *p++) != 0)
- {
- int i = 0;
- int n = 0;
-
- if (c == '\\') switch ((c = *p++))
- {
- case 'a': c = 7; break;
- case 'b': c = '\b'; break;
- case 'e': c = 27; break;
- case 'f': c = '\f'; break;
- case 'n': c = '\n'; break;
- case 'r': c = '\r'; break;
- case 't': c = '\t'; break;
- case 'v': c = '\v'; break;
-
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- c -= '0';
- while (i++ < 2 && isdigit(*p) && *p != '8' && *p != '9')
- c = c * 8 + *p++ - '0';
-
-#if !defined NOUTF8
- if (use_utf8 && c > 255)
- {
- unsigned char buff8[8];
- int ii, utn;
- utn = ord2utf8(c, buff8);
- for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
- c = buff8[ii]; /* Last byte */
- }
-#endif
- break;
-
- case 'x':
-
- /* Handle \x{..} specially - new Perl thing for utf8 */
-
-#if !defined NOUTF8
- if (*p == '{')
- {
- unsigned char *pt = p;
- c = 0;
- while (isxdigit(*(++pt)))
- c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'W');
- if (*pt == '}')
- {
- unsigned char buff8[8];
- int ii, utn;
- utn = ord2utf8(c, buff8);
- for (ii = 0; ii < utn - 1; ii++) *q++ = buff8[ii];
- c = buff8[ii]; /* Last byte */
- p = pt + 1;
- break;
- }
- /* Not correct form; fall through */
- }
-#endif
-
- /* Ordinary \x */
-
- c = 0;
- while (i++ < 2 && isxdigit(*p))
- {
- c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'W');
- p++;
- }
- break;
-
- case 0: /* \ followed by EOF allows for an empty line */
- p--;
- continue;
-
- case '>':
- while(isdigit(*p)) start_offset = start_offset * 10 + *p++ - '0';
- continue;
-
- case 'A': /* Option setting */
- options |= PCRE_ANCHORED;
- continue;
-
- case 'B':
- options |= PCRE_NOTBOL;
- continue;
-
- case 'C':
- if (isdigit(*p)) /* Set copy string */
- {
- while(isdigit(*p)) n = n * 10 + *p++ - '0';
- copystrings |= 1 << n;
- }
- else if (isalnum(*p))
- {
- uschar *npp = copynamesptr;
- while (isalnum(*p)) *npp++ = *p++;
- *npp++ = 0;
- *npp = 0;
- n = pcre_get_stringnumber(re, (char *)copynamesptr);
- if (n < 0)
- fprintf(outfile, "no parentheses with name \"%s\"\n", copynamesptr);
- copynamesptr = npp;
- }
- else if (*p == '+')
- {
- callout_extra = 1;
- p++;
- }
- else if (*p == '-')
- {
- pcre_callout = NULL;
- p++;
- }
- else if (*p == '!')
- {
- callout_fail_id = 0;
- p++;
- while(isdigit(*p))
- callout_fail_id = callout_fail_id * 10 + *p++ - '0';
- callout_fail_count = 0;
- if (*p == '!')
- {
- p++;
- while(isdigit(*p))
- callout_fail_count = callout_fail_count * 10 + *p++ - '0';
- }
- }
- else if (*p == '*')
- {
- int sign = 1;
- callout_data = 0;
- if (*(++p) == '-') { sign = -1; p++; }
- while(isdigit(*p))
- callout_data = callout_data * 10 + *p++ - '0';
- callout_data *= sign;
- callout_data_set = 1;
- }
- continue;
-
-#if !defined NODFA
- case 'D':
-#if !defined NOPOSIX
- if (posix || do_posix)
- printf("** Can't use dfa matching in POSIX mode: \\D ignored\n");
- else
-#endif
- use_dfa = 1;
- continue;
-
- case 'F':
- options |= PCRE_DFA_SHORTEST;
- continue;
-#endif
-
- case 'G':
- if (isdigit(*p))
- {
- while(isdigit(*p)) n = n * 10 + *p++ - '0';
- getstrings |= 1 << n;
- }
- else if (isalnum(*p))
- {
- uschar *npp = getnamesptr;
- while (isalnum(*p)) *npp++ = *p++;
- *npp++ = 0;
- *npp = 0;
- n = pcre_get_stringnumber(re, (char *)getnamesptr);
- if (n < 0)
- fprintf(outfile, "no parentheses with name \"%s\"\n", getnamesptr);
- getnamesptr = npp;
- }
- continue;
-
- case 'L':
- getlist = 1;
- continue;
-
- case 'M':
- find_match_limit = 1;
- continue;
-
- case 'N':
- options |= PCRE_NOTEMPTY;
- continue;
-
- case 'O':
- while(isdigit(*p)) n = n * 10 + *p++ - '0';
- if (n > size_offsets_max)
- {
- size_offsets_max = n;
- free(offsets);
- use_offsets = offsets = (int *)malloc(size_offsets_max * sizeof(int));
- if (offsets == NULL)
- {
- printf("** Failed to get %d bytes of memory for offsets vector\n",
- size_offsets_max * sizeof(int));
- yield = 1;
- goto EXIT;
- }
- }
- use_size_offsets = n;
- if (n == 0) use_offsets = NULL; /* Ensures it can't write to it */
- continue;
-
- case 'P':
- options |= PCRE_PARTIAL;
- continue;
-
- case 'Q':
- while(isdigit(*p)) n = n * 10 + *p++ - '0';
- if (extra == NULL)
- {
- extra = (pcre_extra *)malloc(sizeof(pcre_extra));
- extra->flags = 0;
- }
- extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
- extra->match_limit_recursion = n;
- continue;
-
- case 'q':
- while(isdigit(*p)) n = n * 10 + *p++ - '0';
- if (extra == NULL)
- {
- extra = (pcre_extra *)malloc(sizeof(pcre_extra));
- extra->flags = 0;
- }
- extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
- extra->match_limit = n;
- continue;
-
-#if !defined NODFA
- case 'R':
- options |= PCRE_DFA_RESTART;
- continue;
-#endif
-
- case 'S':
- show_malloc = 1;
- continue;
-
- case 'Z':
- options |= PCRE_NOTEOL;
- continue;
-
- case '?':
- options |= PCRE_NO_UTF8_CHECK;
- continue;
-
- case '<':
- {
- int x = check_newline(p, outfile);
- if (x == 0) goto NEXT_DATA;
- options |= x;
- while (*p++ != '>');
- }
- continue;
- }
- *q++ = c;
- }
- *q = 0;
- len = q - dbuffer;
-
- if ((all_use_dfa || use_dfa) && find_match_limit)
- {
- printf("**Match limit not relevant for DFA matching: ignored\n");
- find_match_limit = 0;
- }
-
- /* Handle matching via the POSIX interface, which does not
- support timing or playing with the match limit or callout data. */
-
-#if !defined NOPOSIX
- if (posix || do_posix)
- {
- int rc;
- int eflags = 0;
- regmatch_t *pmatch = NULL;
- if (use_size_offsets > 0)
- pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * use_size_offsets);
- if ((options & PCRE_NOTBOL) != 0) eflags |= REG_NOTBOL;
- if ((options & PCRE_NOTEOL) != 0) eflags |= REG_NOTEOL;
-
- rc = regexec(&preg, (const char *)bptr, use_size_offsets, pmatch, eflags);
-
- if (rc != 0)
- {
- (void)regerror(rc, &preg, (char *)buffer, buffer_size);
- fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer);
- }
- else if ((((const pcre *)preg.re_pcre)->options & PCRE_NO_AUTO_CAPTURE)
- != 0)
- {
- fprintf(outfile, "Matched with REG_NOSUB\n");
- }
- else
- {
- size_t i;
- for (i = 0; i < (size_t)use_size_offsets; i++)
- {
- if (pmatch[i].rm_so >= 0)
- {
- fprintf(outfile, "%2d: ", (int)i);
- (void)pchars(dbuffer + pmatch[i].rm_so,
- pmatch[i].rm_eo - pmatch[i].rm_so, outfile);
- fprintf(outfile, "\n");
- if (i == 0 && do_showrest)
- {
- fprintf(outfile, " 0+ ");
- (void)pchars(dbuffer + pmatch[i].rm_eo, len - pmatch[i].rm_eo,
- outfile);
- fprintf(outfile, "\n");
- }
- }
- }
- }
- free(pmatch);
- }
-
- /* Handle matching via the native interface - repeats for /g and /G */
-
- else
-#endif /* !defined NOPOSIX */
-
- for (;; gmatched++) /* Loop for /g or /G */
- {
- if (timeitm > 0)
- {
- register int i;
- clock_t time_taken;
- clock_t start_time = clock();
-
-#if !defined NODFA
- if (all_use_dfa || use_dfa)
- {
- int workspace[1000];
- for (i = 0; i < timeitm; i++)
- count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
- options | g_notempty, use_offsets, use_size_offsets, workspace,
- sizeof(workspace)/sizeof(int));
- }
- else
-#endif
-
- for (i = 0; i < timeitm; i++)
- count = pcre_exec(re, extra, (char *)bptr, len,
- start_offset, options | g_notempty, use_offsets, use_size_offsets);
-
- time_taken = clock() - start_time;
- fprintf(outfile, "Execute time %.4f milliseconds\n",
- (((double)time_taken * 1000.0) / (double)timeitm) /
- (double)CLOCKS_PER_SEC);
- }
-
- /* If find_match_limit is set, we want to do repeated matches with
- varying limits in order to find the minimum value for the match limit and
- for the recursion limit. */
-
- if (find_match_limit)
- {
- if (extra == NULL)
- {
- extra = (pcre_extra *)malloc(sizeof(pcre_extra));
- extra->flags = 0;
- }
-
- (void)check_match_limit(re, extra, bptr, len, start_offset,
- options|g_notempty, use_offsets, use_size_offsets,
- PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),
- PCRE_ERROR_MATCHLIMIT, "match()");
-
- count = check_match_limit(re, extra, bptr, len, start_offset,
- options|g_notempty, use_offsets, use_size_offsets,
- PCRE_EXTRA_MATCH_LIMIT_RECURSION, &(extra->match_limit_recursion),
- PCRE_ERROR_RECURSIONLIMIT, "match() recursion");
- }
-
- /* If callout_data is set, use the interface with additional data */
-
- else if (callout_data_set)
- {
- if (extra == NULL)
- {
- extra = (pcre_extra *)malloc(sizeof(pcre_extra));
- extra->flags = 0;
- }
- extra->flags |= PCRE_EXTRA_CALLOUT_DATA;
- extra->callout_data = &callout_data;
- count = pcre_exec(re, extra, (char *)bptr, len, start_offset,
- options | g_notempty, use_offsets, use_size_offsets);
- extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;
- }
-
- /* The normal case is just to do the match once, with the default
- value of match_limit. */
-
-#if !defined NODFA
- else if (all_use_dfa || use_dfa)
- {
- int workspace[1000];
- count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
- options | g_notempty, use_offsets, use_size_offsets, workspace,
- sizeof(workspace)/sizeof(int));
- if (count == 0)
- {
- fprintf(outfile, "Matched, but too many subsidiary matches\n");
- count = use_size_offsets/2;
- }
- }
-#endif
-
- else
- {
- count = pcre_exec(re, extra, (char *)bptr, len,
- start_offset, options | g_notempty, use_offsets, use_size_offsets);
- if (count == 0)
- {
- fprintf(outfile, "Matched, but too many substrings\n");
- count = use_size_offsets/3;
- }
- }
-
- /* Matched */
-
- if (count >= 0)
- {
- int i, maxcount;
-
-#if !defined NODFA
- if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
-#endif
- maxcount = use_size_offsets/3;
-
- /* This is a check against a lunatic return value. */
-
- if (count > maxcount)
- {
- fprintf(outfile,
- "** PCRE error: returned count %d is too big for offset size %d\n",
- count, use_size_offsets);
- count = use_size_offsets/3;
- if (do_g || do_G)
- {
- fprintf(outfile, "** /%c loop abandoned\n", do_g? 'g' : 'G');
- do_g = do_G = FALSE; /* Break g/G loop */
- }
- }
-
- for (i = 0; i < count * 2; i += 2)
- {
- if (use_offsets[i] < 0)
- fprintf(outfile, "%2d: <unset>\n", i/2);
- else
- {
- fprintf(outfile, "%2d: ", i/2);
- (void)pchars(bptr + use_offsets[i],
- use_offsets[i+1] - use_offsets[i], outfile);
- fprintf(outfile, "\n");
- if (i == 0)
- {
- if (do_showrest)
- {
- fprintf(outfile, " 0+ ");
- (void)pchars(bptr + use_offsets[i+1], len - use_offsets[i+1],
- outfile);
- fprintf(outfile, "\n");
- }
- }
- }
- }
-
- for (i = 0; i < 32; i++)
- {
- if ((copystrings & (1 << i)) != 0)
- {
- char copybuffer[256];
- int rc = pcre_copy_substring((char *)bptr, use_offsets, count,
- i, copybuffer, sizeof(copybuffer));
- if (rc < 0)
- fprintf(outfile, "copy substring %d failed %d\n", i, rc);
- else
- fprintf(outfile, "%2dC %s (%d)\n", i, copybuffer, rc);
- }
- }
-
- for (copynamesptr = copynames;
- *copynamesptr != 0;
- copynamesptr += (int)strlen((char*)copynamesptr) + 1)
- {
- char copybuffer[256];
- int rc = pcre_copy_named_substring(re, (char *)bptr, use_offsets,
- count, (char *)copynamesptr, copybuffer, sizeof(copybuffer));
- if (rc < 0)
- fprintf(outfile, "copy substring %s failed %d\n", copynamesptr, rc);
- else
- fprintf(outfile, " C %s (%d) %s\n", copybuffer, rc, copynamesptr);
- }
-
- for (i = 0; i < 32; i++)
- {
- if ((getstrings & (1 << i)) != 0)
- {
- const char *substring;
- int rc = pcre_get_substring((char *)bptr, use_offsets, count,
- i, &substring);
- if (rc < 0)
- fprintf(outfile, "get substring %d failed %d\n", i, rc);
- else
- {
- fprintf(outfile, "%2dG %s (%d)\n", i, substring, rc);
- pcre_free_substring(substring);
- }
- }
- }
-
- for (getnamesptr = getnames;
- *getnamesptr != 0;
- getnamesptr += (int)strlen((char*)getnamesptr) + 1)
- {
- const char *substring;
- int rc = pcre_get_named_substring(re, (char *)bptr, use_offsets,
- count, (char *)getnamesptr, &substring);
- if (rc < 0)
- fprintf(outfile, "copy substring %s failed %d\n", getnamesptr, rc);
- else
- {
- fprintf(outfile, " G %s (%d) %s\n", substring, rc, getnamesptr);
- pcre_free_substring(substring);
- }
- }
-
- if (getlist)
- {
- const char **stringlist;
- int rc = pcre_get_substring_list((char *)bptr, use_offsets, count,
- &stringlist);
- if (rc < 0)
- fprintf(outfile, "get substring list failed %d\n", rc);
- else
- {
- for (i = 0; i < count; i++)
- fprintf(outfile, "%2dL %s\n", i, stringlist[i]);
- if (stringlist[i] != NULL)
- fprintf(outfile, "string list not terminated by NULL\n");
- /* free((void *)stringlist); */
- pcre_free_substring_list(stringlist);
- }
- }
- }
-
- /* There was a partial match */
-
- else if (count == PCRE_ERROR_PARTIAL)
- {
- fprintf(outfile, "Partial match");
-#if !defined NODFA
- if ((all_use_dfa || use_dfa) && use_size_offsets > 2)
- fprintf(outfile, ": %.*s", use_offsets[1] - use_offsets[0],
- bptr + use_offsets[0]);
-#endif
- fprintf(outfile, "\n");
- break; /* Out of the /g loop */
- }
-
- /* Failed to match. If this is a /g or /G loop and we previously set
- g_notempty after a null match, this is not necessarily the end.
- We want to advance the start offset, and continue. In the case of UTF-8
- matching, the advance must be one character, not one byte. Fudge the
- offset values to achieve this. We won't be at the end of the string -
- that was checked before setting g_notempty. */
-
- else
- {
- if (g_notempty != 0)
- {
- int onechar = 1;
- use_offsets[0] = start_offset;
- if (use_utf8)
- {
- while (start_offset + onechar < len)
- {
- int tb = bptr[start_offset+onechar];
- if (tb <= 127) break;
- tb &= 0xc0;
- if (tb != 0 && tb != 0xc0) onechar++;
- }
- }
- use_offsets[1] = start_offset + onechar;
- }
- else
- {
- if (count == PCRE_ERROR_NOMATCH)
- {
- if (gmatched == 0) fprintf(outfile, "No match\n");
- }
- else fprintf(outfile, "Error %d\n", count);
- break; /* Out of the /g loop */
- }
- }
-
- /* If not /g or /G we are done */
-
- if (!do_g && !do_G) break;
-
- /* If we have matched an empty string, first check to see if we are at
- the end of the subject. If so, the /g loop is over. Otherwise, mimic
- what Perl's /g options does. This turns out to be rather cunning. First
- we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the
- same point. If this fails (picked up above) we advance to the next
- character. */
-
- g_notempty = 0;
- if (use_offsets[0] == use_offsets[1])
- {
- if (use_offsets[0] == len) break;
- g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;
- }
-
- /* For /g, update the start offset, leaving the rest alone */
-
- if (do_g) start_offset = use_offsets[1];
-
- /* For /G, update the pointer and length */
-
- else
- {
- bptr += use_offsets[1];
- len -= use_offsets[1];
- }
- } /* End of loop for /g and /G */
-
- NEXT_DATA: continue;
- } /* End of loop for data lines */
-
- CONTINUE:
-
-#if !defined NOPOSIX
- if (posix || do_posix) regfree(&preg);
-#endif
-
- if (re != NULL) new_free(re);
- if (extra != NULL) new_free(extra);
- if (tables != NULL)
- {
- new_free((void *)tables);
- setlocale(LC_CTYPE, "C");
- locale_set = 0;
- }
- }
-
-if (infile == stdin) fprintf(outfile, "\n");
-
-EXIT:
-
-if (infile != NULL && infile != stdin) fclose(infile);
-if (outfile != NULL && outfile != stdout) fclose(outfile);
-
-free(buffer);
-free(dbuffer);
-free(pbuffer);
-free(offsets);
-
-return yield;
-}
-
-/* End of pcretest.c */
diff --git a/ext/pcre/pcrelib/testdata/grepinputx b/ext/pcre/pcrelib/testdata/grepinputx
index 4c02567552..aebba02770 100644
--- a/ext/pcre/pcrelib/testdata/grepinputx
+++ b/ext/pcre/pcrelib/testdata/grepinputx
@@ -39,11 +39,4 @@ eighteen
nineteen
twenty
-Here follows some CR/LF/CRLF test data.
-
-abc
-def
-ghi
-jkl
-
This is the last line of this file.
diff --git a/ext/pcre/pcrelib/testdata/grepoutput b/ext/pcre/pcrelib/testdata/grepoutput
index 804c33fc3f..3241984c1c 100644
--- a/ext/pcre/pcrelib/testdata/grepoutput
+++ b/ext/pcre/pcrelib/testdata/grepoutput
@@ -75,14 +75,7 @@ RC=1
39:nineteen
40:twenty
41:
-42:Here follows some CR/LF/CRLF test data.
-43:
-44:abc
-def
-45:ghi
-46:jkl
-47:
-48:This is the last line of this file.
+42:This is the last line of this file.
---------------------------- Test 12 -----------------------------
Pattern
---------------------------- Test 13 -----------------------------
@@ -164,8 +157,7 @@ eighteen
nineteen
twenty
-Here follows some CR/LF/CRLF test data.
-
+This is the last line of this file.
---------------------------- Test 25 -----------------------------
15-
16-complete pair
@@ -215,8 +207,7 @@ eighteen
nineteen
twenty
-Here follows some CR/LF/CRLF test data.
-
+This is the last line of this file.
---------------------------- Test 27 -----------------------------
four
five
@@ -236,10 +227,7 @@ eighteen
nineteen
twenty
-Here follows some CR/LF/CRLF test data.
-
-abc
-def
+This is the last line of this file.
---------------------------- Test 28 -----------------------------
14-of lines all by themselves.
15-
@@ -291,12 +279,7 @@ eighteen
nineteen
twenty
-Here follows some CR/LF/CRLF test data.
-
-abc
-def
-ghi
-jkl
+This is the last line of this file.
---------------------------- Test 30 -----------------------------
./testdata/grepinput-4-features should be added at the end, because some of the tests involve the
./testdata/grepinput-5-output of line numbers, and we don't want these to change.
@@ -345,8 +328,8 @@ RC=2
./testdata/grepinputx
RC=0
---------------------------- Test 36 -----------------------------
-./testdata/grepinputx
./testdata/grepinput8
+./testdata/grepinputx
RC=0
---------------------------- Test 37 -----------------------------
aaaaa0
@@ -375,10 +358,13 @@ after the binary zero
./testdata/grepinput:597:after the binary zero
---------------------------- Test 42 ------------------------------
595:before
+595:zero
596:zero
597:after
+597:zero
---------------------------- Test 43 ------------------------------
595:before
+595:zero
596:zero
597:zero
---------------------------- Test 44 ------------------------------
@@ -400,30 +386,19 @@ AB.VE
AB.VE the turtle
PUT NEW DATA ABOVE THIS LINE.
---------------------------- Test 49 ------------------------------
-abc
-def
-ghi
-jkl
---------------------------- Test 50 ------------------------------
-def
+over the lazy dog.
---------------------------- Test 51 ------------------------------
-ghi
-jkl
-
-This is the last line of this file.
+fox jumps
---------------------------- Test 52 ------------------------------
-def
-ghi
-jkl
-
-This is the last line of this file.
+36972,6
+36990,4
+37024,4
+37066,5
+37083,4
---------------------------- Test 53 ------------------------------
-ghi
-jkl
-
-This is the last line of this file.
----------------------------- Test 54 ------------------------------
-44:abc
-45:def
-46:ghi
-47:jkl
+595:15,6
+595:33,4
+596:28,4
+597:15,5
+597:32,4
diff --git a/ext/pcre/pcrelib/testdata/grepoutputN b/ext/pcre/pcrelib/testdata/grepoutputN
new file mode 100644
index 0000000000..170a4321ee
--- /dev/null
+++ b/ext/pcre/pcrelib/testdata/grepoutputN
@@ -0,0 +1,22 @@
+---------------------------- Test N1 ------------------------------
+1:abc
+2:def
+---------------------------- Test N2 ------------------------------
+1:abc
+def
+2:ghi
+jkl---------------------------- Test N3 ------------------------------
+2:def
+3:
+ghi
+jkl---------------------------- Test N4 ------------------------------
+2:ghi
+jkl---------------------------- Test N5 ------------------------------
+1:abc
+2:def
+3:ghi
+4:jkl---------------------------- Test N6 ------------------------------
+1:abc
+2:def
+3:ghi
+4:jkl \ No newline at end of file
diff --git a/ext/pcre/pcrelib/testdata/testinput1 b/ext/pcre/pcrelib/testdata/testinput1
index d8ef12bc42..91554ffc49 100644
--- a/ext/pcre/pcrelib/testdata/testinput1
+++ b/ext/pcre/pcrelib/testdata/testinput1
@@ -1494,8 +1494,8 @@
/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/
abcdefghijk\12S
-/ab\hdef/
- abhdef
+/ab\idef/
+ abidef
/a{0}bc/
bc
@@ -3421,11 +3421,6 @@
/((?m)^b)/
a\nb\nc\n
-/(?(1)a|b)/
-
-/(?(1)b|a)/
- a
-
/(x)?(?(1)a|b)/
*** Failers
a
@@ -4018,4 +4013,27 @@
abc
abc\n
+/(.*(.)?)*/
+ abcd
+
+/( (A | (?(1)0|) )* )/x
+ abcd
+
+/( ( (?(1)0|) )* )/x
+ abcd
+
+/( (?(1)0|)* )/x
+ abcd
+
+/[[:abcd:xyz]]/
+ a]
+ :]
+
+/[abc[:x\]pqr]/
+ a
+ [
+ :
+ ]
+ p
+
/ End of testinput1 /
diff --git a/ext/pcre/pcrelib/testdata/testinput10 b/ext/pcre/pcrelib/testdata/testinput10
new file mode 100644
index 0000000000..726a3890a2
--- /dev/null
+++ b/ext/pcre/pcrelib/testdata/testinput10
@@ -0,0 +1,124 @@
+/-- These are a few representative patterns whose lengths and offsets are to be
+shown when the link size is 2. This is just a doublecheck test to ensure the
+sizes don't go horribly wrong when something is changed. The pattern contents
+are all themselves checked in other tests. --/
+
+/((?i)b)/BM
+
+/(?s)(.*X|^B)/BM
+
+/(?s:.*X|^B)/BM
+
+/^[[:alnum:]]/BM
+
+/#/IxMD
+
+/a#/IxMD
+
+/x?+/BM
+
+/x++/BM
+
+/x{1,3}+/BM
+
+/(x)*+/BM
+
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/BM
+
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|BM
+
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|BM
+
+/(a(?1)b)/BM
+
+/(a(?1)+b)/BM
+
+/a(?P<name1>b|c)d(?P<longername2>e)/BM
+
+/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/BM
+
+/(?P<a>a)...(?P=a)bbb(?P>a)d/BM
+
+/abc(?C255)de(?C)f/BM
+
+/abcde/CBM
+
+/\x{100}/8BM
+
+/\x{1000}/8BM
+
+/\x{10000}/8BM
+
+/\x{100000}/8BM
+
+/\x{1000000}/8BM
+
+/\x{4000000}/8BM
+
+/\x{7fffFFFF}/8BM
+
+/[\x{ff}]/8BM
+
+/[\x{100}]/8BM
+
+/\x80/8BM
+
+/\xff/8BM
+
+/\x{0041}\x{2262}\x{0391}\x{002e}/D8M
+
+/\x{D55c}\x{ad6d}\x{C5B4}/D8M
+
+/\x{65e5}\x{672c}\x{8a9e}/D8M
+
+/[\x{100}]/8BM
+
+/[Z\x{100}]/8BM
+
+/^[\x{100}\E-\Q\E\x{150}]/B8M
+
+/^[\QÄ€\E-\QÅ\E]/B8M
+
+/^[\QÄ€\E-\QÅ\E/B8M
+
+/[\p{L}]/BM
+
+/[\p{^L}]/BM
+
+/[\P{L}]/BM
+
+/[\P{^L}]/BM
+
+/[abc\p{L}\x{0660}]/8BM
+
+/[\p{Nd}]/8BM
+
+/[\p{Nd}+-]+/8BM
+
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iBM
+
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8BM
+
+/[\x{105}-\x{109}]/8iBM
+
+/( ( (?(1)0|) )* )/xBM
+
+/( (?(1)0|)* )/xBM
+
+/[a]/BM
+
+/[a]/8BM
+
+/[\xaa]/BM
+
+/[\xaa]/8BM
+
+/[^a]/BM
+
+/[^a]/8BM
+
+/[^\xaa]/BM
+
+/[^\xaa]/8BM
+
+/ End of testinput10 /
diff --git a/ext/pcre/pcrelib/testdata/testinput2 b/ext/pcre/pcrelib/testdata/testinput2
index bb21f4819b..93b0f0996a 100644
--- a/ext/pcre/pcrelib/testdata/testinput2
+++ b/ext/pcre/pcrelib/testdata/testinput2
@@ -28,9 +28,9 @@
*** Failers
def\nabc
-/ab\hdef/X
+/ab\idef/X
-/(?X)ab\hdef/X
+/(?X)ab\idef/X
/x{5,4}/
@@ -82,7 +82,7 @@
\O3abcb
\O6abcb
\O9abcb
- \O12abcb
+ \O12abcb
/(a)bc|(a)(b)\2/I
abc
@@ -126,7 +126,7 @@
/abc/IP
abc
*** Failers
-
+
/^abc|def/IP
abcdef
abcdef\B
@@ -134,23 +134,23 @@
/.*((abc)$|(def))/IP
defabc
\Zdefabc
-
+
/the quick brown fox/IP
the quick brown fox
- *** Failers
- The Quick Brown Fox
+ *** Failers
+ The Quick Brown Fox
/the quick brown fox/IPi
the quick brown fox
- The Quick Brown Fox
+ The Quick Brown Fox
/abc.def/IP
*** Failers
abc\ndef
-
+
/abc$/IP
abc
- abc\n
+ abc\n
/(abc)\2/IP
@@ -162,8 +162,8 @@
/a[]b/
/[^aeiou ]{3,}/I
- co-processors, and for
-
+ co-processors, and for
+
/<.*>/I
abc<def>ghi<klm>nop
@@ -172,25 +172,25 @@
/<.*>/IU
abc<def>ghi<klm>nop
-
+
/(?U)<.*>/I
abc<def>ghi<klm>nop
/<.*?>/IU
abc<def>ghi<klm>nop
-
+
/={3,}/IU
abc========def
-
+
/(?U)={3,}?/I
abc========def
-
+
/(?<!bar|cattle)foo/I
foo
- catfoo
+ catfoo
*** Failers
the barfoo
- and cattlefoo
+ and cattlefoo
/(?<=a+)b/
@@ -236,27 +236,27 @@
/((?i)blah)\s+\1/I
-/((?i)b)/IDS
+/((?i)b)/IDZS
/(a*b|(?i:c*(?-i)d))/IS
/a$/I
a
a\n
- *** Failers
+ *** Failers
\Za
- \Za\n
+ \Za\n
/a$/Im
a
a\n
- \Za\n
- *** Failers
+ \Za\n
+ *** Failers
\Za
-
+
/\Aabc/Im
-/^abc/Im
+/^abc/Im
/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/I
aaaaabbbbbcccccdef
@@ -268,24 +268,24 @@
/(?!alphabet)[ab]/IS
/(?<=foo\n)^bar/Im
- foo\nbarbar
+ foo\nbarbar
***Failers
- rhubarb
+ rhubarb
barbell
- abc\nbarton
+ abc\nbarton
/^(?<=foo\n)bar/Im
- foo\nbarbar
+ foo\nbarbar
***Failers
- rhubarb
+ rhubarb
barbell
- abc\nbarton
+ abc\nbarton
/(?>^abc)/Im
abc
def\nabc
*** Failers
- defabc
+ defabc
/(?<=ab(c+)d)ef/
@@ -300,8 +300,8 @@
a donkey-cart race
*** Failers
cart
- horse-and-cart
-
+ horse-and-cart
+
/(?<=ab(?i)x|y|z)/I
/(?>.*)(?<=(abcd)|(xyz))/I
@@ -314,30 +314,30 @@
ZZZ
zZZ
bZZ
- BZZ
+ BZZ
*** Failers
- ZZ
- abXYZZ
+ ZZ
+ abXYZZ
zzz
- bzz
+ bzz
/(?<!(foo)a)bar/I
bar
- foobbar
+ foobbar
*** Failers
- fooabar
+ fooabar
/This one is here because Perl 5.005_02 doesn't fail it/I
/^(a)?(?(1)a|b)+$/I
*** Failers
- a
+ a
/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/I
/^(a\1?){4}$/I
aaaaaa
-
+
/These are syntax tests from Perl 5.005/I
/a[b-a]/
@@ -398,8 +398,6 @@
/(?(1?)a|b)/
-/(?(1)a|b|c)/
-
/[a[:xyz:/
/(?<=x+)y/
@@ -416,12 +414,12 @@
abcd
abcd\C2
abcd\C5
-
+
/(.{20})/I
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz\C1
abcdefghijklmnopqrstuvwxyz\G1
-
+
/(.{15})/I
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz\C1\G1
@@ -429,30 +427,30 @@
/(.{16})/I
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz\C1\G1\L
-
+
/^(a|(bc))de(f)/I
- adef\G1\G2\G3\G4\L
- bcdef\G1\G2\G3\G4\L
- adefghijk\C0
-
+ adef\G1\G2\G3\G4\L
+ bcdef\G1\G2\G3\G4\L
+ adefghijk\C0
+
/^abc\00def/I
- abc\00def\L\C0
-
-/word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
-)((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
-)?)?)?)?)?)?)?)?)?otherword/IM
+ abc\00def\L\C0
-/.*X/ID
+/word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
+)((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
+)?)?)?)?)?)?)?)?)?otherword/I
-/.*X/IDs
+/.*X/IDZ
-/(.*X|^B)/ID
+/.*X/IDZs
-/(.*X|^B)/IDs
-
-/(?s)(.*X|^B)/ID
+/(.*X|^B)/IDZ
+
+/(.*X|^B)/IDZs
-/(?s:.*X|^B)/ID
+/(?s)(.*X|^B)/IDZ
+
+/(?s:.*X|^B)/IDZ
/\Biss\B/I+
Mississippi
@@ -479,15 +477,15 @@
/^iss/Ig+
ississippi
-
+
/.*iss/Ig+
- abciss\nxyzisspqr
+ abciss\nxyzisspqr
/.i./I+g
Mississippi
Mississippi\A
Missouri river
- Missouri river\A
+ Missouri river\A
/^.is/I+g
Mississippi
@@ -568,15 +566,15 @@
/ab\d+/I
-/a(?(1)b)/I
+/a(?(1)b)(.)/I
-/a(?(1)bag|big)/I
+/a(?(1)bag|big)(.)/I
-/a(?(1)bag|big)*/I
+/a(?(1)bag|big)*(.)/I
-/a(?(1)bag|big)+/I
+/a(?(1)bag|big)+(.)/I
-/a(?(1)b..|b..)/I
+/a(?(1)b..|b..)(.)/I
/ab\d{0}e/I
@@ -586,14 +584,14 @@
ab
\
*** Failers
- \N
-
+ \N
+
/|-/I
abcd
-abc
\Nab-c
*** Failers
- \Nabc
+ \Nabc
/a*(b+)(z)(z)/IP
aaaabbbbzzzz
@@ -603,8 +601,8 @@
aaaabbbbzzzz\O3
aaaabbbbzzzz\O4
aaaabbbbzzzz\O5
-
-/^.?abcd/IS
+
+/^.?abcd/IS
/\( # ( at start
(?: # Non-capturing bracket
@@ -617,26 +615,26 @@
(abcd)
(abcd)xyz
xyz(abcd)
- (ab(xy)cd)pqr
- (ab(xycd)pqr
- () abc ()
+ (ab(xy)cd)pqr
+ (ab(xycd)pqr
+ () abc ()
12(abcde(fsh)xyz(foo(bar))lmno)89
*** Failers
- abcd
+ abcd
abcd)
- (abcd
+ (abcd
/\( ( (?>[^()]+) | (?R) )* \) /Ixg
- (ab(xy)cd)pqr
+ (ab(xy)cd)pqr
1(abcd)(x(y)z)pqr
/\( (?: (?>[^()]+) | (?R) ) \) /Ix
(abcd)
(ab(xy)cd)
- (a(b(c)d)e)
- ((ab))
+ (a(b(c)d)e)
+ ((ab))
*** Failers
- ()
+ ()
/\( (?: (?>[^()]+) | (?R) )? \) /Ix
()
@@ -666,53 +664,53 @@
(ab(cd)ef)
(ab(cd(ef)gh)ij)
-/^[[:alnum:]]/D
+/^[[:alnum:]]/DZ
+
+/^[[:^alnum:]]/DZ
-/^[[:^alnum:]]/D
+/^[[:alpha:]]/DZ
-/^[[:alpha:]]/D
+/^[[:^alpha:]]/DZ
-/^[[:^alpha:]]/D
-
/[_[:alpha:]]/IS
-/^[[:ascii:]]/D
+/^[[:ascii:]]/DZ
-/^[[:^ascii:]]/D
+/^[[:^ascii:]]/DZ
-/^[[:blank:]]/D
+/^[[:blank:]]/DZ
-/^[[:^blank:]]/D
+/^[[:^blank:]]/DZ
/[\n\x0b\x0c\x0d[:blank:]]/IS
-/^[[:cntrl:]]/D
+/^[[:cntrl:]]/DZ
-/^[[:digit:]]/D
+/^[[:digit:]]/DZ
-/^[[:graph:]]/D
+/^[[:graph:]]/DZ
-/^[[:lower:]]/D
+/^[[:lower:]]/DZ
-/^[[:print:]]/D
+/^[[:print:]]/DZ
-/^[[:punct:]]/D
+/^[[:punct:]]/DZ
-/^[[:space:]]/D
+/^[[:space:]]/DZ
-/^[[:upper:]]/D
+/^[[:upper:]]/DZ
-/^[[:xdigit:]]/D
+/^[[:xdigit:]]/DZ
-/^[[:word:]]/D
+/^[[:word:]]/DZ
-/^[[:^cntrl:]]/D
+/^[[:^cntrl:]]/DZ
-/^[12[:^digit:]]/D
+/^[12[:^digit:]]/DZ
-/^[[:^blank:]]/D
+/^[[:^blank:]]/DZ
-/[01[:alpha:]%]/D
+/[01[:alpha:]%]/DZ
/[[.ch.]]/I
@@ -722,18 +720,18 @@
/[[:upper:]]/Ii
A
- a
-
+ a
+
/[[:lower:]]/Ii
A
- a
+ a
/((?-i)[[:lower:]])[[:lower:]]/Ii
ab
aB
*** Failers
Ab
- AB
+ AB
/[\200-\110]/I
@@ -749,120 +747,120 @@
/(main(O)?)+/I
mainmain
mainOmain
-
+
/These are all cases where Perl does it differently (nested captures)/I
/^(a(b)?)+$/I
aba
-
+
/^(aa(bb)?)+$/I
- aabbaa
-
+ aabbaa
+
/^(aa|aa(bb))+$/I
- aabbaa
-
+ aabbaa
+
/^(aa(bb)??)+$/I
- aabbaa
-
+ aabbaa
+
/^(?:aa(bb)?)+$/I
- aabbaa
-
+ aabbaa
+
/^(aa(b(b))?)+$/I
- aabbaa
+ aabbaa
/^(?:aa(b(b))?)+$/I
- aabbaa
+ aabbaa
/^(?:aa(b(?:b))?)+$/I
- aabbaa
+ aabbaa
/^(?:aa(bb(?:b))?)+$/I
- aabbbaa
-
+ aabbbaa
+
/^(?:aa(b(?:bb))?)+$/I
- aabbbaa
+ aabbbaa
/^(?:aa(?:b(b))?)+$/I
- aabbaa
+ aabbaa
/^(?:aa(?:b(bb))?)+$/I
- aabbbaa
+ aabbbaa
/^(aa(b(bb))?)+$/I
- aabbbaa
+ aabbbaa
/^(aa(bb(bb))?)+$/I
- aabbbbaa
+ aabbbbaa
-/--------------------------------------------------------------------/I
-
-/#/IxMD
+/--------------------------------------------------------------------/I
+
+/#/IxDZ
-/a#/IxMD
+/a#/IxDZ
-/[\s]/D
+/[\s]/DZ
-/[\S]/D
+/[\S]/DZ
-/a(?i)b/D
+/a(?i)b/DZ
ab
aB
- *** Failers
- AB
+ *** Failers
+ AB
-/(a(?i)b)/D
+/(a(?i)b)/DZ
ab
aB
- *** Failers
- AB
-
-/ (?i)abc/IxD
+ *** Failers
+ AB
+
+/ (?i)abc/IxDZ
/#this is a comment
- (?i)abc/IxD
+ (?i)abc/IxDZ
-/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/D
+/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/DZ
-/\Q123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/D
+/\Q123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/DZ
-/\Q\E/D
+/\Q\E/DZ
\
-/\Q\Ex/D
+/\Q\Ex/DZ
-/ \Q\E/D
+/ \Q\E/DZ
-/a\Q\E/D
+/a\Q\E/DZ
abc
bca
- bac
+ bac
-/a\Q\Eb/D
+/a\Q\Eb/DZ
abc
-/\Q\Eabc/D
+/\Q\Eabc/DZ
-/x*+\w/D
+/x*+\w/DZ
*** Failers
xxxxx
-
-/x?+/D
-/x++/D
+/x?+/DZ
+
+/x++/DZ
-/x{1,3}+/D
+/x{1,3}+/DZ
-/(x)*+/D
+/(x)*+/DZ
/^(\w++|\s++)*$/I
now is the time for all good men to come to the aid of the party
*** Failers
this is not a line with only words and spaces!
-
+
/(\d++)(\w)/I
12345a
*** Failers
- 12345+
+ 12345+
/a++b/I
aaab
@@ -875,14 +873,14 @@
/([^()]++|\([^()]*\))+/I
((abc(ade)ufh()()x
-
-/\(([^()]++|\([^()]+\))+\)/I
+
+/\(([^()]++|\([^()]+\))+\)/I
(abc)
(abc(def)xyz)
*** Failers
- ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-/(abc){1,3}+/D
+/(abc){1,3}+/DZ
/a+?+/I
@@ -892,17 +890,17 @@
/a{2,3}?+b/IU
-/x(?U)a++b/D
+/x(?U)a++b/DZ
xaaaab
-/(?U)xa++b/D
+/(?U)xa++b/DZ
xaaaab
-/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/D
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/DZ
-/^x(?U)a+b/D
+/^x(?U)a+b/DZ
-/^x(?U)(a+)b/D
+/^x(?U)(a+)b/DZ
/[.x.]/I
@@ -926,30 +924,30 @@
/[[:space:]/I
-/[\s]/IDM
+/[\s]/IDZ
-/[[:space:]]/IDM
+/[[:space:]]/IDZ
-/[[:space:]abcde]/IDM
+/[[:space:]abcde]/IDZ
/< (?: (?(R) \d++ | [^<>]*+) | (?R)) * >/Ix
<>
<abcd>
<abc <123> hij>
<abc <def> hij>
- <abc<>def>
- <abc<>
+ <abc<>def>
+ <abc<>
*** Failers
<abc
-|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDZ
-|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDZ
/(.*)\d+\1/I
/(.*)\d+/I
-
+
/(.*)\d+\1/Is
/(.*)\d+/Is
@@ -958,7 +956,7 @@
/((.*))\d+\1/I
abc123bc
-
+
/a[b]/I
/(?=a).*/I
@@ -977,13 +975,13 @@
/()a/I
-/(?(1)ab|ac)/I
+/(?(1)ab|ac)(.)/I
-/(?(1)abz|acz)/I
+/(?(1)abz|acz)(.)/I
-/(?(1)abz)/I
+/(?(1)abz)(.)/I
-/(?(1)abz)123/I
+/(?(1)abz)(1)23/I
/(a)+/I
@@ -1007,9 +1005,9 @@
/^a/Im
abcde
- xy\nabc
- *** Failers
- xyabc
+ xy\nabc
+ *** Failers
+ xyabc
/c|abc/I
@@ -1019,24 +1017,24 @@
/abc(?C)def/I
abcdef
- 1234abcdef
+ 1234abcdef
*** Failers
abcxyz
- abcxyzf
+ abcxyzf
/abc(?C)de(?C1)f/I
123abcdef
-
-/(?C1)\dabc(?C2)def/I
+
+/(?C1)\dabc(?C2)def/I
1234abcdef
*** Failers
- abcdef
-
+ abcdef
+
/(?C255)ab/I
/(?C256)ab/I
-/(?Cab)xx/I
+/(?Cab)xx/I
/(?C12vr)x/I
@@ -1046,21 +1044,21 @@
/(abc)(?C)de(?C1)f/I
123abcdef
- 123abcdef\C+
- 123abcdef\C-
+ 123abcdef\C+
+ 123abcdef\C-
*** Failers
- 123abcdef\C!1
-
+ 123abcdef\C!1
+
/(?C0)(abc(?C1))*/I
abcabcabc
- abcabc\C!1!3
+ abcabc\C!1!3
*** Failers
- abcabcabc\C!1!3
+ abcabcabc\C!1!3
/(\d{3}(?C))*/I
123\C+
123456\C+
- 123456789\C+
+ 123456789\C+
/((xyz)(?C)p|(?C1)xyzabc)/I
xyzabc\C+
@@ -1070,20 +1068,20 @@
/(?=(abc))(?C)abcdef/I
abcdef\C+
-
+
/(?!(abc)(?C1)d)(?C2)abcxyz/I
- abcxyz\C+
+ abcxyz\C+
/(?<=(abc)(?C))xyz/I
abcxyz\C+
-
+
/a(b+)(c*)(?C1)/I
abbbbbccc\C*1
/a(b+?)(c*?)(?C1)/I
abbbbbccc\C*1
-
-/(?C)abc/I
+
+/(?C)abc/I
/(?C)^abc/I
@@ -1102,7 +1100,7 @@
xxab
xxxab
*** Failers
- xyab
+ xyab
/(ab|(bc|(de|(?1))))/I
@@ -1111,48 +1109,48 @@
/^([^()]|\((?1)*\))*$/I
abc
a(b)c
- a(b(c))d
+ a(b(c))d
*** Failers)
- a(b(c)d
+ a(b(c)d
/^>abc>([^()]|\((?1)*\))*<xyz<$/I
>abc>123<xyz<
>abc>1(2)3<xyz<
>abc>(1(2)3)<xyz<
-/(a(?1)b)/D
+/(a(?1)b)/DZ
-/(a(?1)+b)/D
+/(a(?1)+b)/DZ
/^\W*(?:((.)\W*(?1)\W*\2|)|((.)\W*(?3)\W*\4|\W*.\W*))\W*$/Ii
1221
Satan, oscillate my metallic sonatas!
A man, a plan, a canal: Panama!
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
*** Failers
- The quick brown fox
-
+ The quick brown fox
+
/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/I
12
(((2+2)*-3)-7)
-12
*** Failers
((2+2)*-3)-7)
-
+
/^(x(y|(?1){2})z)/I
xyz
- xxyzxyzz
+ xxyzxyzz
*** Failers
xxyzz
- xxyzxyzxyzz
+ xxyzxyzxyzz
/((< (?: (?(R) \d++ | [^<>]*+) | (?2)) * >))/Ix
<>
<abcd>
<abc <123> hij>
<abc <def> hij>
- <abc<>def>
- <abc<>
+ <abc<>def>
+ <abc<>
*** Failers
<abc
@@ -1166,32 +1164,32 @@
/^(a|b|c)=(?1)+/I
a=a
a=b
- a=bc
+ a=bc
/^(a|b|c)=((?1))+/I
a=a
a=b
- a=bc
+ a=bc
-/a(?P<name1>b|c)d(?P<longername2>e)/D
+/a(?P<name1>b|c)d(?P<longername2>e)/DZ
abde
- acde
+ acde
-/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/D
+/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/DZ
-/(?P<a>a)...(?P=a)bbb(?P>a)d/D
+/(?P<a>a)...(?P=a)bbb(?P>a)d/DZ
/^\W*(?:(?P<one>(?P<two>.)\W*(?P>one)\W*(?P=two)|)|(?P<three>(?P<four>.)\W*(?P>three)\W*(?P=four)|\W*.\W*))\W*$/Ii
1221
Satan, oscillate my metallic sonatas!
A man, a plan, a canal: Panama!
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
*** Failers
- The quick brown fox
-
+ The quick brown fox
+
/((?(R)a|b))\1(?1)?/I
bb
- bbaa
+ bbaa
/(.*)a/Is
@@ -1215,13 +1213,13 @@
/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\32/Is
-/(a)(bc)/IND
+/(a)(bc)/INDZ
abc
-/(?P<one>a)(bc)/IND
+/(?P<one>a)(bc)/INDZ
abc
-/(a)(?P<named>bc)/IND
+/(a)(?P<named>bc)/INDZ
/(a+)*zz/I
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzbbbbbb\M
@@ -1237,11 +1235,11 @@
abcdefgh
abcdefgh\C1\Gtwo
abcdefgh\Cone\Ctwo
- abcdefgh\Cthree
+ abcdefgh\Cthree
-/(?P<Tes>)(?P<Test>)/D
+/(?P<Tes>)(?P<Test>)/DZ
-/(?P<Test>)(?P<Tes>)/D
+/(?P<Test>)(?P<Tes>)/DZ
/(?P<Z>zz)(?P<A>aa)/I
zzaa\CZ
@@ -1254,47 +1252,47 @@
"\[((?P<elem>\d+)(,(?P>elem))*)\]"I
[10,20,30,5,5,4,4,2,43,23,4234]
*** Failers
- []
+ []
"\[((?P<elem>\d+)(,(?P>elem))*)?\]"I
[10,20,30,5,5,4,4,2,43,23,4234]
- []
+ []
-/(a(b(?2)c))?/D
+/(a(b(?2)c))?/DZ
-/(a(b(?2)c))*/D
+/(a(b(?2)c))*/DZ
-/(a(b(?2)c)){0,2}/D
+/(a(b(?2)c)){0,2}/DZ
-/[ab]{1}+/D
+/[ab]{1}+/DZ
/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/Ii
Baby Bjorn Active Carrier - With free SHIPPING!!
/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/IiS
Baby Bjorn Active Carrier - With free SHIPPING!!
-
-/a*.*b/ISD
-/(a|b)*.?c/ISD
+/a*.*b/ISDZ
-/abc(?C255)de(?C)f/D
+/(a|b)*.?c/ISDZ
-/abcde/ICD
+/abc(?C255)de(?C)f/DZ
+
+/abcde/ICDZ
abcde
- abcdfe
-
-/a*b/ICD
+ abcdfe
+
+/a*b/ICDZ
ab
aaaab
- aaaacb
+ aaaacb
-/a+b/ICD
+/a+b/ICDZ
ab
aaaab
- aaaacb
+ aaaacb
-/(abc|def)x/ICD
+/(abc|def)x/ICDZ
abcx
defx
abcdefzx
@@ -1302,43 +1300,43 @@
/(ab|cd){3,4}/IC
ababab
abcdabcd
- abcdcdcdcdcd
+ abcdcdcdcdcd
-/([ab]{,4}c|xy)/ICD
+/([ab]{,4}c|xy)/ICDZ
Note: that { does NOT introduce a quantifier
-/([ab]{1,4}c|xy){4,5}?123/ICD
+/([ab]{1,4}c|xy){4,5}?123/ICDZ
aacaacaacaacaac123
/\b.*/I
ab cd\>1
-
-/\b.*/Is
+
+/\b.*/Is
ab cd\>1
-
+
/(?!.bcd).*/I
- Xbcd12345
+ Xbcd12345
/abcde/I
ab\P
abc\P
abcd\P
- abcde\P
+ abcde\P
the quick brown abc\P
** Failers\P
the quick brown abxyz fox\P
-
+
"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"I
13/05/04\P
13/5/2004\P
- 02/05/09\P
+ 02/05/09\P
1\P
1/2\P
1/2/0\P
- 1/2/04\P
+ 1/2/04\P
0\P
02/\P
- 02/0\P
+ 02/0\P
02/1\P
** Failers\P
\P
@@ -1346,14 +1344,14 @@
33/4/04\P
3/13/04\P
0/1/2003\P
- 0/\P
- 02/0/\P
- 02/13\P
+ 0/\P
+ 02/0/\P
+ 02/13\P
/0{0,2}ABC/I
-
+
/\d{3,}ABC/I
-
+
/\d*ABC/I
/[abc]+DE/I
@@ -1364,7 +1362,7 @@
b\P
c\P
c12\P
- c123\P
+ c123\P
/^(?:\d){3,5}X/I
1\P
@@ -1373,17 +1371,17 @@
1234\P
1234X
12345\P
- 12345X
- *** Failers
- 1X
- 123456\P
+ 12345X
+ *** Failers
+ 1X
+ 123456\P
/abc/I>testsavedregex
<testsavedregex
abc
** Failers
bca
-
+
/abc/IF>testsavedregex
<testsavedregex
abc
@@ -1394,14 +1392,14 @@
<testsavedregex
abc
** Failers
- def
-
+ def
+
/(a|b)/ISF>testsavedregex
<testsavedregex
abc
** Failers
- def
-
+ def
+
~<(\w+)/?>(.)*</(\1)>~smgI
<!DOCTYPE seite SYSTEM "http://www.lco.lineas.de/xmlCms.dtd">\n<seite>\n<dokumenteninformation>\n<seitentitel>Partner der LCO</seitentitel>\n<sprache>de</sprache>\n<seitenbeschreibung>Partner der LINEAS Consulting\nGmbH</seitenbeschreibung>\n<schluesselworte>LINEAS Consulting GmbH Hamburg\nPartnerfirmen</schluesselworte>\n<revisit>30 days</revisit>\n<robots>index,follow</robots>\n<menueinformation>\n<aktiv>ja</aktiv>\n<menueposition>3</menueposition>\n<menuetext>Partner</menuetext>\n</menueinformation>\n<lastedited>\n<autor>LCO</autor>\n<firma>LINEAS Consulting</firma>\n<datum>15.10.2003</datum>\n</lastedited>\n</dokumenteninformation>\n<inhalt>\n\n<absatzueberschrift>Die Partnerfirmen der LINEAS Consulting\nGmbH</absatzueberschrift>\n\n<absatz><link ziel="http://www.ca.com/" zielfenster="_blank">\n<bild name="logo_ca.gif" rahmen="no"/></link> <link\nziel="http://www.ey.com/" zielfenster="_blank"><bild\nname="logo_euy.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><link ziel="http://www.cisco.de/" zielfenster="_blank">\n<bild name="logo_cisco.gif" rahmen="ja"/></link></absatz>\n\n<absatz><link ziel="http://www.atelion.de/"\nzielfenster="_blank"><bild\nname="logo_atelion.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><link ziel="http://www.line-information.de/"\nzielfenster="_blank">\n<bild name="logo_line_information.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><bild name="logo_aw.gif" rahmen="no"/></absatz>\n\n<absatz><link ziel="http://www.incognis.de/"\nzielfenster="_blank"><bild\nname="logo_incognis.gif" rahmen="no"/></link></absatz>\n\n<absatz><link ziel="http://www.addcraft.com/"\nzielfenster="_blank"><bild\nname="logo_addcraft.gif" rahmen="no"/></link></absatz>\n\n<absatz><link ziel="http://www.comendo.com/"\nzielfenster="_blank"><bild\nname="logo_comendo.gif" rahmen="no"/></link></absatz>\n\n</inhalt>\n</seite>
@@ -1409,34 +1407,34 @@
/line\nbreak/I
this is a line\nbreak
- line one\nthis is a line\nbreak in the second line
+ line one\nthis is a line\nbreak in the second line
/line\nbreak/If
this is a line\nbreak
- ** Failers
- line one\nthis is a line\nbreak in the second line
+ ** Failers
+ line one\nthis is a line\nbreak in the second line
/line\nbreak/Imf
this is a line\nbreak
- ** Failers
- line one\nthis is a line\nbreak in the second line
+ ** Failers
+ line one\nthis is a line\nbreak in the second line
/ab.cd/IP
ab-cd
- ab=cd
+ ab=cd
** Failers
ab\ncd
/ab.cd/IPs
ab-cd
- ab=cd
+ ab=cd
ab\ncd
/(?i)(?-i)AbCd/I
AbCd
** Failers
- abcd
-
+ abcd
+
/a{11111111111111111111}/I
/(){64294967295}/I
@@ -1460,35 +1458,35 @@
/[^()]*(?:\((?R)\)[^()]*)*/I
(this(and)that
- (this(and)that)
+ (this(and)that)
(this(and)that)stuff
/[^()]*(?:\((?>(?R))\)[^()]*)*/I
(this(and)that
- (this(and)that)
-
+ (this(and)that)
+
/[^()]*(?:\((?R)\))*[^()]*/I
(this(and)that
- (this(and)that)
+ (this(and)that)
/(?:\((?R)\))*[^()]*/I
(this(and)that
- (this(and)that)
- ((this))
+ (this(and)that)
+ ((this))
/(?:\((?R)\))|[^()]*/I
(this(and)that
- (this(and)that)
+ (this(and)that)
(this)
- ((this))
-
+ ((this))
+
/a(b)c/IPN
abc
-
+
/a(?P<name>b)c/IPN
- abc
-
-/\x{100}/I
+ abc
+
+/\x{100}/I
/\x{0000ff}/I
@@ -1496,44 +1494,44 @@
/^((?P<A>a1)|(?P<A>a2)b)/IJ
a1b\CA
- a2b\CA
+ a2b\CA
** Failers
- a1b\CZ\CA
-
+ a1b\CZ\CA
+
/^(?P<A>a)(?P<A>b)/IJ
ab\CA
-
+
/^(?P<A>a)(?P<A>b)|cd/IJ
ab\CA
- cd\CA
-
+ cd\CA
+
/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
- cdefgh\CA
-
+ cdefgh\CA
+
/^((?P<A>a1)|(?P<A>a2)b)/IJ
a1b\GA
- a2b\GA
+ a2b\GA
** Failers
- a1b\GZ\GA
-
+ a1b\GZ\GA
+
/^(?P<A>a)(?P<A>b)/IJ
ab\GA
-
+
/^(?P<A>a)(?P<A>b)|cd/IJ
ab\GA
- cd\GA
-
+ cd\GA
+
/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
- cdefgh\GA
-
+ cdefgh\GA
+
/(?J)^((?P<A>a1)|(?P<A>a2)b)/I
a1b\CA
- a2b\CA
-
+ a2b\CA
+
/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/I
/ In this next test, J is not set at the outer level; consequently it isn't
-set in the pattern's options; consequently pcre_get_named_substring() produces
+set in the pattern's options; consequently pcre_get_named_substring() produces
a random value. /Ix
/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<C>d)/I
@@ -1543,7 +1541,7 @@ a random value. /Ix
aabc
bc
** Failers
- abc
+ abc
/(?:(?(ZZ)a|b)(?P<ZZ>X))+/I
bXaX
@@ -1562,7 +1560,7 @@ a random value. /Ix
/(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
bXXaYYaY
- bXYaXXaX
+ bXYaXXaX
/()()()()()()()()()(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
bXXaYYaY
@@ -1571,7 +1569,7 @@ a random value. /Ix
/\s*,\s*/IS
\x0b,\x0b
- \x0c,\x0d
+ \x0c,\x0d
/^abc/Im
xyz\nabc
@@ -1579,51 +1577,51 @@ a random value. /Ix
xyz\r\nabc\<lf>
xyz\rabc\<cr>
xyz\r\nabc\<crlf>
- ** Failers
+ ** Failers
xyz\nabc\<cr>
xyz\r\nabc\<cr>
xyz\nabc\<crlf>
xyz\rabc\<crlf>
xyz\rabc\<lf>
-
+
/abc$/Im<lf>
xyzabc
- xyzabc\n
- xyzabc\npqr
- xyzabc\r\<cr>
- xyzabc\rpqr\<cr>
- xyzabc\r\n\<crlf>
- xyzabc\r\npqr\<crlf>
+ xyzabc\n
+ xyzabc\npqr
+ xyzabc\r\<cr>
+ xyzabc\rpqr\<cr>
+ xyzabc\r\n\<crlf>
+ xyzabc\r\npqr\<crlf>
** Failers
- xyzabc\r
- xyzabc\rpqr
- xyzabc\r\n
- xyzabc\r\npqr
-
+ xyzabc\r
+ xyzabc\rpqr
+ xyzabc\r\n
+ xyzabc\r\npqr
+
/^abc/Im<cr>
xyz\rabcdef
xyz\nabcdef\<lf>
- ** Failers
+ ** Failers
xyz\nabcdef
-
+
/^abc/Im<lf>
xyz\nabcdef
xyz\rabcdef\<cr>
- ** Failers
+ ** Failers
xyz\rabcdef
-
+
/^abc/Im<crlf>
xyz\r\nabcdef
xyz\rabcdef\<cr>
- ** Failers
+ ** Failers
xyz\rabcdef
-
+
/^abc/Im<bad>
/abc/I
xyz\rabc\<bad>
- abc
-
+ abc
+
/.*/I<lf>
abc\ndef
abc\rdef
@@ -1651,7 +1649,7 @@ a random value. /Ix
()()()()()()()()()()()()()()()()()()()()
()()()()()()()()()()()()()()()()()()()()
(.(.))/Ix
- XY\O400
+ XY\O400
/(a*b|(?i:c*(?-i)d))/IS
@@ -1667,18 +1665,18 @@ a random value. /Ix
/(d?|c)[ab]xyz/IS
-/^a*b\d/D
+/^a*b\d/DZ
-/^a*+b\d/D
+/^a*+b\d/DZ
-/^a*?b\d/D
+/^a*?b\d/DZ
-/^a+A\d/D
+/^a+A\d/DZ
aaaA5
** Failers
- aaaa5
+ aaaa5
-/^a*A\d/IiD
+/^a*A\d/IiDZ
aaaA5
aaaa5
@@ -1696,141 +1694,141 @@ a random value. /Ix
a
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- )))
-/Ix
+ )))
+/Ix
large nest
-/a*\d/B
+/a*\d/BZ
-/a*\D/B
+/a*\D/BZ
-/0*\d/B
+/0*\d/BZ
-/0*\D/B
+/0*\D/BZ
-/a*\s/B
+/a*\s/BZ
-/a*\S/B
+/a*\S/BZ
-/ *\s/B
+/ *\s/BZ
-/ *\S/B
+/ *\S/BZ
-/a*\w/B
+/a*\w/BZ
-/a*\W/B
+/a*\W/BZ
-/=*\w/B
+/=*\w/BZ
-/=*\W/B
+/=*\W/BZ
-/\d*a/B
+/\d*a/BZ
-/\d*2/B
+/\d*2/BZ
-/\d*\d/B
+/\d*\d/BZ
-/\d*\D/B
+/\d*\D/BZ
-/\d*\s/B
+/\d*\s/BZ
-/\d*\S/B
+/\d*\S/BZ
-/\d*\w/B
+/\d*\w/BZ
-/\d*\W/B
+/\d*\W/BZ
-/\D*a/B
+/\D*a/BZ
-/\D*2/B
+/\D*2/BZ
-/\D*\d/B
+/\D*\d/BZ
-/\D*\D/B
+/\D*\D/BZ
-/\D*\s/B
+/\D*\s/BZ
-/\D*\S/B
+/\D*\S/BZ
-/\D*\w/B
+/\D*\w/BZ
-/\D*\W/B
+/\D*\W/BZ
-/\s*a/B
+/\s*a/BZ
-/\s*2/B
+/\s*2/BZ
-/\s*\d/B
+/\s*\d/BZ
-/\s*\D/B
+/\s*\D/BZ
-/\s*\s/B
+/\s*\s/BZ
-/\s*\S/B
+/\s*\S/BZ
-/\s*\w/B
+/\s*\w/BZ
-/\s*\W/B
+/\s*\W/BZ
-/\S*a/B
+/\S*a/BZ
-/\S*2/B
+/\S*2/BZ
-/\S*\d/B
+/\S*\d/BZ
-/\S*\D/B
+/\S*\D/BZ
-/\S*\s/B
+/\S*\s/BZ
-/\S*\S/B
+/\S*\S/BZ
-/\S*\w/B
+/\S*\w/BZ
-/\S*\W/B
+/\S*\W/BZ
-/\w*a/B
+/\w*a/BZ
-/\w*2/B
+/\w*2/BZ
-/\w*\d/B
+/\w*\d/BZ
-/\w*\D/B
+/\w*\D/BZ
-/\w*\s/B
+/\w*\s/BZ
-/\w*\S/B
+/\w*\S/BZ
-/\w*\w/B
+/\w*\w/BZ
-/\w*\W/B
+/\w*\W/BZ
-/\W*a/B
+/\W*a/BZ
-/\W*2/B
+/\W*2/BZ
-/\W*\d/B
+/\W*\d/BZ
-/\W*\D/B
+/\W*\D/BZ
-/\W*\s/B
+/\W*\s/BZ
-/\W*\S/B
+/\W*\S/BZ
-/\W*\w/B
+/\W*\w/BZ
-/\W*\W/B
+/\W*\W/BZ
-/[^a]+a/B
+/[^a]+a/BZ
-/[^a]+a/Bi
+/[^a]+a/BZi
-/[^a]+A/Bi
+/[^a]+A/BZi
-/[^a]+b/B
+/[^a]+b/BZ
-/[^a]+\d/B
+/[^a]+\d/BZ
-/a*[^a]/B
+/a*[^a]/BZ
/(?P<abc>x)(?P<xyz>y)/I
xy\Cabc\Cxyz
@@ -1848,8 +1846,8 @@ a random value. /Ix
bXaX
bXbX
** Failers
- aXaX
- aXbX
+ aXaX
+ aXbX
/^(?P>abc)(?<abcd>xxx)/
@@ -1857,60 +1855,60 @@ a random value. /Ix
xx
xy
yy
- yx
+ yx
/^(?P>abc)(?P<abc>x|y)/
xx
xy
yy
- yx
+ yx
/^((?(abc)a|b)(?<abc>x|y))+/
bxay
- bxby
+ bxby
** Failers
- axby
+ axby
/^(((?P=abc)|X)(?<abc>x|y))+/
XxXxxx
XxXyyx
XxXyxx
** Failers
- x
+ x
/^(?1)(abc)/
abcabc
/^(?:(?:\1|X)(a|b))+/
Xaaa
- Xaba
+ Xaba
-/^[\E\Qa\E-\Qz\E]+/B
-
-/^[a\Q]bc\E]/B
-
-/^[a-\Q\E]/B
+/^[\E\Qa\E-\Qz\E]+/BZ
+
+/^[a\Q]bc\E]/BZ
-/^(?P>abc)[()](?<abc>)/B
+/^[a-\Q\E]/BZ
-/^((?(abc)y)[()](?P<abc>x))+/B
+/^(?P>abc)[()](?<abc>)/BZ
+
+/^((?(abc)y)[()](?P<abc>x))+/BZ
(xy)x
-
-/^(?P>abc)\Q()\E(?<abc>)/B
-/^(?P>abc)[a\Q(]\E(](?<abc>)/B
+/^(?P>abc)\Q()\E(?<abc>)/BZ
+
+/^(?P>abc)[a\Q(]\E(](?<abc>)/BZ
/^(?P>abc) # this is (a comment)
- (?<abc>)/Bx
+ (?<abc>)/BZx
/^\W*(?:(?<one>(?<two>.)\W*(?&one)\W*\k<two>|)|(?<three>(?<four>.)\W*(?&three)\W*\k'four'|\W*.\W*))\W*$/Ii
1221
Satan, oscillate my metallic sonatas!
A man, a plan, a canal: Panama!
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
*** Failers
- The quick brown fox
-
+ The quick brown fox
+
/(?=(\w+))\1:/I
abcd:
@@ -1921,28 +1919,28 @@ a random value. /Ix
a:aaxyz
ab:ababxyz
** Failers
- a:axyz
- ab:abxyz
+ a:axyz
+ ab:abxyz
/(?'abc'a|b)(?<abc>d|e)\k<abc>{2}/J
adaa
** Failers
addd
- adbb
+ adbb
/(?'abc'a|b)(?<abc>d|e)(?&abc){2}/J
bdaa
bdab
** Failers
- bddd
+ bddd
/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
abd
- ce
-
+ ce
+
/(?(<bc))/
-/(?(''))/
+/(?(''))/
/(?('R')stuff)/
@@ -1959,16 +1957,16 @@ a random value. /Ix
/^(?(DEFINE) (?<A> a) (?<B> b) ) (?&A) (?&B) /x
abcd
-
+
/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
(?(DEFINE)
(?<NAME_PAT>[a-z]+)
(?<ADDRESS_PAT>\d+)
)/x
metcalfe 33
-
+
/^(?(DEFINE) abc | xyz ) /x
-
+
/(?(DEFINE) abc) xyz/xI
/(?(DEFINE) abc){3} xyz/x
@@ -1979,12 +1977,15 @@ a random value. /Ix
/^a.b/<lf>
a\rb
- a\nb\<cr>
+ a\nb\<cr>
+ a\x85b\<anycrlf>
** Failers
a\nb
a\nb\<any>
- a\rb\<cr>
- a\rb\<any>
+ a\rb\<cr>
+ a\rb\<any>
+ a\x85b\<any>
+ a\rb\<anycrlf>
/^abc./mgx<any>
abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 \x{2028}abc8 \x{2029}abc9 JUNK
@@ -1996,55 +1997,55 @@ a random value. /Ix
/a/<any><crlf>
-/^a\Rb/
+/^a\Rb/<bsr_unicode>
a\nb
a\rb
a\r\nb
a\x0bb
a\x0cb
- a\x85b
+ a\x85b
** Failers
- a\n\rb
+ a\n\rb
-/^a\R*b/
+/^a\R*b/<bsr_unicode>
ab
a\nb
a\rb
a\r\nb
a\x0bb
a\x0cb
- a\x85b
- a\n\rb
- a\n\r\x85\x0cb
+ a\x85b
+ a\n\rb
+ a\n\r\x85\x0cb
-/^a\R+b/
+/^a\R+b/<bsr_unicode>
a\nb
a\rb
a\r\nb
a\x0bb
a\x0cb
- a\x85b
- a\n\rb
- a\n\r\x85\x0cb
+ a\x85b
+ a\n\rb
+ a\n\r\x85\x0cb
** Failers
- ab
-
-/^a\R{1,3}b/
+ ab
+
+/^a\R{1,3}b/<bsr_unicode>
a\nb
a\n\rb
a\n\r\x85b
- a\r\n\r\nb
- a\r\n\r\n\r\nb
+ a\r\n\r\nb
+ a\r\n\r\n\r\nb
a\n\r\n\rb
- a\n\n\r\nb
+ a\n\n\r\nb
** Failers
a\n\n\n\rb
a\r
-/^a[\R]b/
+/^a[\R]b/<bsr_unicode>
aRb
** Failers
- a\nb
+ a\nb
/(?&abc)X(?<abc>P)/I
abcPXP123
@@ -2058,7 +2059,7 @@ a random value. /Ix
10.0.0.0
** Failers
10.6
- 455.3.4.5
+ 455.3.4.5
/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
1.2.3.4
@@ -2066,12 +2067,12 @@ a random value. /Ix
10.0.0.0
** Failers
10.6
- 455.3.4.5
-
+ 455.3.4.5
+
/(?:a(?&abc)b)*(?<abc>x)/
123axbaxbaxbx456
123axbaxbaxb456
-
+
/(?:a(?&abc)b){1,5}(?<abc>x)/
123axbaxbaxbx456
@@ -2109,25 +2110,618 @@ a random value. /Ix
/.+foo/
afoo
- ** Failers
- \r\nfoo
- \nfoo
+ ** Failers
+ \r\nfoo
+ \nfoo
/.+foo/<crlf>
afoo
- \nfoo
- ** Failers
- \r\nfoo
+ \nfoo
+ ** Failers
+ \r\nfoo
/.+foo/<any>
afoo
- ** Failers
- \nfoo
- \r\nfoo
+ ** Failers
+ \nfoo
+ \r\nfoo
/.+foo/s
afoo
- \r\nfoo
- \nfoo
+ \r\nfoo
+ \nfoo
+
+/^$/mg<any>
+ abc\r\rxyz
+ abc\n\rxyz
+ ** Failers
+ abc\r\nxyz
+
+/(?m)^$/<any>g+
+ abc\r\n\r\n
+
+/(?m)^$|^\r\n/<any>g+
+ abc\r\n\r\n
+
+/(?m)$/<any>g+
+ abc\r\n\r\n
+
+/abc.$/mgx<anycrlf>
+ abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+
+/^X/m
+ XABC
+ ** Failers
+ XABC\B
+
+/(ab|c)(?-1)/BZ
+ abc
+
+/xy(?+1)(abc)/BZ
+ xyabcabc
+ ** Failers
+ xyabc
+
+/x(?-0)y/
+
+/x(?-1)y/
+
+/x(?+0)y/
+
+/x(?+1)y/
+
+/^(abc)?(?(-1)X|Y)/BZ
+ abcX
+ Y
+ ** Failers
+ abcY
+
+/^((?(+1)X|Y)(abc))+/BZ
+ YabcXabc
+ YabcXabcXabc
+ ** Failers
+ XabcXabc
+
+/(?(-1)a)/BZ
+
+/((?(-1)a))/BZ
+
+/((?(-2)a))/BZ
+
+/^(?(+1)X|Y)(.)/BZ
+ Y!
+
+/(foo)\Kbar/
+ foobar
+
+/(foo)(\Kbar|baz)/
+ foobar
+ foobaz
+
+/(foo\Kbar)baz/
+ foobarbaz
+
+/(?<A>tom|bon)-\k{A}/
+ tom-tom
+ bon-bon
+ ** Failers
+ tom-bon
+
+/(?<A>tom|bon)-\g{A}/
+ tom-tom
+ bon-bon
+
+/\g{A/
+
+/(?|(abc)|(xyz))/BZ
+ >abc<
+ >xyz<
+
+/(x)(?|(abc)|(xyz))(x)/BZ
+ xabcx
+ xxyzx
+
+/(x)(?|(abc)(pqr)|(xyz))(x)/BZ
+ xabcpqrx
+ xxyzx
+
+/(?|(abc)|(xyz))\1/
+ abcabc
+ xyzxyz
+ ** Failers
+ abcxyz
+ xyzabc
+
+/(?|(abc)|(xyz))(?1)/
+ abcabc
+ xyzabc
+ ** Failers
+ xyzxyz
+
+/\H\h\V\v/
+ X X\x0a
+ X\x09X\x0b
+ ** Failers
+ \xa0 X\x0a
+
+/\H*\h+\V?\v{3,4}/
+ \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\xa0\x0a\x0b\x0c
+ ** Failers
+ \x09\x20\xa0\x0a\x0b
+
+/\H{3,4}/
+ XY ABCDE
+ XY PQR ST
+
+/.\h{3,4}./
+ XY AB PQRS
+
+/\h*X\h?\H+Y\H?Z/
+ >XNNNYZ
+ > X NYQZ
+ ** Failers
+ >XYZ
+ > X NY Z
+
+/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
+ >XY\x0aZ\x0aA\x0bNN\x0c
+ >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+
+/[\h]/BZ
+ >\x09<
+
+/[\h]+/BZ
+ >\x09\x20\xa0<
+
+/[\v]/BZ
+
+/[\H]/BZ
+
+/[^\h]/BZ
+
+/[\V]/BZ
+
+/[\x0a\V]/BZ
+
+/\H++X/BZ
+ ** Failers
+ XXXX
+
+/\H+\hY/BZ
+ XXXX Y
+
+/\H+ Y/BZ
+
+/\h+A/BZ
+
+/\v*B/BZ
+
+/\V+\x0a/BZ
+
+/A+\h/BZ
+
+/ *\H/BZ
+
+/A*\v/BZ
+
+/\x0b*\V/BZ
+
+/\d+\h/BZ
+
+/\d*\v/BZ
+
+/S+\h\S+\v/BZ
+
+/\w{3,}\h\w+\v/BZ
+
+/\h+\d\h+\w\h+\S\h+\H/BZ
+
+/\v+\d\v+\w\v+\S\v+\V/BZ
+
+/\H+\h\H+\d/BZ
+
+/\V+\v\V+\w/BZ
+
+/\( (?: [^()]* | (?R) )* \)/x
+(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(00)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)
+
+/[\E]AAA/
+
+/[\Q\E]AAA/
+
+/[^\E]AAA/
+
+/[^\Q\E]AAA/
+
+/[\E^]AAA/
+
+/[\Q\E^]AAA/
+
+/A(*PRUNE)B(*SKIP)C(*THEN)D(*COMMIT)E(*F)F(*FAIL)G(?!)H(*ACCEPT)I/BZ
+
+/^a+(*FAIL)/
+ aaaaaa
+
+/a+b?c+(*FAIL)/
+ aaabccc
+
+/a+b?(*PRUNE)c+(*FAIL)/
+ aaabccc
+
+/a+b?(*COMMIT)c+(*FAIL)/
+ aaabccc
+
+/a+b?(*SKIP)c+(*FAIL)/
+ aaabcccaaabccc
+
+/^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
+ aaaxxxxxx
+ aaa++++++
+ bbbxxxxx
+ bbb+++++
+ cccxxxx
+ ccc++++
+ dddddddd
+
+/^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
+ aaaxxxxxx
+ aaa++++++
+ bbbxxxxx
+ bbb+++++
+ cccxxxx
+ ccc++++
+ dddddddd
+
+/a+b?(*THEN)c+(*FAIL)/
+ aaabccc
+
+/(A (A|B(*ACCEPT)|C) D)(E)/x
+ ABX
+ AADE
+ ACDE
+ ** Failers
+ AD
+
+/^a+(*FAIL)/C
+ aaaaaa
+
+/a+b?c+(*FAIL)/C
+ aaabccc
+
+/a+b?(*PRUNE)c+(*FAIL)/C
+ aaabccc
+
+/a+b?(*COMMIT)c+(*FAIL)/C
+ aaabccc
+
+/a+b?(*SKIP)c+(*FAIL)/C
+ aaabcccaaabccc
+
+/a+b?(*THEN)c+(*FAIL)/C
+ aaabccc
+
+/a(*PRUNE:XXX)b/
+
+/a(*MARK)b/
+
+/(?i:A{1,}\6666666666)/
+
+/\g6666666666/
+
+/[\g6666666666]/
+
+/(?1)\c[/
+
+/.+A/<crlf>
+ \r\nA
+
+/\nA/<crlf>
+ \r\nA
+
+/[\r\n]A/<crlf>
+ \r\nA
+
+/(\r|\n)A/<crlf>
+ \r\nA
+
+/a(*CR)b/
+
+/(*CR)a.b/
+ a\nb
+ ** Failers
+ a\rb
+
+/(*CR)a.b/<lf>
+ a\nb
+ ** Failers
+ a\rb
+
+/(*LF)a.b/<CRLF>
+ a\rb
+ ** Failers
+ a\nb
+
+/(*CRLF)a.b/
+ a\rb
+ a\nb
+ ** Failers
+ a\r\nb
+
+/(*ANYCRLF)a.b/<CR>
+ ** Failers
+ a\rb
+ a\nb
+ a\r\nb
+
+/(*ANY)a.b/<cr>
+ ** Failers
+ a\rb
+ a\nb
+ a\r\nb
+ a\x85b
+
+/a\Rb/I<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x85b
+ a\x0bb
+
+/a\Rb/I<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x85b
+ a\x0bb
+ ** Failers
+ a\x85b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R?b/I<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x85b
+ a\x0bb
+
+/a\R?b/I<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x85b
+ a\x0bb
+ ** Failers
+ a\x85b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R{2,4}b/I<bsr_anycrlf>
+ a\r\n\nb
+ a\n\r\rb
+ a\r\n\r\n\r\n\r\nb
+ ** Failers
+ a\x85\85b
+ a\x0b\0bb
+
+/a\R{2,4}b/I<bsr_unicode>
+ a\r\rb
+ a\n\n\nb
+ a\r\n\n\r\rb
+ a\x85\85b
+ a\x0b\0bb
+ ** Failers
+ a\r\r\r\r\rb
+ a\x85\85b\<bsr_anycrlf>
+ a\x0b\0bb\<bsr_anycrlf>
+
+/(*BSR_ANYCRLF)a\Rb/I
+ a\nb
+ a\rb
+
+/(*BSR_UNICODE)a\Rb/I
+ a\x85b
+
+/(*BSR_ANYCRLF)(*CRLF)a\Rb/I
+ a\nb
+ a\rb
+
+/(*CRLF)(*BSR_UNICODE)a\Rb/I
+ a\x85b
+
+/(*CRLF)(*BSR_ANYCRLF)(*CR)ab/I
+
+/(?<a>)(?&)/
+
+/(?<abc>)(?&a)/
+
+/(?<a>)(?&aaaaaaaaaaaaaaaaaaaaaaa)/
+
+/(?+-a)/
+
+/(?-+a)/
+
+/(?(-1))/
+
+/(?(+10))/
+
+/(?(10))/
+
+/(?(+2))()()/
+
+/(?(2))()()/
+
+/\k''/
+
+/\k<>/
+
+/\k{}/
+
+/(?P=)/
+
+/(?P>)/
+
+/(?!\w)(?R)/
+
+/(?=\w)(?R)/
+
+/(?<!\w)(?R)/
+
+/(?<=\w)(?R)/
+
+/[[:foo:]]/
+
+/[[:1234:]]/
+
+/[[:f\oo:]]/
+
+/[[: :]]/
+
+/[[:...:]]/
+
+/[[:l\ower:]]/
+
+/[[:abc\:]]/
+
+/[abc[:x\]pqr:]]/
+
+/[[:a\dz:]]/
+
+/^(?<name>a|b\g<name>c)/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/^(?<name>a|b\g'name'c)/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/^(a|b\g<1>c)/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/^(a|b\g'1'c)/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/^(a|b\g'-1'c)/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/(^(a|b\g<-1>c))/
+ aaaa
+ bacxxx
+ bbaccxxx
+ bbbacccxx
+
+/(^(a|b\g<-1'c))/
+
+/(^(a|b\g{-1}))/
+ bacxxx
+
+/(?-i:\g<name>)(?i:(?<name>a))/
+ XaaX
+ XAAX
+
+/(?i:\g<name>)(?-i:(?<name>a))/
+ XaaX
+ ** Failers
+ XAAX
+
+/(?-i:\g<+1>)(?i:(a))/
+ XaaX
+ XAAX
+
+/(?=(?<regex>(?#simplesyntax)\$(?<name>[a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}]*)(?:\[(?<index>[a-zA-Z0-9_\x{7f}-\x{ff}]+|\$\g<name>)\]|->\g<name>(\(.*?\))?)?|(?#simple syntax withbraces)\$\{(?:\g<name>(?<indices>\[(?:\g<index>|'(?:\\.|[^'\\])*'|"(?:\g<regex>|\\.|[^"\\])*")\])?|\g<complex>|\$\{\g<complex>\})\}|(?#complexsyntax)\{(?<complex>\$(?<segment>\g<name>(\g<indices>*|\(.*?\))?)(?:->\g<segment>)*|\$\g<complex>|\$\{\g<complex>\})\}))\{/
+
+/(?<n>a|b|c)\g<n>*/
+ abc
+ accccbbb
+
+/^(?+1)(?<a>x|y){0}z/
+ xzxx
+ yzyy
+ ** Failers
+ xxz
+
+/(\3)(\1)(a)/
+ cat
+
+/(\3)(\1)(a)/<JS>
+ cat
+
+/TA]/
+ The ACTA] comes
+
+/TA]/<JS>
+ The ACTA] comes
+
+/(?2)[]a()b](abc)/
+ abcbabc
+
+/(?2)[^]a()b](abc)/
+ abcbabc
+
+/(?1)[]a()b](abc)/
+ abcbabc
+ ** Failers
+ abcXabc
+
+/(?1)[^]a()b](abc)/
+ abcXabc
+ ** Failers
+ abcbabc
+
+/(?2)[]a()b](abc)(xyz)/
+ xyzbabcxyz
+
+/(?&N)[]a(?<N>)](?<M>abc)/
+ abc<abc
+
+/(?&N)[]a(?<N>)](abc)/
+ abc<abc
+
+/a[]b/
+
+/a[^]b/
+
+/a[]b/<JS>
+ ** Failers
+ ab
+
+/a[]+b/<JS>
+ ** Failers
+ ab
+
+/a[]*+b/<JS>
+ ** Failers
+ ab
+
+/a[^]b/<JS>
+ aXb
+ a\nb
+ ** Failers
+ ab
+
+/a[^]+b/<JS>
+ aXb
+ a\nX\nXb
+ ** Failers
+ ab
+
+/a(?!)+b/
+
+/a(*FAIL)+b/
/ End of testinput2 /
diff --git a/ext/pcre/pcrelib/testdata/testinput3 b/ext/pcre/pcrelib/testdata/testinput3
index e6ac826f77..1376c213b4 100644
--- a/ext/pcre/pcrelib/testdata/testinput3
+++ b/ext/pcre/pcrelib/testdata/testinput3
@@ -86,6 +86,6 @@
>>>\xaa<<<
>>>\xba<<<
-/[[:alpha:]][[:lower:]][[:upper:]]/DLfr_FR
+/[[:alpha:]][[:lower:]][[:upper:]]/DZLfr_FR
/ End of testinput3 /
diff --git a/ext/pcre/pcrelib/testdata/testinput4 b/ext/pcre/pcrelib/testdata/testinput4
index 0fb850bffc..c98c085205 100644
--- a/ext/pcre/pcrelib/testdata/testinput4
+++ b/ext/pcre/pcrelib/testdata/testinput4
@@ -523,4 +523,90 @@
/a*\x{100}*\w/8
a
+/\S\S/8g
+ A\x{a3}BC
+
+/\S{2}/8g
+ A\x{a3}BC
+
+/\W\W/8g
+ +\x{a3}==
+
+/\W{2}/8g
+ +\x{a3}==
+
+/\S/8g
+ \x{442}\x{435}\x{441}\x{442}
+
+/[\S]/8g
+ \x{442}\x{435}\x{441}\x{442}
+
+/\D/8g
+ \x{442}\x{435}\x{441}\x{442}
+
+/[\D]/8g
+ \x{442}\x{435}\x{441}\x{442}
+
+/\W/8g
+ \x{2442}\x{2435}\x{2441}\x{2442}
+
+/[\W]/8g
+ \x{2442}\x{2435}\x{2441}\x{2442}
+
+/[\S\s]*/8
+ abc\n\r\x{442}\x{435}\x{441}\x{442}xyz
+
+/[\x{41f}\S]/8g
+ \x{442}\x{435}\x{441}\x{442}
+
+/.[^\S]./8g
+ abc def\x{442}\x{443}xyz\npqr
+
+/.[^\S\n]./8g
+ abc def\x{442}\x{443}xyz\npqr
+
+/[[:^alnum:]]/8g
+ +\x{2442}
+
+/[[:^alpha:]]/8g
+ +\x{2442}
+
+/[[:^ascii:]]/8g
+ A\x{442}
+
+/[[:^blank:]]/8g
+ A\x{442}
+
+/[[:^cntrl:]]/8g
+ A\x{442}
+
+/[[:^digit:]]/8g
+ A\x{442}
+
+/[[:^graph:]]/8g
+ \x19\x{e01ff}
+
+/[[:^lower:]]/8g
+ A\x{422}
+
+/[[:^print:]]/8g
+ \x{19}\x{e01ff}
+
+/[[:^punct:]]/8g
+ A\x{442}
+
+/[[:^space:]]/8g
+ A\x{442}
+
+/[[:^upper:]]/8g
+ a\x{442}
+
+/[[:^word:]]/8g
+ +\x{2442}
+
+/[[:^xdigit:]]/8g
+ M\x{442}
+
+/[^ABCDEFGHIJKLMNOPQRSTUVWXYZÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃÞĀĂĄĆĈĊČĎÄĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIJĴĶĹĻĽĿÅŃŅŇŊŌŎÅŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽÆƂƄƆƇƉƊƋƎÆÆƑƓƔƖƗƘƜÆƟƠƢƤƦƧƩƬƮƯƱƲƳƵƷƸƼDŽLJNJÇÇǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮDZǴǶǷǸǺǼǾȀȂȄȆȈȊȌȎÈȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾÉΆΈΉΊΌΎÎΑΒΓΔΕΖΗΘΙΚΛΜÎΞΟΠΡΣΤΥΦΧΨΩΪΫϒϓϔϘϚϜϞϠϢϤϦϨϪϬϮϴϷϹϺϽϾϿЀÐЂЃЄЅІЇЈЉЊЋЌÐÐŽÐÐБВГДЕЖЗИЙКЛМÐОПРСТУФХЦЧШЩЪЫЬЭЮЯѠѢѤѦѨѪѬѮѰѲѴѶѸѺѼѾҀҊҌҎÒҒҔҖҘҚҜҞҠҢҤҦҨҪҬҮҰҲҴҶҸҺҼҾӀÓÓƒÓ…Ó‡Ó‰Ó‹ÓÓӒӔӖӘӚӜӞӠӢӤӦӨӪӬӮӰӲӴӶӸԀԂԄԆԈԊԌԎԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀÕÕ‚ÕƒÕ„Õ…Õ†Õ‡ÕˆÕ‰ÕŠÕ‹ÕŒÕÕŽÕÕՑՒՓՔՕՖႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀáƒáƒ‚ჃჄჅḀḂḄḆḈḊḌḎá¸á¸’ḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎá¹á¹’ṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎáºáº’ẔẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎá»á»’ỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸἈἉἊἋἌá¼á¼Žá¼á¼˜á¼™á¼šá¼›á¼œá¼á¼¨á¼©á¼ªá¼«á¼¬á¼­á¼®á¼¯á¼¸á¼¹á¼ºá¼»á¼¼á¼½á¼¾á¼¿á½ˆá½‰á½Šá½‹á½Œá½á½™á½›á½á½Ÿá½¨á½©á½ªá½«á½¬á½­á½®á½¯á¾¸á¾¹á¾ºá¾»á¿ˆá¿‰á¿Šá¿‹á¿˜á¿™á¿šá¿›á¿¨á¿©á¿ªá¿«á¿¬á¿¸á¿¹á¿ºá¿»abcdefghijklmnopqrstuvwxyzªµºßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÄăąćĉċÄÄđēĕėęěÄğġģĥħĩīĭįıijĵķĸĺļľŀłńņňʼnŋÅÅőœŕŗřśÅşšţťŧũūŭůűųŵŷźżžſƀƃƅƈƌƃƕƙƚƛƞơƣƥƨƪƫƭưƴƶƹƺƽƾƿdžljnjǎÇǒǔǖǘǚǜÇǟǡǣǥǧǩǫǭǯǰdzǵǹǻǽǿÈȃȅȇȉȋÈÈȑȓȕȗșțÈȟȡȣȥȧȩȫȭȯȱȳȴȵȶȷȸȹȼȿɀÉɑɒɓɔɕɖɗɘəɚɛɜÉɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀÊʂʃʄʅʆʇʈʉʊʋʌÊÊŽÊÊʑʒʓʔʕʖʗʘʙʚʛʜÊʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯÎάέήίΰαβγδεζηθικλμνξοπÏςστυφχψωϊϋόÏÏŽÏϑϕϖϗϙϛÏϟϡϣϥϧϩϫϭϯϰϱϲϳϵϸϻϼабвгдежзийклмнопрÑтуфхцчшщъыьÑÑŽÑÑёђѓєѕіїјљњћќÑўџѡѣѥѧѩѫѭѯѱѳѵѷѹѻѽѿÒÒ‹ÒÒÒ‘Ò“Ò•Ò—Ò™Ò›ÒҟҡңҥҧҩҫҭүұҳҵҷҹһҽҿӂӄӆӈӊӌӎӑӓӕӗәӛÓÓŸÓ¡Ó£Ó¥Ó§Ó©Ó«Ó­Ó¯Ó±Ó³ÓµÓ·Ó¹ÔÔƒÔ…Ô‡Ô‰Ô‹ÔÔÕ¡Õ¢Õ£Õ¤Õ¥Õ¦Õ§Õ¨Õ©ÕªÕ«Õ¬Õ­Õ®Õ¯Õ°Õ±Õ²Õ³Õ´ÕµÕ¶Õ·Õ¸Õ¹ÕºÕ»Õ¼Õ½Õ¾Õ¿Ö€Öւփքօֆևᴀá´á´‚ᴃᴄᴅᴆᴇᴈᴉᴊᴋᴌá´á´Žá´á´á´‘ᴒᴓᴔᴕᴖᴗᴘᴙᴚᴛᴜá´á´žá´Ÿá´ á´¡á´¢á´£á´¤á´¥á´¦á´§á´¨á´©á´ªá´«áµ¢áµ£áµ¤áµ¥áµ¦áµ§áµ¨áµ©áµªáµ«áµ¬áµ­áµ®áµ¯áµ°áµ±áµ²áµ³áµ´áµµáµ¶áµ·áµ¹áµºáµ»áµ¼áµ½áµ¾áµ¿á¶€á¶á¶‚ᶃᶄᶅᶆᶇᶈᶉᶊᶋᶌá¶á¶Žá¶á¶á¶‘ᶒᶓᶔᶕᶖᶗᶘᶙᶚá¸á¸ƒá¸…ḇḉḋá¸á¸á¸‘ḓḕḗḙḛá¸á¸Ÿá¸¡á¸£á¸¥á¸§á¸©á¸«á¸­á¸¯á¸±á¸³á¸µá¸·á¸¹á¸»á¸½á¸¿á¹á¹ƒá¹…ṇṉṋá¹á¹á¹‘ṓṕṗṙṛá¹á¹Ÿá¹¡á¹£á¹¥á¹§á¹©á¹«á¹­á¹¯á¹±á¹³á¹µá¹·á¹¹á¹»á¹½á¹¿áºáºƒáº…ẇẉẋáºáºáº‘ẓẕẖẗẘẙẚẛạảấầẩẫậắằẳẵặẹẻẽếá»á»ƒá»…ệỉịá»á»á»‘ồổỗộớá»á»Ÿá»¡á»£á»¥á»§á»©á»«á»­á»¯á»±á»³á»µá»·á»¹á¼€á¼á¼‚ἃἄἅἆἇá¼á¼‘ἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀá½á½‚ὃὄὅá½á½‘ὒὓὔὕὖὗὠὡὢὣὤὥὦὧὰάὲέὴήὶίὸόὺύὼώᾀá¾á¾‚ᾃᾄᾅᾆᾇá¾á¾‘ᾒᾓᾔᾕᾖᾗᾠᾡᾢᾣᾤᾥᾦᾧᾰᾱᾲᾳᾴᾶᾷιῂῃῄῆῇá¿á¿‘ῒΐῖῗῠῡῢΰῤῥῦῧῲῳῴῶῷâ²â²ƒâ²…ⲇⲉⲋâ²â²â²‘ⲓⲕⲗⲙⲛâ²â²Ÿâ²¡â²£â²¥â²§â²©â²«â²­â²¯â²±â²³â²µâ²·â²¹â²»â²½â²¿â³â³ƒâ³…ⳇⳉⳋâ³â³â³‘ⳓⳕⳗⳙⳛâ³â³Ÿâ³¡â³£â³¤â´€â´â´‚ⴃⴄⴅⴆⴇⴈⴉⴊⴋⴌâ´â´Žâ´â´â´‘ⴒⴓⴔⴕⴖⴗⴘⴙⴚⴛⴜâ´â´žâ´Ÿâ´ â´¡â´¢â´£â´¤â´¥ï¬€ï¬ï¬‚ffifflſtstﬓﬔﬕﬖﬗ\d-_^]/8
+
/ End of testinput4 /
diff --git a/ext/pcre/pcrelib/testdata/testinput5 b/ext/pcre/pcrelib/testdata/testinput5
index 85d3ce63db..8a8e499c1d 100644
--- a/ext/pcre/pcrelib/testdata/testinput5
+++ b/ext/pcre/pcrelib/testdata/testinput5
@@ -1,20 +1,20 @@
-/\x{100}/8DM
+/\x{100}/8DZ
-/\x{1000}/8DM
+/\x{1000}/8DZ
-/\x{10000}/8DM
+/\x{10000}/8DZ
-/\x{100000}/8DM
+/\x{100000}/8DZ
-/\x{1000000}/8DM
+/\x{1000000}/8DZ
-/\x{4000000}/8DM
+/\x{4000000}/8DZ
-/\x{7fffFFFF}/8DM
+/\x{7fffFFFF}/8DZ
-/[\x{ff}]/8DM
+/[\x{ff}]/8DZ
-/[\x{100}]/8DM
+/[\x{100}]/8DZ
/\x{ffffffff}/8
@@ -23,39 +23,39 @@
/^\x{100}a\x{1234}/8
\x{100}a\x{1234}bcd
-/\x80/8D
+/\x80/8DZ
-/\xff/8D
+/\xff/8DZ
-/\x{0041}\x{2262}\x{0391}\x{002e}/D8
+/\x{0041}\x{2262}\x{0391}\x{002e}/DZ8
\x{0041}\x{2262}\x{0391}\x{002e}
-/\x{D55c}\x{ad6d}\x{C5B4}/D8
+/\x{D55c}\x{ad6d}\x{C5B4}/DZ8
\x{D55c}\x{ad6d}\x{C5B4}
-/\x{65e5}\x{672c}\x{8a9e}/D8
+/\x{65e5}\x{672c}\x{8a9e}/DZ8
\x{65e5}\x{672c}\x{8a9e}
-/\x{80}/D8
+/\x{80}/DZ8
-/\x{084}/D8
+/\x{084}/DZ8
-/\x{104}/D8
+/\x{104}/DZ8
-/\x{861}/D8
+/\x{861}/DZ8
-/\x{212ab}/D8
+/\x{212ab}/DZ8
-/.{3,5}X/D8
+/.{3,5}X/DZ8
\x{212ab}\x{212ab}\x{212ab}\x{861}X
-/.{3,5}?/D8
+/.{3,5}?/DZ8
\x{212ab}\x{212ab}\x{212ab}\x{861}
-/-- These tests are here rather than in testinput4 because Perl 5.6 has --/
-/-- some problems with UTF-8 support, in the area of \x{..} where the --/
-/-- value is < 255. It grumbles about invalid UTF-8 strings. --/
+/-- These tests are here rather than in testinput4 because Perl 5.6 has some
+problems with UTF-8 support, in the area of \x{..} where the value is < 255.
+It grumbles about invalid UTF-8 strings. --/
/^[a\x{c0}]b/8
\x{c0}b
@@ -80,29 +80,29 @@
/(?<=\C)X/8
Should produce an error diagnostic
-/-- This one is here not because it's different to Perl, but because the --/
-/-- way the captured single-byte is displayed. (In Perl it becomes a --/
-/-- character, and you can't tell the difference.) --/
+/-- This one is here not because it's different to Perl, but because the way
+the captured single-byte is displayed. (In Perl it becomes a character, and you
+can't tell the difference.) --/
/X(\C)(.*)/8
X\x{1234}
X\nabc
-/^[ab]/8D
+/^[ab]/8DZ
bar
*** Failers
c
\x{ff}
\x{100}
-/^[^ab]/8D
+/^[^ab]/8DZ
c
\x{ff}
\x{100}
*** Failers
aaa
-/[^ab\xC0-\xF0]/8SD
+/[^ab\xC0-\xF0]/8SDZ
\x{f1}
\x{bf}
\x{100}
@@ -111,16 +111,16 @@
\x{c0}
\x{f0}
-/Ä€{3,4}/8SD
+/Ä€{3,4}/8SDZ
\x{100}\x{100}\x{100}\x{100\x{100}
-/(\x{100}+|x)/8SD
+/(\x{100}+|x)/8SDZ
-/(\x{100}*a|x)/8SD
+/(\x{100}*a|x)/8SDZ
-/(\x{100}{0,2}a|x)/8SD
+/(\x{100}{0,2}a|x)/8SDZ
-/(\x{100}{1,2}a|x)/8SD
+/(\x{100}{1,2}a|x)/8SDZ
/\x{100}*(\d+|"(?1)")/8
1234
@@ -132,34 +132,34 @@
*** Failers
\x{100}\x{100}abcd
-/\x{100}/8D
+/\x{100}/8DZ
-/\x{100}*/8D
+/\x{100}*/8DZ
-/a\x{100}*/8D
+/a\x{100}*/8DZ
-/ab\x{100}*/8D
+/ab\x{100}*/8DZ
-/a\x{100}\x{101}*/8D
+/a\x{100}\x{101}*/8DZ
-/a\x{100}\x{101}+/8D
+/a\x{100}\x{101}+/8DZ
-/\x{100}*A/8D
+/\x{100}*A/8DZ
A
-/\x{100}*\d(?R)/8D
+/\x{100}*\d(?R)/8DZ
-/[^\x{c4}]/D
+/[^\x{c4}]/DZ
-/[^\x{c4}]/8D
+/[^\x{c4}]/8DZ
-/[\x{100}]/8DM
+/[\x{100}]/8DZ
\x{100}
Z\x{100}
\x{100}Z
*** Failers
-/[Z\x{100}]/8DM
+/[Z\x{100}]/8DZ
Z\x{100}
\x{100}
\x{100}Z
@@ -174,21 +174,21 @@
\x{105}
\x{ff}
-/[z-\x{100}]/8D
+/[z-\x{100}]/8DZ
-/[z\Qa-d]Ä€\E]/8D
+/[z\Qa-d]Ä€\E]/8DZ
\x{100}
Ä€
-/[\xFF]/D
+/[\xFF]/DZ
>\xff<
-/[\xff]/D8
+/[\xff]/DZ8
>\x{ff}<
-/[^\xFF]/D
+/[^\xFF]/DZ
-/[^\xff]/8D
+/[^\xff]/8DZ
/[Ä-Ü]/8
Ö # Matches without Study
@@ -212,7 +212,7 @@
/ÃÃÃxxx/8
-/ÃÃÃxxx/8?D
+/ÃÃÃxxx/8?DZ
/abc/8
Ã]
@@ -238,20 +238,24 @@
\xf9\x87\x80\x80\x80
\xfc\x84\x80\x80\x80\x80
\xfd\x83\x80\x80\x80\x80
+ \?\xf8\x88\x80\x80\x80
+ \?\xf9\x87\x80\x80\x80
+ \?\xfc\x84\x80\x80\x80\x80
+ \?\xfd\x83\x80\x80\x80\x80
-/\x{100}abc(xyz(?1))/8D
+/\x{100}abc(xyz(?1))/8DZ
-/[^\x{100}]abc(xyz(?1))/8D
+/[^\x{100}]abc(xyz(?1))/8DZ
-/[ab\x{100}]abc(xyz(?1))/8D
+/[ab\x{100}]abc(xyz(?1))/8DZ
-/(\x{100}(b(?2)c))?/D8
+/(\x{100}(b(?2)c))?/DZ8
-/(\x{100}(b(?2)c)){0,2}/D8
+/(\x{100}(b(?2)c)){0,2}/DZ8
-/(\x{100}(b(?1)c))?/D8
+/(\x{100}(b(?1)c))?/DZ8
-/(\x{100}(b(?1)c)){0,2}/D8
+/(\x{100}(b(?1)c)){0,2}/DZ8
/\W/8
A.B
@@ -263,7 +267,7 @@
/a\x{1234}b/P8
a\x{1234}b
-/^\ሴ/8D
+/^\ሴ/8DZ
/\777/I
@@ -271,23 +275,23 @@
\x{1ff}
\777
-/\x{100}*\d/8D
+/\x{100}*\d/8DZ
-/\x{100}*\s/8D
+/\x{100}*\s/8DZ
-/\x{100}*\w/8D
+/\x{100}*\w/8DZ
-/\x{100}*\D/8D
+/\x{100}*\D/8DZ
-/\x{100}*\S/8D
+/\x{100}*\S/8DZ
-/\x{100}*\W/8D
+/\x{100}*\W/8DZ
-/\x{100}+\x{200}/8D
+/\x{100}+\x{200}/8DZ
-/\x{100}+X/8D
+/\x{100}+X/8DZ
-/X+\x{200}/8D
+/X+\x{200}/8DZ
/()()()()()()()()()()
()()()()()()()()()()
@@ -296,11 +300,11 @@
A (x) (?41) B/8x
AxxB
-/^[\x{100}\E-\Q\E\x{150}]/B8
+/^[\x{100}\E-\Q\E\x{150}]/BZ8
-/^[\QÄ€\E-\QÅ\E]/B8
+/^[\QÄ€\E-\QÅ\E]/BZ8
-/^[\QÄ€\E-\QÅ\E/B8
+/^[\QÄ€\E-\QÅ\E/BZ8
/^abc./mgx8<any>
abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK
@@ -308,7 +312,7 @@
/abc.$/mgx8<any>
abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
-/^a\Rb/8
+/^a\Rb/8<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -320,7 +324,7 @@
** Failers
a\n\rb
-/^a\R*b/8
+/^a\R*b/8<bsr_unicode>
ab
a\nb
a\rb
@@ -331,7 +335,7 @@
a\n\rb
a\n\r\x{85}\x0cb
-/^a\R+b/8
+/^a\R+b/8<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -343,7 +347,7 @@
** Failers
ab
-/^a\R{1,3}b/8
+/^a\R{1,3}b/8<bsr_unicode>
a\nb
a\n\rb
a\n\r\x{85}b
@@ -355,4 +359,118 @@
a\n\n\n\rb
a\r
+/\H\h\V\v/8
+ X X\x0a
+ X\x09X\x0b
+ ** Failers
+ \x{a0} X\x0a
+
+/\H*\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\x{a0}\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\x{a0}\x0a\x0b\x0c
+ ** Failers
+ \x09\x20\x{a0}\x0a\x0b
+
+/\H\h\V\v/8
+ \x{3001}\x{3000}\x{2030}\x{2028}
+ X\x{180e}X\x{85}
+ ** Failers
+ \x{2009} X\x0a
+
+/\H*\h+\V?\v{3,4}/8
+ \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x0c\x0d\x0a
+ \x09\x{205f}\x{a0}\x0a\x{2029}\x0c\x{2028}\x0a
+ \x09\x20\x{202f}\x0a\x0b\x0c
+ ** Failers
+ \x09\x{200a}\x{a0}\x{2028}\x0b
+
+/[\h]/8BZ
+ >\x{1680}
+
+/[\h]{3,}/8BZ
+ >\x{1680}\x{180e}\x{2000}\x{2003}\x{200a}\x{202f}\x{205f}\x{3000}<
+
+/[\v]/8BZ
+
+/[\H]/8BZ
+
+/[\V]/8BZ
+
+/.*$/8<any>
+ \x{1ec5}
+
+/-- This tests the stricter UTF-8 check according to RFC 3629. --/
+
+/X/8
+ \x{0}\x{d7ff}\x{e000}\x{10ffff}
+ \x{d800}
+ \x{d800}\?
+ \x{da00}
+ \x{da00}\?
+ \x{dfff}
+ \x{dfff}\?
+ \x{110000}
+ \x{110000}\?
+ \x{2000000}
+ \x{2000000}\?
+ \x{7fffffff}
+ \x{7fffffff}\?
+
+/a\Rb/I8<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x{85}b
+ a\x0bb
+
+/a\Rb/I8<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x{85}b
+ a\x0bb
+ ** Failers
+ a\x{85}b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R?b/I8<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x{85}b
+ a\x0bb
+
+/a\R?b/I8<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x{85}b
+ a\x0bb
+ ** Failers
+ a\x{85}b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/.*a.*=.b.*/8<ANY>
+ QQQ\x{2029}ABCaXYZ=!bPQR
+ ** Failers
+ a\x{2029}b
+ \x61\xe2\x80\xa9\x62
+
+/[[:a\x{100}b:]]/8
+
+/a[^]b/<JS>8
+ a\x{1234}b
+ a\nb
+ ** Failers
+ ab
+
+/a[^]+b/<JS>8
+ aXb
+ a\nX\nX\x{1234}b
+ ** Failers
+ ab
+
/ End of testinput5 /
diff --git a/ext/pcre/pcrelib/testdata/testinput6 b/ext/pcre/pcrelib/testdata/testinput6
index 5a541f362a..0204a7acae 100644
--- a/ext/pcre/pcrelib/testdata/testinput6
+++ b/ext/pcre/pcrelib/testdata/testinput6
@@ -61,7 +61,7 @@
\x{09f}
/^\p{Cs}/8
- \x{dfff}
+ \?\x{dfff}
** Failers
\x{09f}
@@ -69,7 +69,7 @@
a
** Failers
Z
- \x{dfff}
+ \x{e000}
/^\p{Lm}/8
\x{2b0}
@@ -323,20 +323,20 @@
** Failers
WXYZ
-/[\p{L}]/D
+/[\p{L}]/DZ
-/[\p{^L}]/D
+/[\p{^L}]/DZ
-/[\P{L}]/D
+/[\P{L}]/DZ
-/[\P{^L}]/D
+/[\P{^L}]/DZ
-/[abc\p{L}\x{0660}]/8D
+/[abc\p{L}\x{0660}]/8DZ
-/[\p{Nd}]/8DM
+/[\p{Nd}]/8DZ
1234
-/[\p{Nd}+-]+/8DM
+/[\p{Nd}+-]+/8DZ
1234
12-34
12+\x{661}-34
@@ -425,13 +425,13 @@
A\x{391}\x{10427}\x{ff5a}\x{1fb0}
A\x{391}\x{10427}\x{ff3a}\x{1fb8}
-/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iD
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iDZ
-/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8D
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8DZ
-/AB\x{1fb0}/8D
+/AB\x{1fb0}/8DZ
-/AB\x{1fb0}/8Di
+/AB\x{1fb0}/8DZi
/\x{391}+/8i
\x{391}\x{3b1}\x{3b1}\x{3b1}\x{391}
@@ -452,7 +452,7 @@
\x{c0}
\x{e0}
-/[\x{105}-\x{109}]/8iD
+/[\x{105}-\x{109}]/8iDZ
\x{104}
\x{105}
\x{109}
@@ -460,7 +460,7 @@
\x{100}
\x{10a}
-/[z-\x{100}]/8iD
+/[z-\x{100}]/8iDZ
Z
z
\x{39c}
@@ -475,7 +475,7 @@
Y
y
-/[z-\x{100}]/8Di
+/[z-\x{100}]/8DZi
/^\X/8
A
@@ -762,4 +762,149 @@ of case for anything other than the ASCII letters. /
/^\p{Balinese}\p{Cuneiform}\p{Nko}\p{Phags_Pa}\p{Phoenician}/8
\x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
+/The next two are special cases where the lengths of the different cases of the
+same character differ. The first went wrong with heap fram storage; the 2nd
+was broken in all cases./
+
+/^\x{023a}+?(\x{0130}+)/8i
+ \x{023a}\x{2c65}\x{0130}
+
+/^\x{023a}+([^X])/8i
+ \x{023a}\x{2c65}X
+
+/Check property support in non-UTF-8 mode/
+
+/\p{L}{4}/
+ 123abcdefg
+ 123abc\xc4\xc5zz
+
+/\X{1,3}\d/
+ \x8aBCD
+
+/\X?\d/
+ \x8aBCD
+
+/\P{L}?\d/
+ \x8aBCD
+
+/[\PPP\x8a]{1,}\x80/
+ A\x80
+
+/(?:[\PPa*]*){8,}/
+
+/[\P{Any}]/BZ
+
+/[\P{Any}\E]/BZ
+
+/(\P{Yi}+\277)/
+
+/(\P{Yi}+\277)?/
+
+/(?<=\P{Yi}{3}A)X/
+
+/\p{Yi}+(\P{Yi}+)(?1)/
+
+/(\P{Yi}{2}\277)?/
+
+/[\P{Yi}A]/
+
+/[\P{Yi}\P{Yi}\P{Yi}A]/
+
+/[^\P{Yi}A]/
+
+/[^\P{Yi}\P{Yi}\P{Yi}A]/
+
+/(\P{Yi}*\277)*/
+
+/(\P{Yi}*?\277)*/
+
+/(\p{Yi}*+\277)*/
+
+/(\P{Yi}?\277)*/
+
+/(\P{Yi}??\277)*/
+
+/(\p{Yi}?+\277)*/
+
+/(\P{Yi}{0,3}\277)*/
+
+/(\P{Yi}{0,3}?\277)*/
+
+/(\p{Yi}{0,3}+\277)*/
+
+/^[\p{Arabic}]/8
+ \x{60e}
+ \x{656}
+ \x{657}
+ \x{658}
+ \x{659}
+ \x{65a}
+ \x{65b}
+ \x{65c}
+ \x{65d}
+ \x{65e}
+ \x{66a}
+ \x{6e9}
+ \x{6ef}
+ \x{6fa}
+ ** Failers
+ \x{600}
+ \x{650}
+ \x{651}
+ \x{652}
+ \x{653}
+ \x{654}
+ \x{655}
+ \x{65f}
+
+/^\p{Cyrillic}/8
+ \x{1d2b}
+
+/^\p{Common}/8
+ \x{589}
+ \x{60c}
+ \x{61f}
+ \x{964}
+ \x{965}
+ \x{970}
+
+/^\p{Inherited}/8
+ \x{64b}
+ \x{654}
+ \x{655}
+ \x{200c}
+ ** Failers
+ \x{64a}
+ \x{656}
+
+/^\p{Shavian}/8
+ \x{10450}
+ \x{1047f}
+
+/^\p{Deseret}/8
+ \x{10400}
+ \x{1044f}
+
+/^\p{Osmanya}/8
+ \x{10480}
+ \x{1049d}
+ \x{104a0}
+ \x{104a9}
+ ** Failers
+ \x{1049e}
+ \x{1049f}
+ \x{104aa}
+
+/\p{Zl}{2,3}+/8BZ
+ \xe2\x80\xa8\xe2\x80\xa8
+ \x{2028}\x{2028}\x{2028}
+
+/\p{Zl}/8BZ
+
+/\p{Lu}{3}+/8BZ
+
+/\pL{2}+/8BZ
+
+/\p{Cc}{2}+/8BZ
+
/ End of testinput6 /
diff --git a/ext/pcre/pcrelib/testdata/testinput7 b/ext/pcre/pcrelib/testdata/testinput7
index 23b35f16d8..5d593eed65 100644
--- a/ext/pcre/pcrelib/testdata/testinput7
+++ b/ext/pcre/pcrelib/testdata/testinput7
@@ -1931,8 +1931,8 @@
/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/
abcdefghijk\12S
-/ab\hdef/
- abhdef
+/ab\idef/
+ abidef
/a{0}bc/
bc
@@ -4156,7 +4156,7 @@
/abc.$/mgx<any>
abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
-/^a\Rb/
+/^a\Rb/<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -4166,7 +4166,7 @@
** Failers
a\n\rb
-/^a\R*b/
+/^a\R*b/<bsr_unicode>
ab
a\nb
a\rb
@@ -4177,7 +4177,7 @@
a\n\rb
a\n\r\x85\x0cb
-/^a\R+b/
+/^a\R+b/<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -4189,7 +4189,7 @@
** Failers
ab
-/^a\R{1,3}b/
+/^a\R{1,3}b/<bsr_unicode>
a\nb
a\n\rb
a\n\r\x85b
@@ -4201,7 +4201,7 @@
a\n\n\n\rb
a\r
-/^a[\R]b/
+/^a[\R]b/<bsr_unicode>
aRb
** Failers
a\nb
@@ -4229,4 +4229,167 @@
\r\nfoo
\nfoo
+/^$/mg<any>
+ abc\r\rxyz
+ abc\n\rxyz
+ ** Failers
+ abc\r\nxyz
+
+/^X/m
+ XABC
+ ** Failers
+ XABC\B
+
+/(?m)^$/<any>g+
+ abc\r\n\r\n
+
+/(?m)^$|^\r\n/<any>g+
+ abc\r\n\r\n
+
+/(?m)$/<any>g+
+ abc\r\n\r\n
+
+/(?|(abc)|(xyz))/
+ >abc<
+ >xyz<
+
+/(x)(?|(abc)|(xyz))(x)/
+ xabcx
+ xxyzx
+
+/(x)(?|(abc)(pqr)|(xyz))(x)/
+ xabcpqrx
+ xxyzx
+
+/(?|(abc)|(xyz))(?1)/
+ abcabc
+ xyzabc
+ ** Failers
+ xyzxyz
+
+/\H\h\V\v/
+ X X\x0a
+ X\x09X\x0b
+ ** Failers
+ \xa0 X\x0a
+
+/\H*\h+\V?\v{3,4}/
+ \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\xa0\x0a\x0b\x0c
+ ** Failers
+ \x09\x20\xa0\x0a\x0b
+
+/\H{3,4}/
+ XY ABCDE
+ XY PQR ST
+
+/.\h{3,4}./
+ XY AB PQRS
+
+/\h*X\h?\H+Y\H?Z/
+ >XNNNYZ
+ > X NYQZ
+ ** Failers
+ >XYZ
+ > X NY Z
+
+/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
+ >XY\x0aZ\x0aA\x0bNN\x0c
+ >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+
+/.+A/<crlf>
+ \r\nA
+
+/\nA/<crlf>
+ \r\nA
+
+/[\r\n]A/<crlf>
+ \r\nA
+
+/(\r|\n)A/<crlf>
+ \r\nA
+
+/a\Rb/I<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x85b
+ a\x0bb
+
+/a\Rb/I<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x85b
+ a\x0bb
+ ** Failers
+ a\x85b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R?b/I<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x85b
+ a\x0bb
+
+/a\R?b/I<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x85b
+ a\x0bb
+ ** Failers
+ a\x85b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R{2,4}b/I<bsr_anycrlf>
+ a\r\n\nb
+ a\n\r\rb
+ a\r\n\r\n\r\n\r\nb
+ ** Failers
+ a\x85\85b
+ a\x0b\0bb
+
+/a\R{2,4}b/I<bsr_unicode>
+ a\r\rb
+ a\n\n\nb
+ a\r\n\n\r\rb
+ a\x85\85b
+ a\x0b\0bb
+ ** Failers
+ a\r\r\r\r\rb
+ a\x85\85b\<bsr_anycrlf>
+ a\x0b\0bb\<bsr_anycrlf>
+
+/a(?!)|\wbc/
+ abc
+
+/a[]b/<JS>
+ ** Failers
+ ab
+
+/a[]+b/<JS>
+ ** Failers
+ ab
+
+/a[]*+b/<JS>
+ ** Failers
+ ab
+
+/a[^]b/<JS>
+ aXb
+ a\nb
+ ** Failers
+ ab
+
+/a[^]+b/<JS>
+ aXb
+ a\nX\nXb
+ ** Failers
+ ab
+
/ End of testinput7 /
diff --git a/ext/pcre/pcrelib/testdata/testinput8 b/ext/pcre/pcrelib/testdata/testinput8
index a19493fe63..5bcfab5c08 100644
--- a/ext/pcre/pcrelib/testdata/testinput8
+++ b/ext/pcre/pcrelib/testdata/testinput8
@@ -543,7 +543,7 @@
/abc.$/mgx8<any>
abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
-/^a\Rb/8
+/^a\Rb/8<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -555,7 +555,7 @@
** Failers
a\n\rb
-/^a\R*b/8
+/^a\R*b/8<bsr_unicode>
ab
a\nb
a\rb
@@ -566,7 +566,7 @@
a\n\rb
a\n\r\x{85}\x0cb
-/^a\R+b/8
+/^a\R+b/8<bsr_unicode>
a\nb
a\rb
a\r\nb
@@ -578,7 +578,7 @@
** Failers
ab
-/^a\R{1,3}b/8
+/^a\R{1,3}b/8<bsr_unicode>
a\nb
a\n\rb
a\n\r\x{85}b
@@ -590,4 +590,78 @@
a\n\n\n\rb
a\r
+/\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+
+/\V?\v{3,4}/8
+ \x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+
+/\h+\V?\v{3,4}/8
+ >\x09\x20\x{a0}X\x0a\x0a\x0a<
+
+/\V?\v{3,4}/8
+ >\x09\x20\x{a0}X\x0a\x0a\x0a<
+
+/\H\h\V\v/8
+ X X\x0a
+ X\x09X\x0b
+ ** Failers
+ \x{a0} X\x0a
+
+/\H*\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\x{a0}\x0a\x0b\x0c\x0d\x0a
+ \x09\x20\x{a0}\x0a\x0b\x0c
+ ** Failers
+ \x09\x20\x{a0}\x0a\x0b
+
+/\H\h\V\v/8
+ \x{3001}\x{3000}\x{2030}\x{2028}
+ X\x{180e}X\x{85}
+ ** Failers
+ \x{2009} X\x0a
+
+/\H*\h+\V?\v{3,4}/8
+ \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x0c\x0d\x0a
+ \x09\x{205f}\x{a0}\x0a\x{2029}\x0c\x{2028}\x0a
+ \x09\x20\x{202f}\x0a\x0b\x0c
+ ** Failers
+ \x09\x{200a}\x{a0}\x{2028}\x0b
+
+/a\Rb/I8<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x{85}b
+ a\x0bb
+
+/a\Rb/I8<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x{85}b
+ a\x0bb
+ ** Failers
+ a\x{85}b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
+/a\R?b/I8<bsr_anycrlf>
+ a\rb
+ a\nb
+ a\r\nb
+ ** Failers
+ a\x{85}b
+ a\x0bb
+
+/a\R?b/I8<bsr_unicode>
+ a\rb
+ a\nb
+ a\r\nb
+ a\x{85}b
+ a\x0bb
+ ** Failers
+ a\x{85}b\<bsr_anycrlf>
+ a\x0bb\<bsr_anycrlf>
+
/ End of testinput 8 /
diff --git a/ext/pcre/pcrelib/testdata/testinput9 b/ext/pcre/pcrelib/testdata/testinput9
index 23d3d3e434..8a606318b7 100644
--- a/ext/pcre/pcrelib/testdata/testinput9
+++ b/ext/pcre/pcrelib/testdata/testinput9
@@ -148,7 +148,7 @@
\x{09f}
/^\p{Cs}/8
- \x{dfff}
+ \?\x{dfff}
** Failers
\x{09f}
@@ -156,7 +156,7 @@
a
** Failers
Z
- \x{dfff}
+ \x{e000}
/^\p{Lm}/8
\x{2b0}
@@ -813,4 +813,16 @@
\x{1c5}XY
AXY
+/^\x{023a}+?(\x{0130}+)/8i
+ \x{023a}\x{2c65}\x{0130}
+
+/^\x{023a}+([^X])/8i
+ \x{023a}\x{2c65}X
+
+/Check property support in non-UTF-8 mode/
+
+/\p{L}{4}/
+ 123abcdefg
+ 123abc\xc4\xc5zz
+
/ End /
diff --git a/ext/pcre/pcrelib/testdata/testoutput1 b/ext/pcre/pcrelib/testdata/testoutput1
index b513dca417..9b8b268edb 100644
--- a/ext/pcre/pcrelib/testdata/testoutput1
+++ b/ext/pcre/pcrelib/testdata/testoutput1
@@ -2189,9 +2189,9 @@ No match
10: j
11: k
-/ab\hdef/
- abhdef
- 0: abhdef
+/ab\idef/
+ abidef
+ 0: abidef
/a{0}bc/
bc
@@ -5551,12 +5551,6 @@ No match
0: b
1: b
-/(?(1)a|b)/
-
-/(?(1)b|a)/
- a
- 0: a
-
/(x)?(?(1)a|b)/
*** Failers
No match
@@ -6571,4 +6565,44 @@ No match
abc\n
No match
+/(.*(.)?)*/
+ abcd
+ 0: abcd
+ 1:
+
+/( (A | (?(1)0|) )* )/x
+ abcd
+ 0:
+ 1:
+ 2:
+
+/( ( (?(1)0|) )* )/x
+ abcd
+ 0:
+ 1:
+ 2:
+
+/( (?(1)0|)* )/x
+ abcd
+ 0:
+ 1:
+
+/[[:abcd:xyz]]/
+ a]
+ 0: a]
+ :]
+ 0: :]
+
+/[abc[:x\]pqr]/
+ a
+ 0: a
+ [
+ 0: [
+ :
+ 0: :
+ ]
+ 0: ]
+ p
+ 0: p
+
/ End of testinput1 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput10 b/ext/pcre/pcrelib/testdata/testoutput10
new file mode 100644
index 0000000000..4eaaa39183
--- /dev/null
+++ b/ext/pcre/pcrelib/testdata/testoutput10
@@ -0,0 +1,669 @@
+/-- These are a few representative patterns whose lengths and offsets are to be
+shown when the link size is 2. This is just a doublecheck test to ensure the
+sizes don't go horribly wrong when something is changed. The pattern contents
+are all themselves checked in other tests. --/
+
+/((?i)b)/BM
+Memory allocation (code space): 21
+------------------------------------------------------------------
+ 0 17 Bra
+ 3 9 CBra 1
+ 8 01 Opt
+ 10 NC b
+ 12 9 Ket
+ 15 00 Opt
+ 17 17 Ket
+ 20 End
+------------------------------------------------------------------
+
+/(?s)(.*X|^B)/BM
+Memory allocation (code space): 25
+------------------------------------------------------------------
+ 0 21 Bra
+ 3 9 CBra 1
+ 8 AllAny*
+ 10 X
+ 12 6 Alt
+ 15 ^
+ 16 B
+ 18 15 Ket
+ 21 21 Ket
+ 24 End
+------------------------------------------------------------------
+
+/(?s:.*X|^B)/BM
+Memory allocation (code space): 29
+------------------------------------------------------------------
+ 0 25 Bra
+ 3 9 Bra
+ 6 04 Opt
+ 8 AllAny*
+ 10 X
+ 12 8 Alt
+ 15 04 Opt
+ 17 ^
+ 18 B
+ 20 17 Ket
+ 23 00 Opt
+ 25 25 Ket
+ 28 End
+------------------------------------------------------------------
+
+/^[[:alnum:]]/BM
+Memory allocation (code space): 41
+------------------------------------------------------------------
+ 0 37 Bra
+ 3 ^
+ 4 [0-9A-Za-z]
+ 37 37 Ket
+ 40 End
+------------------------------------------------------------------
+
+/#/IxMD
+Memory allocation (code space): 7
+------------------------------------------------------------------
+ 0 3 Bra
+ 3 3 Ket
+ 6 End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Options: extended
+No first char
+No need char
+
+/a#/IxMD
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 a
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Options: extended
+First char = 'a'
+No need char
+
+/x?+/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 x?+
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/x++/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 x++
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/x{1,3}+/BM
+Memory allocation (code space): 19
+------------------------------------------------------------------
+ 0 15 Bra
+ 3 9 Once
+ 6 x
+ 8 x{0,2}
+ 12 9 Ket
+ 15 15 Ket
+ 18 End
+------------------------------------------------------------------
+
+/(x)*+/BM
+Memory allocation (code space): 24
+------------------------------------------------------------------
+ 0 20 Bra
+ 3 14 Once
+ 6 Brazero
+ 7 7 CBra 1
+ 12 x
+ 14 7 KetRmax
+ 17 14 Ket
+ 20 20 Ket
+ 23 End
+------------------------------------------------------------------
+
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/BM
+Memory allocation (code space): 120
+------------------------------------------------------------------
+ 0 116 Bra
+ 3 ^
+ 4 109 CBra 1
+ 9 7 CBra 2
+ 14 a+
+ 16 7 Ket
+ 19 39 CBra 3
+ 24 [ab]+?
+ 58 39 Ket
+ 61 39 CBra 4
+ 66 [bc]+
+100 39 Ket
+103 7 CBra 5
+108 \w*
+110 7 Ket
+113 109 Ket
+116 116 Ket
+119 End
+------------------------------------------------------------------
+
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|BM
+Memory allocation (code space): 826
+------------------------------------------------------------------
+ 0 822 Bra
+ 3 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
+821 \b
+822 822 Ket
+825 End
+------------------------------------------------------------------
+
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|BM
+Memory allocation (code space): 816
+------------------------------------------------------------------
+ 0 812 Bra
+ 3 $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
+811 \b
+812 812 Ket
+815 End
+------------------------------------------------------------------
+
+/(a(?1)b)/BM
+Memory allocation (code space): 28
+------------------------------------------------------------------
+ 0 24 Bra
+ 3 18 CBra 1
+ 8 a
+ 10 6 Once
+ 13 3 Recurse
+ 16 6 Ket
+ 19 b
+ 21 18 Ket
+ 24 24 Ket
+ 27 End
+------------------------------------------------------------------
+
+/(a(?1)+b)/BM
+Memory allocation (code space): 28
+------------------------------------------------------------------
+ 0 24 Bra
+ 3 18 CBra 1
+ 8 a
+ 10 6 Once
+ 13 3 Recurse
+ 16 6 KetRmax
+ 19 b
+ 21 18 Ket
+ 24 24 Ket
+ 27 End
+------------------------------------------------------------------
+
+/a(?P<name1>b|c)d(?P<longername2>e)/BM
+Memory allocation (code space): 42
+------------------------------------------------------------------
+ 0 32 Bra
+ 3 a
+ 5 7 CBra 1
+ 10 b
+ 12 5 Alt
+ 15 c
+ 17 12 Ket
+ 20 d
+ 22 7 CBra 2
+ 27 e
+ 29 7 Ket
+ 32 32 Ket
+ 35 End
+------------------------------------------------------------------
+
+/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/BM
+Memory allocation (code space): 54
+------------------------------------------------------------------
+ 0 41 Bra
+ 3 25 Bra
+ 6 a
+ 8 17 CBra 1
+ 13 c
+ 15 7 CBra 2
+ 20 d
+ 22 7 Ket
+ 25 17 Ket
+ 28 25 Ket
+ 31 7 CBra 3
+ 36 a
+ 38 7 Ket
+ 41 41 Ket
+ 44 End
+------------------------------------------------------------------
+
+/(?P<a>a)...(?P=a)bbb(?P>a)d/BM
+Memory allocation (code space): 43
+------------------------------------------------------------------
+ 0 36 Bra
+ 3 7 CBra 1
+ 8 a
+ 10 7 Ket
+ 13 Any
+ 14 Any
+ 15 Any
+ 16 \1
+ 19 bbb
+ 25 6 Once
+ 28 3 Recurse
+ 31 6 Ket
+ 34 d
+ 36 36 Ket
+ 39 End
+------------------------------------------------------------------
+
+/abc(?C255)de(?C)f/BM
+Memory allocation (code space): 31
+------------------------------------------------------------------
+ 0 27 Bra
+ 3 abc
+ 9 Callout 255 10 1
+ 15 de
+ 19 Callout 0 16 1
+ 25 f
+ 27 27 Ket
+ 30 End
+------------------------------------------------------------------
+
+/abcde/CBM
+Memory allocation (code space): 53
+------------------------------------------------------------------
+ 0 49 Bra
+ 3 Callout 255 0 1
+ 9 a
+ 11 Callout 255 1 1
+ 17 b
+ 19 Callout 255 2 1
+ 25 c
+ 27 Callout 255 3 1
+ 33 d
+ 35 Callout 255 4 1
+ 41 e
+ 43 Callout 255 5 0
+ 49 49 Ket
+ 52 End
+------------------------------------------------------------------
+
+/\x{100}/8BM
+Memory allocation (code space): 10
+------------------------------------------------------------------
+ 0 6 Bra
+ 3 \x{100}
+ 6 6 Ket
+ 9 End
+------------------------------------------------------------------
+
+/\x{1000}/8BM
+Memory allocation (code space): 11
+------------------------------------------------------------------
+ 0 7 Bra
+ 3 \x{1000}
+ 7 7 Ket
+ 10 End
+------------------------------------------------------------------
+
+/\x{10000}/8BM
+Memory allocation (code space): 12
+------------------------------------------------------------------
+ 0 8 Bra
+ 3 \x{10000}
+ 8 8 Ket
+ 11 End
+------------------------------------------------------------------
+
+/\x{100000}/8BM
+Memory allocation (code space): 12
+------------------------------------------------------------------
+ 0 8 Bra
+ 3 \x{100000}
+ 8 8 Ket
+ 11 End
+------------------------------------------------------------------
+
+/\x{1000000}/8BM
+Memory allocation (code space): 13
+------------------------------------------------------------------
+ 0 9 Bra
+ 3 \x{1000000}
+ 9 9 Ket
+ 12 End
+------------------------------------------------------------------
+
+/\x{4000000}/8BM
+Memory allocation (code space): 14
+------------------------------------------------------------------
+ 0 10 Bra
+ 3 \x{4000000}
+ 10 10 Ket
+ 13 End
+------------------------------------------------------------------
+
+/\x{7fffFFFF}/8BM
+Memory allocation (code space): 14
+------------------------------------------------------------------
+ 0 10 Bra
+ 3 \x{7fffffff}
+ 10 10 Ket
+ 13 End
+------------------------------------------------------------------
+
+/[\x{ff}]/8BM
+Memory allocation (code space): 10
+------------------------------------------------------------------
+ 0 6 Bra
+ 3 \x{ff}
+ 6 6 Ket
+ 9 End
+------------------------------------------------------------------
+
+/[\x{100}]/8BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\x{100}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/\x80/8BM
+Memory allocation (code space): 10
+------------------------------------------------------------------
+ 0 6 Bra
+ 3 \x{80}
+ 6 6 Ket
+ 9 End
+------------------------------------------------------------------
+
+/\xff/8BM
+Memory allocation (code space): 10
+------------------------------------------------------------------
+ 0 6 Bra
+ 3 \x{ff}
+ 6 6 Ket
+ 9 End
+------------------------------------------------------------------
+
+/\x{0041}\x{2262}\x{0391}\x{002e}/D8M
+Memory allocation (code space): 18
+------------------------------------------------------------------
+ 0 14 Bra
+ 3 A\x{2262}\x{391}.
+ 14 14 Ket
+ 17 End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Options: utf8
+First char = 'A'
+Need char = '.'
+
+/\x{D55c}\x{ad6d}\x{C5B4}/D8M
+Memory allocation (code space): 19
+------------------------------------------------------------------
+ 0 15 Bra
+ 3 \x{d55c}\x{ad6d}\x{c5b4}
+ 15 15 Ket
+ 18 End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Options: utf8
+First char = 237
+Need char = 180
+
+/\x{65e5}\x{672c}\x{8a9e}/D8M
+Memory allocation (code space): 19
+------------------------------------------------------------------
+ 0 15 Bra
+ 3 \x{65e5}\x{672c}\x{8a9e}
+ 15 15 Ket
+ 18 End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Options: utf8
+First char = 230
+Need char = 158
+
+/[\x{100}]/8BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\x{100}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[Z\x{100}]/8BM
+Memory allocation (code space): 47
+------------------------------------------------------------------
+ 0 43 Bra
+ 3 [Z\x{100}]
+ 43 43 Ket
+ 46 End
+------------------------------------------------------------------
+
+/^[\x{100}\E-\Q\E\x{150}]/B8M
+Memory allocation (code space): 18
+------------------------------------------------------------------
+ 0 14 Bra
+ 3 ^
+ 4 [\x{100}-\x{150}]
+ 14 14 Ket
+ 17 End
+------------------------------------------------------------------
+
+/^[\QÄ€\E-\QÅ\E]/B8M
+Memory allocation (code space): 18
+------------------------------------------------------------------
+ 0 14 Bra
+ 3 ^
+ 4 [\x{100}-\x{150}]
+ 14 14 Ket
+ 17 End
+------------------------------------------------------------------
+
+/^[\QÄ€\E-\QÅ\E/B8M
+Failed: missing terminating ] for character class at offset 15
+
+/[\p{L}]/BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\p{L}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[\p{^L}]/BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\P{L}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[\P{L}]/BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\P{L}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[\P{^L}]/BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\p{L}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[abc\p{L}\x{0660}]/8BM
+Memory allocation (code space): 50
+------------------------------------------------------------------
+ 0 46 Bra
+ 3 [a-c\p{L}\x{660}]
+ 46 46 Ket
+ 49 End
+------------------------------------------------------------------
+
+/[\p{Nd}]/8BM
+Memory allocation (code space): 15
+------------------------------------------------------------------
+ 0 11 Bra
+ 3 [\p{Nd}]
+ 11 11 Ket
+ 14 End
+------------------------------------------------------------------
+
+/[\p{Nd}+-]+/8BM
+Memory allocation (code space): 48
+------------------------------------------------------------------
+ 0 44 Bra
+ 3 [+\-\p{Nd}]+
+ 44 44 Ket
+ 47 End
+------------------------------------------------------------------
+
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iBM
+Memory allocation (code space): 25
+------------------------------------------------------------------
+ 0 21 Bra
+ 3 NC A\x{391}\x{10427}\x{ff3a}\x{1fb0}
+ 21 21 Ket
+ 24 End
+------------------------------------------------------------------
+
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8BM
+Memory allocation (code space): 25
+------------------------------------------------------------------
+ 0 21 Bra
+ 3 A\x{391}\x{10427}\x{ff3a}\x{1fb0}
+ 21 21 Ket
+ 24 End
+------------------------------------------------------------------
+
+/[\x{105}-\x{109}]/8iBM
+Memory allocation (code space): 17
+------------------------------------------------------------------
+ 0 13 Bra
+ 3 [\x{104}-\x{109}]
+ 13 13 Ket
+ 16 End
+------------------------------------------------------------------
+
+/( ( (?(1)0|) )* )/xBM
+Memory allocation (code space): 38
+------------------------------------------------------------------
+ 0 34 Bra
+ 3 28 CBra 1
+ 8 Brazero
+ 9 19 SCBra 2
+ 14 8 Cond
+ 17 1 Cond ref
+ 20 0
+ 22 3 Alt
+ 25 11 Ket
+ 28 19 KetRmax
+ 31 28 Ket
+ 34 34 Ket
+ 37 End
+------------------------------------------------------------------
+
+/( (?(1)0|)* )/xBM
+Memory allocation (code space): 30
+------------------------------------------------------------------
+ 0 26 Bra
+ 3 20 CBra 1
+ 8 Brazero
+ 9 8 SCond
+ 12 1 Cond ref
+ 15 0
+ 17 3 Alt
+ 20 11 KetRmax
+ 23 20 Ket
+ 26 26 Ket
+ 29 End
+------------------------------------------------------------------
+
+/[a]/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 a
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[a]/8BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 a
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[\xaa]/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 \xaa
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[\xaa]/8BM
+Memory allocation (code space): 10
+------------------------------------------------------------------
+ 0 6 Bra
+ 3 \x{aa}
+ 6 6 Ket
+ 9 End
+------------------------------------------------------------------
+
+/[^a]/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 [^a]
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[^a]/8BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 [^a]
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[^\xaa]/BM
+Memory allocation (code space): 9
+------------------------------------------------------------------
+ 0 5 Bra
+ 3 [^\xaa]
+ 5 5 Ket
+ 8 End
+------------------------------------------------------------------
+
+/[^\xaa]/8BM
+Memory allocation (code space): 40
+------------------------------------------------------------------
+ 0 36 Bra
+ 3 [\x00-\xa9\xab-\xff] (neg)
+ 36 36 Ket
+ 39 End
+------------------------------------------------------------------
+
+/ End of testinput10 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput2 b/ext/pcre/pcrelib/testdata/testoutput2
index 45907492f9..4d6d688867 100644
--- a/ext/pcre/pcrelib/testdata/testoutput2
+++ b/ext/pcre/pcrelib/testdata/testoutput2
@@ -78,10 +78,10 @@ No match
def\nabc
No match
-/ab\hdef/X
+/ab\idef/X
Failed: unrecognized character follows \ at offset 3
-/(?X)ab\hdef/X
+/(?X)ab\idef/X
Failed: unrecognized character follows \ at offset 7
/x{5,4}/
@@ -109,7 +109,7 @@ Failed: missing ) at offset 4
Failed: missing ) after comment at offset 7
/(?z)abc/
-Failed: unrecognized character after (? at offset 2
+Failed: unrecognized character after (? or (?- at offset 2
/.*b/I
Capturing subpattern count = 0
@@ -222,7 +222,7 @@ Matched, but too many substrings
0: abcb
1: a
2: b
- \O12abcb
+ \O12abcb
0: abcb
1: a
2: b
@@ -310,7 +310,7 @@ No match
No match
/ab(?z)cd/
-Failed: unrecognized character after (? at offset 4
+Failed: unrecognized character after (? or (?- at offset 4
/^abc|def/I
Capturing subpattern count = 0
@@ -343,7 +343,7 @@ No need char
0: abc
*** Failers
No match: POSIX code 17: match failed
-
+
/^abc|def/IP
abcdef
0: abc
@@ -359,19 +359,19 @@ No match: POSIX code 17: match failed
0: def
1: def
3: def
-
+
/the quick brown fox/IP
the quick brown fox
0: the quick brown fox
- *** Failers
+ *** Failers
No match: POSIX code 17: match failed
- The Quick Brown Fox
+ The Quick Brown Fox
No match: POSIX code 17: match failed
/the quick brown fox/IPi
the quick brown fox
0: the quick brown fox
- The Quick Brown Fox
+ The Quick Brown Fox
0: The Quick Brown Fox
/abc.def/IP
@@ -379,11 +379,11 @@ No match: POSIX code 17: match failed
No match: POSIX code 17: match failed
abc\ndef
No match: POSIX code 17: match failed
-
+
/abc$/IP
abc
0: abc
- abc\n
+ abc\n
0: abc
/(abc)\2/IP
@@ -405,9 +405,9 @@ Partial matching not supported
No options
No first char
No need char
- co-processors, and for
+ co-processors, and for
0: -pr
-
+
/<.*>/I
Capturing subpattern count = 0
Partial matching not supported
@@ -434,7 +434,7 @@ First char = '<'
Need char = '>'
abc<def>ghi<klm>nop
0: <def>
-
+
/(?U)<.*>/I
Capturing subpattern count = 0
Partial matching not supported
@@ -452,7 +452,7 @@ First char = '<'
Need char = '>'
abc<def>ghi<klm>nop
0: <def>ghi<klm>
-
+
/={3,}/IU
Capturing subpattern count = 0
Partial matching not supported
@@ -461,7 +461,7 @@ First char = '='
Need char = '='
abc========def
0: ===
-
+
/(?U)={3,}?/I
Capturing subpattern count = 0
Partial matching not supported
@@ -470,7 +470,7 @@ First char = '='
Need char = '='
abc========def
0: ========
-
+
/(?<!bar|cattle)foo/I
Capturing subpattern count = 0
No options
@@ -478,13 +478,13 @@ First char = 'f'
Need char = 'o'
foo
0: foo
- catfoo
+ catfoo
0: foo
*** Failers
No match
the barfoo
No match
- and cattlefoo
+ and cattlefoo
No match
/(?<=a+)b/
@@ -597,16 +597,16 @@ No options
First char = 'b' (caseless)
Need char = 'h' (caseless)
-/((?i)b)/IDS
+/((?i)b)/IDZS
------------------------------------------------------------------
- 0 17 Bra 0
- 3 9 Bra 1
- 8 01 Opt
- 10 NC b
- 12 9 Ket
- 15 00 Opt
- 17 17 Ket
- 20 End
+ Bra
+ CBra 1
+ 01 Opt
+ NC b
+ Ket
+ 00 Opt
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -631,11 +631,11 @@ No need char
0: a
a\n
0: a
- *** Failers
+ *** Failers
No match
\Za
No match
- \Za\n
+ \Za\n
No match
/a$/Im
@@ -647,20 +647,20 @@ No need char
0: a
a\n
0: a
- \Za\n
+ \Za\n
0: a
- *** Failers
+ *** Failers
No match
\Za
No match
-
+
/\Aabc/Im
Capturing subpattern count = 0
Options: anchored multiline
No first char
No need char
-/^abc/Im
+/^abc/Im
Capturing subpattern count = 0
Options: multiline
First char at start or follows newline
@@ -703,34 +703,36 @@ Starting byte set: a b
/(?<=foo\n)^bar/Im
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: multiline
No first char
Need char = 'r'
- foo\nbarbar
+ foo\nbarbar
0: bar
***Failers
No match
- rhubarb
+ rhubarb
No match
barbell
No match
- abc\nbarton
+ abc\nbarton
No match
/^(?<=foo\n)bar/Im
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: multiline
First char at start or follows newline
Need char = 'r'
- foo\nbarbar
+ foo\nbarbar
0: bar
***Failers
No match
- rhubarb
+ rhubarb
No match
barbell
No match
- abc\nbarton
+ abc\nbarton
No match
/(?>^abc)/Im
@@ -744,7 +746,7 @@ Need char = 'c'
0: abc
*** Failers
No match
- defabc
+ defabc
No match
/(?<=ab(c+)d)ef/
@@ -771,9 +773,9 @@ Need char = 't'
No match
cart
No match
- horse-and-cart
+ horse-and-cart
No match
-
+
/(?<=ab(?i)x|y|z)/I
Capturing subpattern count = 0
No options
@@ -809,17 +811,17 @@ Need char = 'Z'
0: ZZ
bZZ
0: ZZ
- BZZ
+ BZZ
0: ZZ
*** Failers
No match
- ZZ
+ ZZ
No match
- abXYZZ
+ abXYZZ
No match
zzz
No match
- bzz
+ bzz
No match
/(?<!(foo)a)bar/I
@@ -829,11 +831,11 @@ First char = 'b'
Need char = 'r'
bar
0: bar
- foobbar
+ foobbar
0: bar
*** Failers
No match
- fooabar
+ fooabar
No match
/This one is here because Perl 5.005_02 doesn't fail it/I
@@ -849,7 +851,7 @@ No first char
No need char
*** Failers
No match
- a
+ a
No match
/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/I
@@ -867,7 +869,7 @@ No need char
aaaaaa
0: aaaaaa
1: aa
-
+
/These are syntax tests from Perl 5.005/I
Capturing subpattern count = 0
No options
@@ -944,26 +946,23 @@ Failed: missing ) at offset 4
Failed: unrecognized character after (?< at offset 3
/a(?{)b/
-Failed: unrecognized character after (? at offset 3
+Failed: unrecognized character after (? or (?- at offset 3
/a(?{{})b/
-Failed: unrecognized character after (? at offset 3
+Failed: unrecognized character after (? or (?- at offset 3
/a(?{}})b/
-Failed: unrecognized character after (? at offset 3
+Failed: unrecognized character after (? or (?- at offset 3
/a(?{"{"})b/
-Failed: unrecognized character after (? at offset 3
+Failed: unrecognized character after (? or (?- at offset 3
/a(?{"{"}})b/
-Failed: unrecognized character after (? at offset 3
+Failed: unrecognized character after (? or (?- at offset 3
/(?(1?)a|b)/
Failed: malformed number or name after (?( at offset 4
-/(?(1)a|b|c)/
-Failed: conditional group contains more than two branches at offset 10
-
/[a[:xyz:/
Failed: missing terminating ] for character class at offset 8
@@ -1001,7 +1000,7 @@ Need char = 'd'
1: a
2: d
copy substring 5 failed -7
-
+
/(.{20})/I
Capturing subpattern count = 1
Partial matching not supported
@@ -1019,7 +1018,7 @@ No need char
0: abcdefghijklmnopqrst
1: abcdefghijklmnopqrst
1G abcdefghijklmnopqrst (20)
-
+
/(.{15})/I
Capturing subpattern count = 1
Partial matching not supported
@@ -1051,13 +1050,13 @@ No need char
1G abcdefghijklmnop (16)
0L abcdefghijklmnop
1L abcdefghijklmnop
-
+
/^(a|(bc))de(f)/I
Capturing subpattern count = 3
Options: anchored
No first char
No need char
- adef\G1\G2\G3\G4\L
+ adef\G1\G2\G3\G4\L
0: adef
1: a
2: <unset>
@@ -1070,7 +1069,7 @@ get substring 4 failed -7
1L a
2L
3L f
- bcdef\G1\G2\G3\G4\L
+ bcdef\G1\G2\G3\G4\L
0: bcdef
1: bc
2: bc
@@ -1083,40 +1082,40 @@ get substring 4 failed -7
1L bc
2L bc
3L f
- adefghijk\C0
+ adefghijk\C0
0: adef
1: a
2: <unset>
3: f
0C adef (4)
-
+
/^abc\00def/I
Capturing subpattern count = 0
Options: anchored
No first char
No need char
- abc\00def\L\C0
+ abc\00def\L\C0
0: abc\x00def
0C abc (7)
0L abc
-
-/word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
-)((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
-)?)?)?)?)?)?)?)?)?otherword/IM
-Memory allocation (code space): 448
+
+/word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
+)((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+
+)?)?)?)?)?)?)?)?)?otherword/I
Capturing subpattern count = 8
Partial matching not supported
+Contains explicit CR or LF match
No options
First char = 'w'
Need char = 'd'
-/.*X/ID
+/.*X/IDZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 Any*
- 5 X
- 7 7 Ket
- 10 End
+ Bra
+ Any*
+ X
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1124,13 +1123,13 @@ No options
First char at start or follows newline
Need char = 'X'
-/.*X/IDs
+/.*X/IDZs
------------------------------------------------------------------
- 0 7 Bra 0
- 3 Any*
- 5 X
- 7 7 Ket
- 10 End
+ Bra
+ AllAny*
+ X
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1138,18 +1137,18 @@ Options: anchored dotall
No first char
Need char = 'X'
-/(.*X|^B)/ID
+/(.*X|^B)/IDZ
------------------------------------------------------------------
- 0 21 Bra 0
- 3 9 Bra 1
- 8 Any*
- 10 X
- 12 6 Alt
- 15 ^
- 16 B
- 18 15 Ket
- 21 21 Ket
- 24 End
+ Bra
+ CBra 1
+ Any*
+ X
+ Alt
+ ^
+ B
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -1157,37 +1156,37 @@ No options
First char at start or follows newline
No need char
-/(.*X|^B)/IDs
+/(.*X|^B)/IDZs
------------------------------------------------------------------
- 0 21 Bra 0
- 3 9 Bra 1
- 8 Any*
- 10 X
- 12 6 Alt
- 15 ^
- 16 B
- 18 15 Ket
- 21 21 Ket
- 24 End
+ Bra
+ CBra 1
+ AllAny*
+ X
+ Alt
+ ^
+ B
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
Options: anchored dotall
No first char
No need char
-
-/(?s)(.*X|^B)/ID
-------------------------------------------------------------------
- 0 21 Bra 0
- 3 9 Bra 1
- 8 Any*
- 10 X
- 12 6 Alt
- 15 ^
- 16 B
- 18 15 Ket
- 21 21 Ket
- 24 End
+
+/(?s)(.*X|^B)/IDZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ AllAny*
+ X
+ Alt
+ ^
+ B
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -1195,26 +1194,26 @@ Options: anchored dotall
No first char
No need char
-/(?s:.*X|^B)/ID
+/(?s:.*X|^B)/IDZ
------------------------------------------------------------------
- 0 25 Bra 0
- 3 9 Bra 0
- 6 04 Opt
- 8 Any*
- 10 X
- 12 8 Alt
- 15 04 Opt
- 17 ^
- 18 B
- 20 17 Ket
- 23 00 Opt
- 25 25 Ket
- 28 End
+ Bra
+ Bra
+ 04 Opt
+ AllAny*
+ X
+ Alt
+ 04 Opt
+ ^
+ B
+ Ket
+ 00 Opt
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
-No options
-First char at start or follows newline
+Options: anchored
+No first char
No need char
/\Biss\B/I+
@@ -1294,14 +1293,14 @@ No need char
ississippi
0: iss
0+ issippi
-
+
/.*iss/Ig+
Capturing subpattern count = 0
Partial matching not supported
No options
First char at start or follows newline
Need char = 's'
- abciss\nxyzisspqr
+ abciss\nxyzisspqr
0: abciss
0+ \x0axyzisspqr
0: xyziss
@@ -1333,7 +1332,7 @@ Need char = 'i'
0+ river
0: riv
0+ er
- Missouri river\A
+ Missouri river\A
0: Mis
0+ souri river
@@ -1348,6 +1347,7 @@ No need char
/^ab\n/Ig+
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: anchored
No first char
No need char
@@ -1357,6 +1357,7 @@ No need char
/^ab\n/Img+
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: multiline
First char at start or follows newline
Need char = 10
@@ -1595,32 +1596,32 @@ No options
First char = 'a'
Need char = 'b'
-/a(?(1)b)/I
-Capturing subpattern count = 0
+/a(?(1)b)(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
No need char
-/a(?(1)bag|big)/I
-Capturing subpattern count = 0
+/a(?(1)bag|big)(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'g'
-/a(?(1)bag|big)*/I
-Capturing subpattern count = 0
+/a(?(1)bag|big)*(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
No need char
-/a(?(1)bag|big)+/I
-Capturing subpattern count = 0
+/a(?(1)bag|big)+(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'g'
-/a(?(1)b..|b..)/I
-Capturing subpattern count = 0
+/a(?(1)b..|b..)(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'b'
@@ -1646,9 +1647,9 @@ No need char
0:
*** Failers
0:
- \N
+ \N
No match
-
+
/|-/I
Capturing subpattern count = 0
No options
@@ -1662,7 +1663,7 @@ No need char
0: -
*** Failers
0:
- \Nabc
+ \Nabc
No match
/a*(b+)(z)(z)/IP
@@ -1691,8 +1692,8 @@ No match
1: bbbb
2: z
3: z
-
-/^.?abcd/IS
+
+/^.?abcd/IS
Capturing subpattern count = 0
Options: anchored
No first char
@@ -1718,21 +1719,21 @@ Need char = ')'
0: (abcd)
xyz(abcd)
0: (abcd)
- (ab(xy)cd)pqr
+ (ab(xy)cd)pqr
0: (ab(xy)cd)
- (ab(xycd)pqr
+ (ab(xycd)pqr
0: (xycd)
- () abc ()
+ () abc ()
0: ()
12(abcde(fsh)xyz(foo(bar))lmno)89
0: (abcde(fsh)xyz(foo(bar))lmno)
*** Failers
No match
- abcd
+ abcd
No match
abcd)
No match
- (abcd
+ (abcd
No match
/\( ( (?>[^()]+) | (?R) )* \) /Ixg
@@ -1741,7 +1742,7 @@ Partial matching not supported
Options: extended
First char = '('
Need char = ')'
- (ab(xy)cd)pqr
+ (ab(xy)cd)pqr
0: (ab(xy)cd)
1: cd
1(abcd)(x(y)z)pqr
@@ -1760,13 +1761,13 @@ Need char = ')'
0: (abcd)
(ab(xy)cd)
0: (xy)
- (a(b(c)d)e)
+ (a(b(c)d)e)
0: (c)
- ((ab))
+ ((ab))
0: ((ab))
*** Failers
No match
- ()
+ ()
No match
/\( (?: (?>[^()]+) | (?R) )? \) /Ix
@@ -1884,58 +1885,58 @@ Need char = ')'
2: ij
3: (cd(ef)gh)
-/^[[:alnum:]]/D
+/^[[:alnum:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [0-9A-Za-z]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [0-9A-Za-z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^alnum:]]/D
+/^[[:^alnum:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-/:-@[-`{-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-/:-@[-`{-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:alpha:]]/D
+/^[[:alpha:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [A-Za-z]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [A-Za-z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^alpha:]]/D
+/^[[:^alpha:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-@[-`{-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-@[-`{-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-
+
/[_[:alpha:]]/IS
Capturing subpattern count = 0
No options
@@ -1944,52 +1945,52 @@ No need char
Starting byte set: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
_ a b c d e f g h i j k l m n o p q r s t u v w x y z
-/^[[:ascii:]]/D
+/^[[:ascii:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-\x7f]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-\x7f]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^ascii:]]/D
+/^[[:^ascii:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x80-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x80-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:blank:]]/D
+/^[[:blank:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x09 ]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x09 ]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^blank:]]/D
+/^[[:^blank:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-\x08\x0a-\x1f!-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-\x08\x0a-\x1f!-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
@@ -1998,186 +1999,187 @@ No need char
/[\n\x0b\x0c\x0d[:blank:]]/IS
Capturing subpattern count = 0
+Contains explicit CR or LF match
No options
No first char
No need char
Starting byte set: \x09 \x0a \x0b \x0c \x0d \x20
-/^[[:cntrl:]]/D
+/^[[:cntrl:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-\x1f\x7f]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-\x1f\x7f]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:digit:]]/D
+/^[[:digit:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [0-9]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [0-9]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:graph:]]/D
+/^[[:graph:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [!-~]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [!-~]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:lower:]]/D
+/^[[:lower:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [a-z]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [a-z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:print:]]/D
+/^[[:print:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [ -~]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [ -~]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:punct:]]/D
+/^[[:punct:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [!-/:-@[-`{-~]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [!-/:-@[-`{-~]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:space:]]/D
+/^[[:space:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x09-\x0d ]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x09-\x0d ]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:upper:]]/D
+/^[[:upper:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [A-Z]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [A-Z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:xdigit:]]/D
+/^[[:xdigit:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [0-9A-Fa-f]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [0-9A-Fa-f]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:word:]]/D
+/^[[:word:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [0-9A-Z_a-z]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [0-9A-Z_a-z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^cntrl:]]/D
+/^[[:^cntrl:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [ -~\x80-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [ -~\x80-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[12[:^digit:]]/D
+/^[12[:^digit:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-/12:-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-/12:-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/^[[:^blank:]]/D
+/^[[:^blank:]]/DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-\x08\x0a-\x1f!-\xff]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-\x08\x0a-\x1f!-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored
No first char
No need char
-/[01[:alpha:]%]/D
+/[01[:alpha:]%]/DZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [%01A-Za-z]
- 36 36 Ket
- 39 End
+ Bra
+ [%01A-Za-z]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -2200,9 +2202,9 @@ No first char
No need char
A
0: A
- a
+ a
0: a
-
+
/[[:lower:]]/Ii
Capturing subpattern count = 0
Options: caseless
@@ -2210,7 +2212,7 @@ No first char
No need char
A
0: A
- a
+ a
0: a
/((?-i)[[:lower:]])[[:lower:]]/Ii
@@ -2229,7 +2231,7 @@ No need char
1: a
Ab
No match
- AB
+ AB
No match
/[\200-\110]/I
@@ -2543,7 +2545,7 @@ Need char = 'n'
0: mainOmain
1: main
2: O
-
+
/These are all cases where Perl does it differently (nested captures)/I
Capturing subpattern count = 1
No options
@@ -2559,52 +2561,52 @@ No need char
0: aba
1: a
2: b
-
+
/^(aa(bb)?)+$/I
Capturing subpattern count = 2
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: aa
2: bb
-
+
/^(aa|aa(bb))+$/I
Capturing subpattern count = 2
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: aa
2: bb
-
+
/^(aa(bb)??)+$/I
Capturing subpattern count = 2
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: aa
2: bb
-
+
/^(?:aa(bb)?)+$/I
Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: bb
-
+
/^(aa(b(b))?)+$/I
Capturing subpattern count = 3
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: aa
2: bb
@@ -2615,7 +2617,7 @@ Capturing subpattern count = 2
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: bb
2: b
@@ -2625,7 +2627,7 @@ Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: bb
@@ -2634,16 +2636,16 @@ Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbbaa
+ aabbbaa
0: aabbbaa
1: bbb
-
+
/^(?:aa(b(?:bb))?)+$/I
Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbbaa
+ aabbbaa
0: aabbbaa
1: bbb
@@ -2652,7 +2654,7 @@ Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbaa
+ aabbaa
0: aabbaa
1: b
@@ -2661,7 +2663,7 @@ Capturing subpattern count = 1
Options: anchored
No first char
No need char
- aabbbaa
+ aabbbaa
0: aabbbaa
1: bb
@@ -2670,7 +2672,7 @@ Capturing subpattern count = 3
Options: anchored
No first char
No need char
- aabbbaa
+ aabbbaa
0: aabbbaa
1: aa
2: bbb
@@ -2681,75 +2683,73 @@ Capturing subpattern count = 3
Options: anchored
No first char
No need char
- aabbbbaa
+ aabbbbaa
0: aabbbbaa
1: aa
2: bbbb
3: bb
-/--------------------------------------------------------------------/I
+/--------------------------------------------------------------------/I
Capturing subpattern count = 0
No options
First char = '-'
Need char = '-'
-
-/#/IxMD
-Memory allocation (code space): 7
+
+/#/IxDZ
------------------------------------------------------------------
- 0 3 Bra 0
- 3 3 Ket
- 6 End
+ Bra
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: extended
No first char
No need char
-/a#/IxMD
-Memory allocation (code space): 9
+/a#/IxDZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 a
- 5 5 Ket
- 8 End
+ Bra
+ a
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: extended
First char = 'a'
No need char
-/[\s]/D
+/[\s]/DZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x09\x0a\x0c\x0d ]
- 36 36 Ket
- 39 End
+ Bra
+ [\x09\x0a\x0c\x0d ]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[\S]/D
+/[\S]/DZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x00-\x08\x0b\x0e-\x1f!-\xff]
- 36 36 Ket
- 39 End
+ Bra
+ [\x00-\x08\x0b\x0e-\x1f!-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/a(?i)b/D
+/a(?i)b/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 a
- 5 01 Opt
- 7 NC b
- 9 9 Ket
- 12 End
+ Bra
+ a
+ 01 Opt
+ NC b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -2759,22 +2759,22 @@ Need char = 'b' (caseless)
0: ab
aB
0: aB
- *** Failers
+ *** Failers
No match
- AB
+ AB
No match
-/(a(?i)b)/D
+/(a(?i)b)/DZ
------------------------------------------------------------------
- 0 19 Bra 0
- 3 11 Bra 1
- 8 a
- 10 01 Opt
- 12 NC b
- 14 11 Ket
- 17 00 Opt
- 19 19 Ket
- 22 End
+ Bra
+ CBra 1
+ a
+ 01 Opt
+ NC b
+ Ket
+ 00 Opt
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -2786,17 +2786,17 @@ Need char = 'b' (caseless)
aB
0: aB
1: aB
- *** Failers
+ *** Failers
No match
- AB
+ AB
No match
-
-/ (?i)abc/IxD
+
+/ (?i)abc/IxDZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 NC abc
- 9 9 Ket
- 12 End
+ Bra
+ NC abc
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless extended
@@ -2804,47 +2804,47 @@ First char = 'a' (caseless)
Need char = 'c' (caseless)
/#this is a comment
- (?i)abc/IxD
+ (?i)abc/IxDZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 NC abc
- 9 9 Ket
- 12 End
+ Bra
+ NC abc
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless extended
First char = 'a' (caseless)
Need char = 'c' (caseless)
-/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/D
+/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/DZ
------------------------------------------------------------------
- 0 603 Bra 0
- 3 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
-603 603 Ket
-606 End
+ Bra
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = '1'
Need char = '0'
-/\Q123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/D
+/\Q123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/DZ
------------------------------------------------------------------
- 0 603 Bra 0
- 3 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
-603 603 Ket
-606 End
+ Bra
+ 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = '1'
Need char = '0'
-/\Q\E/D
+/\Q\E/DZ
------------------------------------------------------------------
- 0 3 Bra 0
- 3 3 Ket
- 6 End
+ Bra
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -2853,36 +2853,36 @@ No need char
\
0:
-/\Q\Ex/D
+/\Q\Ex/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 x
- 5 5 Ket
- 8 End
+ Bra
+ x
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = 'x'
No need char
-/ \Q\E/D
+/ \Q\E/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3
- 5 5 Ket
- 8 End
+ Bra
+
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = ' '
No need char
-/a\Q\E/D
+/a\Q\E/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 a
- 5 5 Ket
- 8 End
+ Bra
+ a
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -2892,15 +2892,15 @@ No need char
0: a
bca
0: a
- bac
+ bac
0: a
-/a\Q\Eb/D
+/a\Q\Eb/DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 ab
- 7 7 Ket
- 10 End
+ Bra
+ ab
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -2909,25 +2909,25 @@ Need char = 'b'
abc
0: ab
-/\Q\Eabc/D
+/\Q\Eabc/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 abc
- 9 9 Ket
- 12 End
+ Bra
+ abc
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = 'a'
Need char = 'c'
-/x*+\w/D
+/x*+\w/DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 x*+
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ x*+
+ \w
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -2938,25 +2938,25 @@ No need char
0: F
xxxxx
No match
-
-/x?+/D
+
+/x?+/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 x?+
- 5 5 Ket
- 8 End
+ Bra
+ x?+
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/x++/D
+/x++/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 x++
- 5 5 Ket
- 8 End
+ Bra
+ x++
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -2964,15 +2964,15 @@ No options
First char = 'x'
No need char
-/x{1,3}+/D
+/x{1,3}+/DZ
------------------------------------------------------------------
- 0 15 Bra 0
- 3 9 Once
- 6 x
- 8 x{0,2}
- 12 9 Ket
- 15 15 Ket
- 18 End
+ Bra
+ Once
+ x
+ x{0,2}
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -2980,17 +2980,17 @@ No options
First char = 'x'
No need char
-/(x)*+/D
+/(x)*+/DZ
------------------------------------------------------------------
- 0 20 Bra 0
- 3 14 Once
- 6 Brazero
- 7 7 Bra 1
- 12 x
- 14 7 KetRmax
- 17 14 Ket
- 20 20 Ket
- 23 End
+ Bra
+ Once
+ Brazero
+ CBra 1
+ x
+ KetRmax
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -3010,7 +3010,7 @@ No need char
No match
this is not a line with only words and spaces!
No match
-
+
/(\d++)(\w)/I
Capturing subpattern count = 2
Partial matching not supported
@@ -3023,7 +3023,7 @@ No need char
2: a
*** Failers
No match
- 12345+
+ 12345+
No match
/a++b/I
@@ -3064,8 +3064,8 @@ No need char
((abc(ade)ufh()()x
0: abc(ade)ufh()()x
1: x
-
-/\(([^()]++|\([^()]+\))+\)/I
+
+/\(([^()]++|\([^()]+\))+\)/I
Capturing subpattern count = 1
Partial matching not supported
No options
@@ -3079,29 +3079,29 @@ Need char = ')'
1: xyz
*** Failers
No match
- ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-No match
-
-/(abc){1,3}+/D
-------------------------------------------------------------------
- 0 59 Bra 0
- 3 53 Once
- 6 11 Bra 1
- 11 abc
- 17 11 Ket
- 20 Brazero
- 21 32 Bra 0
- 24 11 Bra 1
- 29 abc
- 35 11 Ket
- 38 Brazero
- 39 11 Bra 1
- 44 abc
- 50 11 Ket
- 53 32 Ket
- 56 53 Ket
- 59 59 Ket
- 62 End
+ ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+
+/(abc){1,3}+/DZ
+------------------------------------------------------------------
+ Bra
+ Once
+ CBra 1
+ abc
+ Ket
+ Brazero
+ Bra
+ CBra 1
+ abc
+ Ket
+ Brazero
+ CBra 1
+ abc
+ Ket
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -3120,14 +3120,14 @@ Failed: nothing to repeat at offset 7
/a{2,3}?+b/IU
Failed: nothing to repeat at offset 7
-/x(?U)a++b/D
+/x(?U)a++b/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 x
- 5 a++
- 7 b
- 9 9 Ket
- 12 End
+ Bra
+ x
+ a++
+ b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -3137,14 +3137,14 @@ Need char = 'b'
xaaaab
0: xaaaab
-/(?U)xa++b/D
+/(?U)xa++b/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 x
- 5 a++
- 7 b
- 9 9 Ket
- 12 End
+ Bra
+ x
+ a++
+ b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -3154,26 +3154,26 @@ Need char = 'b'
xaaaab
0: xaaaab
-/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/D
-------------------------------------------------------------------
- 0 116 Bra 0
- 3 ^
- 4 109 Bra 1
- 9 7 Bra 2
- 14 a+
- 16 7 Ket
- 19 39 Bra 3
- 24 [ab]+?
- 58 39 Ket
- 61 39 Bra 4
- 66 [bc]+
-100 39 Ket
-103 7 Bra 5
-108 \w*
-110 7 Ket
-113 109 Ket
-116 116 Ket
-119 End
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/DZ
+------------------------------------------------------------------
+ Bra
+ ^
+ CBra 1
+ CBra 2
+ a+
+ Ket
+ CBra 3
+ [ab]+?
+ Ket
+ CBra 4
+ [bc]+
+ Ket
+ CBra 5
+ \w*
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 5
Partial matching not supported
@@ -3181,15 +3181,15 @@ Options: anchored
No first char
No need char
-/^x(?U)a+b/D
+/^x(?U)a+b/DZ
------------------------------------------------------------------
- 0 10 Bra 0
- 3 ^
- 4 x
- 6 a++
- 8 b
- 10 10 Ket
- 13 End
+ Bra
+ ^
+ x
+ a++
+ b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -3197,17 +3197,17 @@ Options: anchored
No first char
Need char = 'b'
-/^x(?U)(a+)b/D
+/^x(?U)(a+)b/DZ
------------------------------------------------------------------
- 0 18 Bra 0
- 3 ^
- 4 x
- 6 7 Bra 1
- 11 a+?
- 13 7 Ket
- 16 b
- 18 18 Ket
- 21 End
+ Bra
+ ^
+ x
+ CBra 1
+ a+?
+ Ket
+ b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -3248,39 +3248,36 @@ Failed: missing terminating ] for character class at offset 3
/[[:space:]/I
Failed: missing terminating ] for character class at offset 10
-/[\s]/IDM
-Memory allocation (code space): 40
+/[\s]/IDZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x09\x0a\x0c\x0d ]
- 36 36 Ket
- 39 End
+ Bra
+ [\x09\x0a\x0c\x0d ]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[[:space:]]/IDM
-Memory allocation (code space): 40
+/[[:space:]]/IDZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x09-\x0d ]
- 36 36 Ket
- 39 End
+ Bra
+ [\x09-\x0d ]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[[:space:]abcde]/IDM
-Memory allocation (code space): 40
+/[[:space:]abcde]/IDZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x09-\x0d a-e]
- 36 36 Ket
- 39 End
+ Bra
+ [\x09-\x0d a-e]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -3301,37 +3298,35 @@ Need char = '>'
0: <abc <123> hij>
<abc <def> hij>
0: <def>
- <abc<>def>
+ <abc<>def>
0: <abc<>def>
- <abc<>
+ <abc<>
0: <>
*** Failers
No match
<abc
No match
-|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
-Memory allocation (code space): 826
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDZ
------------------------------------------------------------------
- 0 822 Bra 0
- 3 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
-821 \b
-822 822 Ket
-825 End
+ Bra
+ 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
+ \b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = '8'
Need char = 'X'
-|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
-Memory allocation (code space): 816
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDZ
------------------------------------------------------------------
- 0 812 Bra 0
- 3 $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
-811 \b
-812 812 Ket
-815 End
+ Bra
+ $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDD<EjmhUZ?.akp2dF>qmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X
+ \b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -3352,7 +3347,7 @@ Partial matching not supported
No options
First char at start or follows newline
No need char
-
+
/(.*)\d+\1/Is
Capturing subpattern count = 1
Max back reference = 1
@@ -3387,7 +3382,7 @@ No need char
0: bc123bc
1: bc
2: bc
-
+
/a[b]/I
Capturing subpattern count = 0
No options
@@ -3443,26 +3438,26 @@ No options
No first char
Need char = 'a'
-/(?(1)ab|ac)/I
-Capturing subpattern count = 0
+/(?(1)ab|ac)(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
No need char
-/(?(1)abz|acz)/I
-Capturing subpattern count = 0
+/(?(1)abz|acz)(.)/I
+Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'z'
-/(?(1)abz)/I
-Capturing subpattern count = 0
+/(?(1)abz)(.)/I
+Capturing subpattern count = 1
No options
No first char
No need char
-/(?(1)abz)123/I
-Capturing subpattern count = 0
+/(?(1)abz)(1)23/I
+Capturing subpattern count = 1
No options
No first char
Need char = '3'
@@ -3536,11 +3531,11 @@ First char at start or follows newline
Need char = 'a'
abcde
0: a
- xy\nabc
+ xy\nabc
0: a
- *** Failers
+ *** Failers
No match
- xyabc
+ xyabc
No match
/c|abc/I
@@ -3572,7 +3567,7 @@ Need char = 'f'
--->abcdef
0 ^ ^ d
0: abcdef
- 1234abcdef
+ 1234abcdef
--->1234abcdef
0 ^ ^ d
0: abcdef
@@ -3580,7 +3575,7 @@ Need char = 'f'
No match
abcxyz
No match
- abcxyzf
+ abcxyzf
--->abcxyzf
0 ^ ^ d
No match
@@ -3595,8 +3590,8 @@ Need char = 'f'
0 ^ ^ d
1 ^ ^ f
0: abcdef
-
-/(?C1)\dabc(?C2)def/I
+
+/(?C1)\dabc(?C2)def/I
Capturing subpattern count = 0
No options
No first char
@@ -3611,7 +3606,7 @@ Need char = 'f'
0: 4abcdef
*** Failers
No match
- abcdef
+ abcdef
--->abcdef
1 ^ \d
1 ^ \d
@@ -3620,7 +3615,7 @@ No match
1 ^ \d
1 ^ \d
No match
-
+
/(?C255)ab/I
Capturing subpattern count = 0
No options
@@ -3630,7 +3625,7 @@ Need char = 'b'
/(?C256)ab/I
Failed: number after (?C is > 255 at offset 6
-/(?Cab)xx/I
+/(?Cab)xx/I
Failed: closing ) for (?C expected at offset 3
/(?C12vr)x/I
@@ -3659,7 +3654,7 @@ Need char = 'f'
1 ^ ^ f
0: abcdef
1: abc
- 123abcdef\C+
+ 123abcdef\C+
Callout 0: last capture = 1
0: <unset>
1: abc
@@ -3672,17 +3667,17 @@ Callout 1: last capture = 1
^ ^ f
0: abcdef
1: abc
- 123abcdef\C-
+ 123abcdef\C-
0: abcdef
1: abc
*** Failers
No match
- 123abcdef\C!1
+ 123abcdef\C!1
--->123abcdef
0 ^ ^ d
1 ^ ^ f
No match
-
+
/(?C0)(abc(?C1))*/I
Capturing subpattern count = 1
No options
@@ -3696,7 +3691,7 @@ No need char
1 ^ ^ )
0: abcabcabc
1: abc
- abcabc\C!1!3
+ abcabc\C!1!3
--->abcabc
0 ^ (abc(?C1))*
1 ^ ^ )
@@ -3707,7 +3702,7 @@ No need char
--->*** Failers
0 ^ (abc(?C1))*
0:
- abcabcabc\C!1!3
+ abcabcabc\C!1!3
--->abcabcabc
0 ^ (abc(?C1))*
1 ^ ^ )
@@ -3741,7 +3736,7 @@ Callout 0: last capture = 1
^ ^ )
0: 123456
1: 456
- 123456789\C+
+ 123456789\C+
Callout 0: last capture = -1
0: <unset>
--->123456789
@@ -3813,13 +3808,13 @@ Callout 0: last capture = 1
^ a
0: abcdef
1: abc
-
+
/(?!(abc)(?C1)d)(?C2)abcxyz/I
Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'z'
- abcxyz\C+
+ abcxyz\C+
Callout 1: last capture = 1
0: <unset>
1: abc
@@ -3844,7 +3839,7 @@ Callout 0: last capture = 1
^ )
0: xyz
1: abc
-
+
/a(b+)(c*)(?C1)/I
Capturing subpattern count = 2
Partial matching not supported
@@ -3896,8 +3891,8 @@ Callout data = 1
1 ^ ^
Callout data = 1
No match
-
-/(?C)abc/I
+
+/(?C)abc/I
Capturing subpattern count = 0
No options
First char = 'a'
@@ -3954,7 +3949,7 @@ No need char
3: xxab
*** Failers
No match
- xyab
+ xyab
No match
/(ab|(bc|(de|(?1))))/I
@@ -3974,12 +3969,12 @@ No need char
a(b)c
0: a(b)c
1: c
- a(b(c))d
+ a(b(c))d
0: a(b(c))d
1: d
*** Failers)
No match
- a(b(c)d
+ a(b(c)d
No match
/^>abc>([^()]|\((?1)*\))*<xyz<$/I
@@ -3997,36 +3992,36 @@ Need char = '<'
0: >abc>(1(2)3)<xyz<
1: (1(2)3)
-/(a(?1)b)/D
+/(a(?1)b)/DZ
------------------------------------------------------------------
- 0 24 Bra 0
- 3 18 Bra 1
- 8 a
- 10 6 Once
- 13 3 Recurse
- 16 6 Ket
- 19 b
- 21 18 Ket
- 24 24 Ket
- 27 End
+ Bra
+ CBra 1
+ a
+ Once
+ Recurse
+ Ket
+ b
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
First char = 'a'
Need char = 'b'
-/(a(?1)+b)/D
+/(a(?1)+b)/DZ
------------------------------------------------------------------
- 0 24 Bra 0
- 3 18 Bra 1
- 8 a
- 10 6 Once
- 13 3 Recurse
- 16 6 KetRmax
- 19 b
- 21 18 Ket
- 24 24 Ket
- 27 End
+ Bra
+ CBra 1
+ a
+ Once
+ Recurse
+ KetRmax
+ b
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -4056,7 +4051,7 @@ No need char
2: <unset>
3: A man, a plan, a canal: Panama
4: A
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
0: Able was I ere I saw Elba.
1: <unset>
2: <unset>
@@ -4064,9 +4059,9 @@ No need char
4: A
*** Failers
No match
- The quick brown fox
+ The quick brown fox
No match
-
+
/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/I
Capturing subpattern count = 2
Partial matching not supported
@@ -4087,7 +4082,7 @@ No need char
No match
((2+2)*-3)-7)
No match
-
+
/^(x(y|(?1){2})z)/I
Capturing subpattern count = 2
Options: anchored
@@ -4097,7 +4092,7 @@ No need char
0: xyz
1: xyz
2: y
- xxyzxyzz
+ xxyzxyzz
0: xxyzxyzz
1: xxyzxyzz
2: xyzxyz
@@ -4105,7 +4100,7 @@ No need char
No match
xxyzz
No match
- xxyzxyzxyzz
+ xxyzxyzxyzz
No match
/((< (?: (?(R) \d++ | [^<>]*+) | (?2)) * >))/Ix
@@ -4130,11 +4125,11 @@ Need char = '>'
0: <def>
1: <def>
2: <def>
- <abc<>def>
+ <abc<>def>
0: <abc<>def>
1: <abc<>def>
2: <abc<>def>
- <abc<>
+ <abc<>
0: <>
1: <>
2: <>
@@ -4169,7 +4164,7 @@ No need char
a=b
0: a=b
1: a
- a=bc
+ a=bc
0: a=bc
1: a
@@ -4186,26 +4181,26 @@ No need char
0: a=b
1: a
2: b
- a=bc
+ a=bc
0: a=bc
1: a
2: c
-/a(?P<name1>b|c)d(?P<longername2>e)/D
-------------------------------------------------------------------
- 0 32 Bra 0
- 3 a
- 5 7 Bra 1
- 10 b
- 12 5 Alt
- 15 c
- 17 12 Ket
- 20 d
- 22 7 Bra 2
- 27 e
- 29 7 Ket
- 32 32 Ket
- 35 End
+/a(?P<name1>b|c)d(?P<longername2>e)/DZ
+------------------------------------------------------------------
+ Bra
+ a
+ CBra 1
+ b
+ Alt
+ c
+ Ket
+ d
+ CBra 2
+ e
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -4218,28 +4213,28 @@ Need char = 'e'
0: abde
1: b
2: e
- acde
+ acde
0: acde
1: c
2: e
-/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/D
-------------------------------------------------------------------
- 0 41 Bra 0
- 3 25 Bra 0
- 6 a
- 8 17 Bra 1
- 13 c
- 15 7 Bra 2
- 20 d
- 22 7 Ket
- 25 17 Ket
- 28 25 Ket
- 31 7 Bra 3
- 36 a
- 38 7 Ket
- 41 41 Ket
- 44 End
+/(?:a(?P<c>c(?P<d>d)))(?P<a>a)/DZ
+------------------------------------------------------------------
+ Bra
+ Bra
+ a
+ CBra 1
+ c
+ CBra 2
+ d
+ Ket
+ Ket
+ Ket
+ CBra 3
+ a
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 3
Named capturing subpatterns:
@@ -4250,23 +4245,23 @@ No options
First char = 'a'
Need char = 'a'
-/(?P<a>a)...(?P=a)bbb(?P>a)d/D
-------------------------------------------------------------------
- 0 36 Bra 0
- 3 7 Bra 1
- 8 a
- 10 7 Ket
- 13 Any
- 14 Any
- 15 Any
- 16 \1
- 19 bbb
- 25 6 Once
- 28 3 Recurse
- 31 6 Ket
- 34 d
- 36 36 Ket
- 39 End
+/(?P<a>a)...(?P=a)bbb(?P>a)d/DZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ a
+ Ket
+ Any
+ Any
+ Any
+ \1
+ bbb
+ Once
+ Recurse
+ Ket
+ d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Max back reference = 1
@@ -4304,7 +4299,7 @@ No need char
2: <unset>
3: A man, a plan, a canal: Panama
4: A
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
0: Able was I ere I saw Elba.
1: <unset>
2: <unset>
@@ -4312,9 +4307,9 @@ No need char
4: A
*** Failers
No match
- The quick brown fox
+ The quick brown fox
No match
-
+
/((?(R)a|b))\1(?1)?/I
Capturing subpattern count = 1
Max back reference = 1
@@ -4324,7 +4319,7 @@ No need char
bb
0: bb
1: b
- bbaa
+ bbaa
0: bba
1: b
@@ -4413,17 +4408,17 @@ Options: dotall
No first char
No need char
-/(a)(bc)/IND
+/(a)(bc)/INDZ
------------------------------------------------------------------
- 0 21 Bra 0
- 3 5 Bra 0
- 6 a
- 8 5 Ket
- 11 7 Bra 0
- 14 bc
- 18 7 Ket
- 21 21 Ket
- 24 End
+ Bra
+ Bra
+ a
+ Ket
+ Bra
+ bc
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: no_auto_capture
@@ -4432,17 +4427,17 @@ Need char = 'c'
abc
0: abc
-/(?P<one>a)(bc)/IND
+/(?P<one>a)(bc)/INDZ
------------------------------------------------------------------
- 0 23 Bra 0
- 3 7 Bra 1
- 8 a
- 10 7 Ket
- 13 7 Bra 0
- 16 bc
- 20 7 Ket
- 23 23 Ket
- 26 End
+ Bra
+ CBra 1
+ a
+ Ket
+ Bra
+ bc
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Named capturing subpatterns:
@@ -4454,17 +4449,17 @@ Need char = 'c'
0: abc
1: a
-/(a)(?P<named>bc)/IND
+/(a)(?P<named>bc)/INDZ
------------------------------------------------------------------
- 0 23 Bra 0
- 3 5 Bra 0
- 6 a
- 8 5 Ket
- 11 9 Bra 1
- 16 bc
- 20 9 Ket
- 23 23 Ket
- 26 End
+ Bra
+ Bra
+ a
+ Ket
+ CBra 1
+ bc
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Named capturing subpatterns:
@@ -4540,22 +4535,22 @@ Need char = 'h'
2: gh
C cd (2) one
C gh (2) two
- abcdefgh\Cthree
+ abcdefgh\Cthree
no parentheses with name "three"
0: abcdefgh
1: cd
2: gh
copy substring three failed -7
-/(?P<Tes>)(?P<Test>)/D
+/(?P<Tes>)(?P<Test>)/DZ
------------------------------------------------------------------
- 0 19 Bra 0
- 3 5 Bra 1
- 8 5 Ket
- 11 5 Bra 2
- 16 5 Ket
- 19 19 Ket
- 22 End
+ Bra
+ CBra 1
+ Ket
+ CBra 2
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -4565,15 +4560,15 @@ No options
No first char
No need char
-/(?P<Test>)(?P<Tes>)/D
+/(?P<Test>)(?P<Tes>)/DZ
------------------------------------------------------------------
- 0 19 Bra 0
- 3 5 Bra 1
- 8 5 Ket
- 11 5 Bra 2
- 16 5 Ket
- 19 19 Ket
- 22 End
+ Bra
+ CBra 1
+ Ket
+ CBra 2
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -4623,7 +4618,7 @@ Need char = ']'
3: ,4234
*** Failers
No match
- []
+ []
No match
"\[((?P<elem>\d+)(,(?P>elem))*)?\]"I
@@ -4639,96 +4634,96 @@ Need char = ']'
1: 10,20,30,5,5,4,4,2,43,23,4234
2: 10
3: ,4234
- []
+ []
0: []
-/(a(b(?2)c))?/D
-------------------------------------------------------------------
- 0 35 Bra 0
- 3 Brazero
- 4 28 Bra 1
- 9 a
- 11 18 Bra 2
- 16 b
- 18 6 Once
- 21 11 Recurse
- 24 6 Ket
- 27 c
- 29 18 Ket
- 32 28 Ket
- 35 35 Ket
- 38 End
+/(a(b(?2)c))?/DZ
+------------------------------------------------------------------
+ Bra
+ Brazero
+ CBra 1
+ a
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
No options
No first char
No need char
-/(a(b(?2)c))*/D
+/(a(b(?2)c))*/DZ
------------------------------------------------------------------
- 0 35 Bra 0
- 3 Brazero
- 4 28 Bra 1
- 9 a
- 11 18 Bra 2
- 16 b
- 18 6 Once
- 21 11 Recurse
- 24 6 Ket
- 27 c
- 29 18 Ket
- 32 28 KetRmax
- 35 35 Ket
- 38 End
+ Bra
+ Brazero
+ CBra 1
+ a
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ KetRmax
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
No options
No first char
No need char
-/(a(b(?2)c)){0,2}/D
-------------------------------------------------------------------
- 0 73 Bra 0
- 3 Brazero
- 4 66 Bra 0
- 7 28 Bra 1
- 12 a
- 14 18 Bra 2
- 19 b
- 21 6 Once
- 24 14 Recurse
- 27 6 Ket
- 30 c
- 32 18 Ket
- 35 28 Ket
- 38 Brazero
- 39 28 Bra 1
- 44 a
- 46 18 Bra 2
- 51 b
- 53 6 Once
- 56 14 Recurse
- 59 6 Ket
- 62 c
- 64 18 Ket
- 67 28 Ket
- 70 66 Ket
- 73 73 Ket
- 76 End
+/(a(b(?2)c)){0,2}/DZ
+------------------------------------------------------------------
+ Bra
+ Brazero
+ Bra
+ CBra 1
+ a
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Brazero
+ CBra 1
+ a
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
No options
No first char
No need char
-/[ab]{1}+/D
+/[ab]{1}+/DZ
------------------------------------------------------------------
- 0 47 Bra 0
- 3 41 Once
- 6 [ab]{1,1}
- 44 41 Ket
- 47 47 Ket
- 50 End
+ Bra
+ Once
+ [ab]{1,1}
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -4755,15 +4750,15 @@ Study returned NULL
Baby Bjorn Active Carrier - With free SHIPPING!!
0: Baby Bjorn Active Carrier - With free SHIPPING!!
1: Baby Bjorn Active Carrier - With free SHIPPING!!
-
-/a*.*b/ISD
+
+/a*.*b/ISDZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 a*
- 5 Any*
- 7 b
- 9 9 Ket
- 12 End
+ Bra
+ a*
+ Any*
+ b
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -4772,19 +4767,19 @@ No first char
Need char = 'b'
Study returned NULL
-/(a|b)*.?c/ISD
+/(a|b)*.?c/ISDZ
------------------------------------------------------------------
- 0 23 Bra 0
- 3 Brazero
- 4 7 Bra 1
- 9 a
- 11 5 Alt
- 14 b
- 16 12 KetRmax
- 19 Any?
- 21 c
- 23 23 Ket
- 26 End
+ Bra
+ Brazero
+ CBra 1
+ a
+ Alt
+ b
+ KetRmax
+ Any?
+ c
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
No options
@@ -4792,38 +4787,38 @@ No first char
Need char = 'c'
Study returned NULL
-/abc(?C255)de(?C)f/D
+/abc(?C255)de(?C)f/DZ
------------------------------------------------------------------
- 0 27 Bra 0
- 3 abc
- 9 Callout 255 10 1
- 15 de
- 19 Callout 0 16 1
- 25 f
- 27 27 Ket
- 30 End
+ Bra
+ abc
+ Callout 255 10 1
+ de
+ Callout 0 16 1
+ f
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
First char = 'a'
Need char = 'f'
-/abcde/ICD
+/abcde/ICDZ
------------------------------------------------------------------
- 0 49 Bra 0
- 3 Callout 255 0 1
- 9 a
- 11 Callout 255 1 1
- 17 b
- 19 Callout 255 2 1
- 25 c
- 27 Callout 255 3 1
- 33 d
- 35 Callout 255 4 1
- 41 e
- 43 Callout 255 5 0
- 49 49 Ket
- 52 End
+ Bra
+ Callout 255 0 1
+ a
+ Callout 255 1 1
+ b
+ Callout 255 2 1
+ c
+ Callout 255 3 1
+ d
+ Callout 255 4 1
+ e
+ Callout 255 5 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options:
@@ -4838,7 +4833,7 @@ Need char = 'e'
+4 ^ ^ e
+5 ^ ^
0: abcde
- abcdfe
+ abcdfe
--->abcdfe
+0 ^ a
+1 ^^ b
@@ -4846,17 +4841,17 @@ Need char = 'e'
+3 ^ ^ d
+4 ^ ^ e
No match
-
-/a*b/ICD
+
+/a*b/ICDZ
------------------------------------------------------------------
- 0 25 Bra 0
- 3 Callout 255 0 2
- 9 a*+
- 11 Callout 255 2 1
- 17 b
- 19 Callout 255 3 0
- 25 25 Ket
- 28 End
+ Bra
+ Callout 255 0 2
+ a*+
+ Callout 255 2 1
+ b
+ Callout 255 3 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -4875,7 +4870,7 @@ Need char = 'b'
+2 ^ ^ b
+3 ^ ^
0: aaaab
- aaaacb
+ aaaacb
--->aaaacb
+0 ^ a*
+2 ^ ^ b
@@ -4892,16 +4887,16 @@ Need char = 'b'
+3 ^^
0: b
-/a+b/ICD
+/a+b/ICDZ
------------------------------------------------------------------
- 0 25 Bra 0
- 3 Callout 255 0 2
- 9 a++
- 11 Callout 255 2 1
- 17 b
- 19 Callout 255 3 0
- 25 25 Ket
- 28 End
+ Bra
+ Callout 255 0 2
+ a++
+ Callout 255 2 1
+ b
+ Callout 255 3 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -4920,7 +4915,7 @@ Need char = 'b'
+2 ^ ^ b
+3 ^ ^
0: aaaab
- aaaacb
+ aaaacb
--->aaaacb
+0 ^ a+
+2 ^ ^ b
@@ -4932,32 +4927,32 @@ Need char = 'b'
+2 ^^ b
No match
-/(abc|def)x/ICD
-------------------------------------------------------------------
- 0 94 Bra 0
- 3 Callout 255 0 9
- 9 35 Bra 1
- 14 Callout 255 1 1
- 20 a
- 22 Callout 255 2 1
- 28 b
- 30 Callout 255 3 1
- 36 c
- 38 Callout 255 4 0
- 44 33 Alt
- 47 Callout 255 5 1
- 53 d
- 55 Callout 255 6 1
- 61 e
- 63 Callout 255 7 1
- 69 f
- 71 Callout 255 8 0
- 77 68 Ket
- 80 Callout 255 9 1
- 86 x
- 88 Callout 255 10 0
- 94 94 Ket
- 97 End
+/(abc|def)x/ICDZ
+------------------------------------------------------------------
+ Bra
+ Callout 255 0 9
+ CBra 1
+ Callout 255 1 1
+ a
+ Callout 255 2 1
+ b
+ Callout 255 3 1
+ c
+ Callout 255 4 0
+ Alt
+ Callout 255 5 1
+ d
+ Callout 255 6 1
+ e
+ Callout 255 7 1
+ f
+ Callout 255 8 0
+ Ket
+ Callout 255 9 1
+ x
+ Callout 255 10 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Options:
@@ -5064,7 +5059,7 @@ No need char
+12 ^ ^
0: abcdabcd
1: cd
- abcdcdcdcdcd
+ abcdcdcdcdcd
--->abcdcdcdcdcd
+0 ^ (ab|cd){3,4}
+1 ^ a
@@ -5086,34 +5081,34 @@ No need char
0: abcdcdcd
1: cd
-/([ab]{,4}c|xy)/ICD
-------------------------------------------------------------------
- 0 133 Bra 0
- 3 Callout 255 0 14
- 9 90 Bra 1
- 14 Callout 255 1 4
- 20 [ab]
- 53 Callout 255 5 1
- 59 {
- 61 Callout 255 6 1
- 67 ,
- 69 Callout 255 7 1
- 75 4
- 77 Callout 255 8 1
- 83 }
- 85 Callout 255 9 1
- 91 c
- 93 Callout 255 10 0
- 99 25 Alt
-102 Callout 255 11 1
-108 x
-110 Callout 255 12 1
-116 y
-118 Callout 255 13 0
-124 115 Ket
-127 Callout 255 14 0
-133 133 Ket
-136 End
+/([ab]{,4}c|xy)/ICDZ
+------------------------------------------------------------------
+ Bra
+ Callout 255 0 14
+ CBra 1
+ Callout 255 1 4
+ [ab]
+ Callout 255 5 1
+ {
+ Callout 255 6 1
+ ,
+ Callout 255 7 1
+ 4
+ Callout 255 8 1
+ }
+ Callout 255 9 1
+ c
+ Callout 255 10 0
+ Alt
+ Callout 255 11 1
+ x
+ Callout 255 12 1
+ y
+ Callout 255 13 0
+ Ket
+ Callout 255 14 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Options:
@@ -5261,85 +5256,85 @@ No need char
+11 ^ x
No match
-/([ab]{1,4}c|xy){4,5}?123/ICD
-------------------------------------------------------------------
- 0 495 Bra 0
- 3 Callout 255 0 21
- 9 63 Bra 1
- 14 Callout 255 1 9
- 20 [ab]{1,4}
- 58 Callout 255 10 1
- 64 c
- 66 Callout 255 11 0
- 72 25 Alt
- 75 Callout 255 12 1
- 81 x
- 83 Callout 255 13 1
- 89 y
- 91 Callout 255 14 0
- 97 88 Ket
-100 63 Bra 1
-105 Callout 255 1 9
-111 [ab]{1,4}
-149 Callout 255 10 1
-155 c
-157 Callout 255 11 0
-163 25 Alt
-166 Callout 255 12 1
-172 x
-174 Callout 255 13 1
-180 y
-182 Callout 255 14 0
-188 88 Ket
-191 63 Bra 1
-196 Callout 255 1 9
-202 [ab]{1,4}
-240 Callout 255 10 1
-246 c
-248 Callout 255 11 0
-254 25 Alt
-257 Callout 255 12 1
-263 x
-265 Callout 255 13 1
-271 y
-273 Callout 255 14 0
-279 88 Ket
-282 63 Bra 1
-287 Callout 255 1 9
-293 [ab]{1,4}
-331 Callout 255 10 1
-337 c
-339 Callout 255 11 0
-345 25 Alt
-348 Callout 255 12 1
-354 x
-356 Callout 255 13 1
-362 y
-364 Callout 255 14 0
-370 88 Ket
-373 Braminzero
-374 63 Bra 1
-379 Callout 255 1 9
-385 [ab]{1,4}
-423 Callout 255 10 1
-429 c
-431 Callout 255 11 0
-437 25 Alt
-440 Callout 255 12 1
-446 x
-448 Callout 255 13 1
-454 y
-456 Callout 255 14 0
-462 88 Ket
-465 Callout 255 21 1
-471 1
-473 Callout 255 22 1
-479 2
-481 Callout 255 23 1
-487 3
-489 Callout 255 24 0
-495 495 Ket
-498 End
+/([ab]{1,4}c|xy){4,5}?123/ICDZ
+------------------------------------------------------------------
+ Bra
+ Callout 255 0 21
+ CBra 1
+ Callout 255 1 9
+ [ab]{1,4}
+ Callout 255 10 1
+ c
+ Callout 255 11 0
+ Alt
+ Callout 255 12 1
+ x
+ Callout 255 13 1
+ y
+ Callout 255 14 0
+ Ket
+ CBra 1
+ Callout 255 1 9
+ [ab]{1,4}
+ Callout 255 10 1
+ c
+ Callout 255 11 0
+ Alt
+ Callout 255 12 1
+ x
+ Callout 255 13 1
+ y
+ Callout 255 14 0
+ Ket
+ CBra 1
+ Callout 255 1 9
+ [ab]{1,4}
+ Callout 255 10 1
+ c
+ Callout 255 11 0
+ Alt
+ Callout 255 12 1
+ x
+ Callout 255 13 1
+ y
+ Callout 255 14 0
+ Ket
+ CBra 1
+ Callout 255 1 9
+ [ab]{1,4}
+ Callout 255 10 1
+ c
+ Callout 255 11 0
+ Alt
+ Callout 255 12 1
+ x
+ Callout 255 13 1
+ y
+ Callout 255 14 0
+ Ket
+ Braminzero
+ CBra 1
+ Callout 255 1 9
+ [ab]{1,4}
+ Callout 255 10 1
+ c
+ Callout 255 11 0
+ Alt
+ Callout 255 12 1
+ x
+ Callout 255 13 1
+ y
+ Callout 255 14 0
+ Ket
+ Callout 255 21 1
+ 1
+ Callout 255 22 1
+ 2
+ Callout 255 23 1
+ 3
+ Callout 255 24 0
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -5380,8 +5375,8 @@ No first char
No need char
ab cd\>1
0: cd
-
-/\b.*/Is
+
+/\b.*/Is
Capturing subpattern count = 0
Partial matching not supported
Options: dotall
@@ -5389,14 +5384,14 @@ No first char
No need char
ab cd\>1
0: cd
-
+
/(?!.bcd).*/I
Capturing subpattern count = 0
Partial matching not supported
No options
No first char
No need char
- Xbcd12345
+ Xbcd12345
0: bcd12345
/abcde/I
@@ -5410,7 +5405,7 @@ Partial match
Partial match
abcd\P
Partial match
- abcde\P
+ abcde\P
0: abcde
the quick brown abc\P
Partial match
@@ -5418,7 +5413,7 @@ Partial match
No match
the quick brown abxyz fox\P
No match
-
+
"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"I
Capturing subpattern count = 3
Options: anchored
@@ -5433,7 +5428,7 @@ Need char = '/'
1: 13
2: 5
3: 20
- 02/05/09\P
+ 02/05/09\P
0: 02/05/09
1: 02
2: 05
@@ -5443,7 +5438,7 @@ Partial match
Partial match
1/2/0\P
Partial match
- 1/2/04\P
+ 1/2/04\P
0: 1/2/04
1: 1
2: 2
@@ -5451,7 +5446,7 @@ Partial match
Partial match
02/\P
Partial match
- 02/0\P
+ 02/0\P
Partial match
02/1\P
Partial match
@@ -5467,11 +5462,11 @@ No match
No match
0/1/2003\P
No match
- 0/\P
+ 0/\P
No match
- 02/0/\P
+ 02/0/\P
No match
- 02/13\P
+ 02/13\P
No match
/0{0,2}ABC/I
@@ -5480,14 +5475,14 @@ Partial matching not supported
No options
No first char
Need char = 'C'
-
+
/\d{3,}ABC/I
Capturing subpattern count = 0
Partial matching not supported
No options
No first char
Need char = 'C'
-
+
/\d*ABC/I
Capturing subpattern count = 0
Partial matching not supported
@@ -5517,7 +5512,7 @@ Partial match
Partial match
c12\P
Partial match
- c123\P
+ c123\P
0: c123
/^(?:\d){3,5}X/I
@@ -5537,13 +5532,13 @@ Partial match
0: 1234X
12345\P
Partial match
- 12345X
+ 12345X
0: 12345X
- *** Failers
+ *** Failers
No match
- 1X
+ 1X
No match
- 123456\P
+ 123456\P
No match
/abc/I>testsavedregex
@@ -5561,7 +5556,7 @@ No study data
No match
bca
No match
-
+
/abc/IF>testsavedregex
Capturing subpattern count = 0
No options
@@ -5595,9 +5590,9 @@ Study data loaded from testsavedregex
** Failers
0: a
1: a
- def
+ def
No match
-
+
/(a|b)/ISF>testsavedregex
Capturing subpattern count = 1
No options
@@ -5615,9 +5610,9 @@ Study data loaded from testsavedregex
** Failers
0: a
1: a
- def
+ def
No match
-
+
~<(\w+)/?>(.)*</(\1)>~smgI
Capturing subpattern count = 3
Max back reference = 1
@@ -5639,42 +5634,45 @@ No need char
/line\nbreak/I
Capturing subpattern count = 0
+Contains explicit CR or LF match
No options
First char = 'l'
Need char = 'k'
this is a line\nbreak
0: line\x0abreak
- line one\nthis is a line\nbreak in the second line
+ line one\nthis is a line\nbreak in the second line
0: line\x0abreak
/line\nbreak/If
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: firstline
First char = 'l'
Need char = 'k'
this is a line\nbreak
0: line\x0abreak
- ** Failers
+ ** Failers
No match
- line one\nthis is a line\nbreak in the second line
+ line one\nthis is a line\nbreak in the second line
No match
/line\nbreak/Imf
Capturing subpattern count = 0
+Contains explicit CR or LF match
Options: multiline firstline
First char = 'l'
Need char = 'k'
this is a line\nbreak
0: line\x0abreak
- ** Failers
+ ** Failers
No match
- line one\nthis is a line\nbreak in the second line
+ line one\nthis is a line\nbreak in the second line
No match
/ab.cd/IP
ab-cd
0: ab-cd
- ab=cd
+ ab=cd
0: ab=cd
** Failers
No match: POSIX code 17: match failed
@@ -5684,7 +5682,7 @@ No match: POSIX code 17: match failed
/ab.cd/IPs
ab-cd
0: ab-cd
- ab=cd
+ ab=cd
0: ab=cd
ab\ncd
0: ab\x0acd
@@ -5698,9 +5696,9 @@ Need char = 'd'
0: AbCd
** Failers
No match
- abcd
+ abcd
No match
-
+
/a{11111111111111111111}/I
Failed: number too big in {} quantifier at offset 22
@@ -5931,7 +5929,7 @@ No first char
No need char
(this(and)that
0:
- (this(and)that)
+ (this(and)that)
0: (this(and)that)
(this(and)that)stuff
0: (this(and)that)stuff
@@ -5944,9 +5942,9 @@ No first char
No need char
(this(and)that
0:
- (this(and)that)
+ (this(and)that)
0: (this(and)that)
-
+
/[^()]*(?:\((?R)\))*[^()]*/I
Capturing subpattern count = 0
Partial matching not supported
@@ -5955,7 +5953,7 @@ No first char
No need char
(this(and)that
0:
- (this(and)that)
+ (this(and)that)
0: (this(and)that)
/(?:\((?R)\))*[^()]*/I
@@ -5966,9 +5964,9 @@ No first char
No need char
(this(and)that
0:
- (this(and)that)
+ (this(and)that)
0:
- ((this))
+ ((this))
0: ((this))
/(?:\((?R)\))|[^()]*/I
@@ -5979,22 +5977,22 @@ No first char
No need char
(this(and)that
0:
- (this(and)that)
+ (this(and)that)
0:
(this)
0: (this)
- ((this))
+ ((this))
0: ((this))
-
+
/a(b)c/IPN
abc
Matched with REG_NOSUB
-
+
/a(?P<name>b)c/IPN
- abc
+ abc
Matched with REG_NOSUB
-
-/\x{100}/I
+
+/\x{100}/I
Failed: character value in \x{...} sequence is too large at offset 6
/\x{0000ff}/I
@@ -6019,7 +6017,7 @@ No need char
1: a1
2: a1
C a1 (2) A
- a2b\CA
+ a2b\CA
0: a2b
1: a2b
2: <unset>
@@ -6027,14 +6025,14 @@ No need char
C a2 (2) A
** Failers
No match
- a1b\CZ\CA
+ a1b\CZ\CA
no parentheses with name "Z"
0: a1
1: a1
2: a1
copy substring Z failed -7
C a1 (2) A
-
+
/^(?P<A>a)(?P<A>b)/IJ
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -6048,7 +6046,7 @@ No need char
1: a
2: b
C a (1) A
-
+
/^(?P<A>a)(?P<A>b)|cd/IJ
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -6062,10 +6060,10 @@ No need char
1: a
2: b
C a (1) A
- cd\CA
+ cd\CA
0: cd
copy substring A failed -7
-
+
/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
Capturing subpattern count = 4
Named capturing subpatterns:
@@ -6076,14 +6074,14 @@ Named capturing subpatterns:
Options: dupnames
No first char
No need char
- cdefgh\CA
+ cdefgh\CA
0: cdefgh
1: <unset>
2: <unset>
3: ef
4: gh
C ef (2) A
-
+
/^((?P<A>a1)|(?P<A>a2)b)/IJ
Capturing subpattern count = 3
Named capturing subpatterns:
@@ -6097,7 +6095,7 @@ No need char
1: a1
2: a1
G a1 (2) A
- a2b\GA
+ a2b\GA
0: a2b
1: a2b
2: <unset>
@@ -6105,14 +6103,14 @@ No need char
G a2 (2) A
** Failers
No match
- a1b\GZ\GA
+ a1b\GZ\GA
no parentheses with name "Z"
0: a1
1: a1
2: a1
copy substring Z failed -7
G a1 (2) A
-
+
/^(?P<A>a)(?P<A>b)/IJ
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -6126,7 +6124,7 @@ No need char
1: a
2: b
G a (1) A
-
+
/^(?P<A>a)(?P<A>b)|cd/IJ
Capturing subpattern count = 2
Named capturing subpatterns:
@@ -6140,10 +6138,10 @@ No need char
1: a
2: b
G a (1) A
- cd\GA
+ cd\GA
0: cd
copy substring A failed -7
-
+
/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
Capturing subpattern count = 4
Named capturing subpatterns:
@@ -6154,20 +6152,21 @@ Named capturing subpatterns:
Options: dupnames
No first char
No need char
- cdefgh\GA
+ cdefgh\GA
0: cdefgh
1: <unset>
2: <unset>
3: ef
4: gh
G ef (2) A
-
+
/(?J)^((?P<A>a1)|(?P<A>a2)b)/I
Capturing subpattern count = 3
Named capturing subpatterns:
A 2
A 3
Options: anchored dupnames
+Duplicate name status changes
No first char
No need char
a1b\CA
@@ -6175,18 +6174,18 @@ No need char
1: a1
2: a1
C a1 (2) A
- a2b\CA
+ a2b\CA
0: a2b
1: a2b
2: <unset>
3: a2
C a2 (2) A
-
+
/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/I
Failed: two named subpatterns have the same name at offset 37
/ In this next test, J is not set at the outer level; consequently it isn't
-set in the pattern's options; consequently pcre_get_named_substring() produces
+set in the pattern's options; consequently pcre_get_named_substring() produces
a random value. /Ix
Capturing subpattern count = 1
Options: extended
@@ -6201,6 +6200,7 @@ Named capturing subpatterns:
B 3
C 4
Options: anchored
+Duplicate name status changes
No first char
No need char
a bc d\CA\CB\CC
@@ -6227,7 +6227,7 @@ No need char
0: b
** Failers
No match
- abc
+ abc
No match
/(?:(?(ZZ)a|b)(?P<ZZ>X))+/I
@@ -6283,7 +6283,7 @@ No need char
bXXaYYaY
0: bXXaYYaY
1: Y
- bXYaXXaX
+ bXYaXXaX
0: bX
1: X
@@ -6320,7 +6320,7 @@ Need char = ','
Starting byte set: \x09 \x0a \x0c \x0d \x20 ,
\x0b,\x0b
0: ,
- \x0c,\x0d
+ \x0c,\x0d
0: \x0c,\x0d
/^abc/Im
@@ -6338,7 +6338,7 @@ Need char = 'c'
0: abc
xyz\r\nabc\<crlf>
0: abc
- ** Failers
+ ** Failers
No match
xyz\nabc\<cr>
No match
@@ -6350,7 +6350,7 @@ No match
No match
xyz\rabc\<lf>
No match
-
+
/abc$/Im<lf>
Capturing subpattern count = 0
Options: multiline
@@ -6359,29 +6359,29 @@ First char = 'a'
Need char = 'c'
xyzabc
0: abc
- xyzabc\n
+ xyzabc\n
0: abc
- xyzabc\npqr
+ xyzabc\npqr
0: abc
- xyzabc\r\<cr>
+ xyzabc\r\<cr>
0: abc
- xyzabc\rpqr\<cr>
+ xyzabc\rpqr\<cr>
0: abc
- xyzabc\r\n\<crlf>
+ xyzabc\r\n\<crlf>
0: abc
- xyzabc\r\npqr\<crlf>
+ xyzabc\r\npqr\<crlf>
0: abc
** Failers
No match
- xyzabc\r
+ xyzabc\r
No match
- xyzabc\rpqr
+ xyzabc\rpqr
No match
- xyzabc\r\n
+ xyzabc\r\n
No match
- xyzabc\r\npqr
+ xyzabc\r\npqr
No match
-
+
/^abc/Im<cr>
Capturing subpattern count = 0
Options: multiline
@@ -6392,11 +6392,11 @@ Need char = 'c'
0: abc
xyz\nabcdef\<lf>
0: abc
- ** Failers
+ ** Failers
No match
xyz\nabcdef
No match
-
+
/^abc/Im<lf>
Capturing subpattern count = 0
Options: multiline
@@ -6407,11 +6407,11 @@ Need char = 'c'
0: abc
xyz\rabcdef\<cr>
0: abc
- ** Failers
+ ** Failers
No match
xyz\rabcdef
No match
-
+
/^abc/Im<crlf>
Capturing subpattern count = 0
Options: multiline
@@ -6422,11 +6422,11 @@ Need char = 'c'
0: abc
xyz\rabcdef\<cr>
0: abc
- ** Failers
+ ** Failers
No match
xyz\rabcdef
No match
-
+
/^abc/Im<bad>
Unknown newline type at: <bad>
@@ -6438,9 +6438,9 @@ First char = 'a'
Need char = 'c'
xyz\rabc\<bad>
Unknown newline type at: <bad>
- abc
+ abc
0: abc
-
+
/.*/I<lf>
Capturing subpattern count = 0
Partial matching not supported
@@ -6514,7 +6514,7 @@ Capturing subpattern count = 102
Options: extended
No first char
No need char
- XY\O400
+ XY\O400
0: XY
1:
2:
@@ -6669,15 +6669,15 @@ No first char
Need char = 'z'
Starting byte set: a b c d
-/^a*b\d/D
+/^a*b\d/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 ^
- 4 a*+
- 6 b
- 8 \d
- 9 9 Ket
- 12 End
+ Bra
+ ^
+ a*+
+ b
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -6685,15 +6685,15 @@ Options: anchored
No first char
Need char = 'b'
-/^a*+b\d/D
+/^a*+b\d/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 ^
- 4 a*+
- 6 b
- 8 \d
- 9 9 Ket
- 12 End
+ Bra
+ ^
+ a*+
+ b
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -6701,15 +6701,15 @@ Options: anchored
No first char
Need char = 'b'
-/^a*?b\d/D
+/^a*?b\d/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 ^
- 4 a*+
- 6 b
- 8 \d
- 9 9 Ket
- 12 End
+ Bra
+ ^
+ a*+
+ b
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -6717,15 +6717,15 @@ Options: anchored
No first char
Need char = 'b'
-/^a+A\d/D
+/^a+A\d/DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 ^
- 4 a++
- 6 A
- 8 \d
- 9 9 Ket
- 12 End
+ Bra
+ ^
+ a++
+ A
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -6736,18 +6736,18 @@ Need char = 'A'
0: aaaA5
** Failers
No match
- aaaa5
+ aaaa5
No match
-/^a*A\d/IiD
+/^a*A\d/IiDZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 ^
- 4 a*
- 6 NC A
- 8 \d
- 9 9 Ket
- 12 End
+ Bra
+ ^
+ a*
+ NC A
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -6797,8 +6797,8 @@ Starting byte set: a b
a
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
- )))
-/Ix
+ )))
+/Ix
Capturing subpattern count = 203
Options: extended
First char = 'a'
@@ -6821,598 +6821,598 @@ Matched, but too many substrings
13: a
14: a
-/a*\d/B
+/a*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*+
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ a*+
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/a*\D/B
+/a*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ a*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/0*\d/B
+/0*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 0*
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ 0*
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/0*\D/B
+/0*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 0*+
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ 0*+
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/a*\s/B
+/a*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*+
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ a*+
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/a*\S/B
+/a*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ a*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/ *\s/B
+/ *\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 *
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ *
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/ *\S/B
+/ *\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 *+
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ *+
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/a*\w/B
+/a*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ a*
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/a*\W/B
+/a*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 a*+
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ a*+
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/=*\w/B
+/=*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 =*+
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ =*+
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/=*\W/B
+/=*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 =*
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ =*
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\d*a/B
+/\d*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \d*+
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \d*+
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\d*2/B
+/\d*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \d*
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \d*
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\d*\d/B
+/\d*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \d*
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\d*\D/B
+/\d*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*+
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \d*+
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\d*\s/B
+/\d*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*+
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \d*+
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\d*\S/B
+/\d*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \d*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\d*\w/B
+/\d*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \d*
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\d*\W/B
+/\d*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \d*+
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \d*+
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\D*a/B
+/\D*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \D*
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \D*
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\D*2/B
+/\D*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \D*+
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \D*+
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\D*\d/B
+/\D*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*+
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \D*+
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\D*\D/B
+/\D*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \D*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\D*\s/B
+/\D*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \D*
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\D*\S/B
+/\D*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \D*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\D*\w/B
+/\D*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \D*
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\D*\W/B
+/\D*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \D*
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \D*
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\s*a/B
+/\s*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \s*+
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \s*+
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\s*2/B
+/\s*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \s*+
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \s*+
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\s*\d/B
+/\s*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*+
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \s*+
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\s*\D/B
+/\s*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \s*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\s*\s/B
+/\s*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \s*
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\s*\S/B
+/\s*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*+
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \s*+
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\s*\w/B
+/\s*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*+
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \s*+
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\s*\W/B
+/\s*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \s*
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \s*
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\S*a/B
+/\S*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \S*
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \S*
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\S*2/B
+/\S*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \S*
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \S*
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\S*\d/B
+/\S*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \S*
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\S*\D/B
+/\S*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \S*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\S*\s/B
+/\S*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*+
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \S*+
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\S*\S/B
+/\S*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \S*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\S*\w/B
+/\S*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \S*
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\S*\W/B
+/\S*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \S*
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \S*
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\w*a/B
+/\w*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \w*
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \w*
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\w*2/B
+/\w*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \w*
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \w*
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\w*\d/B
+/\w*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \w*
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\w*\D/B
+/\w*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \w*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\w*\s/B
+/\w*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*+
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \w*+
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\w*\S/B
+/\w*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \w*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\w*\w/B
+/\w*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \w*
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\w*\W/B
+/\w*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \w*+
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \w*+
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/\W*a/B
+/\W*a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \W*+
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ \W*+
+ a
+ Ket
+ End
------------------------------------------------------------------
-/\W*2/B
+/\W*2/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \W*+
- 5 2
- 7 7 Ket
- 10 End
+ Bra
+ \W*+
+ 2
+ Ket
+ End
------------------------------------------------------------------
-/\W*\d/B
+/\W*\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*+
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ \W*+
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/\W*\D/B
+/\W*\D/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*
- 5 \D
- 6 6 Ket
- 9 End
+ Bra
+ \W*
+ \D
+ Ket
+ End
------------------------------------------------------------------
-/\W*\s/B
+/\W*\s/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*
- 5 \s
- 6 6 Ket
- 9 End
+ Bra
+ \W*
+ \s
+ Ket
+ End
------------------------------------------------------------------
-/\W*\S/B
+/\W*\S/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*
- 5 \S
- 6 6 Ket
- 9 End
+ Bra
+ \W*
+ \S
+ Ket
+ End
------------------------------------------------------------------
-/\W*\w/B
+/\W*\w/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*+
- 5 \w
- 6 6 Ket
- 9 End
+ Bra
+ \W*+
+ \w
+ Ket
+ End
------------------------------------------------------------------
-/\W*\W/B
+/\W*\W/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \W*
- 5 \W
- 6 6 Ket
- 9 End
+ Bra
+ \W*
+ \W
+ Ket
+ End
------------------------------------------------------------------
-/[^a]+a/B
+/[^a]+a/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 [^a]++
- 5 a
- 7 7 Ket
- 10 End
+ Bra
+ [^a]++
+ a
+ Ket
+ End
------------------------------------------------------------------
-/[^a]+a/Bi
+/[^a]+a/BZi
------------------------------------------------------------------
- 0 7 Bra 0
- 3 [^A]++
- 5 NC a
- 7 7 Ket
- 10 End
+ Bra
+ [^A]++
+ NC a
+ Ket
+ End
------------------------------------------------------------------
-/[^a]+A/Bi
+/[^a]+A/BZi
------------------------------------------------------------------
- 0 7 Bra 0
- 3 [^A]++
- 5 NC A
- 7 7 Ket
- 10 End
+ Bra
+ [^A]++
+ NC A
+ Ket
+ End
------------------------------------------------------------------
-/[^a]+b/B
+/[^a]+b/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 [^a]+
- 5 b
- 7 7 Ket
- 10 End
+ Bra
+ [^a]+
+ b
+ Ket
+ End
------------------------------------------------------------------
-/[^a]+\d/B
+/[^a]+\d/BZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 [^a]+
- 5 \d
- 6 6 Ket
- 9 End
+ Bra
+ [^a]+
+ \d
+ Ket
+ End
------------------------------------------------------------------
-/a*[^a]/B
+/a*[^a]/BZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 a*
- 5 [^a]
- 7 7 Ket
- 10 End
+ Bra
+ a*
+ [^a]
+ Ket
+ End
------------------------------------------------------------------
/(?P<abc>x)(?P<xyz>y)/I
@@ -7463,9 +7463,9 @@ Failed: unrecognized character after (?P at offset 3
1: X
** Failers
No match
- aXaX
+ aXaX
No match
- aXbX
+ aXbX
No match
/^(?P>abc)(?<abcd>xxx)/
@@ -7481,7 +7481,7 @@ Failed: reference to non-existent subpattern at offset 8
yy
0: yy
1: y
- yx
+ yx
0: yx
1: x
@@ -7495,7 +7495,7 @@ Failed: reference to non-existent subpattern at offset 8
yy
0: yy
1: y
- yx
+ yx
0: yx
1: x
@@ -7504,13 +7504,13 @@ Failed: reference to non-existent subpattern at offset 8
0: bxay
1: ay
2: y
- bxby
+ bxby
0: bx
1: bx
2: x
** Failers
No match
- axby
+ axby
No match
/^(((?P=abc)|X)(?<abc>x|y))+/
@@ -7531,7 +7531,7 @@ No match
3: y
** Failers
No match
- x
+ x
No match
/^(?1)(abc)/
@@ -7543,113 +7543,113 @@ No match
Xaaa
0: Xaaa
1: a
- Xaba
+ Xaba
0: Xa
1: a
-/^[\E\Qa\E-\Qz\E]+/B
+/^[\E\Qa\E-\Qz\E]+/BZ
------------------------------------------------------------------
- 0 38 Bra 0
- 3 ^
- 4 [a-z]+
- 38 38 Ket
- 41 End
+ Bra
+ ^
+ [a-z]+
+ Ket
+ End
------------------------------------------------------------------
-
-/^[a\Q]bc\E]/B
+
+/^[a\Q]bc\E]/BZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\]a-c]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\]a-c]
+ Ket
+ End
------------------------------------------------------------------
-
-/^[a-\Q\E]/B
-------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\-a]
- 37 37 Ket
- 40 End
-------------------------------------------------------------------
-
-/^(?P>abc)[()](?<abc>)/B
-------------------------------------------------------------------
- 0 54 Bra 0
- 3 ^
- 4 6 Once
- 7 46 Recurse
- 10 6 Ket
- 13 [()]
- 46 5 Bra 1
- 51 5 Ket
- 54 54 Ket
- 57 End
-------------------------------------------------------------------
-
-/^((?(abc)y)[()](?P<abc>x))+/B
-------------------------------------------------------------------
- 0 66 Bra 0
- 3 ^
- 4 59 Bra 1
- 9 8 Cond
- 12 2 Cond ref
- 15 y
- 17 8 Ket
- 20 [()]
- 53 7 Bra 2
- 58 x
- 60 7 Ket
- 63 59 KetRmax
- 66 66 Ket
- 69 End
+
+/^[a-\Q\E]/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ [\-a]
+ Ket
+ End
+------------------------------------------------------------------
+
+/^(?P>abc)[()](?<abc>)/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ Once
+ Recurse
+ Ket
+ [()]
+ CBra 1
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+
+/^((?(abc)y)[()](?P<abc>x))+/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ CBra 1
+ Cond
+ 2 Cond ref
+ y
+ Ket
+ [()]
+ CBra 2
+ x
+ Ket
+ KetRmax
+ Ket
+ End
------------------------------------------------------------------
(xy)x
0: (xy)x
1: y)x
2: x
-
-/^(?P>abc)\Q()\E(?<abc>)/B
-------------------------------------------------------------------
- 0 25 Bra 0
- 3 ^
- 4 6 Once
- 7 17 Recurse
- 10 6 Ket
- 13 ()
- 17 5 Bra 1
- 22 5 Ket
- 25 25 Ket
- 28 End
-------------------------------------------------------------------
-
-/^(?P>abc)[a\Q(]\E(](?<abc>)/B
-------------------------------------------------------------------
- 0 54 Bra 0
- 3 ^
- 4 6 Once
- 7 46 Recurse
- 10 6 Ket
- 13 [(\]a]
- 46 5 Bra 1
- 51 5 Ket
- 54 54 Ket
- 57 End
+
+/^(?P>abc)\Q()\E(?<abc>)/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ Once
+ Recurse
+ Ket
+ ()
+ CBra 1
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+
+/^(?P>abc)[a\Q(]\E(](?<abc>)/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ Once
+ Recurse
+ Ket
+ [(\]a]
+ CBra 1
+ Ket
+ Ket
+ End
------------------------------------------------------------------
/^(?P>abc) # this is (a comment)
- (?<abc>)/Bx
+ (?<abc>)/BZx
------------------------------------------------------------------
- 0 21 Bra 0
- 3 ^
- 4 6 Once
- 7 13 Recurse
- 10 6 Ket
- 13 5 Bra 1
- 18 5 Ket
- 21 21 Ket
- 24 End
+ Bra
+ ^
+ Once
+ Recurse
+ Ket
+ CBra 1
+ Ket
+ Ket
+ End
------------------------------------------------------------------
/^\W*(?:(?<one>(?<two>.)\W*(?&one)\W*\k<two>|)|(?<three>(?<four>.)\W*(?&three)\W*\k'four'|\W*.\W*))\W*$/Ii
@@ -7680,7 +7680,7 @@ No need char
2: <unset>
3: A man, a plan, a canal: Panama
4: A
- Able was I ere I saw Elba.
+ Able was I ere I saw Elba.
0: Able was I ere I saw Elba.
1: <unset>
2: <unset>
@@ -7688,9 +7688,9 @@ No need char
4: A
*** Failers
No match
- The quick brown fox
+ The quick brown fox
No match
-
+
/(?=(\w+))\1:/I
Capturing subpattern count = 1
Max back reference = 1
@@ -7724,9 +7724,9 @@ Need char = ':'
1: ab
** Failers
No match
- a:axyz
+ a:axyz
No match
- ab:abxyz
+ ab:abxyz
No match
/(?'abc'a|b)(?<abc>d|e)\k<abc>{2}/J
@@ -7738,7 +7738,7 @@ No match
No match
addd
No match
- adbb
+ adbb
No match
/(?'abc'a|b)(?<abc>d|e)(?&abc){2}/J
@@ -7752,20 +7752,20 @@ No match
2: d
** Failers
No match
- bddd
+ bddd
No match
/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
abd
0: abd
1: a
- ce
+ ce
0: ce
-
+
/(?(<bc))/
Failed: malformed number or name after (?( at offset 6
-/(?(''))/
+/(?(''))/
Failed: assertion expected after (?( at offset 4
/(?('R')stuff)/
@@ -7797,7 +7797,7 @@ Failed: reference to non-existent subpattern at offset 29
0: ab
1: <unset>
2: <unset>
-
+
/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
(?(DEFINE)
(?<NAME_PAT>[a-z]+)
@@ -7809,7 +7809,7 @@ Failed: reference to non-existent subpattern at offset 29
2: 33
3: <unset>
4: <unset>
-
+
/^(?(DEFINE) abc | xyz ) /x
Failed: DEFINE group contains more than one branch at offset 22
@@ -7831,17 +7831,23 @@ Matched, but too many substrings
/^a.b/<lf>
a\rb
0: a\x0db
- a\nb\<cr>
+ a\nb\<cr>
0: a\x0ab
+ a\x85b\<anycrlf>
+ 0: a\x85b
** Failers
No match
a\nb
No match
a\nb\<any>
No match
- a\rb\<cr>
+ a\rb\<cr>
No match
- a\rb\<any>
+ a\rb\<any>
+No match
+ a\x85b\<any>
+No match
+ a\rb\<anycrlf>
No match
/^abc./mgx<any>
@@ -7865,12 +7871,11 @@ No match
0: abc9
/a/<cr><any>
-Failed: inconsistent NEWLINE options at offset 0
/a/<any><crlf>
Failed: inconsistent NEWLINE options at offset 0
-/^a\Rb/
+/^a\Rb/<bsr_unicode>
a\nb
0: a\x0ab
a\rb
@@ -7881,14 +7886,14 @@ Failed: inconsistent NEWLINE options at offset 0
0: a\x0bb
a\x0cb
0: a\x0cb
- a\x85b
+ a\x85b
0: a\x85b
** Failers
No match
- a\n\rb
+ a\n\rb
No match
-/^a\R*b/
+/^a\R*b/<bsr_unicode>
ab
0: ab
a\nb
@@ -7901,14 +7906,14 @@ No match
0: a\x0bb
a\x0cb
0: a\x0cb
- a\x85b
+ a\x85b
0: a\x85b
- a\n\rb
+ a\n\rb
0: a\x0a\x0db
- a\n\r\x85\x0cb
+ a\n\r\x85\x0cb
0: a\x0a\x0d\x85\x0cb
-/^a\R+b/
+/^a\R+b/<bsr_unicode>
a\nb
0: a\x0ab
a\rb
@@ -7919,31 +7924,31 @@ No match
0: a\x0bb
a\x0cb
0: a\x0cb
- a\x85b
+ a\x85b
0: a\x85b
- a\n\rb
+ a\n\rb
0: a\x0a\x0db
- a\n\r\x85\x0cb
+ a\n\r\x85\x0cb
0: a\x0a\x0d\x85\x0cb
** Failers
No match
- ab
+ ab
No match
-
-/^a\R{1,3}b/
+
+/^a\R{1,3}b/<bsr_unicode>
a\nb
0: a\x0ab
a\n\rb
0: a\x0a\x0db
a\n\r\x85b
0: a\x0a\x0d\x85b
- a\r\n\r\nb
+ a\r\n\r\nb
0: a\x0d\x0a\x0d\x0ab
- a\r\n\r\n\r\nb
+ a\r\n\r\n\r\nb
0: a\x0d\x0a\x0d\x0a\x0d\x0ab
a\n\r\n\rb
0: a\x0a\x0d\x0a\x0db
- a\n\n\r\nb
+ a\n\n\r\nb
0: a\x0a\x0a\x0d\x0ab
** Failers
No match
@@ -7952,12 +7957,12 @@ No match
a\r
No match
-/^a[\R]b/
+/^a[\R]b/<bsr_unicode>
aRb
0: aRb
** Failers
No match
- a\nb
+ a\nb
No match
/(?&abc)X(?<abc>P)/I
@@ -7999,7 +8004,7 @@ Need char = 'P'
No match
10.6
No match
- 455.3.4.5
+ 455.3.4.5
No match
/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
@@ -8019,9 +8024,9 @@ No match
No match
10.6
No match
- 455.3.4.5
+ 455.3.4.5
No match
-
+
/(?:a(?&abc)b)*(?<abc>x)/
123axbaxbaxbx456
0: axbaxbaxbx
@@ -8029,7 +8034,7 @@ No match
123axbaxbaxb456
0: x
1: x
-
+
/(?:a(?&abc)b){1,5}(?<abc>x)/
123axbaxbaxbx456
0: axbaxbaxbx
@@ -8066,19 +8071,19 @@ No match
2: b
/^(a)\g-2/
-Failed: reference to non-existent subpattern at offset 4
+Failed: reference to non-existent subpattern at offset 7
/^(a)\g/
-Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+Failed: a numbered reference must not be zero at offset 5
/^(a)\g{0}/
-Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+Failed: a numbered reference must not be zero at offset 8
/^(a)\g{3/
-Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+Failed: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number at offset 8
/^(a)\g{4a}/
-Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+Failed: reference to non-existent subpattern at offset 9
/^a.b/<lf>
a\rb
@@ -8091,39 +8096,1539 @@ No match
/.+foo/
afoo
0: afoo
- ** Failers
+ ** Failers
No match
- \r\nfoo
+ \r\nfoo
No match
- \nfoo
+ \nfoo
No match
/.+foo/<crlf>
afoo
0: afoo
- \nfoo
+ \nfoo
0: \x0afoo
- ** Failers
+ ** Failers
No match
- \r\nfoo
+ \r\nfoo
No match
/.+foo/<any>
afoo
0: afoo
- ** Failers
+ ** Failers
No match
- \nfoo
+ \nfoo
No match
- \r\nfoo
+ \r\nfoo
No match
/.+foo/s
afoo
0: afoo
- \r\nfoo
+ \r\nfoo
0: \x0d\x0afoo
- \nfoo
+ \nfoo
0: \x0afoo
+
+/^$/mg<any>
+ abc\r\rxyz
+ 0:
+ abc\n\rxyz
+ 0:
+ ** Failers
+No match
+ abc\r\nxyz
+No match
+
+/(?m)^$/<any>g+
+ abc\r\n\r\n
+ 0:
+ 0+ \x0d\x0a
+
+/(?m)^$|^\r\n/<any>g+
+ abc\r\n\r\n
+ 0:
+ 0+ \x0d\x0a
+ 0: \x0d\x0a
+ 0+
+
+/(?m)$/<any>g+
+ abc\r\n\r\n
+ 0:
+ 0+ \x0d\x0a\x0d\x0a
+ 0:
+ 0+ \x0d\x0a
+ 0:
+ 0+
+
+/abc.$/mgx<anycrlf>
+ abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+ 0: abc1
+ 0: abc4
+ 0: abc5
+ 0: abc9
+
+/^X/m
+ XABC
+ 0: X
+ ** Failers
+No match
+ XABC\B
+No match
+
+/(ab|c)(?-1)/BZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ ab
+ Alt
+ c
+ Ket
+ Once
+ Recurse
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ abc
+ 0: abc
+ 1: ab
+
+/xy(?+1)(abc)/BZ
+------------------------------------------------------------------
+ Bra
+ xy
+ Once
+ Recurse
+ Ket
+ CBra 1
+ abc
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ xyabcabc
+ 0: xyabcabc
+ 1: abc
+ ** Failers
+No match
+ xyabc
+No match
+
+/x(?-0)y/
+Failed: a numbered reference must not be zero at offset 5
+
+/x(?-1)y/
+Failed: reference to non-existent subpattern at offset 5
+
+/x(?+0)y/
+Failed: a numbered reference must not be zero at offset 5
+
+/x(?+1)y/
+Failed: reference to non-existent subpattern at offset 5
+
+/^(abc)?(?(-1)X|Y)/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ Brazero
+ CBra 1
+ abc
+ Ket
+ Cond
+ 1 Cond ref
+ X
+ Alt
+ Y
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ abcX
+ 0: abcX
+ 1: abc
+ Y
+ 0: Y
+ ** Failers
+No match
+ abcY
+No match
+
+/^((?(+1)X|Y)(abc))+/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ CBra 1
+ Cond
+ 2 Cond ref
+ X
+ Alt
+ Y
+ Ket
+ CBra 2
+ abc
+ Ket
+ KetRmax
+ Ket
+ End
+------------------------------------------------------------------
+ YabcXabc
+ 0: YabcXabc
+ 1: Xabc
+ 2: abc
+ YabcXabcXabc
+ 0: YabcXabcXabc
+ 1: Xabc
+ 2: abc
+ ** Failers
+No match
+ XabcXabc
+No match
+
+/(?(-1)a)/BZ
+Failed: reference to non-existent subpattern at offset 6
+
+/((?(-1)a))/BZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ Cond
+ 1 Cond ref
+ a
+ Ket
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+
+/((?(-2)a))/BZ
+Failed: reference to non-existent subpattern at offset 7
+
+/^(?(+1)X|Y)(.)/BZ
+------------------------------------------------------------------
+ Bra
+ ^
+ Cond
+ 1 Cond ref
+ X
+ Alt
+ Y
+ Ket
+ CBra 1
+ Any
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ Y!
+ 0: Y!
+ 1: !
+
+/(foo)\Kbar/
+ foobar
+ 0: bar
+ 1: foo
+
+/(foo)(\Kbar|baz)/
+ foobar
+ 0: bar
+ 1: foo
+ 2: bar
+ foobaz
+ 0: foobaz
+ 1: foo
+ 2: baz
+
+/(foo\Kbar)baz/
+ foobarbaz
+ 0: barbaz
+ 1: foobar
+
+/(?<A>tom|bon)-\k{A}/
+ tom-tom
+ 0: tom-tom
+ 1: tom
+ bon-bon
+ 0: bon-bon
+ 1: bon
+ ** Failers
+No match
+ tom-bon
+No match
+
+/(?<A>tom|bon)-\g{A}/
+ tom-tom
+ 0: tom-tom
+ 1: tom
+ bon-bon
+ 0: bon-bon
+ 1: bon
+
+/\g{A/
+Failed: syntax error in subpattern name (missing terminator) at offset 4
+
+/(?|(abc)|(xyz))/BZ
+------------------------------------------------------------------
+ Bra
+ Bra
+ CBra 1
+ abc
+ Ket
+ Alt
+ CBra 1
+ xyz
+ Ket
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ >abc<
+ 0: abc
+ 1: abc
+ >xyz<
+ 0: xyz
+ 1: xyz
+
+/(x)(?|(abc)|(xyz))(x)/BZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ x
+ Ket
+ Bra
+ CBra 2
+ abc
+ Ket
+ Alt
+ CBra 2
+ xyz
+ Ket
+ Ket
+ CBra 3
+ x
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ xabcx
+ 0: xabcx
+ 1: x
+ 2: abc
+ 3: x
+ xxyzx
+ 0: xxyzx
+ 1: x
+ 2: xyz
+ 3: x
+
+/(x)(?|(abc)(pqr)|(xyz))(x)/BZ
+------------------------------------------------------------------
+ Bra
+ CBra 1
+ x
+ Ket
+ Bra
+ CBra 2
+ abc
+ Ket
+ CBra 3
+ pqr
+ Ket
+ Alt
+ CBra 2
+ xyz
+ Ket
+ Ket
+ CBra 4
+ x
+ Ket
+ Ket
+ End
+------------------------------------------------------------------
+ xabcpqrx
+ 0: xabcpqrx
+ 1: x
+ 2: abc
+ 3: pqr
+ 4: x
+ xxyzx
+ 0: xxyzx
+ 1: x
+ 2: xyz
+ 3: <unset>
+ 4: x
+
+/(?|(abc)|(xyz))\1/
+ abcabc
+ 0: abcabc
+ 1: abc
+ xyzxyz
+ 0: xyzxyz
+ 1: xyz
+ ** Failers
+No match
+ abcxyz
+No match
+ xyzabc
+No match
+
+/(?|(abc)|(xyz))(?1)/
+ abcabc
+ 0: abcabc
+ 1: abc
+ xyzabc
+ 0: xyzabc
+ 1: xyz
+ ** Failers
+No match
+ xyzxyz
+No match
+
+/\H\h\V\v/
+ X X\x0a
+ 0: X X\x0a
+ X\x09X\x0b
+ 0: X\x09X\x0b
+ ** Failers
+No match
+ \xa0 X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/
+ \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
+ 0: \x09 \xa0X\x0a\x0b\x0c\x0d
+ \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
+ 0: \x09 \xa0\x0a\x0b\x0c\x0d
+ \x09\x20\xa0\x0a\x0b\x0c
+ 0: \x09 \xa0\x0a\x0b\x0c
+ ** Failers
+No match
+ \x09\x20\xa0\x0a\x0b
+No match
+
+/\H{3,4}/
+ XY ABCDE
+ 0: ABCD
+ XY PQR ST
+ 0: PQR
+
+/.\h{3,4}./
+ XY AB PQRS
+ 0: B P
+
+/\h*X\h?\H+Y\H?Z/
+ >XNNNYZ
+ 0: XNNNYZ
+ > X NYQZ
+ 0: X NYQZ
+ ** Failers
+No match
+ >XYZ
+No match
+ > X NY Z
+No match
+
+/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
+ >XY\x0aZ\x0aA\x0bNN\x0c
+ 0: XY\x0aZ\x0aA\x0bNN\x0c
+ >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+ 0: \x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+
+/[\h]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x09 \xa0]
+ Ket
+ End
+------------------------------------------------------------------
+ >\x09<
+ 0: \x09
+
+/[\h]+/BZ
+------------------------------------------------------------------
+ Bra
+ [\x09 \xa0]+
+ Ket
+ End
+------------------------------------------------------------------
+ >\x09\x20\xa0<
+ 0: \x09 \xa0
+
+/[\v]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x0a-\x0d\x85]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\H]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x08\x0a-\x1f!-\x9f\xa1-\xff]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[^\h]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x08\x0a-\x1f!-\x9f\xa1-\xff] (neg)
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\V]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x09\x0e-\x84\x86-\xff]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\x0a\V]/BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x0a\x0e-\x84\x86-\xff]
+ Ket
+ End
+------------------------------------------------------------------
+
+/\H++X/BZ
+------------------------------------------------------------------
+ Bra
+ \H++
+ X
+ Ket
+ End
+------------------------------------------------------------------
+ ** Failers
+No match
+ XXXX
+No match
+
+/\H+\hY/BZ
+------------------------------------------------------------------
+ Bra
+ \H++
+ \h
+ Y
+ Ket
+ End
+------------------------------------------------------------------
+ XXXX Y
+ 0: XXXX Y
+
+/\H+ Y/BZ
+------------------------------------------------------------------
+ Bra
+ \H++
+ Y
+ Ket
+ End
+------------------------------------------------------------------
+
+/\h+A/BZ
+------------------------------------------------------------------
+ Bra
+ \h++
+ A
+ Ket
+ End
+------------------------------------------------------------------
+
+/\v*B/BZ
+------------------------------------------------------------------
+ Bra
+ \v*+
+ B
+ Ket
+ End
+------------------------------------------------------------------
+
+/\V+\x0a/BZ
+------------------------------------------------------------------
+ Bra
+ \V++
+ \x0a
+ Ket
+ End
+------------------------------------------------------------------
+
+/A+\h/BZ
+------------------------------------------------------------------
+ Bra
+ A++
+ \h
+ Ket
+ End
+------------------------------------------------------------------
+
+/ *\H/BZ
+------------------------------------------------------------------
+ Bra
+ *+
+ \H
+ Ket
+ End
+------------------------------------------------------------------
+
+/A*\v/BZ
+------------------------------------------------------------------
+ Bra
+ A*+
+ \v
+ Ket
+ End
+------------------------------------------------------------------
+
+/\x0b*\V/BZ
+------------------------------------------------------------------
+ Bra
+ \x0b*+
+ \V
+ Ket
+ End
+------------------------------------------------------------------
+
+/\d+\h/BZ
+------------------------------------------------------------------
+ Bra
+ \d++
+ \h
+ Ket
+ End
+------------------------------------------------------------------
+
+/\d*\v/BZ
+------------------------------------------------------------------
+ Bra
+ \d*+
+ \v
+ Ket
+ End
+------------------------------------------------------------------
+
+/S+\h\S+\v/BZ
+------------------------------------------------------------------
+ Bra
+ S++
+ \h
+ \S++
+ \v
+ Ket
+ End
+------------------------------------------------------------------
+
+/\w{3,}\h\w+\v/BZ
+------------------------------------------------------------------
+ Bra
+ \w{3}
+ \w*+
+ \h
+ \w++
+ \v
+ Ket
+ End
+------------------------------------------------------------------
+
+/\h+\d\h+\w\h+\S\h+\H/BZ
+------------------------------------------------------------------
+ Bra
+ \h++
+ \d
+ \h++
+ \w
+ \h++
+ \S
+ \h++
+ \H
+ Ket
+ End
+------------------------------------------------------------------
+
+/\v+\d\v+\w\v+\S\v+\V/BZ
+------------------------------------------------------------------
+ Bra
+ \v++
+ \d
+ \v++
+ \w
+ \v+
+ \S
+ \v++
+ \V
+ Ket
+ End
+------------------------------------------------------------------
+
+/\H+\h\H+\d/BZ
+------------------------------------------------------------------
+ Bra
+ \H++
+ \h
+ \H+
+ \d
+ Ket
+ End
+------------------------------------------------------------------
+
+/\V+\v\V+\w/BZ
+------------------------------------------------------------------
+ Bra
+ \V++
+ \v
+ \V+
+ \w
+ Ket
+ End
+------------------------------------------------------------------
+
+/\( (?: [^()]* | (?R) )* \)/x
+(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(00)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)
+ 0: (0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(0(00)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)0)
+
+/[\E]AAA/
+Failed: missing terminating ] for character class at offset 7
+
+/[\Q\E]AAA/
+Failed: missing terminating ] for character class at offset 9
+
+/[^\E]AAA/
+Failed: missing terminating ] for character class at offset 8
+
+/[^\Q\E]AAA/
+Failed: missing terminating ] for character class at offset 10
+
+/[\E^]AAA/
+Failed: missing terminating ] for character class at offset 8
+
+/[\Q\E^]AAA/
+Failed: missing terminating ] for character class at offset 10
+
+/A(*PRUNE)B(*SKIP)C(*THEN)D(*COMMIT)E(*F)F(*FAIL)G(?!)H(*ACCEPT)I/BZ
+------------------------------------------------------------------
+ Bra
+ A
+ *PRUNE
+ B
+ *SKIP
+ C
+ *THEN
+ D
+ *COMMIT
+ E
+ *FAIL
+ F
+ *FAIL
+ G
+ *FAIL
+ H
+ *ACCEPT
+ I
+ Ket
+ End
+------------------------------------------------------------------
+
+/^a+(*FAIL)/
+ aaaaaa
+No match
+
+/a+b?c+(*FAIL)/
+ aaabccc
+No match
+
+/a+b?(*PRUNE)c+(*FAIL)/
+ aaabccc
+No match
+
+/a+b?(*COMMIT)c+(*FAIL)/
+ aaabccc
+No match
+
+/a+b?(*SKIP)c+(*FAIL)/
+ aaabcccaaabccc
+No match
+
+/^(?:aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
+ aaaxxxxxx
+ 0: aaaxxxxxx
+ aaa++++++
+ 0: aaa
+ bbbxxxxx
+ 0: bbbxxxxx
+ bbb+++++
+ 0: bbb
+ cccxxxx
+ 0: cccxxxx
+ ccc++++
+ 0: ccc
+ dddddddd
+ 0: ddd
+
+/^(aaa(*THEN)\w{6}|bbb(*THEN)\w{5}|ccc(*THEN)\w{4}|\w{3})/
+ aaaxxxxxx
+ 0: aaaxxxxxx
+ 1: aaaxxxxxx
+ aaa++++++
+ 0: aaa
+ 1: aaa
+ bbbxxxxx
+ 0: bbbxxxxx
+ 1: bbbxxxxx
+ bbb+++++
+ 0: bbb
+ 1: bbb
+ cccxxxx
+ 0: cccxxxx
+ 1: cccxxxx
+ ccc++++
+ 0: ccc
+ 1: ccc
+ dddddddd
+ 0: ddd
+ 1: ddd
+
+/a+b?(*THEN)c+(*FAIL)/
+ aaabccc
+No match
+
+/(A (A|B(*ACCEPT)|C) D)(E)/x
+ ABX
+ 0: AB
+ AADE
+ 0: AADE
+ 1: AAD
+ 2: A
+ 3: E
+ ACDE
+ 0: ACDE
+ 1: ACD
+ 2: C
+ 3: E
+ ** Failers
+No match
+ AD
+No match
+
+/^a+(*FAIL)/C
+ aaaaaa
+--->aaaaaa
+ +0 ^ ^
+ +1 ^ a+
+ +3 ^ ^ (*FAIL)
+ +3 ^ ^ (*FAIL)
+ +3 ^ ^ (*FAIL)
+ +3 ^ ^ (*FAIL)
+ +3 ^ ^ (*FAIL)
+ +3 ^^ (*FAIL)
+No match
+
+/a+b?c+(*FAIL)/C
+ aaabccc
+--->aaabccc
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ c+
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +4 ^ ^ c+
+ +2 ^ ^ b?
+ +4 ^ ^ c+
+ +2 ^^ b?
+ +4 ^^ c+
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ c+
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +4 ^ ^ c+
+ +2 ^^ b?
+ +4 ^^ c+
+ +0 ^ a+
+ +2 ^^ b?
+ +4 ^ ^ c+
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +6 ^ ^ (*FAIL)
+ +4 ^^ c+
+No match
+
+/a+b?(*PRUNE)c+(*FAIL)/C
+ aaabccc
+--->aaabccc
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*PRUNE)
++12 ^ ^ c+
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*PRUNE)
++12 ^ ^ c+
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
+ +0 ^ a+
+ +2 ^^ b?
+ +4 ^ ^ (*PRUNE)
++12 ^ ^ c+
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
++14 ^ ^ (*FAIL)
+No match
+
+/a+b?(*COMMIT)c+(*FAIL)/C
+ aaabccc
+--->aaabccc
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*COMMIT)
++13 ^ ^ c+
++15 ^ ^ (*FAIL)
++15 ^ ^ (*FAIL)
++15 ^ ^ (*FAIL)
+No match
+
+/a+b?(*SKIP)c+(*FAIL)/C
+ aaabcccaaabccc
+--->aaabcccaaabccc
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*SKIP)
++11 ^ ^ c+
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*SKIP)
++11 ^ ^ c+
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
+No match
+
+/a+b?(*THEN)c+(*FAIL)/C
+ aaabccc
+--->aaabccc
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*THEN)
++11 ^ ^ c+
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
+ +0 ^ a+
+ +2 ^ ^ b?
+ +4 ^ ^ (*THEN)
++11 ^ ^ c+
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
+ +0 ^ a+
+ +2 ^^ b?
+ +4 ^ ^ (*THEN)
++11 ^ ^ c+
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
++13 ^ ^ (*FAIL)
+No match
+
+/a(*PRUNE:XXX)b/
+Failed: (*VERB) with an argument is not supported at offset 8
+
+/a(*MARK)b/
+Failed: (*VERB) not recognized at offset 7
+
+/(?i:A{1,}\6666666666)/
+Failed: number is too big at offset 19
+
+/\g6666666666/
+Failed: number is too big at offset 11
+
+/[\g6666666666]/
+Failed: number is too big at offset 12
+
+/(?1)\c[/
+Failed: reference to non-existent subpattern at offset 3
+
+/.+A/<crlf>
+ \r\nA
+No match
+
+/\nA/<crlf>
+ \r\nA
+ 0: \x0aA
+
+/[\r\n]A/<crlf>
+ \r\nA
+ 0: \x0aA
+
+/(\r|\n)A/<crlf>
+ \r\nA
+ 0: \x0aA
+ 1: \x0a
+
+/a(*CR)b/
+Failed: (*VERB) not recognized at offset 5
+
+/(*CR)a.b/
+ a\nb
+ 0: a\x0ab
+ ** Failers
+No match
+ a\rb
+No match
+
+/(*CR)a.b/<lf>
+ a\nb
+ 0: a\x0ab
+ ** Failers
+No match
+ a\rb
+No match
+
+/(*LF)a.b/<CRLF>
+ a\rb
+ 0: a\x0db
+ ** Failers
+No match
+ a\nb
+No match
+
+/(*CRLF)a.b/
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ ** Failers
+No match
+ a\r\nb
+No match
+
+/(*ANYCRLF)a.b/<CR>
+ ** Failers
+No match
+ a\rb
+No match
+ a\nb
+No match
+ a\r\nb
+No match
+
+/(*ANY)a.b/<cr>
+ ** Failers
+No match
+ a\rb
+No match
+ a\nb
+No match
+ a\r\nb
+No match
+ a\x85b
+No match
+
+/a\Rb/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ ** Failers
+No match
+ a\x85b
+No match
+ a\x0bb
+No match
+
+/a\Rb/I<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ a\x85b
+ 0: a\x85b
+ a\x0bb
+ 0: a\x0bb
+ ** Failers
+No match
+ a\x85b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R?b/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ ** Failers
+No match
+ a\x85b
+No match
+ a\x0bb
+No match
+
+/a\R?b/I<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ a\x85b
+ 0: a\x85b
+ a\x0bb
+ 0: a\x0bb
+ ** Failers
+No match
+ a\x85b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R{2,4}b/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Partial matching not supported
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\r\n\nb
+ 0: a\x0d\x0a\x0ab
+ a\n\r\rb
+ 0: a\x0a\x0d\x0db
+ a\r\n\r\n\r\n\r\nb
+ 0: a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0ab
+ ** Failers
+No match
+ a\x85\85b
+No match
+ a\x0b\0bb
+No match
+
+/a\R{2,4}b/I<bsr_unicode>
+Capturing subpattern count = 0
+Partial matching not supported
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\r\rb
+ 0: a\x0d\x0db
+ a\n\n\nb
+ 0: a\x0a\x0a\x0ab
+ a\r\n\n\r\rb
+ 0: a\x0d\x0a\x0a\x0d\x0db
+ a\x85\85b
+No match
+ a\x0b\0bb
+No match
+ ** Failers
+No match
+ a\r\r\r\r\rb
+No match
+ a\x85\85b\<bsr_anycrlf>
+No match
+ a\x0b\0bb\<bsr_anycrlf>
+No match
+
+/(*BSR_ANYCRLF)a\Rb/I
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\nb
+ 0: a\x0ab
+ a\rb
+ 0: a\x0db
+
+/(*BSR_UNICODE)a\Rb/I
+Capturing subpattern count = 0
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\x85b
+ 0: a\x85b
+
+/(*BSR_ANYCRLF)(*CRLF)a\Rb/I
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+Forced newline sequence: CRLF
+First char = 'a'
+Need char = 'b'
+ a\nb
+ 0: a\x0ab
+ a\rb
+ 0: a\x0db
+
+/(*CRLF)(*BSR_UNICODE)a\Rb/I
+Capturing subpattern count = 0
+Options: bsr_unicode
+Forced newline sequence: CRLF
+First char = 'a'
+Need char = 'b'
+ a\x85b
+ 0: a\x85b
+
+/(*CRLF)(*BSR_ANYCRLF)(*CR)ab/I
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+Forced newline sequence: CR
+First char = 'a'
+Need char = 'b'
+
+/(?<a>)(?&)/
+Failed: subpattern name expected at offset 9
+
+/(?<abc>)(?&a)/
+Failed: reference to non-existent subpattern at offset 12
+
+/(?<a>)(?&aaaaaaaaaaaaaaaaaaaaaaa)/
+Failed: reference to non-existent subpattern at offset 32
+
+/(?+-a)/
+Failed: digit expected after (?+ at offset 3
+
+/(?-+a)/
+Failed: unrecognized character after (? or (?- at offset 3
+
+/(?(-1))/
+Failed: reference to non-existent subpattern at offset 6
+
+/(?(+10))/
+Failed: reference to non-existent subpattern at offset 7
+
+/(?(10))/
+Failed: reference to non-existent subpattern at offset 6
+
+/(?(+2))()()/
+
+/(?(2))()()/
+
+/\k''/
+Failed: subpattern name expected at offset 3
+
+/\k<>/
+Failed: subpattern name expected at offset 3
+
+/\k{}/
+Failed: subpattern name expected at offset 3
+
+/(?P=)/
+Failed: subpattern name expected at offset 4
+
+/(?P>)/
+Failed: subpattern name expected at offset 4
+
+/(?!\w)(?R)/
+Failed: recursive call could loop indefinitely at offset 9
+
+/(?=\w)(?R)/
+Failed: recursive call could loop indefinitely at offset 9
+
+/(?<!\w)(?R)/
+Failed: recursive call could loop indefinitely at offset 10
+
+/(?<=\w)(?R)/
+Failed: recursive call could loop indefinitely at offset 10
+
+/[[:foo:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[:1234:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[:f\oo:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[: :]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[:...:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[:l\ower:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[[:abc\:]]/
+Failed: unknown POSIX class name at offset 3
+
+/[abc[:x\]pqr:]]/
+Failed: unknown POSIX class name at offset 6
+
+/[[:a\dz:]]/
+Failed: unknown POSIX class name at offset 3
+
+/^(?<name>a|b\g<name>c)/
+ aaaa
+ 0: a
+ 1: a
+ bacxxx
+ 0: bac
+ 1: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+
+/^(?<name>a|b\g'name'c)/
+ aaaa
+ 0: a
+ 1: a
+ bacxxx
+ 0: bac
+ 1: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+
+/^(a|b\g<1>c)/
+ aaaa
+ 0: a
+ 1: a
+ bacxxx
+ 0: bac
+ 1: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+
+/^(a|b\g'1'c)/
+ aaaa
+ 0: a
+ 1: a
+ bacxxx
+ 0: bac
+ 1: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+
+/^(a|b\g'-1'c)/
+ aaaa
+ 0: a
+ 1: a
+ bacxxx
+ 0: bac
+ 1: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+
+/(^(a|b\g<-1>c))/
+ aaaa
+ 0: a
+ 1: a
+ 2: a
+ bacxxx
+ 0: bac
+ 1: bac
+ 2: bac
+ bbaccxxx
+ 0: bbacc
+ 1: bbacc
+ 2: bbacc
+ bbbacccxx
+ 0: bbbaccc
+ 1: bbbaccc
+ 2: bbbaccc
+
+/(^(a|b\g<-1'c))/
+Failed: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number at offset 15
+
+/(^(a|b\g{-1}))/
+ bacxxx
+No match
+
+/(?-i:\g<name>)(?i:(?<name>a))/
+ XaaX
+ 0: aa
+ 1: a
+ XAAX
+ 0: AA
+ 1: A
+
+/(?i:\g<name>)(?-i:(?<name>a))/
+ XaaX
+ 0: aa
+ 1: a
+ ** Failers
+No match
+ XAAX
+No match
+
+/(?-i:\g<+1>)(?i:(a))/
+ XaaX
+ 0: aa
+ 1: a
+ XAAX
+ 0: AA
+ 1: A
+
+/(?=(?<regex>(?#simplesyntax)\$(?<name>[a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}]*)(?:\[(?<index>[a-zA-Z0-9_\x{7f}-\x{ff}]+|\$\g<name>)\]|->\g<name>(\(.*?\))?)?|(?#simple syntax withbraces)\$\{(?:\g<name>(?<indices>\[(?:\g<index>|'(?:\\.|[^'\\])*'|"(?:\g<regex>|\\.|[^"\\])*")\])?|\g<complex>|\$\{\g<complex>\})\}|(?#complexsyntax)\{(?<complex>\$(?<segment>\g<name>(\g<indices>*|\(.*?\))?)(?:->\g<segment>)*|\$\g<complex>|\$\{\g<complex>\})\}))\{/
+
+/(?<n>a|b|c)\g<n>*/
+ abc
+ 0: abc
+ 1: a
+ accccbbb
+ 0: accccbbb
+ 1: a
+
+/^(?+1)(?<a>x|y){0}z/
+ xzxx
+ 0: xz
+ 1: <unset>
+ yzyy
+ 0: yz
+ 1: <unset>
+ ** Failers
+No match
+ xxz
+No match
+
+/(\3)(\1)(a)/
+ cat
+No match
+
+/(\3)(\1)(a)/<JS>
+ cat
+ 0: a
+ 1:
+ 2:
+ 3: a
+
+/TA]/
+ The ACTA] comes
+ 0: TA]
+
+/TA]/<JS>
+Failed: ] is an invalid data character in JavaScript compatibility mode at offset 2
+
+/(?2)[]a()b](abc)/
+Failed: reference to non-existent subpattern at offset 3
+
+/(?2)[^]a()b](abc)/
+Failed: reference to non-existent subpattern at offset 3
+
+/(?1)[]a()b](abc)/
+ abcbabc
+ 0: abcbabc
+ 1: abc
+ ** Failers
+No match
+ abcXabc
+No match
+
+/(?1)[^]a()b](abc)/
+ abcXabc
+ 0: abcXabc
+ 1: abc
+ ** Failers
+No match
+ abcbabc
+No match
+
+/(?2)[]a()b](abc)(xyz)/
+ xyzbabcxyz
+ 0: xyzbabcxyz
+ 1: abc
+ 2: xyz
+
+/(?&N)[]a(?<N>)](?<M>abc)/
+Failed: reference to non-existent subpattern at offset 4
+
+/(?&N)[]a(?<N>)](abc)/
+Failed: reference to non-existent subpattern at offset 4
+
+/a[]b/
+Failed: missing terminating ] for character class at offset 4
+
+/a[^]b/
+Failed: missing terminating ] for character class at offset 5
+
+/a[]b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[]+b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[]*+b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[^]b/<JS>
+ aXb
+ 0: aXb
+ a\nb
+ 0: a\x0ab
+ ** Failers
+No match
+ ab
+No match
+
+/a[^]+b/<JS>
+ aXb
+ 0: aXb
+ a\nX\nXb
+ 0: a\x0aX\x0aXb
+ ** Failers
+No match
+ ab
+No match
+
+/a(?!)+b/
+Failed: nothing to repeat at offset 5
+
+/a(*FAIL)+b/
+Failed: nothing to repeat at offset 8
/ End of testinput2 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput3 b/ext/pcre/pcrelib/testdata/testoutput3
index c539579832..28b1c3aaaf 100644
--- a/ext/pcre/pcrelib/testdata/testoutput3
+++ b/ext/pcre/pcrelib/testdata/testoutput3
@@ -146,14 +146,14 @@ No match
>>>\xba<<<
0: º
-/[[:alpha:]][[:lower:]][[:upper:]]/DLfr_FR
+/[[:alpha:]][[:lower:]][[:upper:]]/DZLfr_FR
------------------------------------------------------------------
- 0 102 Bra 0
- 3 [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff]
- 36 [a-z\xb5\xdf-\xf6\xf8-\xff]
- 69 [A-Z\xc0-\xd6\xd8-\xde]
-102 102 Ket
-105 End
+ Bra
+ [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff]
+ [a-z\xb5\xdf-\xf6\xf8-\xff]
+ [A-Z\xc0-\xd6\xd8-\xde]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
diff --git a/ext/pcre/pcrelib/testdata/testoutput4 b/ext/pcre/pcrelib/testdata/testoutput4
index 966b28568c..d87ea4bcc4 100644
--- a/ext/pcre/pcrelib/testdata/testoutput4
+++ b/ext/pcre/pcrelib/testdata/testoutput4
@@ -918,4 +918,157 @@ No match
a
0: a
+/\S\S/8g
+ A\x{a3}BC
+ 0: A\x{a3}
+ 0: BC
+
+/\S{2}/8g
+ A\x{a3}BC
+ 0: A\x{a3}
+ 0: BC
+
+/\W\W/8g
+ +\x{a3}==
+ 0: +\x{a3}
+ 0: ==
+
+/\W{2}/8g
+ +\x{a3}==
+ 0: +\x{a3}
+ 0: ==
+
+/\S/8g
+ \x{442}\x{435}\x{441}\x{442}
+ 0: \x{442}
+ 0: \x{435}
+ 0: \x{441}
+ 0: \x{442}
+
+/[\S]/8g
+ \x{442}\x{435}\x{441}\x{442}
+ 0: \x{442}
+ 0: \x{435}
+ 0: \x{441}
+ 0: \x{442}
+
+/\D/8g
+ \x{442}\x{435}\x{441}\x{442}
+ 0: \x{442}
+ 0: \x{435}
+ 0: \x{441}
+ 0: \x{442}
+
+/[\D]/8g
+ \x{442}\x{435}\x{441}\x{442}
+ 0: \x{442}
+ 0: \x{435}
+ 0: \x{441}
+ 0: \x{442}
+
+/\W/8g
+ \x{2442}\x{2435}\x{2441}\x{2442}
+ 0: \x{2442}
+ 0: \x{2435}
+ 0: \x{2441}
+ 0: \x{2442}
+
+/[\W]/8g
+ \x{2442}\x{2435}\x{2441}\x{2442}
+ 0: \x{2442}
+ 0: \x{2435}
+ 0: \x{2441}
+ 0: \x{2442}
+
+/[\S\s]*/8
+ abc\n\r\x{442}\x{435}\x{441}\x{442}xyz
+ 0: abc\x{0a}\x{0d}\x{442}\x{435}\x{441}\x{442}xyz
+
+/[\x{41f}\S]/8g
+ \x{442}\x{435}\x{441}\x{442}
+ 0: \x{442}
+ 0: \x{435}
+ 0: \x{441}
+ 0: \x{442}
+
+/.[^\S]./8g
+ abc def\x{442}\x{443}xyz\npqr
+ 0: c d
+ 0: z\x{0a}p
+
+/.[^\S\n]./8g
+ abc def\x{442}\x{443}xyz\npqr
+ 0: c d
+
+/[[:^alnum:]]/8g
+ +\x{2442}
+ 0: +
+ 0: \x{2442}
+
+/[[:^alpha:]]/8g
+ +\x{2442}
+ 0: +
+ 0: \x{2442}
+
+/[[:^ascii:]]/8g
+ A\x{442}
+ 0: \x{442}
+
+/[[:^blank:]]/8g
+ A\x{442}
+ 0: A
+ 0: \x{442}
+
+/[[:^cntrl:]]/8g
+ A\x{442}
+ 0: A
+ 0: \x{442}
+
+/[[:^digit:]]/8g
+ A\x{442}
+ 0: A
+ 0: \x{442}
+
+/[[:^graph:]]/8g
+ \x19\x{e01ff}
+ 0: \x{19}
+ 0: \x{e01ff}
+
+/[[:^lower:]]/8g
+ A\x{422}
+ 0: A
+ 0: \x{422}
+
+/[[:^print:]]/8g
+ \x{19}\x{e01ff}
+ 0: \x{19}
+ 0: \x{e01ff}
+
+/[[:^punct:]]/8g
+ A\x{442}
+ 0: A
+ 0: \x{442}
+
+/[[:^space:]]/8g
+ A\x{442}
+ 0: A
+ 0: \x{442}
+
+/[[:^upper:]]/8g
+ a\x{442}
+ 0: a
+ 0: \x{442}
+
+/[[:^word:]]/8g
+ +\x{2442}
+ 0: +
+ 0: \x{2442}
+
+/[[:^xdigit:]]/8g
+ M\x{442}
+ 0: M
+ 0: \x{442}
+
+/[^ABCDEFGHIJKLMNOPQRSTUVWXYZÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃÞĀĂĄĆĈĊČĎÄĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIJĴĶĹĻĽĿÅŃŅŇŊŌŎÅŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽÆƂƄƆƇƉƊƋƎÆÆƑƓƔƖƗƘƜÆƟƠƢƤƦƧƩƬƮƯƱƲƳƵƷƸƼDŽLJNJÇÇǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮDZǴǶǷǸǺǼǾȀȂȄȆȈȊȌȎÈȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾÉΆΈΉΊΌΎÎΑΒΓΔΕΖΗΘΙΚΛΜÎΞΟΠΡΣΤΥΦΧΨΩΪΫϒϓϔϘϚϜϞϠϢϤϦϨϪϬϮϴϷϹϺϽϾϿЀÐЂЃЄЅІЇЈЉЊЋЌÐÐŽÐÐБВГДЕЖЗИЙКЛМÐОПРСТУФХЦЧШЩЪЫЬЭЮЯѠѢѤѦѨѪѬѮѰѲѴѶѸѺѼѾҀҊҌҎÒҒҔҖҘҚҜҞҠҢҤҦҨҪҬҮҰҲҴҶҸҺҼҾӀÓÓƒÓ…Ó‡Ó‰Ó‹ÓÓӒӔӖӘӚӜӞӠӢӤӦӨӪӬӮӰӲӴӶӸԀԂԄԆԈԊԌԎԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀÕÕ‚ÕƒÕ„Õ…Õ†Õ‡ÕˆÕ‰ÕŠÕ‹ÕŒÕÕŽÕÕՑՒՓՔՕՖႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀáƒáƒ‚ჃჄჅḀḂḄḆḈḊḌḎá¸á¸’ḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎá¹á¹’ṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎáºáº’ẔẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎá»á»’ỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸἈἉἊἋἌá¼á¼Žá¼á¼˜á¼™á¼šá¼›á¼œá¼á¼¨á¼©á¼ªá¼«á¼¬á¼­á¼®á¼¯á¼¸á¼¹á¼ºá¼»á¼¼á¼½á¼¾á¼¿á½ˆá½‰á½Šá½‹á½Œá½á½™á½›á½á½Ÿá½¨á½©á½ªá½«á½¬á½­á½®á½¯á¾¸á¾¹á¾ºá¾»á¿ˆá¿‰á¿Šá¿‹á¿˜á¿™á¿šá¿›á¿¨á¿©á¿ªá¿«á¿¬á¿¸á¿¹á¿ºá¿»abcdefghijklmnopqrstuvwxyzªµºßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÄăąćĉċÄÄđēĕėęěÄğġģĥħĩīĭįıijĵķĸĺļľŀłńņňʼnŋÅÅőœŕŗřśÅşšţťŧũūŭůűųŵŷźżžſƀƃƅƈƌƃƕƙƚƛƞơƣƥƨƪƫƭưƴƶƹƺƽƾƿdžljnjǎÇǒǔǖǘǚǜÇǟǡǣǥǧǩǫǭǯǰdzǵǹǻǽǿÈȃȅȇȉȋÈÈȑȓȕȗșțÈȟȡȣȥȧȩȫȭȯȱȳȴȵȶȷȸȹȼȿɀÉɑɒɓɔɕɖɗɘəɚɛɜÉɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀÊʂʃʄʅʆʇʈʉʊʋʌÊÊŽÊÊʑʒʓʔʕʖʗʘʙʚʛʜÊʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯÎάέήίΰαβγδεζηθικλμνξοπÏςστυφχψωϊϋόÏÏŽÏϑϕϖϗϙϛÏϟϡϣϥϧϩϫϭϯϰϱϲϳϵϸϻϼабвгдежзийклмнопрÑтуфхцчшщъыьÑÑŽÑÑёђѓєѕіїјљњћќÑўџѡѣѥѧѩѫѭѯѱѳѵѷѹѻѽѿÒÒ‹ÒÒÒ‘Ò“Ò•Ò—Ò™Ò›ÒҟҡңҥҧҩҫҭүұҳҵҷҹһҽҿӂӄӆӈӊӌӎӑӓӕӗәӛÓÓŸÓ¡Ó£Ó¥Ó§Ó©Ó«Ó­Ó¯Ó±Ó³ÓµÓ·Ó¹ÔÔƒÔ…Ô‡Ô‰Ô‹ÔÔÕ¡Õ¢Õ£Õ¤Õ¥Õ¦Õ§Õ¨Õ©ÕªÕ«Õ¬Õ­Õ®Õ¯Õ°Õ±Õ²Õ³Õ´ÕµÕ¶Õ·Õ¸Õ¹ÕºÕ»Õ¼Õ½Õ¾Õ¿Ö€Öւփքօֆևᴀá´á´‚ᴃᴄᴅᴆᴇᴈᴉᴊᴋᴌá´á´Žá´á´á´‘ᴒᴓᴔᴕᴖᴗᴘᴙᴚᴛᴜá´á´žá´Ÿá´ á´¡á´¢á´£á´¤á´¥á´¦á´§á´¨á´©á´ªá´«áµ¢áµ£áµ¤áµ¥áµ¦áµ§áµ¨áµ©áµªáµ«áµ¬áµ­áµ®áµ¯áµ°áµ±áµ²áµ³áµ´áµµáµ¶áµ·áµ¹áµºáµ»áµ¼áµ½áµ¾áµ¿á¶€á¶á¶‚ᶃᶄᶅᶆᶇᶈᶉᶊᶋᶌá¶á¶Žá¶á¶á¶‘ᶒᶓᶔᶕᶖᶗᶘᶙᶚá¸á¸ƒá¸…ḇḉḋá¸á¸á¸‘ḓḕḗḙḛá¸á¸Ÿá¸¡á¸£á¸¥á¸§á¸©á¸«á¸­á¸¯á¸±á¸³á¸µá¸·á¸¹á¸»á¸½á¸¿á¹á¹ƒá¹…ṇṉṋá¹á¹á¹‘ṓṕṗṙṛá¹á¹Ÿá¹¡á¹£á¹¥á¹§á¹©á¹«á¹­á¹¯á¹±á¹³á¹µá¹·á¹¹á¹»á¹½á¹¿áºáºƒáº…ẇẉẋáºáºáº‘ẓẕẖẗẘẙẚẛạảấầẩẫậắằẳẵặẹẻẽếá»á»ƒá»…ệỉịá»á»á»‘ồổỗộớá»á»Ÿá»¡á»£á»¥á»§á»©á»«á»­á»¯á»±á»³á»µá»·á»¹á¼€á¼á¼‚ἃἄἅἆἇá¼á¼‘ἒἓἔἕἠἡἢἣἤἥἦἧἰἱἲἳἴἵἶἷὀá½á½‚ὃὄὅá½á½‘ὒὓὔὕὖὗὠὡὢὣὤὥὦὧὰάὲέὴήὶίὸόὺύὼώᾀá¾á¾‚ᾃᾄᾅᾆᾇá¾á¾‘ᾒᾓᾔᾕᾖᾗᾠᾡᾢᾣᾤᾥᾦᾧᾰᾱᾲᾳᾴᾶᾷιῂῃῄῆῇá¿á¿‘ῒΐῖῗῠῡῢΰῤῥῦῧῲῳῴῶῷâ²â²ƒâ²…ⲇⲉⲋâ²â²â²‘ⲓⲕⲗⲙⲛâ²â²Ÿâ²¡â²£â²¥â²§â²©â²«â²­â²¯â²±â²³â²µâ²·â²¹â²»â²½â²¿â³â³ƒâ³…ⳇⳉⳋâ³â³â³‘ⳓⳕⳗⳙⳛâ³â³Ÿâ³¡â³£â³¤â´€â´â´‚ⴃⴄⴅⴆⴇⴈⴉⴊⴋⴌâ´â´Žâ´â´â´‘ⴒⴓⴔⴕⴖⴗⴘⴙⴚⴛⴜâ´â´žâ´Ÿâ´ â´¡â´¢â´£â´¤â´¥ï¬€ï¬ï¬‚ffifflſtstﬓﬔﬕﬖﬗ\d-_^]/8
+
/ End of testinput4 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput5 b/ext/pcre/pcrelib/testdata/testoutput5
index 61c6842d77..1c745f4cac 100644
--- a/ext/pcre/pcrelib/testdata/testoutput5
+++ b/ext/pcre/pcrelib/testdata/testoutput5
@@ -1,114 +1,105 @@
-/\x{100}/8DM
-Memory allocation (code space): 10
+/\x{100}/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{100}
- 6 6 Ket
- 9 End
+ Bra
+ \x{100}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 196
Need char = 128
-/\x{1000}/8DM
-Memory allocation (code space): 11
+/\x{1000}/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{1000}
- 7 7 Ket
- 10 End
+ Bra
+ \x{1000}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 225
Need char = 128
-/\x{10000}/8DM
-Memory allocation (code space): 12
+/\x{10000}/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 \x{10000}
- 8 8 Ket
- 11 End
+ Bra
+ \x{10000}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 240
Need char = 128
-/\x{100000}/8DM
-Memory allocation (code space): 12
+/\x{100000}/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 \x{100000}
- 8 8 Ket
- 11 End
+ Bra
+ \x{100000}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 244
Need char = 128
-/\x{1000000}/8DM
-Memory allocation (code space): 13
+/\x{1000000}/8DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 \x{1000000}
- 9 9 Ket
- 12 End
+ Bra
+ \x{1000000}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 249
Need char = 128
-/\x{4000000}/8DM
-Memory allocation (code space): 14
+/\x{4000000}/8DZ
------------------------------------------------------------------
- 0 10 Bra 0
- 3 \x{4000000}
- 10 10 Ket
- 13 End
+ Bra
+ \x{4000000}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 252
Need char = 128
-/\x{7fffFFFF}/8DM
-Memory allocation (code space): 14
+/\x{7fffFFFF}/8DZ
------------------------------------------------------------------
- 0 10 Bra 0
- 3 \x{7fffffff}
- 10 10 Ket
- 13 End
+ Bra
+ \x{7fffffff}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 253
Need char = 191
-/[\x{ff}]/8DM
-Memory allocation (code space): 10
+/[\x{ff}]/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{ff}
- 6 6 Ket
- 9 End
+ Bra
+ \x{ff}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 195
Need char = 191
-/[\x{100}]/8DM
-Memory allocation (code space): 15
+/[\x{100}]/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\x{100}]
- 11 11 Ket
- 14 End
+ Bra
+ [\x{100}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -125,36 +116,36 @@ Failed: character value in \x{...} sequence is too large at offset 12
\x{100}a\x{1234}bcd
0: \x{100}a\x{1234}
-/\x80/8D
+/\x80/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{80}
- 6 6 Ket
- 9 End
+ Bra
+ \x{80}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 194
Need char = 128
-/\xff/8D
+/\xff/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{ff}
- 6 6 Ket
- 9 End
+ Bra
+ \x{ff}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 195
Need char = 191
-/\x{0041}\x{2262}\x{0391}\x{002e}/D8
+/\x{0041}\x{2262}\x{0391}\x{002e}/DZ8
------------------------------------------------------------------
- 0 14 Bra 0
- 3 A\x{2262}\x{391}.
- 14 14 Ket
- 17 End
+ Bra
+ A\x{2262}\x{391}.
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -163,12 +154,12 @@ Need char = '.'
\x{0041}\x{2262}\x{0391}\x{002e}
0: A\x{2262}\x{391}.
-/\x{D55c}\x{ad6d}\x{C5B4}/D8
+/\x{D55c}\x{ad6d}\x{C5B4}/DZ8
------------------------------------------------------------------
- 0 15 Bra 0
- 3 \x{d55c}\x{ad6d}\x{c5b4}
- 15 15 Ket
- 18 End
+ Bra
+ \x{d55c}\x{ad6d}\x{c5b4}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -177,12 +168,12 @@ Need char = 180
\x{D55c}\x{ad6d}\x{C5B4}
0: \x{d55c}\x{ad6d}\x{c5b4}
-/\x{65e5}\x{672c}\x{8a9e}/D8
+/\x{65e5}\x{672c}\x{8a9e}/DZ8
------------------------------------------------------------------
- 0 15 Bra 0
- 3 \x{65e5}\x{672c}\x{8a9e}
- 15 15 Ket
- 18 End
+ Bra
+ \x{65e5}\x{672c}\x{8a9e}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -191,74 +182,74 @@ Need char = 158
\x{65e5}\x{672c}\x{8a9e}
0: \x{65e5}\x{672c}\x{8a9e}
-/\x{80}/D8
+/\x{80}/DZ8
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{80}
- 6 6 Ket
- 9 End
+ Bra
+ \x{80}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 194
Need char = 128
-/\x{084}/D8
+/\x{084}/DZ8
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{84}
- 6 6 Ket
- 9 End
+ Bra
+ \x{84}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 194
Need char = 132
-/\x{104}/D8
+/\x{104}/DZ8
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{104}
- 6 6 Ket
- 9 End
+ Bra
+ \x{104}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 196
Need char = 132
-/\x{861}/D8
+/\x{861}/DZ8
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{861}
- 7 7 Ket
- 10 End
+ Bra
+ \x{861}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 224
Need char = 161
-/\x{212ab}/D8
+/\x{212ab}/DZ8
------------------------------------------------------------------
- 0 8 Bra 0
- 3 \x{212ab}
- 8 8 Ket
- 11 End
+ Bra
+ \x{212ab}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 240
Need char = 171
-/.{3,5}X/D8
+/.{3,5}X/DZ8
------------------------------------------------------------------
- 0 13 Bra 0
- 3 Any{3}
- 7 Any{0,2}
- 11 X
- 13 13 Ket
- 16 End
+ Bra
+ Any{3}
+ Any{0,2}
+ X
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -269,13 +260,13 @@ Need char = 'X'
0: \x{212ab}\x{212ab}\x{212ab}\x{861}X
-/.{3,5}?/D8
+/.{3,5}?/DZ8
------------------------------------------------------------------
- 0 11 Bra 0
- 3 Any{3}
- 7 Any{0,2}?
- 11 11 Ket
- 14 End
+ Bra
+ Any{3}
+ Any{0,2}?
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -285,11 +276,9 @@ No need char
\x{212ab}\x{212ab}\x{212ab}\x{861}
0: \x{212ab}\x{212ab}\x{212ab}
-/-- These tests are here rather than in testinput4 because Perl 5.6 has --/
-/-- some problems with UTF-8 support, in the area of \x{..} where the --/
-No match
-/-- value is < 255. It grumbles about invalid UTF-8 strings. --/
-No match
+/-- These tests are here rather than in testinput4 because Perl 5.6 has some
+problems with UTF-8 support, in the area of \x{..} where the value is < 255.
+It grumbles about invalid UTF-8 strings. --/
/^[a\x{c0}]b/8
\x{c0}b
@@ -329,11 +318,9 @@ No match
/(?<=\C)X/8
Failed: \C not allowed in lookbehind assertion at offset 6
-/-- This one is here not because it's different to Perl, but because the --/
-/-- way the captured single-byte is displayed. (In Perl it becomes a --/
-No match
-/-- character, and you can't tell the difference.) --/
-No match
+/-- This one is here not because it's different to Perl, but because the way
+the captured single-byte is displayed. (In Perl it becomes a character, and you
+can't tell the difference.) --/
/X(\C)(.*)/8
X\x{1234}
@@ -345,13 +332,13 @@ No match
1: \x{0a}
2: abc
-/^[ab]/8D
+/^[ab]/8DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [ab]
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [ab]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored utf8
@@ -368,13 +355,13 @@ No match
\x{100}
No match
-/^[^ab]/8D
+/^[^ab]/8DZ
------------------------------------------------------------------
- 0 37 Bra 0
- 3 ^
- 4 [\x00-`c-\xff] (neg)
- 37 37 Ket
- 40 End
+ Bra
+ ^
+ [\x00-`c-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored utf8
@@ -391,12 +378,12 @@ No need char
aaa
No match
-/[^ab\xC0-\xF0]/8SD
+/[^ab\xC0-\xF0]/8SDZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x00-`c-\xbf\xf1-\xff] (neg)
- 36 36 Ket
- 39 End
+ Bra
+ [\x00-`c-\xbf\xf1-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -427,13 +414,13 @@ No match
\x{f0}
No match
-/Ä€{3,4}/8SD
+/Ä€{3,4}/8SDZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 \x{100}{3}
- 8 \x{100}?
- 11 11 Ket
- 14 End
+ Bra
+ \x{100}{3}
+ \x{100}?
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -444,16 +431,16 @@ Study returned NULL
\x{100}\x{100}\x{100}\x{100\x{100}
0: \x{100}\x{100}\x{100}
-/(\x{100}+|x)/8SD
+/(\x{100}+|x)/8SDZ
------------------------------------------------------------------
- 0 19 Bra 0
- 3 8 Bra 1
- 8 \x{100}+
- 11 5 Alt
- 14 x
- 16 13 Ket
- 19 19 Ket
- 22 End
+ Bra
+ CBra 1
+ \x{100}+
+ Alt
+ x
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -462,17 +449,17 @@ No first char
No need char
Starting byte set: x \xc4
-/(\x{100}*a|x)/8SD
+/(\x{100}*a|x)/8SDZ
------------------------------------------------------------------
- 0 21 Bra 0
- 3 10 Bra 1
- 8 \x{100}*+
- 11 a
- 13 5 Alt
- 16 x
- 18 15 Ket
- 21 21 Ket
- 24 End
+ Bra
+ CBra 1
+ \x{100}*+
+ a
+ Alt
+ x
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -481,17 +468,17 @@ No first char
No need char
Starting byte set: a x \xc4
-/(\x{100}{0,2}a|x)/8SD
+/(\x{100}{0,2}a|x)/8SDZ
------------------------------------------------------------------
- 0 23 Bra 0
- 3 12 Bra 1
- 8 \x{100}{0,2}
- 13 a
- 15 5 Alt
- 18 x
- 20 17 Ket
- 23 23 Ket
- 26 End
+ Bra
+ CBra 1
+ \x{100}{0,2}
+ a
+ Alt
+ x
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -500,18 +487,18 @@ No first char
No need char
Starting byte set: a x \xc4
-/(\x{100}{1,2}a|x)/8SD
+/(\x{100}{1,2}a|x)/8SDZ
------------------------------------------------------------------
- 0 26 Bra 0
- 3 15 Bra 1
- 8 \x{100}
- 11 \x{100}{0,1}
- 16 a
- 18 5 Alt
- 21 x
- 23 20 Ket
- 26 26 Ket
- 29 End
+ Bra
+ CBra 1
+ \x{100}
+ \x{100}{0,1}
+ a
+ Alt
+ x
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Partial matching not supported
@@ -544,24 +531,24 @@ No match
\x{100}\x{100}abcd
No match
-/\x{100}/8D
+/\x{100}/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{100}
- 6 6 Ket
- 9 End
+ Bra
+ \x{100}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 196
Need char = 128
-/\x{100}*/8D
+/\x{100}*/8DZ
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{100}*
- 6 6 Ket
- 9 End
+ Bra
+ \x{100}*
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -569,13 +556,13 @@ Options: utf8
No first char
No need char
-/a\x{100}*/8D
+/a\x{100}*/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 a
- 5 \x{100}*
- 8 8 Ket
- 11 End
+ Bra
+ a
+ \x{100}*
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -583,13 +570,13 @@ Options: utf8
First char = 'a'
No need char
-/ab\x{100}*/8D
+/ab\x{100}*/8DZ
------------------------------------------------------------------
- 0 10 Bra 0
- 3 ab
- 7 \x{100}*
- 10 10 Ket
- 13 End
+ Bra
+ ab
+ \x{100}*
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -597,13 +584,13 @@ Options: utf8
First char = 'a'
Need char = 'b'
-/a\x{100}\x{101}*/8D
+/a\x{100}\x{101}*/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 a\x{100}
- 8 \x{101}*
- 11 11 Ket
- 14 End
+ Bra
+ a\x{100}
+ \x{101}*
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -611,13 +598,13 @@ Options: utf8
First char = 'a'
Need char = 128
-/a\x{100}\x{101}+/8D
+/a\x{100}\x{101}+/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 a\x{100}
- 8 \x{101}+
- 11 11 Ket
- 14 End
+ Bra
+ a\x{100}
+ \x{101}+
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -625,13 +612,13 @@ Options: utf8
First char = 'a'
Need char = 129
-/\x{100}*A/8D
+/\x{100}*A/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 \x{100}*+
- 6 A
- 8 8 Ket
- 11 End
+ Bra
+ \x{100}*+
+ A
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -641,16 +628,16 @@ Need char = 'A'
A
0: A
-/\x{100}*\d(?R)/8D
+/\x{100}*\d(?R)/8DZ
------------------------------------------------------------------
- 0 16 Bra 0
- 3 \x{100}*+
- 6 \d
- 7 6 Once
- 10 0 Recurse
- 13 6 Ket
- 16 16 Ket
- 19 End
+ Bra
+ \x{100}*+
+ \d
+ Once
+ Recurse
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -658,37 +645,36 @@ Options: utf8
No first char
No need char
-/[^\x{c4}]/D
+/[^\x{c4}]/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 [^\xc4]
- 5 5 Ket
- 8 End
+ Bra
+ [^\xc4]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[^\x{c4}]/8D
+/[^\x{c4}]/8DZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x00-\xc3\xc5-\xff] (neg)
- 36 36 Ket
- 39 End
+ Bra
+ [\x00-\xc3\xc5-\xff] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
No first char
No need char
-/[\x{100}]/8DM
-Memory allocation (code space): 15
+/[\x{100}]/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\x{100}]
- 11 11 Ket
- 14 End
+ Bra
+ [\x{100}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -703,13 +689,12 @@ No need char
*** Failers
No match
-/[Z\x{100}]/8DM
-Memory allocation (code space): 47
+/[Z\x{100}]/8DZ
------------------------------------------------------------------
- 0 43 Bra 0
- 3 [Z\x{100}]
- 43 43 Ket
- 46 End
+ Bra
+ [Z\x{100}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -739,24 +724,24 @@ No match
\x{ff}
No match
-/[z-\x{100}]/8D
+/[z-\x{100}]/8DZ
------------------------------------------------------------------
- 0 12 Bra 0
- 3 [z-\x{100}]
- 12 12 Ket
- 15 End
+ Bra
+ [z-\x{100}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
No first char
No need char
-/[z\Qa-d]Ä€\E]/8D
+/[z\Qa-d]Ä€\E]/8DZ
------------------------------------------------------------------
- 0 43 Bra 0
- 3 [\-\]adz\x{100}]
- 43 43 Ket
- 46 End
+ Bra
+ [\-\]adz\x{100}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -767,12 +752,12 @@ No need char
Ä€
0: \x{100}
-/[\xFF]/D
+/[\xFF]/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 \xff
- 5 5 Ket
- 8 End
+ Bra
+ \xff
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
@@ -781,12 +766,12 @@ No need char
>\xff<
0: \xff
-/[\xff]/D8
+/[\xff]/DZ8
------------------------------------------------------------------
- 0 6 Bra 0
- 3 \x{ff}
- 6 6 Ket
- 9 End
+ Bra
+ \x{ff}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -795,24 +780,24 @@ Need char = 191
>\x{ff}<
0: \x{ff}
-/[^\xFF]/D
+/[^\xFF]/DZ
------------------------------------------------------------------
- 0 5 Bra 0
- 3 [^\xff]
- 5 5 Ket
- 8 End
+ Bra
+ [^\xff]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[^\xff]/8D
+/[^\xff]/8DZ
------------------------------------------------------------------
- 0 36 Bra 0
- 3 [\x00-\xfe] (neg)
- 36 36 Ket
- 39 End
+ Bra
+ [\x00-\xfe] (neg)
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -852,12 +837,12 @@ Failed: invalid UTF-8 string at offset 0
/ÃÃÃxxx/8
Failed: invalid UTF-8 string at offset 1
-/ÃÃÃxxx/8?D
+/ÃÃÃxxx/8?DZ
------------------------------------------------------------------
- 0 15 Bra 0
- 3 \X{c0}\X{c0}\X{c0}xxx
- 15 15 Ket
- 18 End
+ Bra
+ \X{c0}\X{c0}\X{c0}xxx
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8 no_utf8_check
@@ -902,178 +887,186 @@ No match
\xf1\x8f\x80\x80
No match
\xf8\x88\x80\x80\x80
-No match
+Error -10
\xf9\x87\x80\x80\x80
-No match
+Error -10
\xfc\x84\x80\x80\x80\x80
-No match
+Error -10
\xfd\x83\x80\x80\x80\x80
+Error -10
+ \?\xf8\x88\x80\x80\x80
+No match
+ \?\xf9\x87\x80\x80\x80
+No match
+ \?\xfc\x84\x80\x80\x80\x80
+No match
+ \?\xfd\x83\x80\x80\x80\x80
No match
-/\x{100}abc(xyz(?1))/8D
+/\x{100}abc(xyz(?1))/8DZ
------------------------------------------------------------------
- 0 35 Bra 0
- 3 \x{100}abc
- 12 20 Bra 1
- 17 xyz
- 23 6 Once
- 26 12 Recurse
- 29 6 Ket
- 32 20 Ket
- 35 35 Ket
- 38 End
+ Bra
+ \x{100}abc
+ CBra 1
+ xyz
+ Once
+ Recurse
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Options: utf8
First char = 196
Need char = 'z'
-/[^\x{100}]abc(xyz(?1))/8D
+/[^\x{100}]abc(xyz(?1))/8DZ
------------------------------------------------------------------
- 0 40 Bra 0
- 3 [^\x{100}]
- 11 abc
- 17 20 Bra 1
- 22 xyz
- 28 6 Once
- 31 17 Recurse
- 34 6 Ket
- 37 20 Ket
- 40 40 Ket
- 43 End
+ Bra
+ [^\x{100}]
+ abc
+ CBra 1
+ xyz
+ Once
+ Recurse
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Options: utf8
No first char
Need char = 'z'
-/[ab\x{100}]abc(xyz(?1))/8D
+/[ab\x{100}]abc(xyz(?1))/8DZ
------------------------------------------------------------------
- 0 72 Bra 0
- 3 [ab\x{100}]
- 43 abc
- 49 20 Bra 1
- 54 xyz
- 60 6 Once
- 63 49 Recurse
- 66 6 Ket
- 69 20 Ket
- 72 72 Ket
- 75 End
+ Bra
+ [ab\x{100}]
+ abc
+ CBra 1
+ xyz
+ Once
+ Recurse
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 1
Options: utf8
No first char
Need char = 'z'
-/(\x{100}(b(?2)c))?/D8
-------------------------------------------------------------------
- 0 36 Bra 0
- 3 Brazero
- 4 29 Bra 1
- 9 \x{100}
- 12 18 Bra 2
- 17 b
- 19 6 Once
- 22 12 Recurse
- 25 6 Ket
- 28 c
- 30 18 Ket
- 33 29 Ket
- 36 36 Ket
- 39 End
+/(\x{100}(b(?2)c))?/DZ8
+------------------------------------------------------------------
+ Bra
+ Brazero
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Options: utf8
No first char
No need char
-/(\x{100}(b(?2)c)){0,2}/D8
-------------------------------------------------------------------
- 0 75 Bra 0
- 3 Brazero
- 4 68 Bra 0
- 7 29 Bra 1
- 12 \x{100}
- 15 18 Bra 2
- 20 b
- 22 6 Once
- 25 15 Recurse
- 28 6 Ket
- 31 c
- 33 18 Ket
- 36 29 Ket
- 39 Brazero
- 40 29 Bra 1
- 45 \x{100}
- 48 18 Bra 2
- 53 b
- 55 6 Once
- 58 15 Recurse
- 61 6 Ket
- 64 c
- 66 18 Ket
- 69 29 Ket
- 72 68 Ket
- 75 75 Ket
- 78 End
+/(\x{100}(b(?2)c)){0,2}/DZ8
+------------------------------------------------------------------
+ Bra
+ Brazero
+ Bra
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Brazero
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Options: utf8
No first char
No need char
-/(\x{100}(b(?1)c))?/D8
-------------------------------------------------------------------
- 0 36 Bra 0
- 3 Brazero
- 4 29 Bra 1
- 9 \x{100}
- 12 18 Bra 2
- 17 b
- 19 6 Once
- 22 4 Recurse
- 25 6 Ket
- 28 c
- 30 18 Ket
- 33 29 Ket
- 36 36 Ket
- 39 End
+/(\x{100}(b(?1)c))?/DZ8
+------------------------------------------------------------------
+ Bra
+ Brazero
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Options: utf8
No first char
No need char
-/(\x{100}(b(?1)c)){0,2}/D8
-------------------------------------------------------------------
- 0 75 Bra 0
- 3 Brazero
- 4 68 Bra 0
- 7 29 Bra 1
- 12 \x{100}
- 15 18 Bra 2
- 20 b
- 22 6 Once
- 25 7 Recurse
- 28 6 Ket
- 31 c
- 33 18 Ket
- 36 29 Ket
- 39 Brazero
- 40 29 Bra 1
- 45 \x{100}
- 48 18 Bra 2
- 53 b
- 55 6 Once
- 58 7 Recurse
- 61 6 Ket
- 64 c
- 66 18 Ket
- 69 29 Ket
- 72 68 Ket
- 75 75 Ket
- 78 End
+/(\x{100}(b(?1)c)){0,2}/DZ8
+------------------------------------------------------------------
+ Bra
+ Brazero
+ Bra
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Brazero
+ CBra 1
+ \x{100}
+ CBra 2
+ b
+ Once
+ Recurse
+ Ket
+ c
+ Ket
+ Ket
+ Ket
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 2
Options: utf8
@@ -1094,13 +1087,13 @@ No need char
a\x{1234}b
0: a\x{1234}b
-/^\ሴ/8D
+/^\ሴ/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 ^
- 4 \x{1234}
- 8 8 Ket
- 11 End
+ Bra
+ ^
+ \x{1234}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: anchored utf8
@@ -1120,13 +1113,13 @@ Need char = 191
\777
0: \x{1ff}
-/\x{100}*\d/8D
+/\x{100}*\d/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*+
- 6 \d
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*+
+ \d
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1134,13 +1127,13 @@ Options: utf8
No first char
No need char
-/\x{100}*\s/8D
+/\x{100}*\s/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*+
- 6 \s
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*+
+ \s
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1148,13 +1141,13 @@ Options: utf8
No first char
No need char
-/\x{100}*\w/8D
+/\x{100}*\w/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*+
- 6 \w
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*+
+ \w
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1162,13 +1155,13 @@ Options: utf8
No first char
No need char
-/\x{100}*\D/8D
+/\x{100}*\D/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*
- 6 \D
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*
+ \D
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1176,13 +1169,13 @@ Options: utf8
No first char
No need char
-/\x{100}*\S/8D
+/\x{100}*\S/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*
- 6 \S
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*
+ \S
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1190,13 +1183,13 @@ Options: utf8
No first char
No need char
-/\x{100}*\W/8D
+/\x{100}*\W/8DZ
------------------------------------------------------------------
- 0 7 Bra 0
- 3 \x{100}*
- 6 \W
- 7 7 Ket
- 10 End
+ Bra
+ \x{100}*
+ \W
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1204,13 +1197,13 @@ Options: utf8
No first char
No need char
-/\x{100}+\x{200}/8D
+/\x{100}+\x{200}/8DZ
------------------------------------------------------------------
- 0 9 Bra 0
- 3 \x{100}++
- 6 \x{200}
- 9 9 Ket
- 12 End
+ Bra
+ \x{100}++
+ \x{200}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1218,13 +1211,13 @@ Options: utf8
First char = 196
Need char = 128
-/\x{100}+X/8D
+/\x{100}+X/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 \x{100}++
- 6 X
- 8 8 Ket
- 11 End
+ Bra
+ \x{100}++
+ X
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1232,13 +1225,13 @@ Options: utf8
First char = 196
Need char = 'X'
-/X+\x{200}/8D
+/X+\x{200}/8DZ
------------------------------------------------------------------
- 0 8 Bra 0
- 3 X++
- 5 \x{200}
- 8 8 Ket
- 11 End
+ Bra
+ X++
+ \x{200}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -1269,25 +1262,25 @@ Matched, but too many substrings
13:
14:
-/^[\x{100}\E-\Q\E\x{150}]/B8
+/^[\x{100}\E-\Q\E\x{150}]/BZ8
------------------------------------------------------------------
- 0 14 Bra 0
- 3 ^
- 4 [\x{100}-\x{150}]
- 14 14 Ket
- 17 End
+ Bra
+ ^
+ [\x{100}-\x{150}]
+ Ket
+ End
------------------------------------------------------------------
-/^[\QÄ€\E-\QÅ\E]/B8
+/^[\QÄ€\E-\QÅ\E]/BZ8
------------------------------------------------------------------
- 0 14 Bra 0
- 3 ^
- 4 [\x{100}-\x{150}]
- 14 14 Ket
- 17 End
+ Bra
+ ^
+ [\x{100}-\x{150}]
+ Ket
+ End
------------------------------------------------------------------
-/^[\QÄ€\E-\QÅ\E/B8
+/^[\QÄ€\E-\QÅ\E/BZ8
Failed: missing terminating ] for character class at offset 15
/^abc./mgx8<any>
@@ -1314,7 +1307,7 @@ Failed: missing terminating ] for character class at offset 15
0: abc8
0: abc9
-/^a\Rb/8
+/^a\Rb/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\rb
@@ -1336,7 +1329,7 @@ No match
a\n\rb
No match
-/^a\R*b/8
+/^a\R*b/8<bsr_unicode>
ab
0: ab
a\nb
@@ -1356,7 +1349,7 @@ No match
a\n\r\x{85}\x0cb
0: a\x{0a}\x{0d}\x{85}\x{0c}b
-/^a\R+b/8
+/^a\R+b/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\rb
@@ -1378,7 +1371,7 @@ No match
ab
No match
-/^a\R{1,3}b/8
+/^a\R{1,3}b/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\n\rb
@@ -1400,4 +1393,239 @@ No match
a\r
No match
+/\H\h\V\v/8
+ X X\x0a
+ 0: X X\x{0a}
+ X\x09X\x0b
+ 0: X\x{09}X\x{0b}
+ ** Failers
+No match
+ \x{a0} X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ 0: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}\x{0d}
+ \x09\x20\x{a0}\x0a\x0b\x0c\x0d\x0a
+ 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}\x{0d}
+ \x09\x20\x{a0}\x0a\x0b\x0c
+ 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}
+ ** Failers
+No match
+ \x09\x20\x{a0}\x0a\x0b
+No match
+
+/\H\h\V\v/8
+ \x{3001}\x{3000}\x{2030}\x{2028}
+ 0: \x{3001}\x{3000}\x{2030}\x{2028}
+ X\x{180e}X\x{85}
+ 0: X\x{180e}X\x{85}
+ ** Failers
+No match
+ \x{2009} X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/8
+ \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x0c\x0d\x0a
+ 0: \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x{0c}\x{0d}
+ \x09\x{205f}\x{a0}\x0a\x{2029}\x0c\x{2028}\x0a
+ 0: \x{09}\x{205f}\x{a0}\x{0a}\x{2029}\x{0c}\x{2028}
+ \x09\x20\x{202f}\x0a\x0b\x0c
+ 0: \x{09} \x{202f}\x{0a}\x{0b}\x{0c}
+ ** Failers
+No match
+ \x09\x{200a}\x{a0}\x{2028}\x0b
+No match
+
+/[\h]/8BZ
+------------------------------------------------------------------
+ Bra
+ [\x09 \xa0\x{1680}\x{180e}\x{2000}-\x{200a}\x{202f}\x{205f}\x{3000}]
+ Ket
+ End
+------------------------------------------------------------------
+ >\x{1680}
+ 0: \x{1680}
+
+/[\h]{3,}/8BZ
+------------------------------------------------------------------
+ Bra
+ [\x09 \xa0\x{1680}\x{180e}\x{2000}-\x{200a}\x{202f}\x{205f}\x{3000}]{3,}
+ Ket
+ End
+------------------------------------------------------------------
+ >\x{1680}\x{180e}\x{2000}\x{2003}\x{200a}\x{202f}\x{205f}\x{3000}<
+ 0: \x{1680}\x{180e}\x{2000}\x{2003}\x{200a}\x{202f}\x{205f}\x{3000}
+
+/[\v]/8BZ
+------------------------------------------------------------------
+ Bra
+ [\x0a-\x0d\x85\x{2028}-\x{2029}]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\H]/8BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x08\x0a-\x1f!-\x9f\xa1-\xff\x{100}-\x{167f}\x{1681}-\x{180d}\x{180f}-\x{1fff}\x{200b}-\x{202e}\x{2030}-\x{205e}\x{2060}-\x{2fff}\x{3001}-\x{7fffffff}]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\V]/8BZ
+------------------------------------------------------------------
+ Bra
+ [\x00-\x09\x0e-\x84\x86-\xff\x{100}-\x{2027}\x{2029}-\x{7fffffff}]
+ Ket
+ End
+------------------------------------------------------------------
+
+/.*$/8<any>
+ \x{1ec5}
+ 0: \x{1ec5}
+
+/-- This tests the stricter UTF-8 check according to RFC 3629. --/
+
+/X/8
+ \x{0}\x{d7ff}\x{e000}\x{10ffff}
+No match
+ \x{d800}
+Error -10
+ \x{d800}\?
+No match
+ \x{da00}
+Error -10
+ \x{da00}\?
+No match
+ \x{dfff}
+Error -10
+ \x{dfff}\?
+No match
+ \x{110000}
+Error -10
+ \x{110000}\?
+No match
+ \x{2000000}
+Error -10
+ \x{2000000}\?
+No match
+ \x{7fffffff}
+Error -10
+ \x{7fffffff}\?
+No match
+
+/a\Rb/I8<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ ** Failers
+No match
+ a\x{85}b
+No match
+ a\x0bb
+No match
+
+/a\Rb/I8<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ a\x{85}b
+ 0: a\x{85}b
+ a\x0bb
+ 0: a\x{0b}b
+ ** Failers
+No match
+ a\x{85}b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R?b/I8<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ ** Failers
+No match
+ a\x{85}b
+No match
+ a\x0bb
+No match
+
+/a\R?b/I8<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ a\x{85}b
+ 0: a\x{85}b
+ a\x0bb
+ 0: a\x{0b}b
+ ** Failers
+No match
+ a\x{85}b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/.*a.*=.b.*/8<ANY>
+ QQQ\x{2029}ABCaXYZ=!bPQR
+ 0: ABCaXYZ=!bPQR
+ ** Failers
+No match
+ a\x{2029}b
+No match
+ \x61\xe2\x80\xa9\x62
+No match
+
+/[[:a\x{100}b:]]/8
+Failed: unknown POSIX class name at offset 3
+
+/a[^]b/<JS>8
+ a\x{1234}b
+ 0: a\x{1234}b
+ a\nb
+ 0: a\x{0a}b
+ ** Failers
+No match
+ ab
+No match
+
+/a[^]+b/<JS>8
+ aXb
+ 0: aXb
+ a\nX\nX\x{1234}b
+ 0: a\x{0a}X\x{0a}X\x{1234}b
+ ** Failers
+No match
+ ab
+No match
+
/ End of testinput5 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput6 b/ext/pcre/pcrelib/testdata/testoutput6
index a8bb0adaaa..db825b08c1 100644
--- a/ext/pcre/pcrelib/testdata/testoutput6
+++ b/ext/pcre/pcrelib/testdata/testoutput6
@@ -99,7 +99,7 @@ No match
No match
/^\p{Cs}/8
- \x{dfff}
+ \?\x{dfff}
0: \x{dfff}
** Failers
No match
@@ -113,7 +113,7 @@ No match
No match
Z
No match
- \x{dfff}
+ \x{e000}
No match
/^\p{Lm}/8
@@ -548,73 +548,72 @@ No match
WXYZ
No match
-/[\p{L}]/D
+/[\p{L}]/DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\p{L}]
- 11 11 Ket
- 14 End
+ Bra
+ [\p{L}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[\p{^L}]/D
+/[\p{^L}]/DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\P{L}]
- 11 11 Ket
- 14 End
+ Bra
+ [\P{L}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[\P{L}]/D
+/[\P{L}]/DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\P{L}]
- 11 11 Ket
- 14 End
+ Bra
+ [\P{L}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[\P{^L}]/D
+/[\P{^L}]/DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\p{L}]
- 11 11 Ket
- 14 End
+ Bra
+ [\p{L}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
No options
No first char
No need char
-/[abc\p{L}\x{0660}]/8D
+/[abc\p{L}\x{0660}]/8DZ
------------------------------------------------------------------
- 0 46 Bra 0
- 3 [a-c\p{L}\x{660}]
- 46 46 Ket
- 49 End
+ Bra
+ [a-c\p{L}\x{660}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
No first char
No need char
-/[\p{Nd}]/8DM
-Memory allocation (code space): 15
+/[\p{Nd}]/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 [\p{Nd}]
- 11 11 Ket
- 14 End
+ Bra
+ [\p{Nd}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
@@ -623,13 +622,12 @@ No need char
1234
0: 1
-/[\p{Nd}+-]+/8DM
-Memory allocation (code space): 48
+/[\p{Nd}+-]+/8DZ
------------------------------------------------------------------
- 0 44 Bra 0
- 3 [+\-\p{Nd}]+
- 44 44 Ket
- 47 End
+ Bra
+ [+\-\p{Nd}]+
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Partial matching not supported
@@ -779,48 +777,48 @@ No match
A\x{391}\x{10427}\x{ff3a}\x{1fb8}
0: A\x{391}\x{10427}\x{ff3a}\x{1fb8}
-/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iD
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8iDZ
------------------------------------------------------------------
- 0 21 Bra 0
- 3 NC A\x{391}\x{10427}\x{ff3a}\x{1fb0}
- 21 21 Ket
- 24 End
+ Bra
+ NC A\x{391}\x{10427}\x{ff3a}\x{1fb0}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless utf8
First char = 'A' (caseless)
No need char
-/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8D
+/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/8DZ
------------------------------------------------------------------
- 0 21 Bra 0
- 3 A\x{391}\x{10427}\x{ff3a}\x{1fb0}
- 21 21 Ket
- 24 End
+ Bra
+ A\x{391}\x{10427}\x{ff3a}\x{1fb0}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 'A'
Need char = 176
-/AB\x{1fb0}/8D
+/AB\x{1fb0}/8DZ
------------------------------------------------------------------
- 0 11 Bra 0
- 3 AB\x{1fb0}
- 11 11 Ket
- 14 End
+ Bra
+ AB\x{1fb0}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: utf8
First char = 'A'
Need char = 176
-/AB\x{1fb0}/8Di
+/AB\x{1fb0}/8DZi
------------------------------------------------------------------
- 0 11 Bra 0
- 3 NC AB\x{1fb0}
- 11 11 Ket
- 14 End
+ Bra
+ NC AB\x{1fb0}
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless utf8
@@ -857,12 +855,12 @@ Need char = 'B' (caseless)
\x{e0}
0: \x{e0}
-/[\x{105}-\x{109}]/8iD
+/[\x{105}-\x{109}]/8iDZ
------------------------------------------------------------------
- 0 13 Bra 0
- 3 [\x{104}-\x{109}]
- 13 13 Ket
- 16 End
+ Bra
+ [\x{104}-\x{109}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless utf8
@@ -881,12 +879,12 @@ No match
\x{10a}
No match
-/[z-\x{100}]/8iD
+/[z-\x{100}]/8iDZ
------------------------------------------------------------------
- 0 20 Bra 0
- 3 [Z\x{39c}\x{178}z-\x{101}]
- 20 20 Ket
- 23 End
+ Bra
+ [Z\x{39c}\x{178}z-\x{101}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless utf8
@@ -919,12 +917,12 @@ No match
y
No match
-/[z-\x{100}]/8Di
+/[z-\x{100}]/8DZi
------------------------------------------------------------------
- 0 20 Bra 0
- 3 [Z\x{39c}\x{178}z-\x{101}]
- 20 20 Ket
- 23 End
+ Bra
+ [Z\x{39c}\x{178}z-\x{101}]
+ Ket
+ End
------------------------------------------------------------------
Capturing subpattern count = 0
Options: caseless utf8
@@ -1432,4 +1430,253 @@ of case for anything other than the ASCII letters. /
\x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
0: \x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
+/The next two are special cases where the lengths of the different cases of the
+same character differ. The first went wrong with heap fram storage; the 2nd
+was broken in all cases./
+
+/^\x{023a}+?(\x{0130}+)/8i
+ \x{023a}\x{2c65}\x{0130}
+ 0: \x{23a}\x{2c65}\x{130}
+ 1: \x{130}
+
+/^\x{023a}+([^X])/8i
+ \x{023a}\x{2c65}X
+ 0: \x{23a}\x{2c65}
+ 1: \x{2c65}
+
+/Check property support in non-UTF-8 mode/
+
+/\p{L}{4}/
+ 123abcdefg
+ 0: abcd
+ 123abc\xc4\xc5zz
+ 0: abc\xc4
+
+/\X{1,3}\d/
+ \x8aBCD
+No match
+
+/\X?\d/
+ \x8aBCD
+No match
+
+/\P{L}?\d/
+ \x8aBCD
+No match
+
+/[\PPP\x8a]{1,}\x80/
+ A\x80
+ 0: A\x80
+
+/(?:[\PPa*]*){8,}/
+
+/[\P{Any}]/BZ
+------------------------------------------------------------------
+ Bra
+ [\P{Any}]
+ Ket
+ End
+------------------------------------------------------------------
+
+/[\P{Any}\E]/BZ
+------------------------------------------------------------------
+ Bra
+ [\P{Any}]
+ Ket
+ End
+------------------------------------------------------------------
+
+/(\P{Yi}+\277)/
+
+/(\P{Yi}+\277)?/
+
+/(?<=\P{Yi}{3}A)X/
+
+/\p{Yi}+(\P{Yi}+)(?1)/
+
+/(\P{Yi}{2}\277)?/
+
+/[\P{Yi}A]/
+
+/[\P{Yi}\P{Yi}\P{Yi}A]/
+
+/[^\P{Yi}A]/
+
+/[^\P{Yi}\P{Yi}\P{Yi}A]/
+
+/(\P{Yi}*\277)*/
+
+/(\P{Yi}*?\277)*/
+
+/(\p{Yi}*+\277)*/
+
+/(\P{Yi}?\277)*/
+
+/(\P{Yi}??\277)*/
+
+/(\p{Yi}?+\277)*/
+
+/(\P{Yi}{0,3}\277)*/
+
+/(\P{Yi}{0,3}?\277)*/
+
+/(\p{Yi}{0,3}+\277)*/
+
+/^[\p{Arabic}]/8
+ \x{60e}
+ 0: \x{60e}
+ \x{656}
+ 0: \x{656}
+ \x{657}
+ 0: \x{657}
+ \x{658}
+ 0: \x{658}
+ \x{659}
+ 0: \x{659}
+ \x{65a}
+ 0: \x{65a}
+ \x{65b}
+ 0: \x{65b}
+ \x{65c}
+ 0: \x{65c}
+ \x{65d}
+ 0: \x{65d}
+ \x{65e}
+ 0: \x{65e}
+ \x{66a}
+ 0: \x{66a}
+ \x{6e9}
+ 0: \x{6e9}
+ \x{6ef}
+ 0: \x{6ef}
+ \x{6fa}
+ 0: \x{6fa}
+ ** Failers
+No match
+ \x{600}
+No match
+ \x{650}
+No match
+ \x{651}
+No match
+ \x{652}
+No match
+ \x{653}
+No match
+ \x{654}
+No match
+ \x{655}
+No match
+ \x{65f}
+No match
+
+/^\p{Cyrillic}/8
+ \x{1d2b}
+ 0: \x{1d2b}
+
+/^\p{Common}/8
+ \x{589}
+ 0: \x{589}
+ \x{60c}
+ 0: \x{60c}
+ \x{61f}
+ 0: \x{61f}
+ \x{964}
+ 0: \x{964}
+ \x{965}
+ 0: \x{965}
+ \x{970}
+ 0: \x{970}
+
+/^\p{Inherited}/8
+ \x{64b}
+ 0: \x{64b}
+ \x{654}
+ 0: \x{654}
+ \x{655}
+ 0: \x{655}
+ \x{200c}
+ 0: \x{200c}
+ ** Failers
+No match
+ \x{64a}
+No match
+ \x{656}
+No match
+
+/^\p{Shavian}/8
+ \x{10450}
+ 0: \x{10450}
+ \x{1047f}
+ 0: \x{1047f}
+
+/^\p{Deseret}/8
+ \x{10400}
+ 0: \x{10400}
+ \x{1044f}
+ 0: \x{1044f}
+
+/^\p{Osmanya}/8
+ \x{10480}
+ 0: \x{10480}
+ \x{1049d}
+ 0: \x{1049d}
+ \x{104a0}
+ 0: \x{104a0}
+ \x{104a9}
+ 0: \x{104a9}
+ ** Failers
+No match
+ \x{1049e}
+No match
+ \x{1049f}
+No match
+ \x{104aa}
+No match
+
+/\p{Zl}{2,3}+/8BZ
+------------------------------------------------------------------
+ Bra
+ prop Zl {2}
+ prop Zl ?+
+ Ket
+ End
+------------------------------------------------------------------
+ \xe2\x80\xa8\xe2\x80\xa8
+ 0: \x{2028}\x{2028}
+ \x{2028}\x{2028}\x{2028}
+ 0: \x{2028}\x{2028}\x{2028}
+
+/\p{Zl}/8BZ
+------------------------------------------------------------------
+ Bra
+ prop Zl
+ Ket
+ End
+------------------------------------------------------------------
+
+/\p{Lu}{3}+/8BZ
+------------------------------------------------------------------
+ Bra
+ prop Lu {3}
+ Ket
+ End
+------------------------------------------------------------------
+
+/\pL{2}+/8BZ
+------------------------------------------------------------------
+ Bra
+ prop L {2}
+ Ket
+ End
+------------------------------------------------------------------
+
+/\p{Cc}{2}+/8BZ
+------------------------------------------------------------------
+ Bra
+ prop Cc {2}
+ Ket
+ End
+------------------------------------------------------------------
+
/ End of testinput6 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput7 b/ext/pcre/pcrelib/testdata/testoutput7
index 5bddc1e153..9ded29d678 100644
--- a/ext/pcre/pcrelib/testdata/testoutput7
+++ b/ext/pcre/pcrelib/testdata/testoutput7
@@ -3039,9 +3039,9 @@ No match
abcdefghijk\12S
0: abcdefghijk\x0aS
-/ab\hdef/
- abhdef
- 0: abhdef
+/ab\idef/
+ abidef
+ 0: abidef
/a{0}bc/
bc
@@ -6824,7 +6824,7 @@ No match
0: abc6
0: abc9
-/^a\Rb/
+/^a\Rb/<bsr_unicode>
a\nb
0: a\x0ab
a\rb
@@ -6842,7 +6842,7 @@ No match
a\n\rb
No match
-/^a\R*b/
+/^a\R*b/<bsr_unicode>
ab
0: ab
a\nb
@@ -6862,7 +6862,7 @@ No match
a\n\r\x85\x0cb
0: a\x0a\x0d\x85\x0cb
-/^a\R+b/
+/^a\R+b/<bsr_unicode>
a\nb
0: a\x0ab
a\rb
@@ -6884,7 +6884,7 @@ No match
ab
No match
-/^a\R{1,3}b/
+/^a\R{1,3}b/<bsr_unicode>
a\nb
0: a\x0ab
a\n\rb
@@ -6906,7 +6906,7 @@ No match
a\r
No match
-/^a[\R]b/
+/^a[\R]b/<bsr_unicode>
aRb
0: aRb
** Failers
@@ -6952,4 +6952,306 @@ No match
\nfoo
0: \x0afoo
+/^$/mg<any>
+ abc\r\rxyz
+ 0:
+ abc\n\rxyz
+ 0:
+ ** Failers
+No match
+ abc\r\nxyz
+No match
+
+/^X/m
+ XABC
+ 0: X
+ ** Failers
+No match
+ XABC\B
+No match
+
+/(?m)^$/<any>g+
+ abc\r\n\r\n
+ 0:
+ 0+ \x0d\x0a
+
+/(?m)^$|^\r\n/<any>g+
+ abc\r\n\r\n
+ 0: \x0d\x0a
+ 0+
+ 1:
+
+/(?m)$/<any>g+
+ abc\r\n\r\n
+ 0:
+ 0+ \x0d\x0a\x0d\x0a
+ 0:
+ 0+ \x0d\x0a
+ 0:
+ 0+
+
+/(?|(abc)|(xyz))/
+ >abc<
+ 0: abc
+ >xyz<
+ 0: xyz
+
+/(x)(?|(abc)|(xyz))(x)/
+ xabcx
+ 0: xabcx
+ xxyzx
+ 0: xxyzx
+
+/(x)(?|(abc)(pqr)|(xyz))(x)/
+ xabcpqrx
+ 0: xabcpqrx
+ xxyzx
+ 0: xxyzx
+
+/(?|(abc)|(xyz))(?1)/
+ abcabc
+ 0: abcabc
+ xyzabc
+ 0: xyzabc
+ ** Failers
+No match
+ xyzxyz
+No match
+
+/\H\h\V\v/
+ X X\x0a
+ 0: X X\x0a
+ X\x09X\x0b
+ 0: X\x09X\x0b
+ ** Failers
+No match
+ \xa0 X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/
+ \x09\x20\xa0X\x0a\x0b\x0c\x0d\x0a
+ 0: \x09 \xa0X\x0a\x0b\x0c\x0d
+ 1: \x09 \xa0X\x0a\x0b\x0c
+ \x09\x20\xa0\x0a\x0b\x0c\x0d\x0a
+ 0: \x09 \xa0\x0a\x0b\x0c\x0d
+ 1: \x09 \xa0\x0a\x0b\x0c
+ \x09\x20\xa0\x0a\x0b\x0c
+ 0: \x09 \xa0\x0a\x0b\x0c
+ ** Failers
+No match
+ \x09\x20\xa0\x0a\x0b
+No match
+
+/\H{3,4}/
+ XY ABCDE
+ 0: ABCD
+ 1: ABC
+ XY PQR ST
+ 0: PQR
+
+/.\h{3,4}./
+ XY AB PQRS
+ 0: B P
+ 1: B
+
+/\h*X\h?\H+Y\H?Z/
+ >XNNNYZ
+ 0: XNNNYZ
+ > X NYQZ
+ 0: X NYQZ
+ ** Failers
+No match
+ >XYZ
+No match
+ > X NY Z
+No match
+
+/\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/
+ >XY\x0aZ\x0aA\x0bNN\x0c
+ 0: XY\x0aZ\x0aA\x0bNN\x0c
+ >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+ 0: \x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c
+
+/.+A/<crlf>
+ \r\nA
+No match
+
+/\nA/<crlf>
+ \r\nA
+ 0: \x0aA
+
+/[\r\n]A/<crlf>
+ \r\nA
+ 0: \x0aA
+
+/(\r|\n)A/<crlf>
+ \r\nA
+ 0: \x0aA
+
+/a\Rb/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ ** Failers
+No match
+ a\x85b
+No match
+ a\x0bb
+No match
+
+/a\Rb/I<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ a\x85b
+ 0: a\x85b
+ a\x0bb
+ 0: a\x0bb
+ ** Failers
+No match
+ a\x85b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R?b/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ ** Failers
+No match
+ a\x85b
+No match
+ a\x0bb
+No match
+
+/a\R?b/I<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x0db
+ a\nb
+ 0: a\x0ab
+ a\r\nb
+ 0: a\x0d\x0ab
+ a\x85b
+ 0: a\x85b
+ a\x0bb
+ 0: a\x0bb
+ ** Failers
+No match
+ a\x85b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R{2,4}b/I<bsr_anycrlf>
+Capturing subpattern count = 0
+Partial matching not supported
+Options: bsr_anycrlf
+First char = 'a'
+Need char = 'b'
+ a\r\n\nb
+ 0: a\x0d\x0a\x0ab
+ a\n\r\rb
+ 0: a\x0a\x0d\x0db
+ a\r\n\r\n\r\n\r\nb
+ 0: a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0ab
+ ** Failers
+No match
+ a\x85\85b
+No match
+ a\x0b\0bb
+No match
+
+/a\R{2,4}b/I<bsr_unicode>
+Capturing subpattern count = 0
+Partial matching not supported
+Options: bsr_unicode
+First char = 'a'
+Need char = 'b'
+ a\r\rb
+ 0: a\x0d\x0db
+ a\n\n\nb
+ 0: a\x0a\x0a\x0ab
+ a\r\n\n\r\rb
+ 0: a\x0d\x0a\x0a\x0d\x0db
+ a\x85\85b
+No match
+ a\x0b\0bb
+No match
+ ** Failers
+No match
+ a\r\r\r\r\rb
+No match
+ a\x85\85b\<bsr_anycrlf>
+No match
+ a\x0b\0bb\<bsr_anycrlf>
+No match
+
+/a(?!)|\wbc/
+ abc
+ 0: abc
+
+/a[]b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[]+b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[]*+b/<JS>
+ ** Failers
+No match
+ ab
+No match
+
+/a[^]b/<JS>
+ aXb
+ 0: aXb
+ a\nb
+ 0: a\x0ab
+ ** Failers
+No match
+ ab
+No match
+
+/a[^]+b/<JS>
+ aXb
+ 0: aXb
+ a\nX\nXb
+ 0: a\x0aX\x0aXb
+ ** Failers
+No match
+ ab
+No match
+
/ End of testinput7 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput8 b/ext/pcre/pcrelib/testdata/testoutput8
index f8251ff5ea..631e5b82f9 100644
--- a/ext/pcre/pcrelib/testdata/testoutput8
+++ b/ext/pcre/pcrelib/testdata/testoutput8
@@ -1052,7 +1052,7 @@ No match
0: abc8
0: abc9
-/^a\Rb/8
+/^a\Rb/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\rb
@@ -1074,7 +1074,7 @@ No match
a\n\rb
No match
-/^a\R*b/8
+/^a\R*b/8<bsr_unicode>
ab
0: ab
a\nb
@@ -1094,7 +1094,7 @@ No match
a\n\r\x{85}\x0cb
0: a\x{0a}\x{0d}\x{85}\x{0c}b
-/^a\R+b/8
+/^a\R+b/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\rb
@@ -1116,7 +1116,7 @@ No match
ab
No match
-/^a\R{1,3}b/8
+/^a\R{1,3}b/8<bsr_unicode>
a\nb
0: a\x{0a}b
a\n\rb
@@ -1138,4 +1138,150 @@ No match
a\r
No match
+/\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ 0: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}\x{0d}
+ 1: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}
+
+/\V?\v{3,4}/8
+ \x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ 0: X\x{0a}\x{0b}\x{0c}\x{0d}
+ 1: X\x{0a}\x{0b}\x{0c}
+
+/\h+\V?\v{3,4}/8
+ >\x09\x20\x{a0}X\x0a\x0a\x0a<
+ 0: \x{09} \x{a0}X\x{0a}\x{0a}\x{0a}
+
+/\V?\v{3,4}/8
+ >\x09\x20\x{a0}X\x0a\x0a\x0a<
+ 0: X\x{0a}\x{0a}\x{0a}
+
+/\H\h\V\v/8
+ X X\x0a
+ 0: X X\x{0a}
+ X\x09X\x0b
+ 0: X\x{09}X\x{0b}
+ ** Failers
+No match
+ \x{a0} X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/8
+ \x09\x20\x{a0}X\x0a\x0b\x0c\x0d\x0a
+ 0: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}\x{0d}
+ 1: \x{09} \x{a0}X\x{0a}\x{0b}\x{0c}
+ \x09\x20\x{a0}\x0a\x0b\x0c\x0d\x0a
+ 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}\x{0d}
+ 1: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}
+ \x09\x20\x{a0}\x0a\x0b\x0c
+ 0: \x{09} \x{a0}\x{0a}\x{0b}\x{0c}
+ ** Failers
+No match
+ \x09\x20\x{a0}\x0a\x0b
+No match
+
+/\H\h\V\v/8
+ \x{3001}\x{3000}\x{2030}\x{2028}
+ 0: \x{3001}\x{3000}\x{2030}\x{2028}
+ X\x{180e}X\x{85}
+ 0: X\x{180e}X\x{85}
+ ** Failers
+No match
+ \x{2009} X\x0a
+No match
+
+/\H*\h+\V?\v{3,4}/8
+ \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x0c\x0d\x0a
+ 0: \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x{0c}\x{0d}
+ 1: \x{1680}\x{180e}\x{2007}X\x{2028}\x{2029}\x{0c}
+ \x09\x{205f}\x{a0}\x0a\x{2029}\x0c\x{2028}\x0a
+ 0: \x{09}\x{205f}\x{a0}\x{0a}\x{2029}\x{0c}\x{2028}
+ 1: \x{09}\x{205f}\x{a0}\x{0a}\x{2029}\x{0c}
+ \x09\x20\x{202f}\x0a\x0b\x0c
+ 0: \x{09} \x{202f}\x{0a}\x{0b}\x{0c}
+ ** Failers
+No match
+ \x09\x{200a}\x{a0}\x{2028}\x0b
+No match
+
+/a\Rb/I8<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ ** Failers
+No match
+ a\x{85}b
+No match
+ a\x0bb
+No match
+
+/a\Rb/I8<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ a\x{85}b
+ 0: a\x{85}b
+ a\x0bb
+ 0: a\x{0b}b
+ ** Failers
+No match
+ a\x{85}b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
+/a\R?b/I8<bsr_anycrlf>
+Capturing subpattern count = 0
+Options: bsr_anycrlf utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ ** Failers
+No match
+ a\x{85}b
+No match
+ a\x0bb
+No match
+
+/a\R?b/I8<bsr_unicode>
+Capturing subpattern count = 0
+Options: bsr_unicode utf8
+First char = 'a'
+Need char = 'b'
+ a\rb
+ 0: a\x{0d}b
+ a\nb
+ 0: a\x{0a}b
+ a\r\nb
+ 0: a\x{0d}\x{0a}b
+ a\x{85}b
+ 0: a\x{85}b
+ a\x0bb
+ 0: a\x{0b}b
+ ** Failers
+No match
+ a\x{85}b\<bsr_anycrlf>
+No match
+ a\x0bb\<bsr_anycrlf>
+No match
+
/ End of testinput 8 /
diff --git a/ext/pcre/pcrelib/testdata/testoutput9 b/ext/pcre/pcrelib/testdata/testoutput9
index 000e2b9882..acaeb398dd 100644
--- a/ext/pcre/pcrelib/testdata/testoutput9
+++ b/ext/pcre/pcrelib/testdata/testoutput9
@@ -271,7 +271,7 @@ No match
No match
/^\p{Cs}/8
- \x{dfff}
+ \?\x{dfff}
0: \x{dfff}
** Failers
No match
@@ -285,7 +285,7 @@ No match
No match
Z
No match
- \x{dfff}
+ \x{e000}
No match
/^\p{Lm}/8
@@ -1624,4 +1624,20 @@ No match
AXY
No match
+/^\x{023a}+?(\x{0130}+)/8i
+ \x{023a}\x{2c65}\x{0130}
+ 0: \x{23a}\x{2c65}\x{130}
+
+/^\x{023a}+([^X])/8i
+ \x{023a}\x{2c65}X
+ 0: \x{23a}\x{2c65}
+
+/Check property support in non-UTF-8 mode/
+
+/\p{L}{4}/
+ 123abcdefg
+ 0: abcd
+ 123abc\xc4\xc5zz
+ 0: abc\xc4
+
/ End /
diff --git a/ext/pcre/pcrelib/ucpinternal.h b/ext/pcre/pcrelib/ucpinternal.h
index 811a373c88..a96667b0a8 100644
--- a/ext/pcre/pcrelib/ucpinternal.h
+++ b/ext/pcre/pcrelib/ucpinternal.h
@@ -17,7 +17,7 @@ typedef struct cnode {
#define f0_scriptmask 0xff000000 /* Mask for script field */
#define f0_scriptshift 24 /* Shift for script value */
-#define f0_rangeflag 0x00f00000 /* Flag for a range item */
+#define f0_rangeflag 0x00800000 /* Flag for a range item */
#define f0_charmask 0x001fffff /* Mask for code point value */
/* Things for the f1 field */
diff --git a/ext/pcre/pcrelib/ucptable.c b/ext/pcre/pcrelib/ucptable.h
index 0b17906b12..a274d443ee 100644
--- a/ext/pcre/pcrelib/ucptable.c
+++ b/ext/pcre/pcrelib/ucptable.h
@@ -2,7 +2,7 @@
property table. See ucpinternal.h for a description of the layout.
This version was made from the Unicode 5.0.0 tables. */
-static cnode ucp_table[] = {
+static const cnode ucp_table[] = {
{ 0x09800000, 0x0000001f },
{ 0x09000020, 0x74000000 },
{ 0x09800021, 0x54000002 },
@@ -539,7 +539,8 @@ static cnode ucp_table[] = {
{ 0x21000293, 0x14000000 },
{ 0x21000294, 0x1c000000 },
{ 0x21800295, 0x1400001a },
- { 0x218002b0, 0x18000011 },
+ { 0x218002b0, 0x18000008 },
+ { 0x098002b9, 0x18000008 },
{ 0x098002c2, 0x60000003 },
{ 0x098002c6, 0x1800000b },
{ 0x098002d2, 0x6000000d },
@@ -1039,15 +1040,18 @@ static cnode ucp_table[] = {
{ 0x198005f3, 0x54000001 },
{ 0x09800600, 0x04000003 },
{ 0x0000060b, 0x5c000000 },
- { 0x0980060c, 0x54000001 },
+ { 0x0900060c, 0x54000000 },
+ { 0x0000060d, 0x54000000 },
{ 0x0080060e, 0x68000001 },
{ 0x00800610, 0x30000005 },
{ 0x0900061b, 0x54000000 },
- { 0x0080061e, 0x54000001 },
+ { 0x0000061e, 0x54000000 },
+ { 0x0900061f, 0x54000000 },
{ 0x00800621, 0x1c000019 },
{ 0x09000640, 0x18000000 },
{ 0x00800641, 0x1c000009 },
- { 0x1b80064b, 0x30000013 },
+ { 0x1b80064b, 0x3000000a },
+ { 0x00800656, 0x30000008 },
{ 0x09800660, 0x34000009 },
{ 0x0080066a, 0x54000003 },
{ 0x0080066e, 0x1c000001 },
@@ -1074,7 +1078,8 @@ static cnode ucp_table[] = {
{ 0x31000711, 0x30000000 },
{ 0x31800712, 0x1c00001d },
{ 0x31800730, 0x3000001a },
- { 0x3180074d, 0x1c000020 },
+ { 0x3180074d, 0x1c000002 },
+ { 0x00800750, 0x1c00001d },
{ 0x37800780, 0x1c000025 },
{ 0x378007a6, 0x3000000a },
{ 0x370007b1, 0x1c000000 },
@@ -1460,7 +1465,10 @@ static cnode ucp_table[] = {
{ 0x1f0017dd, 0x30000000 },
{ 0x1f8017e0, 0x34000009 },
{ 0x1f8017f0, 0x3c000009 },
- { 0x25801800, 0x54000005 },
+ { 0x25801800, 0x54000001 },
+ { 0x09801802, 0x54000001 },
+ { 0x25001804, 0x54000000 },
+ { 0x09001805, 0x54000000 },
{ 0x25001806, 0x44000000 },
{ 0x25801807, 0x54000003 },
{ 0x2580180b, 0x30000002 },
@@ -1513,14 +1521,20 @@ static cnode ucp_table[] = {
{ 0x3d801b61, 0x68000009 },
{ 0x3d801b6b, 0x30000008 },
{ 0x3d801b74, 0x68000008 },
- { 0x21801d00, 0x1400002b },
- { 0x21801d2c, 0x18000035 },
- { 0x21801d62, 0x14000015 },
+ { 0x21801d00, 0x14000025 },
+ { 0x13801d26, 0x14000004 },
+ { 0x0c001d2b, 0x14000000 },
+ { 0x21801d2c, 0x18000030 },
+ { 0x13801d5d, 0x18000004 },
+ { 0x21801d62, 0x14000003 },
+ { 0x13801d66, 0x14000004 },
+ { 0x21801d6b, 0x1400000c },
{ 0x0c001d78, 0x18000000 },
{ 0x21801d79, 0x14000003 },
{ 0x21001d7d, 0x14000ee6 },
{ 0x21801d7e, 0x1400001c },
- { 0x21801d9b, 0x18000024 },
+ { 0x21801d9b, 0x18000023 },
+ { 0x13001dbf, 0x18000000 },
{ 0x1b801dc0, 0x3000000a },
{ 0x1b801dfe, 0x30000001 },
{ 0x21001e00, 0x24000001 },
@@ -1982,7 +1996,9 @@ static cnode ucp_table[] = {
{ 0x13001ffc, 0x2000fff7 },
{ 0x13801ffd, 0x60000001 },
{ 0x09802000, 0x7400000a },
- { 0x0980200b, 0x04000004 },
+ { 0x0900200b, 0x04000000 },
+ { 0x1b80200c, 0x04000001 },
+ { 0x0980200e, 0x04000001 },
{ 0x09802010, 0x44000005 },
{ 0x09802016, 0x54000001 },
{ 0x09002018, 0x50000000 },
@@ -2615,7 +2631,8 @@ static cnode ucp_table[] = {
{ 0x090030a0, 0x44000000 },
{ 0x1d8030a1, 0x1c000059 },
{ 0x090030fb, 0x54000000 },
- { 0x098030fc, 0x18000002 },
+ { 0x090030fc, 0x18000000 },
+ { 0x1d8030fd, 0x18000001 },
{ 0x1d0030ff, 0x1c000000 },
{ 0x03803105, 0x1c000027 },
{ 0x17803131, 0x1c00005d },
@@ -2630,7 +2647,8 @@ static cnode ucp_table[] = {
{ 0x0980322a, 0x68000019 },
{ 0x09003250, 0x68000000 },
{ 0x09803251, 0x3c00000e },
- { 0x17803260, 0x6800001f },
+ { 0x17803260, 0x6800001d },
+ { 0x0980327e, 0x68000001 },
{ 0x09803280, 0x3c000009 },
{ 0x0980328a, 0x68000026 },
{ 0x098032b1, 0x3c00000e },
@@ -2678,7 +2696,8 @@ static cnode ucp_table[] = {
{ 0x1900fb3e, 0x1c000000 },
{ 0x1980fb40, 0x1c000001 },
{ 0x1980fb43, 0x1c000001 },
- { 0x1980fb46, 0x1c00006b },
+ { 0x1980fb46, 0x1c000009 },
+ { 0x0080fb50, 0x1c000061 },
{ 0x0080fbd3, 0x1c00016a },
{ 0x0900fd3e, 0x58000000 },
{ 0x0900fd3f, 0x48000000 },
@@ -2944,7 +2963,8 @@ static cnode ucp_table[] = {
{ 0x0d01044d, 0x1400ffd8 },
{ 0x0d01044e, 0x1400ffd8 },
{ 0x0d01044f, 0x1400ffd8 },
- { 0x2e810450, 0x1c00004d },
+ { 0x2e810450, 0x1c00002f },
+ { 0x2c810480, 0x1c00001d },
{ 0x2c8104a0, 0x34000009 },
{ 0x0b810800, 0x1c000005 },
{ 0x0b010808, 0x1c000000 },
diff --git a/ext/pcre/upgrade-pcre.php b/ext/pcre/upgrade-pcre.php
new file mode 100644
index 0000000000..43a98c94be
--- /dev/null
+++ b/ext/pcre/upgrade-pcre.php
@@ -0,0 +1,117 @@
+<?php
+
+// script to upgrade PCRE. just drop the pcre-x.x.tar.xx here and run the script
+
+$pattern = 'pcre-*.tar.*';
+$newpcre = glob($pattern);
+
+if (count($newpcre) > 1) {
+ echo "more than one '$pattern' file. aborting\n";
+ print_r($newpcre);
+ exit;
+}
+
+if (count($newpcre) == 0) {
+ die("need one '$pattern' file. aborting.\n");
+}
+
+
+$newpcre = $newpcre[0];
+
+if (strpos($newpcre, 'gz')) {
+ system("tar xfz $newpcre");
+} elseif (strpos($newpcre, 'bz2')) {
+ system("tar xfj $newpcre");
+} else {
+ die("file type not recognized: $newpcre\n");
+}
+
+$newpcre = substr($newpcre, 0, strpos($newpcre, '.tar'));
+$dirlen = strlen('pcrelib');
+
+function recurse($path)
+{
+ global $newpcre, $dirlen;
+
+ foreach (scandir($path) as $file) {
+
+ if ($file[0] === '.' ||
+ $file === 'CVS' ||
+ @substr_compare($file, '.lo', -3, 3) === 0 ||
+ @substr_compare($file, '.loT', -4, 4) === 0 ||
+ @substr_compare($file, '.o', -2, 2) === 0) continue;
+
+ $file = "$path/$file";
+
+ if (is_dir($file)) {
+ recurse($file);
+ continue;
+ }
+
+ echo "processing $file... ";
+
+ $newfile = $newpcre . substr($file, $dirlen);
+
+ if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
+ $newfile = $tmp;
+ }
+
+
+ if (!is_file($newfile)) {
+ die("$newfile is not available any more\n");
+ }
+
+ // maintain file mtimes so that cvs doesnt get crazy
+ if (file_get_contents($newfile) !== file_get_contents($file)) {
+ copy($newfile, $file);
+ }
+
+ // always include the config.h file
+ $content = file_get_contents($newfile);
+ $newcontent = preg_replace('/#\s*ifdef HAVE_CONFIG_H\s*(.+)\s*#\s*endif/', '$1', $content);
+
+ if ($content !== $newcontent) {
+ file_put_contents($file, $newcontent);
+ }
+
+ echo "OK\n";
+ }
+
+}
+
+
+recurse('pcrelib');
+
+$dirorig = scandir('pcrelib/testdata');
+$k = array_search('CVS', $dirorig);
+unset($dirorig[$k]);
+
+$dirnew = scandir("$newpcre/testdata");
+$diff = array_diff($dirorig, $dirnew);
+
+foreach ($diff as $file) {
+ $file2 = 'pcrelib'.substr($file, strlen($newpcre));
+ copy($file, $file2);
+}
+
+
+// the config.h needs special care
+$prepend_config_h = '
+#include <php_compat.h>
+#undef PACKAGE_NAME
+#undef PACKAGE_VERSION
+#undef PACKAGE_TARNAME
+#undef PACKAGE_STRING
+
+#define SUPPORT_UCP
+#define SUPPORT_UTF8
+
+
+';
+
+file_put_contents('pcrelib/config.h', $prepend_config_h . file_get_contents('pcrelib/config.h'));
+
+
+echo "\nThe End :-)\n\n"
+
+?>