diff --git a/CMakeLists.txt b/CMakeLists.txt index 93b893c..796b389 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,8 +149,8 @@ SET(PCRE2_SUPPORT_JIT OFF CACHE BOOL SET(PCRE2_SUPPORT_PCRE2GREP_JIT ON CACHE BOOL "Enable use of Just-in-time compiling in pcre2grep.") -SET(PCRE2_SUPPORT_UTF OFF CACHE BOOL - "Enable support for Unicode Transformation Format (UTF-8/UTF-16/UTF-32) encoding.") +SET(PCRE2_SUPPORT_UNICODE OFF CACHE BOOL + "Enable support for Unicode and UTF-8/UTF-16/UTF-32 encoding.") SET(PCRE2_SUPPORT_BSR_ANYCRLF OFF CACHE BOOL "ON=Backslash-R matches only LF CR and CRLF, OFF=Backslash-R matches all Unicode Linebreaks") @@ -245,9 +245,9 @@ IF(PCRE2_SUPPORT_BSR_ANYCRLF) SET(BSR_ANYCRLF 1) ENDIF(PCRE2_SUPPORT_BSR_ANYCRLF) -IF(PCRE2_SUPPORT_UTF) - SET(SUPPORT_UTF 1) -ENDIF(PCRE2_SUPPORT_UTF) +IF(PCRE2_SUPPORT_UNICODE) + SET(SUPPORT_UNICODE 1) +ENDIF(PCRE2_SUPPORT_UNICODE) IF(PCRE2_SUPPORT_JIT) SET(SUPPORT_JIT 1) @@ -709,7 +709,7 @@ IF(PCRE2_SHOW_REPORT) MESSAGE(STATUS " Build 16 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE16}") MESSAGE(STATUS " Build 32 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE32}") MESSAGE(STATUS " Enable JIT compiling support .... : ${PCRE2_SUPPORT_JIT}") - MESSAGE(STATUS " Enable UTF support .............. : ${PCRE2_SUPPORT_UTF}") + MESSAGE(STATUS " Enable Unicode support .......... : ${PCRE2_SUPPORT_UNICODE}") MESSAGE(STATUS " Newline char/sequence ........... : ${PCRE2_NEWLINE}") MESSAGE(STATUS " \\R matches only ANYCRLF ......... : ${PCRE2_SUPPORT_BSR_ANYCRLF}") MESSAGE(STATUS " EBCDIC coding ................... : ${PCRE2_EBCDIC}") diff --git a/Makefile.am b/Makefile.am index 1742708..ae2d4a8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,7 +76,10 @@ AM_CPPFLAGS = -I$(builddir)/src -I$(srcdir)/src # doc/html/pcreunicode.html # FIXME -#dist_man_MANS = \ +dist_man_MANS = \ + doc/pcre2api.3 + + # doc/pcre2-config.1 \ # doc/pcre2.3 \ # doc/pcre2-16.3 \ @@ -108,7 +111,6 @@ AM_CPPFLAGS = -I$(builddir)/src -I$(srcdir)/src # doc/pcre2_utf16_to_host_byte_order.3 \ # doc/pcre2_utf32_to_host_byte_order.3 \ # doc/pcre2_version.3 \ -# doc/pcre2api.3 \ # doc/pcre2build.3 \ # doc/pcre2callout.3 \ # doc/pcre2compat.3 \ diff --git a/RunTest b/RunTest index bc44693..9b55a70 100755 --- a/RunTest +++ b/RunTest @@ -314,10 +314,11 @@ else fi fi -# UTF support always applies to all bit sizes if both are supported; we can't -# have UTF-8 support without UTF-16 or UTF-32 support. +# UTF support is implied by Unicode support, and it always applies to all bit +# sizes if both are supported; we can't have UTF-8 support without UTF-16 or +# UTF-32 support. -$sim ./pcre2test -C utf >/dev/null +$sim ./pcre2test -C unicode >/dev/null utf=$? jitopt= diff --git a/config-cmake.h.in b/config-cmake.h.in index 6245d5c..7bf7146 100644 --- a/config-cmake.h.in +++ b/config-cmake.h.in @@ -25,7 +25,7 @@ #cmakedefine SUPPORT_JIT 1 #cmakedefine SUPPORT_PCRE2GREP_JIT 1 -#cmakedefine SUPPORT_UTF 1 +#cmakedefine SUPPORT_UNICODE 1 #cmakedefine SUPPORT_VALGRIND 1 #cmakedefine BSR_ANYCRLF 1 diff --git a/configure.ac b/configure.ac index 39ac508..fa0e41f 100644 --- a/configure.ac +++ b/configure.ac @@ -137,11 +137,11 @@ AC_ARG_ENABLE(rebuild-chartables, [rebuild character tables in current locale]), , enable_rebuild_chartables=no) -# Handle --enable-utf (disabled by default) -AC_ARG_ENABLE(utf, - AS_HELP_STRING([--enable-utf], - [enable UTF-8/16/32 support (incompatible with --enable-ebcdic)]), - , enable_utf=unset) +# Handle --enable-unicode (disabled by default) +AC_ARG_ENABLE(unicode, + AS_HELP_STRING([--enable-unicode], + [enable Unicode support (incompatible with --enable-ebcdic)]), + , enable_unicode=unset) # Handle newline options ac_pcre2_newline=lf @@ -288,10 +288,10 @@ then AC_MSG_ERROR([At least one of the 8, 16 or 32 bit libraries must be enabled]) fi -# enable_utf is disabled by default. -if test "x$enable_utf" = "xunset" +# enable_unicode is disabled by default. +if test "x$enable_unicode" = "xunset" then - enable_utf=no + enable_unicode=no fi # Convert the newline identifier into the appropriate integer value. These must @@ -320,8 +320,8 @@ fi # if test "x$enable_ebcdic" = "xyes"; then enable_rebuild_chartables=yes - if test "x$enable_utf" = "xyes"; then - AC_MSG_ERROR([support for EBCDIC and UTF-8/16/32 cannot be enabled at the same time]) + if test "x$enable_unicode" = "xyes"; then + AC_MSG_ERROR([support for EBCDIC and Unicode cannot be enabled at the same time]) fi fi @@ -372,7 +372,7 @@ AM_CONDITIONAL(WITH_PCRE16, test "x$enable_pcre16" = "xyes") AM_CONDITIONAL(WITH_PCRE32, test "x$enable_pcre32" = "xyes") AM_CONDITIONAL(WITH_REBUILD_CHARTABLES, test "x$enable_rebuild_chartables" = "xyes") AM_CONDITIONAL(WITH_JIT, test "x$enable_jit" = "xyes") -AM_CONDITIONAL(WITH_UTF, test "x$enable_utf" = "xyes") +AM_CONDITIONAL(WITH_UNICODE, test "x$enable_unicode" = "xyes") AM_CONDITIONAL(WITH_VALGRIND, test "x$enable_valgrind" = "xyes") # Checks for typedefs, structures, and compiler characteristics. @@ -513,12 +513,12 @@ if test "$enable_pcre2grep_jit" = "yes"; then Define to any value to enable JIT support in pcre2grep.]) fi -if test "$enable_utf" = "yes"; then - AC_DEFINE([SUPPORT_UTF], [], [ - Define to any value to enable support for the UTF-8/16/32 Unicode encoding. +if test "$enable_unicode" = "yes"; then + AC_DEFINE([SUPPORT_UNICODE], [], [ + Define to any value to enable support for Unicode and UTF encoding. This will work even in an EBCDIC environment, but it is incompatible with the EBCDIC macro. That is, PCRE2 can support *either* EBCDIC - code *or* ASCII/UTF-8/16/32, but not both at once.]) + code *or* ASCII/Unicode, but not both at once.]) fi if test "$enable_stack_for_recursion" = "no"; then @@ -854,7 +854,7 @@ $PACKAGE-$VERSION configuration summary: Build 16-bit pcre2 library ...... : ${enable_pcre16} Build 32-bit pcre2 library ...... : ${enable_pcre32} Enable JIT compiling support .... : ${enable_jit} - Enable UTF-8/16/32 support ...... : ${enable_utf} + Enable Unicode support .......... : ${enable_unicode} Newline char/sequence ........... : ${enable_newline} \R matches only ANYCRLF ......... : ${enable_bsr_anycrlf} EBCDIC coding ................... : ${enable_ebcdic} diff --git a/doc/pcre2api.3 b/doc/pcre2api.3 new file mode 100644 index 0000000..b7b350e --- /dev/null +++ b/doc/pcre2api.3 @@ -0,0 +1,2704 @@ +.TH PCRE2API 3 "16 September 2014" "PCRE2 10.00" +.SH NAME +PCRE2 - Perl-compatible regular expressions (revised API) +.sp +.B #include +.sp +PCRE2 is a new API for PCRE. This document contains a description of all its +functions. See the +.\" HREF +\fBpcre2\fP +.\" +document for an overview of all the PCRE2 documentation. +. +. +.SH "PCRE2 NATIVE API BASIC FUNCTIONS" +.rs +.sp +.nf +.B pcre2_code *pcre2_compile(PCRE2_SPTR \fIpattern\fP, PCRE2_SIZE \fIlength\fP, +.B " uint32_t \fIoptions\fP, int *\fIerrorcode\fP, PCRE2_SIZE *\fIerroroffset,\fP" +.B " pcre2_compile_context *\fIccontext\fP);" +.sp +.B pcre2_code_free(pcre2_code *\fIcode\fP); +.sp +.B pcre2_match_data_create(uint32_t \fIovecsize\fP, +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_match_data_create_from_pattern(pcre2_code *\fIcode\fP, +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B int pcre2_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP);" +.sp +.B int pcre2_dfa_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP," +.B " int *\fIworkspace\fP, PCRE2_SIZE \fIwscount\fP);" +.sp +.B void pcre2_match_data_free(pcre2_match_data *\fImatch_data\fP); +.fi +. +. +.SH "PCRE2 NATIVE API AUXILIARY MATCH FUNCTIONS" +.rs +.sp +.nf +.B PCRE2_SIZE pcre2_get_leftchar(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SPTR pcre2_get_mark(pcre2_match_data *\fImatch_data\fP); +.sp +.B uint32_t pcre2_get_ovector_count(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE pcre2_get_rightchar(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *\fImatch_data\fP); +.fi +. +. +.SH "PCRE2 NATIVE API GENERAL CONTEXT FUNCTIONS" +.rs +.sp +.nf +.B pcre2_general_context *pcre2_general_context_create( +.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *)," +.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);" +.sp +.B pcre2_general_context *pcre2_general_context_copy( +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B void pcre2_general_context_free(pcre2_general_context *\fIgcontext\fP); +.fi +. +. +.SH "PCRE2 NATIVE API COMPILE CONTEXT FUNCTIONS" +.rs +.sp +.nf +.B pcre2_compile_context *pcre2_compile_context_create( +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_compile_context *pcre2_compile_context_copy( +.B " pcre2_compile_context *\fIccontext\fP);" +.sp +.B void pcre2_compile_context_free(pcre2_compile_context *\fIccontext\fP); +.sp +.B int pcre2_set_bsr_compile(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_character_tables(pcre2_compile_context *\fIccontext\fP, +.B " const unsigned char *\fItables\fP);" +.sp +.B int pcre2_set_newline_compile(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_parens_nest_limit(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_compile_recursion_guard(pcre2_compile_context *\fIccontext\fP, +.B " int (*\fIguard_function\fP)(uint32_t));" +.fi +. +. +.SH "PCRE2 NATIVE API MATCH CONTEXT FUNCTIONS" +.rs +.sp +.nf +.B pcre2_match_context *pcre2_match_context_create( +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_match_context *pcre2_match_context_copy( +.B " pcre2_match_context *\fImcontext\fP);" +.sp +.B void pcre2_match_context_free(pcre2_match_context *\fImcontext\fP); +.sp +.B int pcre2_set_bsr_match(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_callout(pcre2_match_context *\fImcontext\fP, +.B " int (*\fIcallout_function\fP)(pcre2_callout_block *)," +.B " void *\fIcallout_data\fP);" +.sp +.B int pcre2_set_match_limit(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_newline_match(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_recursion_limit(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.sp +.B int pcre2_set_recursion_memory_management( +.B " pcre2_match_context *\fImcontext\fP," +.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *)," +.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);" +.fi +. +. +.SH "PCRE2 NATIVE API STRING EXTRACTION FUNCTIONS" +.rs +.sp +.nf +.B int pcre2_substring_copy_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR *\fIbuffer\fP, PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B int pcre2_substring_copy_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_UCHAR *\fIbuffer\fP," +.B " PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP); +.sp +.B int pcre2_substring_get_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR **\fIbufferptr\fP, PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B int pcre2_substring_get_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_UCHAR **\fIbufferptr\fP," +.B " PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B int pcre2_substring_length_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_SIZE *\fIlength\fP);" +.sp +.B int pcre2_substring_length_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_SIZE *\fIlength\fP);" +.sp +.B int pcre2_substring_nametable_scan(const pcre2_code *\fIcode\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_SPTR *\fIfirst\fP, PCRE2_SPTR *\fIlast\fP);" +.sp +.B int pcre2_substring_number_from_name(const pcre2_code *\fIcode\fP, +.B " PCRE2_SPTR \fIname\fP);" +.sp +.B void pcre2_substring_list_free(PCRE2_SPTR *\fIlist\fP); +.sp +.B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP); +.fi +. +. +.SH "PCRE2 NATIVE API JIT FUNCTIONS" +.rs +.sp +.nf +.B int pcre2_jit_compile(pcre2_code *\fIcode\fP, uint32_t \fIoptions\fP); +.sp +.B int pcre2_jit_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP, pcre2_jit_stack *\fIjit_stack\fP);" +.sp +.B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP); +.sp +.B pcre2_jit_stack *pcre2_jit_stack_alloc(pcre2_general_context *\fIgcontext\fP, +.B " PCRE2_SIZE \fIstartsize\fP, PCRE2_SIZE \fImaxsize\fP);" +.sp +.B void pcre2_jit_stack_assign(const pcre2_code *\fIcode\fP, +.B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);" +.sp +.B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP); +.fi +. +. +.SH "PCRE2 NATIVE API AUXILIARY FUNCTIONS" +.rs +.sp +.nf +.B int pcre2_get_error_message(int \fIerrorcode\fP, PCRE2_UCHAR *\fIbuffer\fP, +.B " PCRE2_SIZE \fIbufflen\fP);" +.sp +.B const unsigned char *pcre2_maketables(pcre2_general_context *\fIgcontext\fP); +.sp +.B int pcre2_pattern_info(const pcre2 *\fIcode\fP, uint32_t \fIwhat\fP, void *\fIwhere\fP); +.sp +.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP, PCRE2_SIZE \fIlength\fP); +.sp +. +. +.SH "PCRE2 8-BIT, 16-BIT, AND 32-BIT LIBRARIES" +.rs +.sp +There are three PCRE2 libraries, supporting 8-bit, 16-bit, and 32-bit code +units, respectively. However, there is just one header file, \fBpcre2.h\fP. +This contains the function prototypes and other definitions for all three +libraries. One, two, or all three can be installed simultaneously. On Unix-like +systems the libraries are called \fBlibpcre2-8\fP, \fBlibpcre2-16\fP, and +\fBlibpcre2-32\fP, and they can also co-exist with the original PCRE libraries. +.P +Character strings are passed to and from a PCRE2 library as a sequence of +unsigned integers in code units of the appropriate width. Every PCRE2 function +comes in three different forms, one for each library, for example: +.sp + \fBpcre2_compile_8()\fP + \fBpcre2_compile_16()\fP + \fBpcre2_compile_32()\fP +.sp +There are also three different sets of data types: +.sp + \fBPCRE2_UCHAR8, PCRE2_UCHAR16, PCRE2_UCHAR32\fP + \fBPCRE2_SPTR8, PCRE2_SPTR16, PCRE2_SPTR32\fP +.sp +The UCHAR types define unsigned code units of the appropriate widths. For +example, PCRE2_UCHAR16 is usually defined as `uint16_t'. The SPTR types are +constant pointers to the equivalent UCHAR types, that is, they are pointers to +vectors of unsigned code units. +.P +Many applications use only one code unit width. For their convenience, macros +are defined whose names are the generic forms such as \fBpcre2_compile()\fP and +PCRE2_SPTR. These macros use the value of the macro PCRE2_CODE_UNIT_WIDTH to +generate the appropriate width-specific function and macro names. +PCRE2_CODE_UNIT_WIDTH is not defined by default. An application must define it +to be 8, 16, or 32 before including \fBpcre2.h\fP in order to make use of the +generic names. +.P +Applications that use more than one code unit width can be linked with more +than one PCRE2 library, but must define PCRE2_CODE_UNIT_WIDTH to be 0 before +including \fBpcre2.h\fP, and then use the real function names. Any code that is +to be included in an environment where the value of PCRE2_CODE_UNIT_WIDTH is +unknown should also use the real function names. (Unfortunately, it is not +possible in C code to save and restore the value of a macro.) +.P +If PCRE2_CODE_UNIT_WIDTH is not defined before including \fBpcre2.h\fP, a +compiler error occurs. +.P +When using multiple libraries in an application, you must take care when +processing any particular pattern to use only functions from a single library. +For example, if you want to run a match using a pattern that was compiled with +\fBpcre2_compile_16()\fP, you must do so with \fBpcre2_match_16()\fP, not +\fBpcre2_match_8()\fP. +.P +In the function summaries above, and in the rest of this document and other +PCRE2 documents, functions and data types are described using their generic +names, without the 8, 16, or 32 suffix. +. +. +.SH "PCRE2 API OVERVIEW" +.rs +.sp +PCRE2 has its own native API, which is described in this document. There are +also some wrapper functions for the 8-bit library that correspond to the +POSIX regular expression API, but they do not give access to all the +functionality. They are described in the +.\" HREF +\fBpcre2posix\fP +.\" +documentation. Both these APIs define a set of C function calls. +.P +The native API C data types, function prototypes, option values, and error +codes are defined in the header file \fBpcre2.h\fP, which contains definitions +of PCRE2_MAJOR and PCRE2_MINOR, the major and minor release numbers for the +library. Applications can use these to include support for different releases +of PCRE2. +.P +In a Windows environment, if you want to statically link an application program +against a non-dll PCRE2 library, you must define PCRE2_STATIC before including +\fBpcre2.h\fP. +.P +The functions \fBpcre2_compile()\fP, and \fBpcre2_match()\fP are used for +compiling and matching regular expressions in a Perl-compatible manner. A +sample program that demonstrates the simplest way of using them is provided in +the file called \fIpcre2demo.c\fP in the PCRE2 source distribution. A listing +of this program is given in the +.\" HREF +\fBpcre2demo\fP +.\" +documentation, and the +.\" HREF +\fBpcre2sample\fP +.\" +documentation describes how to compile and run it. +.P +Just-in-time compiler support is an optional feature of PCRE2 that can be built +in appropriate hardware environments. It greatly speeds up the matching +performance of many patterns. Programs can request that it be used if +available, by calling \fBpcre2_jit_compile()\fP after a pattern has been +successfully compiled by \fBpcre2_compile()\fP. This does nothing if JIT +support is not available. +.P +More complicated programs might need to make use of the specialist functions +\fBpcre2_jit_stack_alloc()\fP, \fBpcre2_jit_stack_free()\fP, and +\fBpcre2_jit_stack_assign()\fP in order to control the JIT code's memory usage. +.P +JIT matching is automatically used by \fBpcre2_match()\fP if it is available. +There is also a direct interface for JIT matching, which gives improved +performance. The JIT-specific functions are discussed in the +.\" HREF +\fBpcre2jit\fP +.\" +documentation. +.P +A second matching function, \fBpcre2_dfa_exec()\fP, which is not +Perl-compatible, is also provided. This uses a different algorithm for the +matching. The alternative algorithm finds all possible matches (at a given +point in the subject), and scans the subject just once (unless there are +lookbehind assertions). However, this algorithm does not return captured +substrings. A description of the two matching algorithms and their advantages +and disadvantages is given in the +.\" HREF +\fBpcre2matching\fP +.\" +documentation. There is no JIT support for \fBpcre2_dfa_match()\fP. +.P +In addition to the main compiling and matching functions, there are convenience +functions for extracting captured substrings from a subject string that is +matched by \fBpcre2_match()\fP. They are: +.sp + \fBpcre2_substring_copy_byname()\fP + \fBpcre2_substring_copy_bynumber()\fP + \fBpcre2_substring_get_byname()\fP + \fBpcre2_substring_get_bynumber()\fP + \fBpcre2_substring_list_get()\fP + \fBpcre2_substring_length_byname()\fP + \fBpcre2_substring_length_bynumber()\fP + \fBpcre2_substring_nametable_scan()\fP + \fBpcre2_substring_number_from_name()\fP +.sp +\fBpcre2_substring_free()\fP and \fBpcre2_substring_list_free()\fP are also +provided, to free the memory used for extracted strings. +.P +There are functions for finding out information about a compiled pattern +(\fBpcre2_pattern_info()\fP) and about the configuration with which PCRE2 was +built (\fBpcre2_config()\fP). +. +. +.\" HTML +.SH NEWLINES +.rs +.sp +PCRE2 supports five different conventions for indicating line breaks in +strings: a single CR (carriage return) character, a single LF (linefeed) +character, the two-character sequence CRLF, any of the three preceding, or any +Unicode newline sequence. The Unicode newline sequences are the three just +mentioned, 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). +.P +Each of the first three conventions is used by at least one operating system as +its standard newline sequence. When PCRE2 is built, a default can be specified. +The default default is LF, which is the Unix standard. When PCRE2 is run, the +default can be overridden, either when a pattern is compiled, or when it is +matched. +.P +The newline convention can be changed when calling \fBpcre2_compile()\fP, or it +can be specified by special text at the start of the pattern itself; this +overrides any other settings. See the +.\" HREF +\fBpcre2pattern\fP +.\" +page for details of the special character sequences. +.P +In the PCRE2 documentation the word "newline" is used to mean "the character 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 advancement for a +non-anchored pattern. There is more detail about this in the +.\" HTML +.\" +section on \fBpcre2_match()\fP options +.\" +below. +.P +The choice of newline convention does not affect the interpretation of +the \en or \er escape sequences, nor does it affect what \eR matches, which has +its own separate control. +. +. +.SH MULTITHREADING +.rs +.sp +In a multithreaded application it is important to keep thread-specific data +separate from data that can be shared between threads. The PCRE2 library code +itself is thread-safe: it contains no static or global variables. The API is +designed to be fairly simple for non-threaded applications while at the same +time ensuring that multithreaded applications can use it. +.P +There are several different blocks of data that are used to pass information +between the application and the PCRE libraries. +.P +(1) A pointer to the compiled form of a pattern is returned to the user when +\fBpcre2_compile()\fP is successful. The data in the compiled pattern is fixed, +and does not change when the pattern is matched. Therefore, it is thread-safe, +that is, the same compiled pattern can be used by more than one thread +simultaneously. An application can compile all its patterns at the start, +before forking off multiple threads that use them. However, if the just-in-time +optimization feature is being used, it needs separate memory stack areas for +each thread. See the +.\" HREF +\fBpcre2jit\fP +.\" +documentation for more details. +.P +(2) The next section below introduces the idea of "contexts" in which PCRE2 +functions are called. A context is nothing more than a collection of parameters +that control the way PCRE2 operates. Grouping a number of parameters together +in a context is a convenient way of passing them to a PCRE2 function without +using lots of arguments. The parameters that are stored in contexts are in some +sense "advanced features" of the API. Many straightforward applications will +not need to use contexts. +.P +In a multithreaded application, if the parameters in a context are values that +are never changed, the same context can be used by all the threads. However, if +any thread needs to change any value in a context, it must make its own +thread-specific copy. +.P +(3) The matching functions need a block of memory for working space and for +storing the results of a match. This includes details of what was matched, as +well as additional information such as the name of a (*MARK) setting. Each +thread must provide its own version of this memory. +. +. +.SH "PCRE2 CONTEXTS" +.rs +.sp +Some PCRE2 functions have a lot of parameters, many of which are used only by +specialist applications, for example, those that use custom memory management +or non-standard character tables. To keep function argument lists at a +reasonable size, and at the same time to keep the API extensible, "uncommon" +parameters are passed to certain functions in a \fBcontext\fP instead of +directly. A context is just a block of memory that holds the parameter values. +Applications that do not need to adjust any of the context parameters can pass +NULL when a context pointer is required. +.P +There are three different types of context: a general context that is relevant +for several PCRE2 operations, a compile-time context, and a match-time context. +. +. +.SS "The general context" +.rs +.sp +At present, this context just contains pointers to (and data for) external +memory management functions that are called from several places in the PCRE2 +library. The context is named `general' rather than specifically `memory' +because in future other fields may be added. If you do not want to supply your +own custom memory management functions, you do not need to bother with a +general context. A general context is created by: +.sp +.nf +.B pcre2_general_context *pcre2_general_context_create( +.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *)," +.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);" +.fi +.sp +The two function pointers specify custom memory management functions, whose +prototypes are: +.sp + \fBvoid *private_malloc(PCRE2_SIZE, void *);\fP + \fBvoid private_free(void *, void *);\fP +.sp +Whenever code in PCRE2 calls these functions, the final argument is the value +of \fImemory_data\fP. Either of the first two arguments of the creation +function may be NULL, in which case the system memory management functions +\fImalloc()\fP and \fIfree()\fP are used. (This is not currently useful, as +there are no other fields in a general context, but in future there might be.) +The \fIprivate_malloc()\fP function is used (if supplied) to obtain memory for +storing the context, and all three values are saved as part of the context. +.P +Whenever PCRE2 creates a data block of any kind, the block contains a pointer +to the \fIfree()\fP function that matches the \fImalloc()\fP function that was +used. When the time comes to free the block, this function is called. +.P +A general context can be copied by calling: +.sp +.nf +.B pcre2_general_context *pcre2_general_context_copy( +.B " pcre2_general_context *\fIgcontext\fP);" +.fi +.sp +The memory used for a general context should be freed by calling: +.sp +.nf +.B void pcre2_general_context_free(pcre2_general_context *\fIgcontext\fP); +.fi +.sp +. +. +.\" HTML +.SS "The compile context" +.rs +.sp +A compile context is required if you want to change the default values of any +of the following compile-time parameters: +.sp + What \eR matches (Unicode newlines or CR, LF, CRLF only); + PCRE2's character tables; + The newline character sequence; + The compile time nested parentheses limit; + An external function for stack checking. +.sp +A compile context is also required if you are using custom memory management. +If none of these apply, just pass NULL as the context argument of +\fIpcre2_compile()\fP. +.P +A compile context is created, copied, and freed by the following functions: +.sp +.nf +.B pcre2_compile_context *pcre2_compile_context_create( +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_compile_context *pcre2_compile_context_copy( +.B " pcre2_compile_context *\fIccontext\fP);" +.sp +.B void pcre2_compile_context_free(pcre2_compile_context *\fIccontext\fP); +.fi +.sp +A compile context is created with default values for its parameters. These can +be changed by calling the following functions, which return 0 on success, or +PCRE2_ERROR_BADDATA if invalid data is detected. +.sp +.nf +.B int pcre2_set_bsr_compile(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +The value must be PCRE2_BSR_ANYCRLF, to specify that \eR matches only CR, LF, +or CRLF, or PCRE2_BSR_UNICODE, to specify that \eR matches any Unicode line +ending sequence. The value of this parameter does not affect what is compiled; +it is just saved with the compiled pattern. The value is used by the JIT +compiler and by the two interpreted matching functions, \fIpcre2_match()\fP and +\fIpcre2_dfa_match()\fP. You can change the value when calling these functions, +but doing so disables the use of JIT. +.sp +.nf +.B int pcre2_set_character_tables(pcre2_compile_context *\fIccontext\fP, +.B " const unsigned char *\fItables\fP);" +.fi +.sp +The value must be the result of a call to \fIpcre2_maketables()\fP, whose only +argument is a general context. This function builds a set of character tables +in the current locale. +.sp +.nf +.B int pcre2_set_newline_compile(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +This specifies which characters or character sequences are to be recognized as +newlines. The value must be one of PCRE2_NEWLINE_CR (carriage return only), +PCRE2_NEWLINE_LF (linefeed only), PCRE2_NEWLINE_CRLF (the two-character +sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any of the above), or +PCRE2_NEWLINE_ANY (any Unicode newline sequence). +.P +When a pattern is compiled with the PCRE2_EXTENDED option, the value of this +parameter affects the recognition of white space and the end of internal +comments starting with #. The value is saved with the compiled pattern for +subsequent use by the JIT compiler and by the two interpreted matching +functions, \fIpcre2_match()\fP and \fIpcre2_dfa_match()\fP. You can change the +value when calling these functions, but doing so disables the use of JIT. +.sp +.nf +.B int pcre2_set_parens_nest_limit(pcre2_compile_context *\fIccontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +This parameter ajusts the limit, set when PCRE2 is built (default 250), on the +depth of parenthesis nesting in a pattern. This limit stops rogue patterns +using up too much system stack when being compiled. +.sp +.nf +.B int pcre2_set_compile_recursion_guard(pcre2_compile_context *\fIccontext\fP, +.B " int (*\fIguard_function\fP)(uint32_t));" +.fi +.sp +There is at least one application that runs PCRE2 in threads with very limited +system stack, where running out of stack is to be avoided at all costs. The +parenthesis limit above cannot take account of how much stack is actually +available. For a finer control, you can supply a function that is called +whenever \fBpcre2_compile()\fP starts to compile a parenthesized part of a +pattern. The argument to the function gives the current depth of nesting. The +function should return zero if all is well, or non-zero to force an error. +. +. +.\" HTML +.SS "The match context" +.rs +.sp +A match context is required if you want to change the default values of any +of the following match-time parameters: +.sp + What \eR matches (Unicode newlines or CR, LF, CRLF only); + A callout function; + The limit for calling \fImatch()\fP; + The limit for calling \fImatch()\fP recursively; + The newline character sequence; +.sp +A match context is also required if you are using custom memory management. +If none of these apply, just pass NULL as the context argument of +\fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or \fBpcre2_jit_match()\fP. +Changing the newline value or what \eR matches at match time disables the use +of JIT via \fBpcre2_match()\fP. +.P +A match context is created, copied, and freed by the following functions: +.sp +.nf +.B pcre2_match_context *pcre2_match_context_create( +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_match_context *pcre2_match_context_copy( +.B " pcre2_match_context *\fImcontext\fP);" +.sp +.B void pcre2_match_context_free(pcre2_match_context *\fImcontext\fP); +.fi +.sp +A match context is created with default values for its parameters. These can +be changed by calling the following functions, which return 0 on success, or +PCRE2_ERROR_BADDATA if invalid data is detected. +.sp +.nf +.B int pcre2_set_bsr_match(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +The value must be PCRE2_BSR_ANYCRLF, to specify that \eR matches only CR, LF, +or CRLF, or PCRE2_BSR_UNICODE, to specify that \eR matches any Unicode line +ending sequence. If you want to make use of JIT matching, you should not use +this function, but instead set the value in a compile context. +.sp +.nf +.B int pcre2_set_callout(pcre2_match_context *\fImcontext\fP, +.B " int (*\fIcallout_function\fP)(pcre2_callout_block *)," +.B " void *\fIcallout_data\fP);" +.fi +.sp +This sets up a "callout" function, which PCRE2 will call at specified points +during a matching operation. Details are given in the +.\" HREF +\fBpcre2callout\fP +.\" +documentation. +.sp +.nf +.B int pcre2_set_match_limit(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +The \fImatch_limit\fP parameter provides a means of preventing PCRE2 from using +up too many resources when processing patterns that are not going to match, but +which have a very large number of possibilities in their search trees. The +classic example is a pattern that uses nested unlimited repeats. +.P +Internally, \fBpcre2_match()\fP uses a function called \fBmatch()\fP, which it +calls repeatedly (sometimes recursively). The limit set by \fImatch_limit\fP is +imposed on the number of times this function is called during a match, which +has the effect of limiting the amount of backtracking that can take place. For +patterns that are not anchored, the count restarts from zero for each position +in the subject string. This limit is not relevant to \fBpcre2_dfa_match()\fP, +which ignores it. +.P +When \fBpcre2_match()\fP is called with a pattern that was successfully studied +with \fBpcre2_jit_compile()\fP, the way that the matching is executed is +entirely different. However, there is still the possibility of runaway matching +that goes on for a very long time, and so the \fImatch_limit\fP value is also +used in this case (but in a different way) to limit how long the matching can +continue. +.P +The default value for the limit can be set when PCRE2 is built; the default +default is 10 million, which handles all but the most extreme cases. If the +limit is exceeded, \fBpcre2_match()\fP returns PCRE2_ERROR_MATCHLIMIT. A value +for the match limit may also be supplied by an item at the start of a pattern +of the form +.sp + (*LIMIT_MATCH=ddd) +.sp +where ddd is a decimal number. However, such a setting is ignored unless ddd is +less than the limit set by the caller of \fBpcre2_match()\fP or, if no such +limit is set, less than the default. +.sp +.nf +.B int pcre2_set_recursion_limit(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +The \fIrecursion_limit\fP parameter is similar to \fImatch_limit\fP, but +instead of limiting the total number of times that \fBmatch()\fP is called, it +limits the depth of recursion. The recursion depth is a smaller number than the +total number of calls, because not all calls to \fBmatch()\fP are recursive. +This limit is of use only if it is set smaller than \fImatch_limit\fP. +.P +Limiting the recursion depth limits the amount of system stack that can be +used, or, when PCRE2 has been compiled to use memory on the heap instead of the +stack, the amount of heap memory that can be used. This limit is not relevant, +and is ignored, when matching is done using JIT compiled code or by the +\fBpcre2_dfa_match()\fP function. +.P +The default value for \fIrecursion_limit\fP can be set when PCRE2 is built; the +default default is the same value as the default for \fImatch_limit\fP. If the +limit is exceeded, \fBpcre2_match()\fP returns PCRE2_ERROR_RECURSIONLIMIT. A +value for the recursion limit may also be supplied by an item at the start of a +pattern of the form +.sp + (*LIMIT_RECURSION=ddd) +.sp +where ddd is a decimal number. However, such a setting is ignored unless ddd is +less than the limit set by the caller of \fBpcre2_match()\fP or, if no such +limit is set, less than the default. +.sp +.nf +.B int pcre2_set_newline_match(pcre2_match_context *\fImcontext\fP, +.B " uint32_t \fIvalue\fP);" +.fi +.sp +This specifies which characters or character sequences are to be recognized as +newlines. The value must be one of PCRE2_NEWLINE_CR (carriage return only), +PCRE2_NEWLINE_LF (linefeed only), PCRE2_NEWLINE_CRLF (the two-character +sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any of the above), or +PCRE2_NEWLINE_ANY (any Unicode newline sequence). If you want to make use of +JIT matching, you should not use this function, but instead set the value in a +compile context. +.sp +.nf +.B int pcre2_set_recursion_memory_management( +.B " pcre2_match_context *\fImcontext\fP," +.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *)," +.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);" +.fi +.sp +This function sets up two additional custom memory management functions for use +by \fBpcre2_match()\fP when PCRE2 is compiled to use the heap for remembering +backtracking data, instead of recursive function calls that use the system +stack. There is a discussion about PCRE2's stack usage in the +.\" HREF +\fBpcre2stack\fP +.\" +documentation. See the +.\" HREF +\fBpcre2build\fP +.\" +documentation for details of how to build PCRE2. Using the heap for recursion +is a non-standard way of building PCRE2, for use in environments that have +limited stacks. Because of the greater use of memory management, +\fBpcre2_match()\fP runs more slowly. Functions that are different to the +general custom memory functions are provided so that special-purpose external +code can be used for this case, because the memory blocks are all the same +size. The blocks are retained by \fBpcre2_match()\fP until it is about to exit +so that they can be re-used when possible during the match. In the absence of +these functions, the normal custom memory management functions are used, if +supplied, otherwise the system functions. +. +. +.SH "CHECKING BUILD-TIME OPTIONS" +.rs +.sp +.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP, PCRE2_SIZE \fIlength\fP); +.P +The function \fBpcre2_config()\fP makes it possible for a PCRE2 client to +discover which optional features have been compiled into the PCRE2 library. The +.\" HREF +\fBpcre2build\fP +.\" +documentation has more details about these optional features. +.P +The first argument for \fBpcre2_config()\fP specifies which information is +required. The second argument is a pointer to memory into which the information +is placed, with the final argument giving the length of this memory in bytes. +For calls that return numerical values, \fIwhere\fP should point to +appropriately aligned memory, with \fIlength\fP set to at least the "sizeof" +the data type. +.P +The returned value from \fBpcre2_config()\fP is zero on success, or the +negative error code PCRE2_ERROR_BADOPTION if the value in the first argument is +not recognized. The following information is available: +.sp + PCRE2_CONFIG_BSR +.sp +The output is an integer whose value indicates what character sequences the \eR +escape sequence matches by default. A value of 0 means that \eR matches any +Unicode line ending sequence; a value of 1 means that \eR matches only CR, LF, +or CRLF. The default can be overridden when a pattern is compiled or matched. +.sp + PCRE2_CONFIG_JIT +.sp +The output is an integer that is set to one if support for just-in-time +compiling is available; otherwise it is set to zero. +.sp + PCRE2_CONFIG_JITTARGET +.sp +FIXME: this needs sorting out once JIT is implemented. +If JIT support is available, the string contains the name of the architecture +for which the JIT compiler is configured, for example "x86 32bit (little endian ++ unaligned)". If JIT support is not available, FIXME. +.sp + PCRE2_CONFIG_LINKSIZE +.sp +The output is an integer that contains the number of bytes used for internal +linkage in compiled regular expressions. When PCRE2 is configured, the value +can be set to 2, 3, or 4, with the default being 2. This is the value that is +returned by \fBpcre2_config()\fP. However, when the 16-bit library is compiled, +a value of 3 is rounded up to 4, and when the 32-bit library is compiled, +internal linkages always use 4 bytes, so the configured value is not relevant. +.P +The default value of 2 for the 8-bit and 16-bit libraries is sufficient for all +but the most massive patterns, since it allows the size of the compiled pattern +to be up to 64K code units. Larger values allow larger regular expressions to +be compiled by those two libraries, but at the expense of slower matching. +.sp + PCRE2_CONFIG_MATCHLIMIT +.sp +The output is an unsigned long integer that gives the default limit for the +number of internal matching function calls in a \fBpcre2_match()\fP execution. +Further details are given with \fBpcre2_match()\fP below. +.sp + PCRE2_CONFIG_NEWLINE +.sp +The output is an integer whose value specifies the default character sequence +that is recognized as meaning "newline". The values are: +.sp + 1 Carriage return (CR) + 2 Linefeed (LF) + 3 Carriage return, linefeed (CRLF) + 4 Any Unicode line ending + 5 Any of CR, LF, or CRLF +.sp +The default should normally correspond to the standard sequence for your +operating system. +.sp + PCRE2_CONFIG_PARENSLIMIT +.sp +The output is an unsigned long integer that gives the maximum depth of nesting +of parentheses (of any kind) in a pattern. This limit is imposed to cap the +amount of system stack used when a pattern is compiled. It is specified when +PCRE2 is built; the default is 250. This limit does not take into account the +stack that may already be used by the calling application. For finer control +over compilation stack usage, see \fBpcre2_set_compile_recursion_guard()\fP. +.sp + PCRE2_CONFIG_RECURSIONLIMIT +.sp +The output is an unsigned long integer that gives the default limit for the +depth of recursion when calling the internal matching function in a +\fBpcre2_match()\fP execution. Further details are given with +\fBpcre2_match()\fP below. +.sp + PCRE2_CONFIG_STACKRECURSE +.sp +The output is an integer that is set to one if internal recursion when running +\fBpcre2_match()\fP is implemented by recursive function calls that use the +system stack to remember their state. This is the usual way that PCRE2 is +compiled. The output is zero if PCRE2 was compiled to use blocks of data on the +heap instead of recursive function calls. +.sp + PCRE2_CONFIG_UNICODE_VERSION +.sp +The \fIwhere\fP argument should point to a buffer that is at least 24 code +units long. If PCRE2 has been compiled without Unicode support, this is filled +with the text "Unicode not supported". Otherwise, the Unicode version string +(for example, "7.0.0") is returnd. The string is zero-terminated. +.sp + PCRE2_CONFIG_UNICODE +.sp +The output is an integer that is set to one if Unicode support is available; +otherwise it is set to zero. Unicode support implies UTF support. +.sp + PCRE2_CONFIG_VERSION +.sp +The \fIwhere\fP argument should point to a buffer that is at least 12 code +units long. It is filled with the PCRE2 version string, zero-terminated. +. +. +.SH "COMPILING A PATTERN" +.rs +.sp +.nf +.B pcre2_code *pcre2_compile(PCRE2_SPTR \fIpattern\fP, PCRE2_SIZE \fIlength\fP, +.B " uint32_t \fIoptions\fP, int *\fIerrorcode\fP, PCRE2_SIZE *\fIerroroffset,\fP" +.B " pcre2_compile_context *\fIccontext\fP);" +.sp +.B pcre2_code_free(pcre2_code *\fIcode\fP); +.fi +.P +This function compiles a pattern, defined by a pointer to a string of code +units and a length, into an internal form. If the pattern is zero-terminated, +the length should be specified as PCRE2_ZERO_TERMINATED. The function returns a +pointer to a block of memory that contains the compiled pattern and related +data. The caller must free the memory by calling \fBpcre2_code_free()\fP when +it is no longer needed. +.P +If the compile context argument \fIccontext\fP is NULL, the memory is obtained +by calling \fBmalloc()\fP. Otherwise, it is obtained from the same memory +function that was used for the compile context. +.P +The \fIoptions\fP argument contains various bit settings that affect the +compilation. 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, but some others as well) can also be set and unset from +within the pattern (see the detailed description in the +.\" HREF +\fBpcre2pattern\fP +.\" +documentation). +.P +For those options that can be different in different parts of the pattern, the +contents of the \fIoptions\fP argument specifies their settings at the start of +compilation. The PCRE2_ANCHORED, PCRE2_NO_UTF_CHECK, and +PCRE2_NO_START_OPTIMIZE options can be set at the time of matching as well as +at compile time. +.P +Other, less frequently required compile-time parameters (for example, the +newline setting) can be provided in a compile context (as described +.\" HTML +.\" +above). +.\" +.P +If \fIerrorcode\fP or \fIerroroffset\fP is NULL, \fBpcre2_compile()\fP returns +NULL immediately. Otherwise, if compilation of a pattern fails, +\fBpcre2_compile()\fP returns NULL, having set these variables to an error code +and an offset (number of code units) within the pattern, respectively. The +\fBpcre2_get_error_message()\fP function provides a textual message for each +error code. Compilation errors are positive numbers, but UTF formatting errors +are negative numbers. For an invalid UTF-8 or UTF-16 string, the offset is that +of the first code unit of the failing character. +.P +Some errors are not detected until the whole pattern has been scanned; in these +cases, the offset passed back is the length of the pattern. Note that the +offset is in code units, not characters, even in a UTF mode. It may sometimes +point into the middle of a UTF-8 or UTF-16 character. +.P +This code fragment shows a typical straightforward call to +\fBpcre2_compile()\fP: +.sp + pcre2_code *re; + PCRE2_SIZE erroffset; + int errorcode; + re = pcre2_compile( + "^A.*Z", /* the pattern */ + PCRE2_ZERO_TERMINATED, /* the pattern is zero-terminated */ + 0, /* default options */ + &errorcode, /* for error code */ + &erroffset, /* for error offset */ + NULL); /* no compile context */ +.sp +The following names for option bits are defined in the \fBpcre2.h\fP header +file: +.sp + PCRE2_ANCHORED +.sp +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 only way to do it in +Perl. +.sp + PCRE2_ALLOW_EMPTY_CLASS +.sp +By default, for compatibility with Perl, a closing square bracket that +immediately follows an opening one is treated as a data character for the +class. When PCRE2_ALLOW_EMPTY_CLASS is set, it terminates the class, which +therefore contains no characters and so can never match. +.sp + PCRE2_ALT_BSUX +.sp +This option request alternative handling of three escape sequences, which +makes PCRE2's behaviour more like ECMAscript (aka JavaScript). When it is set: +.P +(1) \eU matches an upper case "U" character; by default \eU causes a compile +time error (Perl uses \eU to upper case subsequent characters). +.P +(2) \eu matches a lower case "u" character unless it is followed by four +hexadecimal digits, in which case the hexadecimal number defines the code point +to match. By default, \eu causes a compile time error (Perl uses it to upper +case the following character). +.P +(3) \ex matches a lower case "x" character unless it is followed by two +hexadecimal digits, in which case the hexadecimal number defines the code point +to match. By default, as in Perl, a hexadecimal number is always expected after +\ex, but it may have zero, one, or two digits (so, for example, \exz matches a +binary zero character followed by z). +.sp + PCRE2_AUTO_CALLOUT +.sp +If this bit is set, \fBpcre2_compile()\fP automatically inserts callout items, +all with number 255, before each pattern item. For discussion of the callout +facility, see the +.\" HREF +\fBpcre2callout\fP +.\" +documentation. +.sp + PCRE2_CASELESS +.sp +If this bit is set, letters in the pattern match both upper and lower case +letters in the subject. It is equivalent to Perl's /i option, and it can be +changed within a pattern by a (?i) option setting. +.sp + PCRE2_DOLLAR_ENDONLY +.sp +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 PCRE2_DOLLAR_ENDONLY option is ignored if PCRE2_MULTILINE is +set. There is no equivalent to this option in Perl, and no way to set it within +a pattern. +.sp + PCRE2_DOTALL +.sp +If this bit is set, a dot metacharacter in the pattern matches any character, +including one that indicates a newline. However, it only ever matches one +character, even if newlines are coded as CRLF. Without this option, a dot does +not match when the current position in the subject 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. +.sp + PCRE2_DUPNAMES +.sp +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 the +.\" HREF +\fBpcre2pattern\fP +.\" +documentation. +.sp + PCRE2_EXTENDED +.sp +If this bit is set, most white space characters in the pattern are totally +ignored except when escaped or inside a character class. However, white space +is not allowed within sequences such as (?> that introduce various +parenthesized subpatterns, nor within numerical quantifiers such as {1,3}. +Ignorable white space is permitted between an item and a following quantifier +and between a quantifier and a following + that indicates possessiveness. +.P +PCRE2_EXTENDED also causes characters between an unescaped # outside a +character class and the next newline, inclusive, to be ignored, which makes it +possible to include comments inside complicated patterns. Note that the end of +this type of comment is a literal newline sequence in the pattern; escape +sequences that happen to represent a newline do not count. PCRE2_EXTENDED is +equivalent to Perl's /x option, and it can be changed within a pattern by a +(?x) option setting. +.P +Which characters are interpreted as newlines can be specified by a setting in +the compile context that is passed to \fBpcre2_compile()\fP or by a special +sequence at the start of the pattern, as described in the section entitled +.\" HTML +.\" +"Newline conventions" +.\" +in the \fBpcre2pattern\fP documentation. A default is defined when PCRE2 is +built. +.sp + PCRE2_FIRSTLINE +.sp +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. +.sp + PCRE2_MATCH_UNSET_BACKREF +.sp +If this option is set, a back reference to an unset subpattern group matches an +empty string (by default this causes the current matching alternative to fail). +A pattern such as (\e1)(a) succeeds when this option is set (assuming it can +find an "a" in the subject), whereas it fails by default, for Perl +compatibility. Setting this option makes PCRE2 behave more like ECMAscript (aka +JavaScript). +.sp + PCRE2_MULTILINE +.sp +By default, for the purposes of matching "start of line" and "end of line", +PCRE2 treats the subject string as consisting of a single line of characters, +even if it actually contains newlines. The "start of line" metacharacter (^) +matches only at the start of the string, and the "end of line" metacharacter +($) matches only at the end of the string, or before a terminating newline +(except when PCRE2_DOLLAR_ENDONLY is set). Note, however, that unless +PCRE2_DOTALL is set, the "any character" metacharacter (.) does not match at a +newline. This behaviour (for ^, $, and dot) is the same as Perl. +.P +When PCRE2_MULTILINE it is set, the "start of line" and "end of line" +constructs match immediately following or immediately before internal newlines +in the subject string, respectively, as well as at the very start and end. This +is equivalent to Perl's /m option, and it can be changed within a pattern by a +(?m) option setting. If there are no newlines in a subject string, or no +occurrences of ^ or $ in a pattern, setting PCRE2_MULTILINE has no effect. +.sp + PCRE2_NEVER_UCP +.sp +This option locks out the use of Unicode properties for handling \eB, \eb, \eD, +\ed, \eS, \es, \eW, \ew, and some of the POSIX character classes, as described +for the PCRE2_UCP option below. In particular, it prevents the creator of the +pattern from enabling this facility by starting the pattern with (*UCP). This +may be useful in applications that process patterns from external sources. The +option combination PCRE_UCP and PCRE_NEVER_UCP causes an error. +.sp + PCRE2_NEVER_UTF +.sp +This option locks out interpretation of the pattern as UTF-8, UTF-16, or +UTF-32, depending on which library is in use. In particular, it prevents the +creator of the pattern from switching to UTF interpretation by starting the +pattern with (*UTF). This may be useful in applications that process patterns +from external sources. The combination of PCRE2_UTF and PCRE2_NEVER_UTF causes +an error. +.sp + PCRE2_NO_AUTO_CAPTURE +.sp +If this option is set, it disables the use of numbered capturing parentheses in +the pattern. Any opening parenthesis that is not followed by ? behaves as if it +were followed by ?: but named parentheses can still be used for capturing (and +they acquire numbers in the usual way). There is no equivalent of this option +in Perl. +.sp + PCRE2_NO_AUTO_POSSESS +.sp +If this option is set, it disables "auto-possessification", which is an +optimization that, for example, turns a+b into a++b in order to avoid +backtracks into a+ that can never be successful. However, if callouts are in +use, auto-possessification means that some callouts are never taken. You can +set this option if you want the matching functions to do a full unoptimized +search and run all the callouts, but it is mainly provided for testing +purposes. +.sp + PCRE2_NO_START_OPTIMIZE +.sp +This is an option that acts at matching time; that is, it is really an option +for \fBpcre2_match()\fP or \fBpcre_dfa_match()\fP. If it is set at compile +time, it is remembered with the compiled pattern and assumed at matching time. +This is necessary if you want to use JIT execution, because the JIT compiler +needs to know whether or not this option is set. For details, see the +discussion of PCRE2_NO_START_OPTIMIZE in the section on \fBpcre2_match()\fP +options +.\" HTML +.\" +below. +.\" +.sp + PCRE2_NO_UTF_CHECK +.sp +When PCRE2_UTF is set, the validity of the pattern as a UTF string is +automatically checked. There are discussions about the validity of +.\" HTML +.\" +UTF-8 strings, +.\" +.\" HTML +.\" +UTF-16 strings, +.\" +and +.\" HTML +.\" +UTF-32 strings +.\" +in the +.\" HREF +\fBpcre2unicode\fP +.\" +document. +If an invalid UTF sequence is found, \fBpcre2_compile()\fP returns a negative +error code. +.P +If you know that your pattern is valid, and you want to skip this check for +performance reasons, you can set the PCRE2_NO_UTF_CHECK option. When it is set, +the effect of passing an invalid UTF string as a pattern is undefined. It may +cause your program to crash or loop. Note that this option can also be passed +to \fBpcre2_match()\fP and \fBpcre_dfa_match()\fP, to suppress validity +checking of the subject string. +.sp + PCRE2_UCP +.sp +This option changes the way PCRE2 processes \eB, \eb, \eD, \ed, \eS, \es, \eW, +\ew, and some of the POSIX character classes. By default, only ASCII characters +are recognized, but if PCRE2_UCP is set, Unicode properties are used instead to +classify characters. More details are given in the section on +.\" HTML +.\" +generic character types +.\" +in the +.\" HREF +\fBpcre2pattern\fP +.\" +page. If you set PCRE2_UCP, matching one of the items it affects takes much +longer. The option is available only if PCRE2 has been compiled with UTF +support. +.sp + PCRE2_UNGREEDY +.sp +This option inverts the "greediness" of the quantifiers so that they are not +greedy by default, but become greedy if followed by "?". It is not compatible +with Perl. It can also be set by a (?U) option setting within the pattern. +.sp + PCRE2_UTF +.sp +This option causes PCRE2 to regard both the pattern and the subject strings +that are subsequently processed as strings of UTF characters instead of +single-code-unit strings. However, it is available only when PCRE2 is built to +include UTF support. If not, the use of this option provokes an error. Details +of how this option changes the behaviour of PCRE2 are given in the +.\" HREF +\fBpcre2unicode\fP +.\" +page. +. +. +.SH "COMPILATION ERROR CODES" +.rs +.sp +There are over 80 positive error codes that \fBpcre2_compile()\fP may return if +it finds an error in the pattern. There are also some negative error codes that +are used for invalid UTF strings. These are the same as given by +\fBpcre2_match()\fP and \fBpcre2_dfa_match()\fP, and are described in the +.\" HREF +\fBpcre2unicode\fP +.\" +page. The \fBpcre2_get_error_message()\fP function can be called to obtain a +textual error message from any error code. +. +. +.SH "JUST-IN-TIME (JIT) COMPILATION" +.rs +.sp +.nf +.B int pcre2_jit_compile(pcre2_code *\fIcode\fP, uint32_t \fIoptions\fP); +.sp +.B int pcre2_jit_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP, pcre2_jit_stack *\fIjit_stack\fP);" +.sp +.B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP); +.sp +.B pcre2_jit_stack *pcre2_jit_stack_alloc(pcre2_general_context *\fIgcontext\fP, +.B " PCRE2_SIZE \fIstartsize\fP, PCRE2_SIZE \fImaxsize\fP);" +.sp +.B void pcre2_jit_stack_assign(const pcre2_code *\fIcode\fP, +.B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);" +.sp +.B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP); +.fi +.P +These functions provide support for JIT compilation, which, if the just-in-time +compiler is available, further processes a compiled pattern into machine code +that executes much faster than the \fBpcre2_match()\fP interpretive matching +function. Full details are given in the +.\" HREF +\fBpcre2jit\fP +.\" +documentation. +.P +JIT compilation is a heavyweight optimization. It can take some time for +patterns to be analyzed, and for one-off matches and simple patterns the +benefit of faster execution might be offset by a much slower compilation time. +Most, but not all patterns can be optimized by the JIT compiler. +. +. +.\" HTML +.SH "LOCALE SUPPORT" +.rs +.sp +PCRE2 handles caseless matching, and determines whether characters are letters, +digits, or whatever, by reference to a set of tables, indexed by character code +point. When running in UTF-8 mode, or using the 16-bit or 32-bit libraries, +this applies only to characters with code points less than 256. By default, +higher-valued code points never match escapes such as \ew or \ed. However, if +PCRE2 is built with UTF support, all characters can be tested with \ep and \eP, +or, alternatively, the PCRE2_UCP option can be set when a pattern is compiled; +this causes \ew and friends to use Unicode property support instead of the +built-in tables. +.P +The use of locales with Unicode is discouraged. If you are handling characters +with code points greater than 128, you should either use Unicode support, or +use locales, but not try to mix the two. +.P +PCRE2 contains an internal set of character tables that are used by default. +These are sufficient for many applications. Normally, the internal tables +recognize only ASCII characters. However, when PCRE2 is built, it is possible +to cause the internal tables to be rebuilt in the default "C" locale of the +local system, which may cause them to be different. +.P +The internal tables can be overridden by tables supplied by the application +that calls PCRE2. 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. +.P +External tables are built by calling the \fBpcre2_maketables()\fP function, in +the relevant locale. The result can be passed to \fBpcre2_compile()\fP as often +as necessary, by creating a compile context and calling +\fBpcre2_set_character_tables()\fP to set the tables pointer therein. 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: +.sp + setlocale(LC_CTYPE, "fr_FR"); + tables = pcre2_maketables(NULL); + ccontext = pcre2_compile_context_create(NULL); + pcre2_set_character_tables(ccontext, tables); + re = pcre2_compile(..., ccontext); +.sp +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". It is the +caller's responsibility to ensure that the memory containing the tables remains +available for as long as it is needed. +.P +The pointer that is passed (via the compile context) to \fBpcre2_compile()\fP +is saved with the compiled pattern, and the same tables are used by +\fBpcre2_match()\fP and \fBpcre_dfa_match()\fP. Thus, for any single pattern, +compilation, and matching all happen in the same locale, but different patterns +can be processed in different locales. +. +. +.\" HTML +.SH "INFORMATION ABOUT A COMPILED PATTERN" +.rs +.sp +.nf +.B int pcre2_pattern_info(const pcre2 *\fIcode\fP, uint32_t \fIwhat\fP, void *\fIwhere\fP); +.fi +.P +The \fBpcre2_pattern_info()\fP function returns information about a compiled +pattern. The first argument is a pointer to the compiled pattern. The second +argument specifies which piece of information is required, and the third +argument is a pointer to a variable to receive the data. The yield of the +function is zero for success, or one of the following negative numbers: +.sp + PCRE2_ERROR_NULL the argument \fIcode\fP was NULL + the argument \fIwhere\fP was NULL + PCRE2_ERROR_BADMAGIC the "magic number" was not found + PCRE2_ERROR_BADOPTION the value of \fIwhat\fP was invalid + PCRE2_ERROR_UNSET the requested field is not set +.sp +The "magic number" is placed at the start of each compiled pattern as an simple +check against passing an arbitrary memory pointer. +Here is +a typical call of \fBpcre2_pattern_info()\fP, to obtain the length of the compiled +pattern: +.sp + int rc; + size_t length; + rc = pcre2_pattern_info( + re, /* result of pcre2_compile() */ + PCRE2_INFO_SIZE, /* what is required */ + &length); /* where to put the data */ +.sp +The possible values for the second argument are defined in \fBpcre2.h\fP, and +are as follows: +.sp + PCRE2_INFO_ALLOPTIONS + PCRE2_INFO_ARGOPTIONS +.sp +Return a copy of the pattern's options. The third argument should point to a +\fBuint32_t\fP variable. PCRE2_INFO_ARGOPTIONS returns exactly the options that +were passed to \fBpcre2_compile()\fP, whereas PCRE2_INFO_ALLOPTIONS returns +the compile options as modified 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 PCRE2_EXTENDED option, the result is PCRE2_CASELESS, +PCRE2_MULTILINE, and PCRE2_EXTENDED. +.P +A pattern is automatically anchored by PCRE2 if all of its top-level +alternatives begin with one of the following: +.sp + ^ unless PCRE2_MULTILINE is set + \eA always + \eG always +.\" JOIN + .* if PCRE2_DOTALL is set and there are no back + references to the subpattern in which .* appears +.sp +For such patterns, the PCRE2_ANCHORED bit is set in the options returned for +PCRE2_INFO_ALLOPTIONS. +.sp + PCRE2_INFO_BACKREFMAX +.sp +Return the number of the highest back reference in the pattern. The third +argument should point to an \fBuint32_t\fP variable. Zero is returned if there +are no back references. +.sp + PCRE2_INFO_BSR +.sp +The output is a uint32_t whose value indicates what character sequences the \eR +escape sequence matches by default. A value of 0 means that \eR matches any +Unicode line ending sequence; a value of 1 means that \eR matches only CR, LF, +or CRLF. The default can be overridden when a pattern is matched. +.sp + PCRE2_INFO_CAPTURECOUNT +.sp +Return the number of capturing subpatterns in the pattern. The third argument +should point to an \fBuint32_t\fP variable. +.sp + PCRE2_INFO_FIRSTCODETYPE +.sp +Return information about the first code unit of any matched string, for a +non-anchored pattern. The third argument should point to an \fBuint32_t\fP +variable. +.P +If there is a fixed first value, for example, the letter "c" from a pattern +such as (cat|cow|coyote), 1 is returned, and the character value can be +retrieved using PCRE2_INFO_FIRSTCODEUNIT. If there is no fixed first value, and +if either +.sp +(a) the pattern was compiled with the PCRE2_MULTILINE option, and every branch +starts with "^", or +.sp +(b) every branch of the pattern starts with ".*" and PCRE2_DOTALL is not set +(if it were set, the pattern would be anchored), +.sp +2 is returned, indicating that the pattern matches only at the start of a +subject string or after any newline within the string. Otherwise 0 is +returned. For anchored patterns, 0 is returned. +.sp + PCRE2_INFO_FIRSTCODEUNIT +.sp +Return the value of the first code unit of any matched string in the situation +where PCRE2_INFO_FIRSTCODETYPE returns 1; otherwise return 0. The third +argument should point to an \fBuint32_t\fP variable. In the 8-bit library, the +value is always less than 256. In the 16-bit library the value can be up to +0xffff. In the 32-bit library in UTF-32 mode the value can be up to 0x10ffff, +and up to 0xffffffff when not using UTF-32 mode. +.sp + PCRE2_INFO_FIRSTBITMAP +.sp +In the absence of a single first code unit for a non-anchored pattern, +\fBpcre2_compile()\fP may construct a 256-bit table that defines a fixed set of +values for the first code unit in any match. For example, a pattern that starts +with [abc] results in a table with three bits set. When code unit values +greater than 255 are supported, the flag bit for 255 means "any code unit of +value 255 or above". If such a table was constructed, a pointer to it is +returned. Otherwise NULL is returned. The third argument should point to an +\fBconst uint8_t *\fP variable. +.sp + PCRE2_INFO_HASCRORLF +.sp +Return 1 if the pattern contains any explicit matches for CR or LF characters, +otherwise 0. The third argument should point to an \fBuint32_t\fP variable. An +explicit match is either a literal CR or LF character, or \er or \en. +.sp + PCRE2_INFO_JCHANGED +.sp +Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise +0. The third argument should point to an \fBuint32_t\fP variable. (?J) and +(?-J) set and unset the local PCRE2_DUPNAMES option, respectively. +.sp + PCRE2_INFO_JITSIZE +.sp +If the compiled pattern was successfully processed by +\fBpcre2_jit_compile()\fP, return the size of the JIT compiled code, otherwise +return zero. The third argument should point to a \fBsize_t\fP variable. +.sp + PCRE2_INFO_LASTCODETYPE +.sp +Returns 1 if there is a rightmost literal code unit that must exist in any +matched string, other than at its start. The third argument should point to an +\fBuint32_t\fP variable. If there is no such value, 0 is returned. When 1 is +returned, the code unit value itself can be retrieved using +PCRE2_INFO_LASTCODEUNIT. +.P +For anchored patterns, a last literal value is recorded only if it follows +something of variable length. For example, for the pattern /^a\ed+z\ed+/ the +returned value is 1 (with "z" returned from PCRE2_INFO_LASTCODEUNIT), but for +/^a\edz\ed/ the returned value is 0. +.sp + PCRE2_INFO_LASTCODEUNIT +.sp +Return the value of the rightmost literal data unit that must exist in any +matched string, other than at its start, if such a value has been recorded. The +third argument should point to an \fBuint32_t\fP variable. If there is no such +value, 0 is returned. +.sp + PCRE2_INFO_MATCHEMPTY +.sp +Return 1 if the pattern can match an empty string, otherwise 0. The third +argument should point to an \fBuint32_t\fP variable. +.sp + PCRE2_INFO_MATCHLIMIT +.sp +If the pattern set a match limit by including an item of the form +(*LIMIT_MATCH=nnnn) at the start, the value is returned. The third argument +should point to an unsigned 32-bit integer. If no such value has been set, the +call to \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. +.sp + PCRE2_INFO_MAXLOOKBEHIND +.sp +Return the number of characters (not code units) in the longest lookbehind +assertion in the pattern. The third argument should point to an unsigned 32-bit +integer. This information is useful when doing multi-segment matching using the +partial matching facilities. Note that the simple assertions \eb and \eB +require a one-character lookbehind. \eA also registers a one-character +lookbehind, though it does not actually inspect the previous character. This is +to ensure that at least one character from the old segment is retained when a +new segment is processed. Otherwise, if there are no lookbehinds in the +pattern, \eA might match incorrectly at the start of a new segment. +.sp + PCRE2_INFO_MINLENGTH +.sp +If a minimum length for matching subject strings was computed, its value is +returned. Otherwise the returned value is 0. The value is a number of +characters, which in UTF mode may be different from the number of code units. +The third argument should point to an \fBuint32_t\fP variable. The value is a +lower bound to the length of any matching string. There may not be any strings +of that length that do actually match, but every string that does match is at +least that long. +.sp + PCRE2_INFO_NAMECOUNT + PCRE2_INFO_NAMEENTRYSIZE + PCRE2_INFO_NAMETABLE +.sp +PCRE2 supports the use of named as well as numbered capturing parentheses. The +names are just an additional way of identifying the parentheses, which still +acquire numbers. Several convenience functions such as +\fBpcre2_substring_get_byname()\fP are provided for extracting captured +substrings 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 \fBpcre2_match()\fP below). To do the conversion, +you need to use the name-to-number map, which is described by these three +values. +.P +The map consists of a number of fixed-size entries. PCRE2_INFO_NAMECOUNT gives +the number of entries, and PCRE2_INFO_NAMEENTRYSIZE gives the size of each +entry; both of these return a \fBuint32_t\fP value. The entry size depends on +the length of the longest name. PCRE2_INFO_NAMETABLE returns a pointer to the +first entry of the table. This is a PCRE2_SPTR pointer to a block of code +units. In the 8-bit library, the first two bytes of each entry are the number +of the capturing parenthesis, most significant byte first. In the 16-bit +library, the pointer points to 16-bit data units, the first of which contains +the parenthesis number. In the 32-bit library, the pointer points to 32-bit +data units, the first of which contains the parenthesis number. The rest of the +entry is the corresponding name, zero terminated. +.P +The names are in alphabetical order. If (?| is used to create multiple groups +with the same number, as described in the +.\" HTML +.\" +section on duplicate subpattern numbers +.\" +in the +.\" HREF +\fBpcre2pattern\fP +.\" +page, the groups may be given the same name, but there is only one entry in the +table. Different names for groups of the same number are not permitted. +.P +Duplicate names for subpatterns with different numbers are permitted, but only +if PCRE2_DUPNAMES is set. They appear in the table in the order in which they +were found in the pattern. In the absence of (?| this is the order of +increasing number; when (?| is used this is not necessarily the case because +later subpatterns may have lower numbers. +.P +As a simple example of the name/number table, consider the following pattern +after compilation by the 8-bit library (assume PCRE2_EXTENDED is set, so white +space - including newlines - is ignored): +.sp +.\" JOIN + (? (?(\ed\ed)?\ed\ed) - + (?\ed\ed) - (?\ed\ed) ) +.sp +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 ??: +.sp + 00 01 d a t e 00 ?? + 00 05 d a y 00 ?? ?? + 00 04 m o n t h 00 + 00 02 y e a r 00 ?? +.sp +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. +.sp + PCRE2_INFO_NEWLINE +.sp +The output is a \fBuint32_t\fP whose value specifies the default character +sequence that will be recognized as meaning "newline" while matching. The +values are: +.sp + 1 Carriage return (CR) + 2 Linefeed (LF) + 3 Carriage return, linefeed (CRLF) + 4 Any Unicode line ending + 5 Any of CR, LF, or CRLF +.sp +The default can be overridden when a pattern is matched. +.sp + PCRE2_INFO_RECURSIONLIMIT +.sp +If the pattern set a recursion limit by including an item of the form +(*LIMIT_RECURSION=nnnn) at the start, the value is returned. The third +argument should point to an unsigned 32-bit integer. If no such value has been +set, the call to \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. +.sp + PCRE2_INFO_SIZE +.sp +Return the size of the compiled pattern in bytes (for all three libraries). The +third argument should point to a \fBsize_t\fP variable. This value does not +include the size of the \fBpcre2_code\fP structure that is returned by +\fBpcre_compile()\fP. The value that is used when \fBpcre2_compile()\fP is +getting memory in which to place the compiled data is the value returned by +this option plus the size of the \fBpcre2_code\fP structure. Processing a +pattern with the JIT compiler does not alter the value returned by this option. +. +. +.\" HTML +.SH "THE MATCH DATA BLOCK" +.rs +.sp +.nf +.B pcre2_match_data_create(uint32_t \fIovecsize\fP, +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B pcre2_match_data_create_from_pattern(pcre2_code *\fIcode\fP, +.B " pcre2_general_context *\fIgcontext\fP);" +.sp +.B void pcre2_match_data_free(pcre2_match_data *\fImatch_data\fP); +.fi +.P +Information about successful and unsuccessful matches is placed in a match +data block, which is an opaque structure that is accessed by function calls. In +particular, the match data block contains a vector of offsets into the subject +string that define the matched part of the subject and any substrings that were +capured. This is know as the \fIovector\fP. +.P +Before calling \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP you must create a +match data block by calling one of the creation functions above. For +\fBpcre2_match_data_create()\fP, the first argument is the number of pairs of +offsets in the \fIovector\fP. One pair of offsets is required to identify the +string that matched the whole pattern, with another pair for each captured +substring. For example, a value of 4 creates enough space to record the +matched portion of the subject plus three captured substrings. +.P +For \fBpcre2_match_data_create_from_pattern()\fP, the first argument is a +pointer to a compiled pattern. In this case the ovector is created to be +exactly the right size to hold all the substrings a pattern might capture. +.P +The second argument of both these functions ia a pointer to a general context, +which can specify custom memory management for obtaining the memory for the +match data block. If you are not using custom memory management, pass NULL. +.P +A match data block can be used many times, with the same or different compiled +patterns. When it is no longer needed, it should be freed by calling +\fBpcre2_match_data_free()\fP. How to extract information from a match data +block after a match operation is described in the sections on +.\" HTML +.\" +matched strings +.\" +and +.\" HTML +.\" +other match data +.\" +below. +. +. +.SH "MATCHING A PATTERN: THE TRADITIONAL FUNCTION" +.rs +.sp +.nf +.B int pcre2_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP);" +.fi +.P +The function \fBpcre2_match()\fP is called to match a subject string against a +compiled pattern, which is passed in the \fIcode\fP argument. You can call +\fBpcre2_match()\fP with the same \fIcode\fP argument as many times as you +like, in order to find multiple matches in the subject string or to match +different subject strings with the same pattern. +.P +This function is the main matching facility of the library, and it operates in +a Perl-like manner. For specialist use there is also an alternative matching +function, which is described +.\" HTML +.\" +below +.\" +in the section about the \fBpcre2_dfa_match()\fP function. +.P +Here is an example of a simple call to \fBpcre2_match()\fP: +.sp + pcre2_match_data *md = pcre2_match_data_create(4, NULL); + int rc = pcre2_match( + re, /* result of pcre2_compile() */ + "some string", /* the subject string */ + 11, /* the length of the subject string */ + 0, /* start at offset 0 in the subject */ + 0, /* default options */ + match_data, /* the match data block */ + NULL); /* a match context; NULL means use defaults */ +.sp +If the subject string is zero-terminated, the length can be given as +PCRE2_ZERO_TERMINATED. A match context must be provided if certain less common +matching parameters are to be changed. For details, see the section on +.\" HTML +.\" +the match context +.\" +above. +. +. +.SS "The string to be matched by \fBpcre2_match()\fP" +.rs +.sp +The subject string is passed to \fBpcre2_match()\fP as a pointer in +\fIsubject\fP, a length in \fIlength\fP, and a starting offset in +\fIstartoffset\fP. The length and offset are in code units, not characters. +That is, they are in bytes for the 8-bit library, 16-bit code units for the +16-bit library, and 32-bit code units for the 32-bit library, whether or not +UTF processing is enabled. +.P +If \fIstartoffset\fP is greater than the length of the subject, +\fBpcre2_match()\fP returns PCRE2_ERROR_BADOFFSET. 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. In UTF-8 or UTF-16 mode, the starting offset +must point to the start of a character, or to the end of the subject (in UTF-32 +mode, one code unit equals one character, so all offsets are valid). Like the +pattern string, the subject may contain binary zeroes. +.P +A non-zero starting offset is useful when searching for another match in the +same subject by calling \fBpcre2_match()\fP again after a previous success. +Setting \fIstartoffset\fP differs from passing over a shortened string and +setting PCRE2_NOTBOL in the case of a pattern that begins with any kind of +lookbehind. For example, consider the pattern +.sp + \eBiss\eB +.sp +which finds occurrences of "iss" in the middle of words. (\eB matches only if +the current position in the subject is not a word boundary.) When applied to +the string "Mississipi" the first call to \fBpcre2_match()\fP finds the first +occurrence. If \fBpcre2_match()\fP is called again with just the remainder of +the subject, namely "issipi", it does not match, because \eB is always false at +the start of the subject, which is deemed to be a word boundary. However, if +\fBpcre2_match()\fP is passed the entire string again, but with +\fIstartoffset\fP set to 4, it finds the second occurrence of "iss" because it +is able to look behind the starting point to discover that it is preceded by a +letter. +.P +Finding all the matches in a subject is tricky when the pattern can match an +empty string. It is possible to emulate Perl's /g behaviour by first trying the +match again at the same offset, with the PCRE2_NOTEMPTY_ATSTART and +PCRE2_ANCHORED options, and then if that fails, advancing the starting offset +and trying an ordinary match again. There is some code that demonstrates how to +do this in the +.\" HREF +\fBpcre2demo\fP +.\" +sample program. In the most general case, you have to check to see if the +newline convention recognizes CRLF as a newline, and if so, and the current +character is CR followed by LF, advance the starting offset by two characters +instead of one. +.P +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 subject. +. +. +.\" HTML +.SS "Option bits for \fBpcre2_match()\fP" +.rs +.sp +The unused bits of the \fIoptions\fP argument for \fBpcre2_match()\fP must be +zero. The only bits that may be set are PCRE2_ANCHORED, +PCRE2_NOTBOL, PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, +PCRE2_NO_START_OPTIMIZE, PCRE2_NO_UTF_CHECK, PCRE2_PARTIAL_HARD, and +PCRE2_PARTIAL_SOFT. Their action is described below. +.P +If the pattern was successfully processed by the just-in-time (JIT) compiler, +the only supported options for matching using the JIT code are PCRE2_NOTBOL, +PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_UTF_CHECK, +PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. If an unsupported option is used, +JIT matching is disabled and the normal interpretive code in +\fBpcre2_match()\fP is run. +.sp + PCRE2_ANCHORED +.sp +The PCRE2_ANCHORED option limits \fBpcre2_match()\fP to matching at the first +matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out +to be anchored by virtue of its contents, it cannot be made unachored at +matching time. Note that setting the option at match time disables JIT +matching. +.sp + PCRE2_NOTBOL +.sp +This option specifies that first character of the subject string is not the +beginning of a line, so the circumflex metacharacter should not match before +it. Setting this without PCRE2_MULTILINE (at compile time) causes circumflex +never to match. This option affects only the behaviour of the circumflex +metacharacter. It does not affect \eA. +.sp + PCRE2_NOTEOL +.sp +This option specifies that the end of the subject string is not the end of a +line, so the dollar metacharacter should not match it nor (except in multiline +mode) a newline immediately before it. Setting this without PCRE2_MULTILINE (at +compile time) causes dollar never to match. This option affects only the +behaviour of the dollar metacharacter. It does not affect \eZ or \ez. +.sp + PCRE2_NOTEMPTY +.sp +An empty string is not considered to be a valid match if this option is set. If +there are alternatives in the pattern, they are tried. If all the alternatives +match the empty string, the entire match fails. For example, if the pattern +.sp + a?b? +.sp +is applied to a string not beginning with "a" or "b", it matches an empty +string at the start of the subject. With PCRE2_NOTEMPTY set, this match is not +valid, so PCRE2 searches further into the string for occurrences of "a" or "b". +.sp + PCRE2_NOTEMPTY_ATSTART +.sp +This is like PCRE2_NOTEMPTY, except that an empty string match that is not at +the start of the subject is permitted. If the pattern is anchored, such a match +can occur only if the pattern contains \eK. +.sp + PCRE2_NO_START_OPTIMIZE +.sp +There are a number of optimizations that \fBpcre2_match()\fP uses at the start +of a match, in order to speed up the process. For example, if it is known that +an unanchored match must start with a specific character, it searches the +subject for that character, and fails immediately if it cannot find it, without +actually running the main matching function. This means that a special item +such as (*COMMIT) at the start of a pattern is not considered until after a +suitable starting point for the match has been found. Also, when callouts or +(*MARK) items are in use, these "start-up" optimizations can cause them to be +skipped if the pattern is never actually used. The start-up optimizations are +in effect a pre-scan of the subject that takes place before the pattern is run. +.P +The PCRE2_NO_START_OPTIMIZE option disables the start-up optimizations, +possibly causing performance to suffer, but ensuring that in cases where the +result is "no match", the callouts do occur, and that items such as (*COMMIT) +and (*MARK) are considered at every possible starting position in the subject +string. If PCRE2_NO_START_OPTIMIZE is set at compile time, it cannot be unset +at matching time. The use of PCRE2_NO_START_OPTIMIZE at matching time (that is, +passing it to \fBpcre2_match()\fP) disables JIT execution; in this situation, +matching is always done using interpretively. +.P +Setting PCRE2_NO_START_OPTIMIZE can change the outcome of a matching operation. +Consider the pattern +.sp + (*COMMIT)ABC +.sp +When this is compiled, PCRE2 records the fact that a match must start with the +character "A". Suppose the subject string is "DEFABC". The start-up +optimization scans along the subject, finds "A" and runs the first match +attempt from there. The (*COMMIT) item means that the pattern must match the +current starting position, which in this case, it does. However, if the same +match is run with PCRE2_NO_START_OPTIMIZE set, the initial scan along the +subject string does not happen. The first match attempt is run starting from +"D" and when this fails, (*COMMIT) prevents any further matches being tried, so +the overall result is "no match". There are also other start-up optimizations. +For example, a minimum length for the subject may be recorded. Consider the +pattern +.sp + (*MARK:A)(X|Y) +.sp +The minimum length for a match is one character. If the subject is "ABC", there +will be attempts to match "ABC", "BC", and "C". An attempt to match an empty +string at the end of the subject does not take place, because PCRE2 knows that +the subject is now too short, and so the (*MARK) is never encountered. In this +case, the optimization does not affect the overall match result, which is still +"no match", but it does affect the auxiliary information that is returned. +.sp + PCRE2_NO_UTF_CHECK +.sp +When PCRE2_UTF is set at compile time, the validity of the subject as a UTF +string is checked by default when \fBpcre2_match()\fP is subsequently called. +The entire string is checked before any other processing takes place, and a +negative error code is returned if the check fails. There are several UTF error +codes for each code unit width, corresponding to different problems with the +code unit sequence. The value of \fIstartoffset\fP is also checked, to ensure +that it points to the start of a character or to the end of the subject. There +are discussions about the validity of +.\" HTML +.\" +UTF-8 strings, +.\" +.\" HTML +.\" +UTF-16 strings, +.\" +and +.\" HTML +.\" +UTF-32 strings +.\" +in the +.\" HREF +\fBpcre2unicode\fP +.\" +page. +.P +If you know that your subject is valid, and you want to skip these checks for +performance reasons, you can set the PCRE2_NO_UTF_CHECK option when calling +\fBpcre2_match()\fP. You might want to do this for the second and subsequent +calls to \fBpcre2_match()\fP if you are making repeated calls to find all the +matches in a single subject string. +.P +NOTE: When PCRE2_NO_UTF_CHECK is set, the effect of passing an invalid string +as a subject, or an invalid value of \fIstartoffset\fP, is undefined. Your +program may crash or loop indefinitely. +.sp + PCRE2_PARTIAL_HARD + PCRE2_PARTIAL_SOFT +.sp +These options turn on the partial matching feature. A partial match occurs if +the end of the subject string is reached successfully, but there are not enough +subject characters to complete the match. If this happens when +PCRE2_PARTIAL_SOFT (but not PCRE2_PARTIAL_HARD) is set, matching continues by +testing any remaining alternatives. Only if no complete match can be found is +PCRE2_ERROR_PARTIAL returned instead of PCRE2_ERROR_NOMATCH. In other words, +PCRE2_PARTIAL_SOFT says that the caller is prepared to handle a partial match, +but only if no complete match can be found. +.P +If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this case, if +a partial match is found, \fBpcre2_match()\fP immediately returns +PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other +words, when PCRE2_PARTIAL_HARD is set, a partial match is considered to be more +important that an alternative complete match. +.P +There is a more detailed discussion of partial and multi-segment matching, with +examples, in the +.\" HREF +\fBpcre2partial\fP +.\" +documentation. +. +. +. +.SH "NEWLINE HANDLING WHEN MATCHING" +.rs +.sp +When PCRE2 is built, a default newline convention is set; this is usually the +standard convention for the operating system. The default can be overridden in +either a +.\" HTML +.\" +compile context +.\" +or a +.\" HTML +.\" +match context. +.\" +However, changing the newline convention at match time disables JIT matching. +During matching, the newline choice affects the behaviour of the dot, +circumflex, and dollar metacharacters. It may also alter the way the match +position is advanced after a match failure for an unanchored pattern. +.P +When PCRE2_NEWLINE_CRLF, PCRE2_NEWLINE_ANYCRLF, or PCRE2_NEWLINE_ANY is set, +and a match attempt for an unanchored pattern fails when the current 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. +.P +The above rule is a compromise that makes the most common cases work as +expected. For example, if the pattern is .+A (and the PCRE2_DOTALL option is +not set), it does not match the string "\er\enA" because, after failing at the +start, it skips both the CR and the LF before retrying. However, the pattern +[\er\en]A does match that string, because it contains an explicit CR or LF +reference, and so advances only by one character after the first failure. +.P +An explicit match for CR of LF is either a literal appearance of one of those +characters in the pattern, or one of the \er or \en escape sequences. Implicit +matches such as [^X] do not count, nor does \es (which includes CR and LF in +the characters that it matches). +.P +Notwithstanding the above, anomalous effects may still occur when CRLF is a +valid newline sequence and explicit \er or \en escapes appear in the pattern. +. +. +.\" HTML +.SH "HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS" +.rs +.sp +.nf +.B uint32_t pcre2_get_ovector_count(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *\fImatch_data\fP); +.fi +.P +In general, a pattern matches a certain portion of the subject, and in +addition, further substrings from the subject may be picked out by +parenthesized 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 substring. +PCRE2 supports several other kinds of parenthesized subpattern that do not +cause substrings to be captured. The \fBpcre2_pattern_info()\fP function can be +used to find out how many capturing subpatterns there are in a compiled +pattern. +.P +The overall matched string and any captured substrings are returned to the +caller via a vector of PCRE2_SIZE values, called the \fBovector\fP. This is +contained within the +.\" HTML +.\" +match data block. +.\" +You can obtain direct access to the ovector by calling +\fBpcre2_get_ovector_pointer()\fP to find its address, and +\fBpcre2_get_ovector_count()\fP to find the number of pairs of values it +contains. Alternatively, you can use the auxiliary functions for accessing +captured substrings +.\" HTML +.\" +by number +.\" +or +.\" HTML +.\" +by name +.\" +(see below). +.P +Within the ovector, the first in each pair of values is set to the offset of +the first code unit of a substring, and the second is set to the offset of the +first code unit after the end of a substring. These values are always code unit +offsets, not character offsets. That is, they are byte offsets in the 8-bit +library, 16-bit offsets in the 16-bit library, and 32-bit offsets in the 32-bit +library. +.P +The first pair of offsets (that is, \fIovector[0]\fP and \fIovector[1]\fP) +identifies the portion of the subject string that was matched by the entire +pattern. The next pair is used for the first capturing subpattern, and so on. +The value returned by \fBpcre2_match()\fP 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 that just the first pair of offsets +has been set. +.P +If a capturing subpattern is matched repeatedly within a single match +operation, it is the last portion of the string that it matched that is +returned. +.P +If the ovector is too small to hold all the captured substring offsets, as much +as possible is filled in, and the function returns a value of zero. If neither +the actual string matched nor any captured substrings are of interest, +\fBpcre2_match()\fP may be called with a match data block whose ovector is of +zero length. However, if the pattern contains back references and the +\fIovector\fP is not big enough to remember the related substrings, PCRE2 has +to get additional memory for use during matching. Thus it is usually advisable +to set up a match data block containing an ovector of reasonable size. +.P +It is possible for capturing subpattern number \fIn+1\fP to match some part of +the subject when subpattern \fIn\fP has not been used at all. For example, 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 corresponding to unused subpatterns +are set to PCRE2_UNSET. +.P +Offset values that correspond to unused subpatterns at the end of the +expression are also set to PCRE2_UNSET. 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. The offsets for for the second and third capturing +subpatterns (assuming the vector is large enough, of course) are set to +PCRE2_UNSET. +.P +Elements in the ovector that do not correspond to capturing parentheses in the +pattern are never changed. That is, if a pattern contains \fIn\fP capturing +parentheses, no more than \fIovector[0]\fP to \fIovector[2n+1]\fP are set by +\fBpcre2_match()\fP. The other elements retain whatever values they previously +had. +. +. +.\" HTML +.SS "Other information about the match" +.rs +.sp +.nf +.B PCRE2_SPTR pcre2_get_mark(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE pcre2_get_leftchar(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE pcre2_get_rightchar(pcre2_match_data *\fImatch_data\fP); +.sp +.B PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *\fImatch_data\fP); +.fi +.P +In addition to the offsets in the ovector, other information about a match is +retained in the match data block and can be retrieved by the above functions. +.P +When a (*MARK) name is to be passed back, \fBpcre2_get_mark()\fP returns a +pointer to the zero-terminated name, which is within the compiled pattern. +Otherwise NULL is returned. A (*MARK) name may be available after a failed +match or a partial match, as well as after a successful one. +.P +The other three functions yield values that give information about the part of +the subject string that was inspected during a successful match or a partial +match. Their results are undefined after a failed match. They return the +following values, respectively: +.sp +(1) The offset of the leftmost character that was inspected during the match. +This can be earlier than the point at which the match started if the pattern +contains lookbehind assertions or \eb or \eB at the start. +.sp +(2) The offset of the character that follows the rightmost character that was +inspected during the match. This can be after the end of the match if the +pattern contains lookahead assertions. +.sp +(3) The offset of the character at which the successful or partial match +started. This can be different to the value of \fIovector[0]\fP if the pattern +contains the \eK escape sequence. +.P +For example, if the pattern (?<=abc)xx\eKyy(?=def) is matched against the +string "123abcxxyydef123", the resulting offsets are: +.sp + ovector[0] 8 + ovector[1] 10 + leftchar 3 + rightchar 13 + startchar 6 +.sp +The \fBallusedtext\fP modifier in \fBpcre2test\fP can be used to display a +longer string that shows the leftmost and rightmost characters in a match +instead of just the matched string. +. +. +.\" HTML +.SS "Error return values from \fBpcre2_match()\fP" +.rs +.sp +If \fBpcre2_match()\fP fails, it returns a negative number. This can be +converted to a text string by calling \fBpcre2_get_error_message()\fP. Negative +error codes are also returned by other functions, and are documented with them. +The codes are given names in the header file. If UTF checking is in force and +an invalid UTF subject string is detected, one of a number of UTF-specific +negative error codes is returned. Details are given in the +.\" HREF +\fBpcre2unicode\fP +.\" +page. The following are the other errors that may be returned by +\fBpcre2_match()\fP: +.sp + PCRE2_ERROR_NOMATCH +.sp +The subject string did not match the pattern. +.sp + PCRE2_ERROR_PARTIAL +.sp +The subject string did not match, but it did match partially. See the +.\" HREF +\fBpcre2partial\fP +.\" +documentation for details of partial matching. +.sp + PCRE2_ERROR_BADMAGIC +.sp +PCRE2 stores a 4-byte "magic number" at the start of the compiled code, to +catch the case when it is passed a junk pointer. This is the error that is +returned when the magic number is not present. +.sp + PCRE2_ERROR_BADMODE +.sp +This error is given when a pattern that was compiled by the 8-bit library is +passed to a 16-bit or 32-bit library function, or vice versa. +.sp + PCRE2_ERROR_BADOFFSET +.sp +The value of \fIstartoffset\fP greater than the length of the subject. +.sp + PCRE2_ERROR_BADOPTION +.sp +An unrecognized bit was set in the \fIoptions\fP argument. +.sp + PCRE2_ERROR_BADUTFOFFSET +.sp +The UTF code unit sequence that was passed as a subject was checked and found +to be valid (the PCRE2_NO_UTF_CHECK option was not set), but the value of +\fIstartoffset\fP did not point to the beginning of a UTF character or the end +of the subject. +.sp + PCRE2_ERROR_CALLOUT +.sp +This error is never generated by \fBpcre2_match()\fP itself. It is provided for +use by callout functions that want to cause \fBpcre2_match()\fP to return a +distinctive error code. See the +.\" HREF +\fBpcre2callout\fP +.\" +documentation for details. +.sp + PCRE2_ERROR_INTERNAL +.sp +An unexpected internal error has occurred. This error could be caused by a bug +in PCRE2 or by overwriting of the compiled pattern. +.sp + PCRE2_ERROR_JIT_BADOPTION +.sp +This error is returned when a pattern that was successfully studied using JIT +is being matched, but the matching mode (partial or complete match) does not +correspond to any JIT compilation mode. When the JIT fast path function is +used, this error may be also given for invalid options. See the +.\" HREF +\fBpcre2jit\fP +.\" +documentation for more details. +.sp + PCRE2_ERROR_JIT_STACKLIMIT +.sp +This error is returned when a pattern that was successfully studied using JIT +is being matched, but the memory available for the just-in-time processing +stack is not large enough. See the +.\" HREF +\fBpcre2jit\fP +.\" +documentation for more details. +.sp + PCRE2_ERROR_MATCHLIMIT +.sp +The backtracking limit was reached. +.sp + PCRE2_ERROR_NOMEMORY +.sp +If a pattern contains back references, but the ovector is not big enough to +remember the referenced substrings, PCRE2 gets a block of memory at the start +of matching to use for this purpose. There are some other special cases where +extra memory is needed during matching. This error is given when memory cannot +be obtained. +.sp + PCRE2_ERROR_NULL +.sp +Either the \fIcode\fP, \fIsubject\fP, or \fImatch_data\fP argument was passed +as NULL. +.sp + PCRE2_ERROR_RECURSELOOP +.sp +This error is returned when \fBpcre2_match()\fP detects a recursion loop within +the pattern. Specifically, it means that either the whole pattern or a +subpattern has been called recursively for the second time at the same position +in the subject string. Some simple patterns that might do this are detected and +faulted at compile time, but more complicated cases, in particular mutual +recursions between two different subpatterns, cannot be detected until run +time. +.sp + PCRE2_ERROR_RECURSIONLIMIT +.sp +The internal recursion limit was reached. +. +. +.\" HTML +.SH "EXTRACTING CAPTURED SUBSTRINGS BY NUMBER" +.rs +.sp +.nf +.B int pcre2_substring_length_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_SIZE *\fIlength\fP);" +.sp +.B int pcre2_substring_copy_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_UCHAR *\fIbuffer\fP," +.B " PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B int pcre2_substring_get_bynumber(pcre2_match_data *\fImatch_data\fP, +.B " unsigned int \fInumber\fP, PCRE2_UCHAR **\fIbufferptr\fP," +.B " PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP); +.fi +.P +Captured substrings can be accessed directly by using the ovector as described +.\" HTML +.\" +above. +.\" +For convenience, auxiliary functions are provided for extracting captured +substrings as new, separate, zero-terminated strings. The functions in this +section identify substrings by number. The next section describes similar +functions for extracting substrings by name. 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. +.P +You can find the length in code units of a captured substring without +extracting it by calling \fBpcre2_substring_length_bynumber()\fP. The first +argument is a pointer to the match data block, the second is the group number, +and the third is a pointer to a variable into which the length is placed. +.P +The \fBpcre2_substring_copy_bynumber()\fP function copies one string into a +supplied buffer, whereas \fBpcre2_substring_get_bynumber()\fP copies it into +new memory, obtained using the same memory allocation function that was used +for the match data block. The first two arguments of these functions are a +pointer to the match data block and a capturing group number. A group number of +zero extracts the substring that matched the entire pattern, and higher values +extract the captured substrings. +.P +The final arguments of \fBpcre2_substring_copy_bynumber()\fP are a pointer to +the buffer and a pointer to a variable that contains its length in code units. +This is updated to contain the actual number of code units used, excluding the +terminating zero. +.P +For \fBpcre2_substring_get_bynumber()\fP the third and fourth arguments point +to variables that are updated with a pointer to the new memory and the number +of code units that comprise the substring, again excluding the terminating +zero. When the substring is no longer needed, the memory should be freed by +calling \fBpcre2_substring_free()\fP. +.P +The return value from these functions is zero for success, or one of these +error codes: +.sp + PCRE2_ERROR_NOMEMORY +.sp +The buffer was too small for \fBpcre2_substring_copy_bynumber()\fP, or the +attempt to get memory failed for \fBpcre2_substring_get_bynumber()\fP. +.sp + PCRE2_ERROR_NOSUBSTRING +.sp +No substring with the given number was captured. This could be because there is +no capturing group of that number in the pattern, or because the group with +that number did not participate in the match, or because the ovector was too +small to capture that group. +. +. +.SH "EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS" +.rs +.sp +.nf +.B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP); +.sp +.B void pcre2_substring_list_free(PCRE2_SPTR *\fIlist\fP); +.fi +.P +The \fBpcre2_substring_list_get()\fP function extracts all available substrings +and builds a list of pointers to them, and a second list that contains their +lengths (in code units), excluding a terminating zero that is added to each of +them. All this is done in a single block of memory that is obtained using the +same memory allocation function that was used to get the match data block. +.P +The address of the memory block is returned via \fIlistptr\fP, which is also +the start of the list of string pointers. The end of the list is marked by a +NULL pointer. The address of the list of lengths is returned via +\fIlengthsptr\fP. If your strings do not contain binary zeros and you do not +therefore need the lengths, you may supply NULL as the \fBlengthsptr\fP +argument to disable the creation of a list of lengths. The yield of the +function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the memory block +could not be obtained. When the list is no longer needed, it should be freed by +calling \fBpcre2_substring_list_free()\fP. +.P +If this function encounters a substring that is unset, which can happen when +capturing subpattern number \fIn+1\fP matches some part of the subject, but +subpattern \fIn\fP has not been used at all, it returns an empty string. This +can be distinguished from a genuine zero-length substring by inspecting the +appropriate offset in the ovector, which contains PCRE2_UNSET for unset +substrings. +. +. +.\" HTML +.SH "EXTRACTING CAPTURED SUBSTRINGS BY NAME" +.rs +.sp +.nf +.B int pcre2_substring_number_from_name(const pcre2_code *\fIcode\fP, +.B " PCRE2_SPTR \fIname\fP);" +.sp +.B int pcre2_substring_length_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_SIZE *\fIlength\fP);" +.sp +.B int pcre2_substring_copy_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR *\fIbuffer\fP, PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B int pcre2_substring_get_byname(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_UCHAR **\fIbufferptr\fP, PCRE2_SIZE *\fIbufflen\fP);" +.sp +.B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP); +.fi +.P +To extract a substring by name, you first have to find associated number. +For example, for this pattern: +.sp + (a+)b(?\ed+)... +.sp +the number of the subpattern called "xxx" is 2. If the name is known to be +unique (PCRE2_DUPNAMES was not set), you can find the number from the name by +calling \fBpcre2_substring_number_from_name()\fP. The first argument is the +compiled pattern, and the second is the name. The yield of the function is the +subpattern number, or PCRE2_ERROR_NOSUBSTRING if there is no subpattern of that +name. +.P +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 +"byname" functions that correspond to the "bynumber" functions, the only +difference being that the second argument is a name instead of a number. +However, if PCRE2_DUPNAMES is set and there are duplicate names, +the behaviour may not be what you want (see the next section). +.P +\fBWarning:\fP If the pattern uses the (?| feature to set up multiple +subpatterns with the same number, as described in the +.\" HTML +.\" +section on duplicate subpattern numbers +.\" +in the +.\" HREF +\fBpcre2pattern\fP +.\" +page, you cannot use names to distinguish the different subpatterns, because +names are not included in the compiled code. The matching process uses only +numbers. For this reason, the use of different names for subpatterns of the +same number causes an error at compile time. +. +. +.SH "DUPLICATE SUBPATTERN NAMES" +.rs +.sp +.nf +.B int pcre2_substring_nametable_scan(const pcre2_code *\fIcode\fP, +.B " PCRE2_SPTR \fIname\fP, PCRE2_SPTR *\fIfirst\fP, PCRE2_SPTR *\fIlast\fP);" +.fi +.P +When a pattern is compiled with the PCRE2_DUPNAMES option, names for +subpatterns are not required to be unique. Duplicate names are always allowed +for subpatterns with the same number, created by using the (?| feature. Indeed, +if such subpatterns are named, they are required to use the same names. +.P +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 +.\" HREF +\fBpcre2pattern\fP +.\" +documentation. +.P +When duplicates are present, \fBpcre2_substring_copy_byname()\fP and +\fBpcre2_substring_get_byname()\fP return the first substring corresponding to +the given name that is set. If none are set, PCRE2_ERROR_NOSUBSTRING is +returned. The \fBpcre2_substring_number_from_name()\fP function returns one of +the numbers that are associated with the name, but it is not defined which it +is. +.P +If you want to get full details of all captured substrings for a given name, +you must use the \fBpcre2_substring_nametable_scan()\fP function. The first +argument is the compiled pattern, and the second is the name. If the third and +fourth arguments are NULL, the function returns a group number (it is not +defined which). Otherwise, the third and fourth arguments must be pointers to +variables that are updated by the function. After it has run, they point to the +first and last entries in the name-to-number table for the given name, and the +function returns the length of each entry. In both cases, +PCRE2_ERROR_NOSUBSTRING is returned if there are no entries for the given name. +.P +The format of the name table is described above in the section entitled +\fIInformation about a pattern\fP +.\" HTML +.\" +above. +.\" +Given all the relevant entries for the name, you can extract each of their +numbers, and hence the captured data. +. +. +.SH "FINDING ALL POSSIBLE MATCHES" +.rs +.sp +The traditional matching function uses a similar algorithm to Perl, which stops +when it finds the first match, starting at a given point in the subject. If you +want to find all possible matches, or the longest possible match at a given +position, consider using the alternative matching function (see below) instead. +If you cannot use the alternative function, you can kludge it up by making use +of the callout facility, which is described in the +.\" HREF +\fBpcre2callout\fP +.\" +documentation. +.P +What you have to do is to insert a callout right at the end of the pattern. +When your callout function is called, extract and save the current matched +substring. Then return 1, which forces \fBpcre2_match()\fP to backtrack and try +other alternatives. Ultimately, when it runs out of matches, +\fBpcre2_match()\fP will yield PCRE2_ERROR_NOMATCH. +. +. +.\" HTML +.SH "MATCHING A PATTERN: THE ALTERNATIVE FUNCTION" +.rs +.sp +.nf +.B int pcre2_dfa_match(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, +.B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," +.B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," +.B " pcre2_match_context *\fImcontext\fP," +.B " int *\fIworkspace\fP, PCRE2_SIZE \fIwscount\fP);" +.fi +.P +The function \fBpcre2_dfa_match()\fP is called to match a subject string +against a compiled pattern, using a matching algorithm that scans the subject +string just once, and does not backtrack. This has different characteristics to +the normal algorithm, and is not compatible with Perl. Some of the features of +PCRE2 patterns are not supported. Nevertheless, there are times when this kind +of matching can be useful. For a discussion of the two matching algorithms, and +a list of features that \fBpcre2_dfa_match()\fP does not support, see the +.\" HREF +\fBpcre2matching\fP +.\" +documentation. +.P +The arguments for the \fBpcre2_dfa_match()\fP function are the same as for +\fBpcre2_match()\fP, plus two extras. The ovector within the match data block +is used in a different way, and this is described below. The other common +arguments are used in the same way as for \fBpcre2_match()\fP, so their +description is not repeated here. +.P +The two additional arguments provide workspace for the function. The workspace +vector should contain at least 20 elements. It is used for keeping track of +multiple paths through the pattern tree. More workspace is needed for patterns +and subjects where there are a lot of potential matches. +.P +Here is an example of a simple call to \fBpcre2_dfa_match()\fP: +.sp + int wspace[20]; + pcre2_match_data *md = pcre2_match_data_create(4, NULL); + int rc = pcre2_dfa_match( + re, /* result of pcre2_compile() */ + "some string", /* the subject string */ + 11, /* the length of the subject string */ + 0, /* start at offset 0 in the subject */ + 0, /* default options */ + match_data, /* the match data block */ + NULL, /* a match context; NULL means use defaults */ + wspace, /* working space vector */ + 20); /* number of elements (NOT size in bytes) */ +. +.SS "Option bits for \fBpcre_dfa_match()\fP" +.rs +.sp +The unused bits of the \fIoptions\fP argument for \fBpcre2_dfa_match()\fP must +be zero. The only bits that may be set are PCRE2_ANCHORED, PCRE2_NOTBOL, +PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_UTF_CHECK, +PCRE2_NO_START_OPTIMIZE, PCRE2_PARTIAL_HARD, PCRE2_PARTIAL_SOFT, +PCRE2_DFA_SHORTEST, and PCRE2_DFA_RESTART. All but the last four of these are +exactly the same as for \fBpcre2_match()\fP, so their description is not +repeated here. +.sp + PCRE2_PARTIAL_HARD + PCRE2_PARTIAL_SOFT +.sp +These have the same general effect as they do for \fBpcre2_match()\fP, but the +details are slightly different. When PCRE2_PARTIAL_HARD is set for +\fBpcre2_dfa_match()\fP, it returns PCRE2_ERROR_PARTIAL if the end of the +subject is reached and there is still at least one matching possibility that +requires additional characters. This happens even if some complete matches have +already been found. When PCRE2_PARTIAL_SOFT is set, the return code +PCRE2_ERROR_NOMATCH is converted into PCRE2_ERROR_PARTIAL if the end of the +subject is reached, there have been no complete matches, but there is still at +least one matching possibility. The portion of the string that was inspected +when the longest partial match was found is set as the first matching string in +both cases. There is a more detailed discussion of partial and multi-segment +matching, with examples, in the +.\" HREF +\fBpcre2partial\fP +.\" +documentation. +.sp + PCRE2_DFA_SHORTEST +.sp +Setting the PCRE2_DFA_SHORTEST option causes the matching algorithm to stop as +soon as it has found one match. Because of the way the alternative algorithm +works, this is necessarily the shortest possible match at the first possible +matching point in the subject string. +.sp + PCRE2_DFA_RESTART +.sp +When \fBpcre2_dfa_match()\fP returns a partial match, it is possible to call it +again, with additional subject characters, and have it continue with the same +match. The PCRE2_DFA_RESTART option requests this action; when it is set, the +\fIworkspace\fP and \fIwscount\fP options must reference the same vector as +before because data about the match so far is left in them after a partial +match. There is more discussion of this facility in the +.\" HREF +\fBpcre2partial\fP +.\" +documentation. +. +. +.SS "Successful returns from \fBpcre2_dfa_match()\fP" +.rs +.sp +When \fBpcre2_dfa_match()\fP succeeds, it may have matched more than one +substring in the subject. Note, however, that all the matches from one run of +the function start at the same point in the subject. The shorter matches are +all initial substrings of the longer matches. For example, if the pattern +.sp + <.*> +.sp +is matched against the string +.sp + This is no more +.sp +the three matched strings are +.sp + + + +.sp +On success, the yield of the function is a number greater than zero, which is +the number of matched substrings. The offsets of the substrings are returned in +the ovector, and can be extracted in the same way as for \fBpcre2_match()\fP. +They are returned in reverse order of length; that is, the longest +matching string is given first. If there were too many matches to fit into +the ovector, the yield of the function is zero, and the vector is filled with +the longest matches. +.P +NOTE: PCRE2's "auto-possessification" optimization usually applies to character +repeats at the end of a pattern (as well as internally). For example, the +pattern "a\ed+" is compiled as if it were "a\ed++" because there is no point in +backtracking into the repeated digits. For DFA matching, this means that only +one possible match is found. If you really do want multiple matches in such +cases, either use an ungreedy repeat ("a\ed+?") or set the +PCRE2_NO_AUTO_POSSESS option when compiling. +. +. +.SS "Error returns from \fBpcre2_dfa_match()\fP" +.rs +.sp +The \fBpcre2_dfa_match()\fP function returns a negative number when it fails. +Many of the errors are the same as for \fBpcre2_match()\fP, as described +.\" HTML +.\" +above. +.\" +There are in addition the following errors that are specific to +\fBpcre2_dfa_match()\fP: +.sp + PCRE2_ERROR_DFA_UITEM +.sp +This return is given if \fBpcre2_dfa_match()\fP encounters an item in the +pattern that it does not support, for instance, the use of \eC or a back +reference. +.sp + PCRE2_ERROR_DFA_UCOND +.sp +This return is given if \fBpcre2_dfa_match()\fP encounters a condition item +that uses a back reference for the condition, or a test for recursion in a +specific group. These are not supported. +.sp + PCRE2_ERROR_DFA_WSSIZE +.sp +This return is given if \fBpcre2_dfa_match()\fP runs out of space in the +\fIworkspace\fP vector. +.sp + PCRE2_ERROR_DFA_RECURSE +.sp +When a recursive subpattern is processed, the matching function calls itself +recursively, using private memory for the ovector and \fIworkspace\fP. This +error is given if the internal ovector is not large enough. This should be +extremely rare, as a vector of size 1000 is used. +.sp + PCRE2_ERROR_DFA_BADRESTART +.sp +When \fBpcre2_dfa_match()\fP is called with the \fBpcre2_dfa_RESTART\fP option, +some plausibility checks are made on the contents of the workspace, which +should contain data about the previous partial match. If any of these checks +fail, this error is given. +. +. +.SH "SEE ALSO" +.rs +.sp +\fBpcre2build\fP(3), \fBpcre2libs\fP(3), \fBpcre2callout\fP(3), +\fBpcre2matching\fP(3), \fBpcre2partial\fP(3), \fBpcre2posix\fP(3), +\fBpcre2demo(3)\fP, \fBpcre2sample\fP(3), \fBpcre2stack\fP(3). +. +. +.SH AUTHOR +.rs +.sp +.nf +Philip Hazel +University Computing Service +Cambridge CB2 3QH, England. +.fi +. +. +.SH REVISION +.rs +.sp +.nf +Last updated: 16 September 2014 +Copyright (c) 1997-2014 University of Cambridge. +.fi diff --git a/doc/pcre2test.1 b/doc/pcre2test.1 index 9aa9d34..1da6dfa 100644 --- a/doc/pcre2test.1 +++ b/doc/pcre2test.1 @@ -120,7 +120,7 @@ to the same value: pcre16 the 16-bit library was built pcre32 the 32-bit library was built pcre8 the 8-bit library was built - utf UTF and Unicode property support is available + unicode Unicode support is available .sp If an unknown option is given, an error message is output; the exit code is 0. .TP 10 diff --git a/doc/pcre2unicode.3 b/doc/pcre2unicode.3 new file mode 100644 index 0000000..3e0eaf4 --- /dev/null +++ b/doc/pcre2unicode.3 @@ -0,0 +1,254 @@ +.TH PCRE2UNICODE 3 "16 September 2014" "PCRE2 10.00" +.SH NAME +PCRE - Perl-compatible regular expressions (revised API) +.SH "UNICODE AND UTF SUPPORT" +.rs +.sp +When PCRE2 is built with Unicode support, it acquires knowledge of Unicode +character properties and can process text strings in UTF-8, UTF-16, or UTF-32 +format (depending on the code unit width). By default, PCRE2 assumes that one +code unit is one character. To process a pattern as a UTF string, where a +character may require more than one code unit, you must call +.\" HREF +\fBpcre2_compile()\fP +.\" +with the PCRE2_UTF option flag, or the pattern must start with the sequence +(*UTF). When either of these is the case, both the pattern and any subject +strings that are matched against it are treated as UTF strings instead of +strings of individual one-code-unit characters. +.P +If you build PCRE2 with Unicode support, the library will be bigger, but the +additional run time overhead is limited to testing the PCRE2_UTF flag +occasionally, so should not be very much. +. +. +.SH "UNICODE PROPERTY SUPPORT" +.rs +.sp +When PCRE2 is built with Unicode support, the escape sequences \ep{..}, +\eP{..}, and \eX can be used. The Unicode 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&. Full lists are given in the +.\" HREF +\fBpcre2pattern\fP +.\" +and +.\" HREF +\fBpcre2syntax\fP +.\" +documentation. Only the short names for properties are supported. For example, +\ep{L} matches a letter. Its Perl synonym, \ep{Letter}, 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. +. +. +.SH "WIDE CHARACTERS AND UTF MODES" +.rs +.sp +Codepoints less than 256 can be specified in patterns by either braced or +unbraced hexadecimal escape sequences (for example, \ex{b3} or \exb3). Larger +values have to use braced sequences. Unbraced octal code points up to \e777 are +also recognized; larger ones can be coded using \eo{...}. +.P +In UTF modes, repeat quantifiers apply to complete UTF characters, not to +individual code units. +.P +In UTF modes, the dot metacharacter matches one UTF character instead of a +single code unit. +.P +The escape sequence \eC can be used to match a single code unit, in a UTF mode, +but its use can lead to some strange effects because it breaks up multi-unit +characters (see the description of \eC in the +.\" HREF +\fBpcre2pattern\fP +.\" +documentation). The use of \eC is not supported in the alternative matching +function \fBpcre2_dfa_exec()\fP, nor is it supported in UTF mode by the JIT +optimization. If JIT optimization is requested for a UTF pattern that contains +\eC, it will not succeed, and so the matching will be carried out by the normal +interpretive function. +.P +The character escapes \eb, \eB, \ed, \eD, \es, \eS, \ew, and \eW correctly test +characters of any code value, but, by default, the characters that PCRE2 +recognizes as digits, spaces, or word characters remain the same set as in +non-UTF mode, all with code points less than 256. This remains true even when +PCRE2 is built to include Unicode support, because to do otherwise would slow +down matching in many common cases. Note that this also applies to \eb +and \eB, because they are defined in terms of \ew and \eW. If you want +to test for a wider sense of, say, "digit", you can use explicit Unicode +property tests such as \ep{Nd}. Alternatively, if you set the PCRE2_UCP option, +the way that the character escapes work is changed so that Unicode properties +are used to determine which characters match. There are more details in the +section on +.\" HTML +.\" +generic character types +.\" +in the +.\" HREF +\fBpcre2pattern\fP +.\" +documentation. +.P +Similarly, characters that match the POSIX named character classes are all +low-valued characters, unless the PCRE2_UCP option is set. +.P +However, the special horizontal and vertical white space matching escapes (\eh, +\eH, \ev, and \eV) do match all the appropriate Unicode characters, whether or +not PCRE2_UCP is set. +.P +Case-insensitive matching in UTF mode makes use of Unicode properties. A few +Unicode characters such as Greek sigma have more than two codepoints that are +case-equivalent, and these are treated as such. +. +. +.SH "VALIDITY OF UTF STRINGS" +.rs +.sp +When the PCRE2_UTF option is set, the strings passed as patterns and subjects +are (by default) checked for validity on entry to the relevant functions. +If an invalid UTF string is passed, an error return is given. +.P +UTF-16 and UTF-32 strings can indicate their endianness by special code knows +as a byte-order mark (BOM). The PCRE2 functions do not handle this, expecting +strings to be in host byte order. +.P +The entire string is checked before any other processing takes place. In +addition to checking the format of the string, there is a check to ensure that +all code points lie in the range U+0 to U+10FFFF, excluding the surrogate area. +The so-called "non-character" code points are not excluded because Unicode +corrigendum #9 makes it clear that they should not be. +.P +Characters in the "Surrogate Area" of Unicode are reserved for use by UTF-16, +where they are used in pairs to encode code points with values greater than +0xFFFF. The code points that are encoded by UTF-16 pairs are available +independently in the UTF-8 and UTF-32 encodings. (In other words, the whole +surrogate thing is a fudge for UTF-16 which unfortunately messes up UTF-8 and +UTF-32.) +.P +In some situations, you may already know that your strings are valid, and +therefore want to skip these checks in order to improve performance, for +example in the case of a long subject string that is being scanned repeatedly. +If you set the PCRE2_NO_UTF_CHECK flag at compile time or at run time, PCRE2 +assumes that the pattern or subject it is given (respectively) contains only +valid UTF code unit sequences. +.P +Passing PCRE2_NO_UTF_CHECK to \fBpcre2_compile()\fP just disables the check for +the pattern; it does not also apply to subject strings. If you want to disable +the check for a subject string you must pass this option to \fBpcre2_exec()\fP +or \fBpcre2_dfa_exec()\fP. +.P +If you pass an invalid UTF string when PCRE2_NO_UTF_CHECK is set, the result +is undefined and your program may crash or loop indefinitely. +. +. +.\" HTML +.SS "Errors in UTF-8 strings" +.rs +.sp +The following negative error codes are given for invalid UTF-8 strings: +.sp + PCRE2_ERROR_UTF8_ERR1 + PCRE2_ERROR_UTF8_ERR2 + PCRE2_ERROR_UTF8_ERR3 + PCRE2_ERROR_UTF8_ERR4 + PCRE2_ERROR_UTF8_ERR5 +.sp +The string ends with a truncated UTF-8 character; the code specifies how many +bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 characters to be +no longer than 4 bytes, the encoding scheme (originally defined by RFC 2279) +allows for up to 6 bytes, and this is checked first; hence the possibility of +4 or 5 missing bytes. +.sp + PCRE2_ERROR_UTF8_ERR6 + PCRE2_ERROR_UTF8_ERR7 + PCRE2_ERROR_UTF8_ERR8 + PCRE2_ERROR_UTF8_ERR9 + PCRE2_ERROR_UTF8_ERR10 +.sp +The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of the +character do not have the binary value 0b10 (that is, either the most +significant bit is 0, or the next bit is 1). +.sp + PCRE2_ERROR_UTF8_ERR11 + PCRE2_ERROR_UTF8_ERR12 +.sp +A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long; +these code points are excluded by RFC 3629. +.sp + PCRE2_ERROR_UTF8_ERR13 +.sp +A 4-byte character has a value greater than 0x10fff; these code points are +excluded by RFC 3629. +.sp + PCRE2_ERROR_UTF8_ERR14 +.sp +A 3-byte character has a value in the range 0xd800 to 0xdfff; this range of +code points are reserved by RFC 3629 for use with UTF-16, and so are excluded +from UTF-8. +.sp + PCRE2_ERROR_UTF8_ERR15 + PCRE2_ERROR_UTF8_ERR16 + PCRE2_ERROR_UTF8_ERR17 + PCRE2_ERROR_UTF8_ERR18 + PCRE2_ERROR_UTF8_ERR19 +.sp +A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes for a +value that can be represented by fewer bytes, which is invalid. For example, +the two bytes 0xc0, 0xae give the value 0x2e, whose correct coding uses just +one byte. +.sp + PCRE2_ERROR_UTF8_ERR20 +.sp +The two most significant bits of the first byte of a character have the binary +value 0b10 (that is, the most significant bit is 1 and the second is 0). Such a +byte can only validly occur as the second or subsequent byte of a multi-byte +character. +.sp + PCRE2_ERROR_UTF8_ERR21 +.sp +The first byte of a character has the value 0xfe or 0xff. These values can +never occur in a valid UTF-8 string. +. +. +.\" HTML +.SS "Errors in UTF-16 strings" +.rs +.sp +The following negative error codes are given for invalid UTF-16 strings: +.sp + PCRE_UTF16_ERR1 Missing low surrogate at end of string + PCRE_UTF16_ERR2 Invalid low surrogate follows high surrogate + PCRE_UTF16_ERR3 Isolated low surrogate +.sp +. +. +.\" HTML +.SS "Errors in UTF-32 strings" +.rs +.sp +The following negative error codes are given for invalid UTF-32 strings: +.sp + PCRE_UTF32_ERR1 Surrogate character (range from 0xd800 to 0xdfff) + PCRE_UTF32_ERR2 Code point is greater than 0x10ffff +.sp +. +. +.SH AUTHOR +.rs +.sp +.nf +Philip Hazel +University Computing Service +Cambridge CB2 3QH, England. +.fi +. +. +.SH REVISION +.rs +.sp +.nf +Last updated: 16 September 2014 +Copyright (c) 1997-2014 University of Cambridge. +.fi diff --git a/maint/ManyConfigTests b/maint/ManyConfigTests index 879eab4..fafbfff 100755 --- a/maint/ManyConfigTests +++ b/maint/ManyConfigTests @@ -202,7 +202,7 @@ if [ $ISGCC -ne 0 -a $usemain -ne 0 ]; then echo "---------- Maximally configured test with -O2 ----------" SAVECLFAGS="$CFLAGS" CFLAGS="$CFLAGS -O2" - opts="--disable-shared --enable-utf $enable_jit --enable-pcre16 --enable-pcre32" + opts="--disable-shared --enable-unicode $enable_jit --enable-pcre16 --enable-pcre32" runtest CFLAGS="$SAVECFLAGS" fi @@ -211,23 +211,23 @@ if [ $usemain -ne 0 ]; then echo "---------- Non-JIT tests in the current directory ----------" for opts in \ "" \ - "--enable-utf --disable-static" \ + "--enable-unicode --disable-static" \ "--disable-stack-for-recursion --disable-shared" \ - "--enable-utf --disable-shared" \ - "--enable-utf --disable-stack-for-recursion --disable-shared" \ - "--enable-utf --with-link-size=3 --disable-shared" \ + "--enable-unicode --disable-shared" \ + "--enable-unicode --disable-stack-for-recursion --disable-shared" \ + "--enable-unicode --with-link-size=3 --disable-shared" \ "--enable-rebuild-chartables --disable-shared" \ "--enable-newline-is-any --disable-shared" \ "--enable-newline-is-cr --disable-shared" \ "--enable-newline-is-crlf --disable-shared" \ "--enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared" \ - "--enable-utf --enable-newline-is-any --disable-stack-for-recursion --disable-static" \ + "--enable-unicode --enable-newline-is-any --disable-stack-for-recursion --disable-static" \ "--enable-pcre16" \ "--enable-pcre16 --disable-stack-for-recursion --disable-shared" \ - "--enable-pcre16 --enable-utf --disable-stack-for-recursion --disable-shared" \ + "--enable-pcre16 --enable-unicode --disable-stack-for-recursion --disable-shared" \ "--enable-pcre32" \ "--enable-pcre32 --disable-stack-for-recursion --disable-shared" \ - "--enable-pcre32 --enable-utf --disable-stack-for-recursion --disable-shared" \ + "--enable-pcre32 --enable-unicode --disable-stack-for-recursion --disable-shared" \ "--enable-pcre32 --enable-pcre16 --disable-shared" \ "--enable-pcre32 --enable-pcre16 --disable-pcre8 --disable-shared" do @@ -241,18 +241,18 @@ if [ $usejit -ne 0 ]; then echo "---------- JIT tests in the current directory ----------" for opts in \ "--enable-jit --disable-shared" \ - "--enable-jit --enable-utf --disable-shared" \ - "--enable-jit --enable-utf --with-link-size=3 --disable-shared" \ - "--enable-jit --enable-pcre16 --enable-utf --disable-shared" \ + "--enable-jit --enable-unicode --disable-shared" \ + "--enable-jit --enable-unicode --with-link-size=3 --disable-shared" \ + "--enable-jit --enable-pcre16 --enable-unicode --disable-shared" \ "--enable-jit --enable-pcre16 --disable-pcre8 --disable-shared" \ - "--enable-jit --enable-pcre16 --disable-pcre8 --enable-utf --disable-shared" \ - "--enable-jit --enable-pcre16 --enable-utf --with-link-size=3 --disable-shared" \ - "--enable-jit --enable-pcre16 --enable-utf --with-link-size=4 --disable-shared" \ - "--enable-jit --enable-pcre32 --enable-utf --disable-shared" \ + "--enable-jit --enable-pcre16 --disable-pcre8 --enable-unicode --disable-shared" \ + "--enable-jit --enable-pcre16 --enable-unicode --with-link-size=3 --disable-shared" \ + "--enable-jit --enable-pcre16 --enable-unicode --with-link-size=4 --disable-shared" \ + "--enable-jit --enable-pcre32 --enable-unicode --disable-shared" \ "--enable-jit --enable-pcre32 --disable-pcre8 --disable-shared" \ - "--enable-jit --enable-pcre32 --disable-pcre8 --enable-utf --disable-shared" \ - "--enable-jit --enable-pcre32 --enable-utf --with-link-size=4 --disable-shared" \ - "--enable-jit --enable-pcre32 --enable-pcre16 --disable-pcre8 --enable-utf --enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared" + "--enable-jit --enable-pcre32 --disable-pcre8 --enable-unicode --disable-shared" \ + "--enable-jit --enable-pcre32 --enable-unicode --with-link-size=4 --disable-shared" \ + "--enable-jit --enable-pcre32 --enable-pcre16 --disable-pcre8 --enable-unicode --enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared" do runtest done @@ -267,8 +267,8 @@ if [ $usevalgrind -ne 0 ]; then withvalgrind="with valgrind" for opts in \ - "--enable-utf --disable-stack-for-recursion --disable-shared" \ - "--enable-utf --with-link-size=3 --disable-shared" \ + "--enable-unicode --disable-stack-for-recursion --disable-shared" \ + "--enable-unicode --with-link-size=3 --disable-shared" \ "--disable-shared" do opts="--enable-valgrind $opts" @@ -277,8 +277,8 @@ if [ $usevalgrind -ne 0 ]; then if [ $usejit -ne 0 ]; then for opts in \ - "--enable-jit --enable-utf --disable-shared" \ - "--enable-jit --enable-pcre16 --enable-pcre32 --enable-utf" + "--enable-jit --enable-unicode --disable-shared" \ + "--enable-jit --enable-pcre16 --enable-pcre32 --enable-unicode" do opts="--enable-valgrind $opts" runtest @@ -324,7 +324,7 @@ fi if [ $usetmp -ne 0 ]; then for opts in \ - "--enable-utf --disable-shared" + "--enable-unicode --disable-shared" do runtest done diff --git a/maint/MultiStage2.py b/maint/MultiStage2.py index 19998a6..e1f1e33 100755 --- a/maint/MultiStage2.py +++ b/maint/MultiStage2.py @@ -472,7 +472,7 @@ print("condition to cut out the tables when not needed. But don't leave") print("a totally empty module because some compilers barf at that.") print("Instead, just supply small dummy tables. */") print() -print("#ifndef SUPPORT_UTF") +print("#ifndef SUPPORT_UNICODE") print("const ucd_record PRIV(ucd_records)[] = {{0,0,0,0,0 }};") print("const uint8_t PRIV(ucd_stage1)[] = {0};") print("const uint16_t PRIV(ucd_stage2)[] = {0};") @@ -507,7 +507,7 @@ print_table(min_stage2, 'PRIV(ucd_stage2)', min_block_size) print("#if UCD_BLOCK_SIZE != %d" % min_block_size) print("#error Please correct UCD_BLOCK_SIZE in pcre2_internal.h") print("#endif") -print("#endif /* SUPPORT_UTF */") +print("#endif /* SUPPORT_UNICODE */") print() print("#endif /* PCRE2_PCRE2TEST */") diff --git a/maint/ucptest.c b/maint/ucptest.c index bb976c1..f0e89b3 100644 --- a/maint/ucptest.c +++ b/maint/ucptest.c @@ -19,8 +19,8 @@ one. */ #include "../src/config.h" #endif -#ifndef SUPPORT_UTF -#define SUPPORT_UTF +#ifndef SUPPORT_UNICODE +#define SUPPORT_UNICODE #endif #include diff --git a/src/config.h.generic b/src/config.h.generic index 67fa46a..f403f22 100644 --- a/src/config.h.generic +++ b/src/config.h.generic @@ -278,11 +278,11 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to any value to enable the 8 bit PCRE2 library. */ /* #undef SUPPORT_PCRE8 */ -/* Define to any value to enable support for the UTF-8/16/32 Unicode encoding. - This will work even in an EBCDIC environment, but it is incompatible with - the EBCDIC macro. That is, PCRE2 can support *either* EBCDIC code *or* - ASCII/UTF-8/16/32, but not both at once. */ -/* #undef SUPPORT_UTF */ +/* Define to any value to enable support for Unicode and UTF encoding. This + will work even in an EBCDIC environment, but it is incompatible with the + EBCDIC macro. That is, PCRE2 can support *either* EBCDIC code *or* + ASCII/Unicode, but not both at once. */ +/* #undef SUPPORT_UNICODE */ /* Define to any value for valgrind support to find invalid memory reads. */ /* #undef SUPPORT_VALGRIND */ diff --git a/src/pcre2.h.in b/src/pcre2.h.in index 99146bd..d351bf7 100644 --- a/src/pcre2.h.in +++ b/src/pcre2.h.in @@ -193,32 +193,32 @@ must all be greater than zero. */ #define PCRE2_ERROR_UTF32_ERR1 (-27) #define PCRE2_ERROR_UTF32_ERR2 (-28) -/* Error codes for pcre2[_dfa]_match() */ +/* Error codes for pcre2[_dfa]_match(), substring extraction functions, and +context functions. */ -#define PCRE2_ERROR_BADCOUNT (-29) -#define PCRE2_ERROR_BADENDIANNESS (-30) -#define PCRE2_ERROR_BADLENGTH (-31) -#define PCRE2_ERROR_BADMAGIC (-32) -#define PCRE2_ERROR_BADMODE (-33) -#define PCRE2_ERROR_BADOFFSET (-34) -#define PCRE2_ERROR_BADOPTION (-35) -#define PCRE2_ERROR_BADUTFOFFSET (-36) -#define PCRE2_ERROR_CALLOUT (-37) /* Never used by PCRE2 itself */ -#define PCRE2_ERROR_DFA_BADRESTART (-38) -#define PCRE2_ERROR_DFA_RECURSE (-39) -#define PCRE2_ERROR_DFA_UCOND (-40) -#define PCRE2_ERROR_DFA_UITEM (-41) -#define PCRE2_ERROR_DFA_UMLIMIT (-42) -#define PCRE2_ERROR_DFA_WSSIZE (-43) -#define PCRE2_ERROR_INTERNAL (-44) -#define PCRE2_ERROR_JIT_BADOPTION (-45) -#define PCRE2_ERROR_JIT_STACKLIMIT (-46) -#define PCRE2_ERROR_MATCHLIMIT (-47) -#define PCRE2_ERROR_NOMEMORY (-48) -#define PCRE2_ERROR_NOSUBSTRING (-49) -#define PCRE2_ERROR_NULL (-50) -#define PCRE2_ERROR_RECURSELOOP (-51) -#define PCRE2_ERROR_RECURSIONLIMIT (-52) +#define PCRE2_ERROR_BADDATA (-29) +#define PCRE2_ERROR_BADLENGTH (-30) +#define PCRE2_ERROR_BADMAGIC (-31) +#define PCRE2_ERROR_BADMODE (-32) +#define PCRE2_ERROR_BADOFFSET (-33) +#define PCRE2_ERROR_BADOPTION (-34) +#define PCRE2_ERROR_BADUTFOFFSET (-35) +#define PCRE2_ERROR_CALLOUT (-36) /* Never used by PCRE2 itself */ +#define PCRE2_ERROR_DFA_BADRESTART (-37) +#define PCRE2_ERROR_DFA_RECURSE (-38) +#define PCRE2_ERROR_DFA_UCOND (-39) +#define PCRE2_ERROR_DFA_UITEM (-40) +#define PCRE2_ERROR_DFA_WSSIZE (-41) +#define PCRE2_ERROR_INTERNAL (-42) +#define PCRE2_ERROR_JIT_BADOPTION (-43) +#define PCRE2_ERROR_JIT_STACKLIMIT (-44) +#define PCRE2_ERROR_MATCHLIMIT (-45) +#define PCRE2_ERROR_NOMEMORY (-46) +#define PCRE2_ERROR_NOSUBSTRING (-47) +#define PCRE2_ERROR_NULL (-48) +#define PCRE2_ERROR_RECURSELOOP (-49) +#define PCRE2_ERROR_RECURSIONLIMIT (-50) +#define PCRE2_ERROR_UNSET (-51) /* Request types for pcre2_pattern_info() */ @@ -257,8 +257,8 @@ must all be greater than zero. */ #define PCRE2_CONFIG_PARENSLIMIT 7 #define PCRE2_CONFIG_RECURSIONLIMIT 5 #define PCRE2_CONFIG_STACKRECURSE 8 -#define PCRE2_CONFIG_UNICODE_VERSION 9 -#define PCRE2_CONFIG_UTF 10 +#define PCRE2_CONFIG_UNICODE 9 +#define PCRE2_CONFIG_UNICODE_VERSION 10 #define PCRE2_CONFIG_VERSION 11 /* Types for code units in patterns and subject strings. */ @@ -338,7 +338,7 @@ expanded for each width below. Start with functions that give general information. */ #define PCRE2_GENERAL_INFO_FUNCTIONS \ -PCRE2_EXP_DECL int pcre2_config(int, void *, PCRE2_SIZE); +PCRE2_EXP_DECL int pcre2_config(uint32_t, void *, PCRE2_SIZE); /* Functions for manipulating contexts. */ @@ -437,16 +437,16 @@ PCRE2_EXP_DECL PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *); PCRE2_EXP_DECL int pcre2_substring_copy_byname(pcre2_match_data *, \ PCRE2_SPTR, PCRE2_UCHAR *, PCRE2_SIZE *); \ PCRE2_EXP_DECL int pcre2_substring_copy_bynumber(pcre2_match_data *, \ - int, PCRE2_UCHAR *, PCRE2_SIZE *); \ + unsigned int, PCRE2_UCHAR *, PCRE2_SIZE *); \ PCRE2_EXP_DECL void pcre2_substring_free(PCRE2_UCHAR *); \ PCRE2_EXP_DECL int pcre2_substring_get_byname(pcre2_match_data *, \ PCRE2_SPTR, PCRE2_UCHAR **, PCRE2_SIZE *); \ PCRE2_EXP_DECL int pcre2_substring_get_bynumber(pcre2_match_data *, \ - int, PCRE2_UCHAR **, PCRE2_SIZE *); \ + unsigned int, PCRE2_UCHAR **, PCRE2_SIZE *); \ PCRE2_EXP_DECL int pcre2_substring_length_byname(pcre2_match_data *, \ PCRE2_SPTR, PCRE2_SIZE *); \ PCRE2_EXP_DECL int pcre2_substring_length_bynumber(pcre2_match_data *, \ - int, PCRE2_SIZE *); \ + unsigned int, PCRE2_SIZE *); \ PCRE2_EXP_DECL int pcre2_substring_nametable_scan(const pcre2_code *, \ PCRE2_SPTR, PCRE2_SPTR *, PCRE2_SPTR *); \ PCRE2_EXP_DECL int pcre2_substring_number_from_name(\ @@ -622,24 +622,27 @@ PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS #undef PCRE2_OTHER_FUNCTIONS #undef PCRE2_TYPES_STRUCTURES_AND_FUNCTIONS -/* Re-define PCRE2_SUFFIX to use the external width value, if defined. -Otherwise, undefine the other macros and make PCRE2_SUFFIX a no-op, to reduce -confusion. */ +/* PCRE2_CODE_UNIT_WIDTH must be defined. If it is 8, 16, or 32, redefine +PCRE2_SUFFIX to use it. If it is 0, undefine the other macros and make +PCRE2_SUFFIX a no-op. Otherwise, generate an error. */ #undef PCRE2_SUFFIX -#ifdef PCRE2_CODE_UNIT_WIDTH -#if PCRE2_CODE_UNIT_WIDTH != 8 && \ - PCRE2_CODE_UNIT_WIDTH != 16 && \ - PCRE2_CODE_UNIT_WIDTH != 32 -#error PCRE2_CODE_UNIT_WIDTH must be 8, 16, or 32 -#endif +#ifndef PCRE2_CODE_UNIT_WIDTH +#error PCRE2_CODE_UNIT_WIDTH must be defined before including pcre2.h. +#error Use 8, 16, or 32; or 0 for a multi-width application. +#else /* PCRE2_CODE_UNIT_WIDTH is defined */ +#if PCRE2_CODE_UNIT_WIDTH == 8 || \ + PCRE2_CODE_UNIT_WIDTH == 16 || \ + PCRE2_CODE_UNIT_WIDTH == 32 #define PCRE2_SUFFIX(a) PCRE2_GLUE(a, PCRE2_CODE_UNIT_WIDTH) -#else +#elif PCRE2_CODE_UNIT_WIDTH == 0 #undef PCRE2_JOIN #undef PCRE2_GLUE #define PCRE2_SUFFIX(a) a -#endif - +#else +#error PCRE2_CODE_UNIT_WIDTH must be 0, 8, 16, or 32. +#endif +#endif /* PCRE2_CODE_UNIT_WIDTH is defined */ #ifdef __cplusplus } /* extern "C" */ diff --git a/src/pcre2_auto_possess.c b/src/pcre2_auto_possess.c index 866f98a..56ec430 100644 --- a/src/pcre2_auto_possess.c +++ b/src/pcre2_auto_possess.c @@ -231,7 +231,7 @@ static const uint8_t opcode_possessify[] = { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /************************************************* * Check a character and a property * *************************************************/ @@ -311,7 +311,7 @@ switch(ptype) return FALSE; } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ @@ -368,7 +368,7 @@ PCRE2_UCHAR base; PCRE2_SPTR end; uint32_t chr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE uint32_t *clist_dest; const uint32_t *clist_src; #else @@ -451,7 +451,7 @@ switch(c) GETCHARINCTEST(chr, code); list[2] = chr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (chr < 128 || (chr < 256 && !utf)) list[3] = fcc[chr]; else @@ -470,7 +470,7 @@ switch(c) list[4] = NOTACHAR; return code; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP: case OP_NOTPROP: if (code[0] != PT_CLIST) @@ -812,7 +812,7 @@ for(;;) leftop = base_list[0]; rightop = list[0]; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE accepted = FALSE; /* Always set in non-unicode case. */ if (leftop == OP_PROP || leftop == OP_NOTPROP) { @@ -915,7 +915,7 @@ for(;;) } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ accepted = leftop >= FIRST_AUTOTAB_OP && leftop <= LAST_AUTOTAB_LEFT_OP && rightop >= FIRST_AUTOTAB_OP && rightop <= LAST_AUTOTAB_RIGHT_OP && @@ -1039,7 +1039,7 @@ for(;;) case OP_EOD: /* Can always possessify before \z */ break; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP: case OP_NOTPROP: if (!check_char_prop(chr, list_ptr[2], list_ptr[3], diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 87a571c..664a4fc 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -433,7 +433,7 @@ static const int posix_class_maps[] = { /* Table of substitutes for \d etc when PCRE2_UCP is set. They are replaced by Unicode property escapes. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE static const PCRE2_UCHAR string_PNd[] = { CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET, CHAR_N, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' }; @@ -541,7 +541,7 @@ static PCRE2_SPTR posix_substitutes[] = { NULL /* ^xdigit */ }; #define POSIX_SUBSIZE (sizeof(posix_substitutes) / sizeof(PCRE2_UCHAR *)) -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Masks for checking option settings. */ @@ -887,7 +887,7 @@ for (;;) case OP_NOTI: branchlength++; cc += 2; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); #endif break; @@ -901,7 +901,7 @@ for (;;) case OP_NOTEXACTI: branchlength += (int)GET2(cc,1); cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); #endif break; @@ -1315,7 +1315,7 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE); actual length is stored in the compiled code, so we must update "code" here. */ -#if defined SUPPORT_UTF || PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 case OP_XCLASS: ccode = code += GET(code, 1); goto CHECK_CLASS_REPEAT; @@ -1325,7 +1325,7 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE); case OP_NCLASS: ccode = code + PRIV(OP_lengths)[OP_CLASS]; -#if defined SUPPORT_UTF || PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 CHECK_CLASS_REPEAT: #endif @@ -2062,7 +2062,7 @@ return escape; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /************************************************* * Handle \P and \p * *************************************************/ @@ -2678,7 +2678,7 @@ return -1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /************************************************* * Get othercase range * *************************************************/ @@ -2740,7 +2740,7 @@ for (++c; c <= d; c++) *cptr = c; /* Rest of input range */ return 0; } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ @@ -2780,7 +2780,7 @@ range. */ if ((options & PCRE2_CASELESS) != 0) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((options & PCRE2_UTF) != 0) { int rc; @@ -2810,7 +2810,7 @@ if ((options & PCRE2_CASELESS) != 0) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ @@ -2844,7 +2844,7 @@ if (end >= start) { PCRE2_UCHAR *uchardata = *uchardptr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((options & PCRE2_UTF) != 0) { if (start < end) @@ -2860,7 +2860,7 @@ if (end >= start) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Without UTF support, character values are constrained by the bit length, and can only be > 256 for 16-bit and 32-bit libraries. */ @@ -3042,7 +3042,7 @@ uint8_t classbits[32]; not do this for other options (e.g. PCRE2_EXTENDED) because they may change dynamically as we process the pattern. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE BOOL utf = (options & PCRE2_UTF) != 0; #if PCRE2_CODE_UNIT_WIDTH != 32 PCRE2_UCHAR utf_units[6]; /* For setting up multi-cu chars */ @@ -3235,7 +3235,7 @@ for (;; ptr++) break; } ptr++; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) FORWARDCHAR(ptr); #endif } @@ -3474,7 +3474,7 @@ for (;; ptr++) goto FAILED; } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(c)) { /* Braces are required because the */ GETCHARLEN(c, ptr, ptr); /* macro generates multiple statements */ @@ -3556,7 +3556,7 @@ for (;; ptr++) that are not available via \p or \P generate XCL_PROP/XCL_NOTPROP directly. UCP support is not available unless UTF support is.*/ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((options & PCRE2_UCP) != 0) { unsigned int ptype = 0; @@ -3599,7 +3599,7 @@ for (;; ptr++) break; } } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* In the non-UCP case, or when UCP makes no difference, we build the bit map for the POSIX class in a chunk of local store because we may be @@ -3689,7 +3689,7 @@ for (;; ptr++) switch (escape) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case ESC_du: /* These are the values given for \d etc */ case ESC_DU: /* when PCRE2_UCP is set. We replace the */ case ESC_wu: /* escape sequence with an appropriate \p */ @@ -3757,7 +3757,7 @@ for (;; ptr++) cb, PRIV(vspace_list)); break; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case ESC_p: case ESC_P: { @@ -3840,7 +3840,7 @@ for (;; ptr++) /* Otherwise, we have a potential range; pick up the next character */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { /* Braces are required because the */ GETCHARLEN(d, ptr, ptr); /* macro generates multiple statements */ @@ -3940,7 +3940,7 @@ for (;; ptr++) if (negate_class) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE int d; #endif if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; @@ -3951,7 +3951,7 @@ for (;; ptr++) one other case. If so, generate a special OP_NOTPROP item instead of OP_NOTI. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && (options & PCRE2_CASELESS) != 0 && (d = UCD_CASESET(c)) != 0) { @@ -4032,7 +4032,7 @@ for (;; ptr++) be listed) there are no characters < 256, we can omit the bitmap in the actual compiled code. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (xclass && (!should_flip_negation || (options & PCRE2_UCP) != 0)) #elif PCRE2_CODE_UNIT_WIDTH != 8 if (xclass && !should_flip_negation) @@ -4157,7 +4157,7 @@ for (;; ptr++) break; } p++; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) FORWARDCHAR(p); #endif } /* Loop for comment characters */ @@ -4265,7 +4265,7 @@ for (;; ptr++) /* If previous was a character type match (\d or similar), abolish it and create a suitable repeat item. The code is shared with single-character repeats by setting op_type to add a suitable offset into repeat_type. Note - the the Unicode property types will be present only when SUPPORT_UTF is + the the Unicode property types will be present only when SUPPORT_UNICODE is defined, but we don't wrap the little bits of code here because it just makes it horribly messy. */ @@ -4880,7 +4880,7 @@ for (;; ptr++) case OP_NOTEXACT: case OP_NOTEXACTI: tempcode += PRIV(OP_lengths)[*tempcode]; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(tempcode[-1])) tempcode += GET_EXTRALEN(tempcode[-1]); #endif @@ -6407,7 +6407,7 @@ for (;; ptr++) /* So are Unicode property matches, if supported. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE else if (escape == ESC_P || escape == ESC_p) { BOOL negated; @@ -6442,7 +6442,7 @@ for (;; ptr++) if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) && cb->max_lookbehind == 0) cb->max_lookbehind = 1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (escape >= ESC_DU && escape <= ESC_wu) { nestptr = ptr + 1; /* Where to resume */ @@ -6479,7 +6479,7 @@ for (;; ptr++) mclength = 1; mcbuffer[0] = c; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(c)) ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr)); #endif @@ -6493,7 +6493,7 @@ for (;; ptr++) /* For caseless UTF mode, check whether this character has more than one other case. If so, generate a special OP_PROP item instead of OP_CHARI. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && (options & PCRE2_CASELESS) != 0) { GETCHAR(c, mcbuffer); @@ -7527,7 +7527,7 @@ ptr += skipatstart; /* Can't support UTF or UCP unless PCRE2 has been compiled with UTF support. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE if ((cb.external_options & (PCRE2_UTF|PCRE2_UCP)) != 0) { errorcode = ERR32; @@ -7911,7 +7911,7 @@ if ((re->overall_options & PCRE2_ANCHORED) == 0) points and cannot have another case. In 16-bit and 32-bit modes, we can check wide characters when UTF (and therefore UCP) is supported. */ -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 else if (firstcu <= MAX_UTF_CODE_POINT && UCD_OTHERCASE(firstcu) != firstcu) re->flags |= PCRE2_FIRSTCASELESS; @@ -7945,7 +7945,7 @@ if (reqcuflags >= 0 && { if (cb.fcc[reqcu] != reqcu) re->flags |= PCRE2_LASTCASELESS; } -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 else if (reqcu <= MAX_UTF_CODE_POINT && UCD_OTHERCASE(reqcu) != reqcu) re->flags |= PCRE2_LASTCASELESS; #endif diff --git a/src/pcre2_config.c b/src/pcre2_config.c index c6b0cbe..86bc7fd 100644 --- a/src/pcre2_config.c +++ b/src/pcre2_config.c @@ -75,7 +75,7 @@ Returns: 0 if data returned */ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_config(int what, void *where, size_t length) +pcre2_config(uint32_t what, void *where, size_t length) { if (length < sizeof(int)) return PCRE2_ERROR_BADLENGTH; @@ -145,7 +145,7 @@ switch (what) case PCRE2_CONFIG_UNICODE_VERSION: { -#if defined SUPPORT_UTF +#if defined SUPPORT_UNICODE const char *v = PRIV(unicode_version); #else const char *v = "Unicode not supported"; @@ -158,8 +158,8 @@ switch (what) } break; - case PCRE2_CONFIG_UTF: -#if defined SUPPORT_UTF + case PCRE2_CONFIG_UNICODE: +#if defined SUPPORT_UNICODE *((int *)where) = 1; #else *((int *)where) = 0; diff --git a/src/pcre2_context.c b/src/pcre2_context.c index 564f642..f4e592a 100644 --- a/src/pcre2_context.c +++ b/src/pcre2_context.c @@ -263,8 +263,9 @@ if (mcontext != NULL) * Set values in contexts * *************************************************/ -/* All these functions return 1 for success or 0 if invalid data is given. Only -some of the functions are able to test the validity of the data. */ +/* All these functions return 0 for success or PCRE2_ERROR_BADDATA if invalid +data is given. Only some of the functions are able to test the validity of the +data. */ /* ------------ Compile contexts ------------ */ @@ -274,7 +275,7 @@ pcre2_set_character_tables(pcre2_compile_context *ccontext, const unsigned char *tables) { ccontext->tables = tables; -return 1; +return 0; } PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION @@ -285,10 +286,10 @@ switch(value) case PCRE2_BSR_ANYCRLF: case PCRE2_BSR_UNICODE: ccontext->bsr_convention = value; - return 1; + return 0; default: - return 0; + return PCRE2_ERROR_BADDATA; } } @@ -303,10 +304,10 @@ switch(newline) case PCRE2_NEWLINE_ANY: case PCRE2_NEWLINE_ANYCRLF: ccontext->newline_convention = newline; - return 1; + return 0; default: - return 0; + return PCRE2_ERROR_BADDATA; } } @@ -314,7 +315,7 @@ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t limit) { ccontext->parens_nest_limit = limit; -return 1; +return 0; } PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION @@ -322,7 +323,7 @@ pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext, int (*guard)(uint32_t)) { ccontext->stack_guard = guard; -return 1; +return 0; } @@ -336,10 +337,10 @@ switch(value) case PCRE2_BSR_ANYCRLF: case PCRE2_BSR_UNICODE: mcontext->bsr_convention = value; - return 1; + return 0; default: - return 0; + return PCRE2_ERROR_BADDATA; } } @@ -354,10 +355,10 @@ switch(newline) case PCRE2_NEWLINE_ANY: case PCRE2_NEWLINE_ANYCRLF: mcontext->newline_convention = newline; - return 1; + return 0; default: - return 0; + return PCRE2_ERROR_BADDATA; } } @@ -367,21 +368,21 @@ pcre2_set_callout(pcre2_match_context *mcontext, { mcontext->callout = callout; mcontext->callout_data = callout_data; -return 1; +return 0; } PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t limit) { mcontext->match_limit = limit; -return 1; +return 0; } PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit) { mcontext->recursion_limit = limit; -return 1; +return 0; } PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION @@ -399,7 +400,7 @@ mcontext->stack_memctl.memory_data = mydata; (void)myfree; (void)mydata; #endif -return 1; +return 0; } /* End of pcre2_context.c */ diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index 72925e0..afe5f7b 100644 --- a/src/pcre2_dfa_match.c +++ b/src/pcre2_dfa_match.c @@ -391,7 +391,7 @@ PCRE2_SPTR start_subject = mb->start_subject; PCRE2_SPTR end_subject = mb->end_subject; PCRE2_SPTR start_code = mb->start_code; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE BOOL utf = (mb->poptions & PCRE2_UTF) != 0; #else BOOL utf = FALSE; @@ -447,7 +447,7 @@ if (*first_op == OP_REVERSE) /* If we can't go back the amount required for the longest lookbehind pattern, go back as far as we can; some alternatives may still be viable. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /* In character mode we have to step back character by character */ if (utf) @@ -570,11 +570,11 @@ for (;;) if (ptr < end_subject) { clen = 1; /* Number of data items in the character */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE GETCHARLENTEST(c, ptr, clen); #else c = *ptr; -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ } else { @@ -652,9 +652,9 @@ for (;;) if (coptable[codevalue] > 0) { dlen = 1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ d = code[coptable[codevalue]]; if (codevalue >= OP_TYPESTAR) { @@ -948,11 +948,11 @@ for (;;) { PCRE2_SPTR temp = ptr - 1; if (temp < mb->start_used_ptr) mb->start_used_ptr = temp; -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 32 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 if (utf) { BACKCHAR(temp); } #endif GETCHARTEST(d, temp); -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((mb->poptions & PCRE2_UCP) != 0) { if (d == '_') left_word = TRUE; else @@ -972,12 +972,12 @@ for (;;) if (ptr >= mb->last_used_ptr) { PCRE2_SPTR temp = ptr + 1; -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 32 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 if (utf) { FORWARDCHAR(temp); } #endif mb->last_used_ptr = temp; } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((mb->poptions & PCRE2_UCP) != 0) { if (c == '_') right_word = TRUE; else @@ -1003,7 +1003,7 @@ for (;;) if the support is in the binary; otherwise a compile-time error occurs. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP: case OP_NOTPROP: if (clen > 0) @@ -1258,7 +1258,7 @@ for (;;) argument. It keeps the code above fast for the other cases. The argument is in the d variable. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP_EXTRA + OP_TYPEPLUS: case OP_PROP_EXTRA + OP_TYPEMINPLUS: case OP_PROP_EXTRA + OP_TYPEPOSPLUS: @@ -1501,7 +1501,7 @@ for (;;) break; /*-----------------------------------------------------------------*/ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP_EXTRA + OP_TYPEQUERY: case OP_PROP_EXTRA + OP_TYPEMINQUERY: case OP_PROP_EXTRA + OP_TYPEPOSQUERY: @@ -1785,7 +1785,7 @@ for (;;) break; /*-----------------------------------------------------------------*/ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE case OP_PROP_EXTRA + OP_TYPEEXACT: case OP_PROP_EXTRA + OP_TYPEUPTO: case OP_PROP_EXTRA + OP_TYPEMINUPTO: @@ -2063,7 +2063,7 @@ for (;;) case OP_CHARI: if (clen == 0) break; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { if (c == d) { ADD_NEW(state_offset + dlen + 1, 0); } else @@ -2077,7 +2077,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ { if (TABLE_GET(c, lcc, c) == TABLE_GET(d, lcc, d)) @@ -2086,7 +2086,7 @@ for (;;) break; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /*-----------------------------------------------------------------*/ /* This is a tricky one because it can match more than one character. Find out how many characters to skip, and then set up a negative state @@ -2222,11 +2222,11 @@ for (;;) if (clen > 0) { unsigned int otherd; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); if (c != d && c != otherd) { ADD_NEW(state_offset + dlen + 1, 0); } @@ -2257,11 +2257,11 @@ for (;;) uint32_t otherd = NOTACHAR; if (caseless) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) @@ -2300,11 +2300,11 @@ for (;;) uint32_t otherd = NOTACHAR; if (caseless) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) @@ -2341,11 +2341,11 @@ for (;;) uint32_t otherd = NOTACHAR; if (caseless) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) @@ -2374,11 +2374,11 @@ for (;;) uint32_t otherd = NOTACHAR; if (caseless) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) @@ -2414,11 +2414,11 @@ for (;;) uint32_t otherd = NOTACHAR; if (caseless) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && d >= 128) otherd = UCD_OTHERCASE(d); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ otherd = TABLE_GET(d, fcc, d); } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) @@ -2747,7 +2747,7 @@ for (;;) for (rc = rc*2 - 2; rc >= 0; rc -= 2) { int charcount = local_offsets[rc+1] - local_offsets[rc]; -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 32 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 if (utf) { PCRE2_SPTR p = start_subject + local_offsets[rc]; @@ -2851,7 +2851,7 @@ for (;;) PCRE2_SPTR p = ptr; PCRE2_SPTR pp = local_ptr; charcount = (int)(pp - p); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 32 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 if (utf) while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--; #endif ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1)); @@ -2933,7 +2933,7 @@ for (;;) } else { -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 32 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 if (utf) { PCRE2_SPTR p = start_subject + local_offsets[0]; @@ -3106,14 +3106,24 @@ if (re == NULL || subject == NULL || workspace == NULL || match_data == NULL) if (wscount < 20) return PCRE2_ERROR_DFA_WSSIZE; if (start_offset > length) return PCRE2_ERROR_BADOFFSET; -/* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. However, if the magic number is equal to -REVERSED_MAGIC_NUMBER we return with PCRE2_ERROR_BADENDIANNESS, which -means that the pattern is likely compiled with different endianness. */ +/* FIXME: Remove BADENDIANNESS if saving/restoring is not to be implemented. */ + +/* Check that the first field in the block is the magic number. If it is not, +return with PCRE2_ERROR_BADMAGIC. */ + +if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; + +#ifdef FIXME +If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add +this comment and code: + +/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return +with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled +with different endianness. */ -if (re->magic_number != MAGIC_NUMBER) return re->magic_number == REVERSED_MAGIC_NUMBER? PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC; +#endif /* Check the code unit width. */ @@ -3238,7 +3248,7 @@ switch(newline) we must also check that a starting offset does not point into the middle of a multiunit character. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) { match_data->rc = PRIV(valid_utf)(subject, length, &(match_data->rightchar)); @@ -3253,7 +3263,7 @@ if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) return PCRE2_ERROR_BADUTFOFFSET; #endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Set up the first code unit to match, if available. The first_codeunit value is never set for an anchored regular expression, but the anchoring may be @@ -3270,7 +3280,7 @@ if (!anchored) if ((re->flags & PCRE2_FIRSTCASELESS) != 0) { first_cu2 = TABLE_GET(first_cu, mb->tables + fcc_offset, first_cu); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 if (utf && first_cu > 127) first_cu2 = UCD_OTHERCASE(first_cu); #endif } @@ -3290,7 +3300,7 @@ if ((re->flags & PCRE2_LASTSET) != 0) if ((re->flags & PCRE2_LASTCASELESS) != 0) { req_cu2 = TABLE_GET(req_cu, mb->tables + fcc_offset, req_cu); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 if (utf && req_cu > 127) req_cu2 = UCD_OTHERCASE(req_cu); #endif } @@ -3327,7 +3337,7 @@ for (;;) if (firstline) { PCRE2_SPTR t = start_match; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { while (t < mb->end_subject && !IS_NEWLINE(t)) @@ -3362,7 +3372,7 @@ for (;;) { if (start_match > mb->start_subject + start_offset) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { while (start_match < end_subject && !WAS_NEWLINE(start_match)) @@ -3516,7 +3526,7 @@ for (;;) if (firstline && IS_NEWLINE(start_match)) break; start_match++; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { ACROSSCHAR(start_match < end_subject, *start_match, diff --git a/src/pcre2_error.c b/src/pcre2_error.c index b60841c..20e9a79 100644 --- a/src/pcre2_error.c +++ b/src/pcre2_error.c @@ -198,35 +198,34 @@ static const char match_error_texts[] = "UTF-16 error: isolated low surrogate\0" "UTF-32 error: code points 0xd800-0xdfff are not defined\0" "UTF-32 error: code points greater than 0x10ffff are not defined\0" - "bad count value\0" + "bad data value\0" /* 30 */ - "pattern compiled with other endianness\0" "bad length\0" "magic number missing\0" "pattern compiled in wrong mode: 8/16/32-bit error\0" "bad offset value\0" - /* 35 */ "bad option value\0" + /* 35 */ "bad offset into UTF string\0" "callout error code\0" /* Never returned by PCRE2 itself */ "invalid data in workspace for DFA restart\0" "too much recursion for DFA matching\0" - /* 40 */ "backreference condition or recursion test not supported for DFA matching\0" + /* 40 */ "item unsupported for DFA matching\0" - "match limit not supported for DFA matching\0" "workspace size exceeded in DFA matching\0" "internal error - pattern overwritten?\0" - /* 45 */ "bad JIT option\0" "JIT stack limit reached\0" + /* 45 */ "match limit exceeded\0" "no more memory\0" "unknown or unset substring\0" - /* 50 */ "NULL argument passed\0" "nested recursion at the same subject position\0" + /* 50 */ "recursion limit exceeded\0" + "requested value is not set\0" ; diff --git a/src/pcre2_internal.h b/src/pcre2_internal.h index 759f3d5..576cc0c 100644 --- a/src/pcre2_internal.h +++ b/src/pcre2_internal.h @@ -38,11 +38,11 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ -/* We do not support both EBCDIC and UTF at the same time. The "configure" +/* We do not support both EBCDIC and Unicode at the same time. The "configure" script prevents both being selected, but not everybody uses "configure". */ -#if defined EBCDIC && defined SUPPORT_UTF -#error The use of both EBCDIC and SUPPORT_UTF is not supported. +#if defined EBCDIC && defined SUPPORT_UNICODE +#error The use of both EBCDIC and SUPPORT_UNICODE is not supported. #endif /* Standard C headers */ @@ -597,14 +597,14 @@ there are some longer strings as well. This means that, on EBCDIC platforms, the PCRE library can handle either EBCDIC, or UTF-8, but not both. To support both in the same compiled library -would need different lookups depending on whether PCRE_UTF8 was set or not. +would need different lookups depending on whether PCRE2_UTF was set or not. This would make it impossible to use characters in switch/case statements, which would reduce performance. For a theoretical use (which nobody has asked for) in a minority area (EBCDIC platforms), this is not sensible. Any application that did need both could compile two versions of the library, using macros to give the functions distinct names. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE /* UTF-8 support is not enabled; use the platform-dependent character literals so that PCRE works in both ASCII and EBCDIC environments, but only in non-UTF @@ -920,7 +920,7 @@ a positive value. */ #define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH=" #define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION=" -#else /* SUPPORT_UTF */ +#else /* SUPPORT_UNICODE */ /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode @@ -1189,7 +1189,7 @@ only. */ #define STRING_LIMIT_MATCH_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_M STR_A STR_T STR_C STR_H STR_EQUALS_SIGN #define STRING_LIMIT_RECURSION_EQ STR_L STR_I STR_M STR_I STR_T STR_UNDERSCORE STR_R STR_E STR_C STR_U STR_R STR_S STR_I STR_O STR_N STR_EQUALS_SIGN -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* -------------------- End of character and string names -------------------*/ @@ -1775,10 +1775,10 @@ typedef struct { /* ----------------- Items that need PCRE2_CODE_UNIT_WIDTH ----------------- */ -/* When this file is included by pcre2test, PCRE2_CODE_UNIT_WIDTH is not -defined, so the following items are omitted. */ +/* When this file is included by pcre2test, PCRE2_CODE_UNIT_WIDTH is defined as +0, so the following items are omitted. */ -#ifdef PCRE2_CODE_UNIT_WIDTH +#if defined PCRE2_CODE_UNIT_WIDTH && PCRE2_CODE_UNIT_WIDTH != 0 /* This is the largest non-UTF code point. */ diff --git a/src/pcre2_intmodedep.h b/src/pcre2_intmodedep.h index e656138..d4c4a72 100644 --- a/src/pcre2_intmodedep.h +++ b/src/pcre2_intmodedep.h @@ -208,9 +208,9 @@ tables. */ #if PCRE2_CODE_UNIT_WIDTH == 8 #define MAX_255(c) TRUE #define MAX_MARK ((1u << 8) - 1) -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE #define SUPPORT_WIDE_CHARS -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ #define TABLE_GET(c, table, default) ((table)[c]) #else /* Code units are 16 or 32 bits */ @@ -246,7 +246,7 @@ complicated ones for UTF characters. GETCHARLENTEST and other macros are not used when UTF is not supported. To make sure they can never even appear when UTF support is omitted, we don't even define them. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE /* #define MAX_UTF_SINGLE_CU */ /* #define HAS_EXTRALEN(c) */ @@ -263,7 +263,7 @@ UTF support is omitted, we don't even define them. */ /* #define FORWARDCHAR(eptr) */ /* #define ACROSSCHAR(condition, eptr, action) */ -#else /* SUPPORT_UTF */ +#else /* SUPPORT_UNICODE */ /* ------------------- 8-bit support ------------------ */ @@ -527,7 +527,7 @@ These are all no-ops since all UTF-32 characters fit into one pcre_uchar. */ #define PUTCHAR(c, p) (*p = c, 1) #endif /* UTF-32 character handling */ -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Mode-dependent macros that have the same definition in all modes. */ diff --git a/src/pcre2_match.c b/src/pcre2_match.c index 4754cdf..c5760fe 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -145,7 +145,7 @@ static int match_ref(PCRE2_SIZE offset, PCRE2_SIZE offset_top, register PCRE2_SPTR eptr, match_block *mb, BOOL caseless, PCRE2_SIZE *lengthptr) { -#if defined SUPPORT_UTF +#if defined SUPPORT_UNICODE BOOL utf = (mb->poptions & PCRE2_UTF) != 0; #endif @@ -173,7 +173,7 @@ length = mb->ovector[offset+1] - mb->ovector[offset]; if (caseless) { -#if defined SUPPORT_UTF +#if defined SUPPORT_UNICODE if (utf) { /* Match characters up to the end of the reference. NOTE: the number of @@ -352,7 +352,7 @@ typedef struct heapframe { struct heapframe *Xprevframe; struct heapframe *Xnextframe; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE PCRE2_SPTR Xcharptr; #endif PCRE2_SPTR Xeptr; @@ -378,7 +378,7 @@ typedef struct heapframe { uint32_t Xop; uint32_t Xsave_capture_last; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE uint32_t Xprop_value; int Xprop_type; int Xprop_fail_result; @@ -399,7 +399,7 @@ typedef struct heapframe { eptrblock Xnewptrb; recursion_info Xnew_recursive; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE PCRE2_UCHAR Xocchars[6]; #endif } heapframe; @@ -610,7 +610,7 @@ HEAP_RECURSE: /* Ditto for the local variables */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE #define charptr frame->Xcharptr #define prop_value frame->Xprop_value #define prop_type frame->Xprop_type @@ -666,7 +666,7 @@ declarations can be cut out in a block. The only declarations within blocks below are for variables that do not have to be preserved over a recursive call to RMATCH(). */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE PCRE2_SPTR charptr; #endif PCRE2_SPTR callpat; @@ -684,7 +684,7 @@ uint32_t number; uint32_t op; uint32_t save_capture_last; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE uint32_t prop_value; int prop_type; int prop_fail_result; @@ -721,7 +721,7 @@ the alternative names that are used. */ /* These statements are here to stop the compiler complaining about unitialized variables. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE prop_value = 0; prop_fail_result = 0; #endif @@ -742,7 +742,7 @@ 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_UTF +#ifdef SUPPORT_UNICODE utf = (mb->poptions & PCRE2_UTF) != 0; #else utf = FALSE; @@ -1662,7 +1662,7 @@ for (;;) back a number of characters, not bytes. */ case OP_REVERSE: -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { i = GET(ecode, 1); @@ -2197,7 +2197,7 @@ for (;;) be "non-word" characters. Remember the earliest consulted character for partial matching. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { /* Get status of previous character */ @@ -2257,7 +2257,7 @@ for (;;) if (eptr == mb->start_subject) prev_is_word = FALSE; else { if (eptr <= mb->start_used_ptr) mb->start_used_ptr = eptr - 1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((mb->poptions & PCRE2_UCP) != 0) { c = eptr[-1]; @@ -2283,7 +2283,7 @@ for (;;) else { if (eptr >= mb->last_used_ptr) mb->last_used_ptr = eptr + 1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if ((mb->poptions & PCRE2_UCP) != 0) { c = *eptr; @@ -2334,7 +2334,7 @@ for (;;) RRETURN(MATCH_NOMATCH); } eptr++; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) ACROSSCHAR(eptr < mb->end_subject, *eptr, eptr++); #endif ecode++; @@ -2550,7 +2550,7 @@ for (;;) ecode++; break; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /* Check the next character by Unicode property. We will get here only if the support is in the binary; otherwise a compile-time error occurs. */ @@ -2684,7 +2684,7 @@ for (;;) CHECK_PARTIAL(); ecode++; break; -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Match a back reference, possibly repeatedly. Look past the end of the @@ -2955,7 +2955,7 @@ for (;;) /* First, ensure the minimum number of matches are present. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { for (i = 1; i <= min; i++) @@ -3007,7 +3007,7 @@ for (;;) if (minimize) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { for (fi = min;; fi++) @@ -3063,7 +3063,7 @@ for (;;) { pp = eptr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { for (i = min; i < max; i++) @@ -3232,7 +3232,7 @@ for (;;) SCHECK_PARTIAL(); break; } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE GETCHARLENTEST(c, eptr, len); #else c = *eptr; @@ -3248,7 +3248,7 @@ for (;;) RMATCH(eptr, ecode, offset_top, mb, eptrb, RM21); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) BACKCHAR(eptr); #endif } @@ -3262,7 +3262,7 @@ for (;;) /* Match a single character, casefully */ case OP_CHAR: -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { length = 1; @@ -3299,7 +3299,7 @@ for (;;) RRETURN(MATCH_NOMATCH); } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { length = 1; @@ -3334,7 +3334,7 @@ for (;;) if (fc != dc) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (dc != UCD_OTHERCASE(fc)) #endif RRETURN(MATCH_NOMATCH); @@ -3342,7 +3342,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ { @@ -3436,7 +3436,7 @@ for (;;) for speed. */ REPEATCHAR: -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { length = 1; @@ -3527,7 +3527,7 @@ for (;;) value of fc will always be < 128. */ } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* When not in UTF-8 mode, load a single-byte character. */ fc = *ecode++; @@ -3547,11 +3547,11 @@ for (;;) /* fc must be < 128 if UTF is enabled. */ foc = mb->fcc[fc]; #else -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && fc > 127) foc = UCD_OTHERCASE(fc); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ foc = TABLE_GET(fc, mb->fcc, fc); #endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ @@ -3682,7 +3682,7 @@ for (;;) SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t ch, och; @@ -3705,7 +3705,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ { register uint32_t ch = ecode[1]; c = *eptr++; @@ -3803,14 +3803,14 @@ for (;;) if (op >= OP_NOTSTARI) /* Caseless */ { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && fc > 127) foc = UCD_OTHERCASE(fc); else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ foc = TABLE_GET(fc, mb->fcc, fc); -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -3826,7 +3826,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ { for (i = 1; i <= min; i++) @@ -3845,7 +3845,7 @@ for (;;) if (minimize) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -3864,7 +3864,7 @@ for (;;) } } else -#endif /*SUPPORT_UTF */ +#endif /*SUPPORT_UNICODE */ /* Not UTF mode */ { for (fi = min;; fi++) @@ -3890,7 +3890,7 @@ for (;;) { pp = eptr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -3917,7 +3917,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ { for (i = min; i < max; i++) @@ -3947,7 +3947,7 @@ for (;;) else { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -3981,7 +3981,7 @@ for (;;) if (minimize) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -4025,7 +4025,7 @@ for (;;) { pp = eptr; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { register uint32_t d; @@ -4144,7 +4144,7 @@ for (;;) REPEATTYPE: ctype = *ecode++; /* Code for the character type */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (ctype == OP_PROP || ctype == OP_NOTPROP) { prop_fail_result = ctype == OP_NOTPROP; @@ -4162,7 +4162,7 @@ for (;;) if (min > 0) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (prop_type >= 0) { switch(prop_type) @@ -4378,11 +4378,11 @@ for (;;) } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Handle all other cases when the coding is UTF-8 */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) switch(ctype) { case OP_ANY: @@ -4631,7 +4631,7 @@ for (;;) } /* End switch(ctype) */ else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Code for the non-UTF-8 case for minimum matching of operators other than OP_PROP and OP_NOTPROP. */ @@ -4889,7 +4889,7 @@ for (;;) if (minimize) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (prop_type >= 0) { switch(prop_type) @@ -5138,9 +5138,9 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { for (fi = min;; fi++) @@ -5410,7 +5410,7 @@ for (;;) { pp = eptr; /* Remember where we started */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (prop_type >= 0) { switch(prop_type) @@ -5696,9 +5696,9 @@ for (;;) } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { switch(ctype) @@ -5940,7 +5940,7 @@ for (;;) } } else -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Not UTF mode */ { switch(ctype) @@ -6219,13 +6219,13 @@ switch (frame->Xwhere) #ifdef SUPPORT_WIDE_CHARS LBL(20) LBL(21) #endif -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE LBL(16) LBL(18) LBL(22) LBL(23) LBL(28) LBL(30) LBL(32) LBL(34) LBL(42) LBL(46) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) LBL(59) LBL(60) LBL(61) LBL(62) LBL(67) -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ default: return PCRE2_ERROR_INTERNAL; } @@ -6398,14 +6398,21 @@ if (code == NULL || subject == NULL || match_data == NULL) return PCRE2_ERROR_NULL; if (start_offset > length) return PCRE2_ERROR_BADOFFSET; -/* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. However, if the magic number is equal to -REVERSED_MAGIC_NUMBER we return with PCRE2_ERROR_BADENDIANNESS, which -means that the pattern is likely compiled with different endianness. */ +/* Check that the first field in the block is the magic number. */ + +if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; + +#ifdef FIXME +If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add +this comment and code: + +/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return +with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled +with different endianness. */ -if (re->magic_number != MAGIC_NUMBER) return re->magic_number == REVERSED_MAGIC_NUMBER? PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC; +#endif /* Check the code unit width. */ @@ -6451,7 +6458,7 @@ mb->partial = ((options & PCRE2_PARTIAL_HARD) != 0)? 2 : we must also check that a starting offset does not point into the middle of a multiunit character. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) { match_data->rc = PRIV(valid_utf)(subject, length, &(match_data->rightchar)); @@ -6466,7 +6473,7 @@ if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) return PCRE2_ERROR_BADUTFOFFSET; #endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* If the pattern was successfully studied with JIT support, run the JIT executable instead of the rest of this function. Most options must be set at @@ -6539,7 +6546,7 @@ mb->match_limit = (mcontext->match_limit < re->limit_match)? mcontext->match_limit : re->limit_match; mb->match_limit_recursion = (mcontext->recursion_limit < re->limit_recursion)? mcontext->recursion_limit : re->limit_recursion; - + /* Pointers to the individual character tables */ mb->lcc = re->tables + lcc_offset; @@ -6640,7 +6647,7 @@ if (!anchored) if ((re->flags & PCRE2_FIRSTCASELESS) != 0) { first_cu2 = TABLE_GET(first_cu, mb->fcc, first_cu); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 if (utf && first_cu > 127) first_cu2 = UCD_OTHERCASE(first_cu); #endif } @@ -6660,7 +6667,7 @@ if ((re->flags & PCRE2_LASTSET) != 0) if ((re->flags & PCRE2_LASTCASELESS) != 0) { req_cu2 = TABLE_GET(req_cu, mb->fcc, req_cu); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH != 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 if (utf && req_cu > 127) req_cu2 = UCD_OTHERCASE(req_cu); #endif } @@ -6696,7 +6703,7 @@ for(;;) if (firstline) { PCRE2_SPTR t = start_match; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { while (t < mb->end_subject && !IS_NEWLINE(t)) @@ -6731,7 +6738,7 @@ for(;;) { if (start_match > mb->start_subject + start_offset) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { while (start_match < end_subject && !WAS_NEWLINE(start_match)) @@ -6905,7 +6912,7 @@ for(;;) case MATCH_THEN: mb->ignore_skip_arg = 0; new_start_match = start_match + 1; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) ACROSSCHAR(new_start_match < end_subject, *new_start_match, new_start_match++); diff --git a/src/pcre2_newline.c b/src/pcre2_newline.c index 0b08c99..c3d6298 100644 --- a/src/pcre2_newline.c +++ b/src/pcre2_newline.c @@ -81,12 +81,12 @@ PRIV(is_newline)(PCRE2_SPTR ptr, uint32_t type, PCRE2_SPTR endptr, { uint32_t c; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { GETCHAR(c, ptr); } else c = *ptr; #else (void)utf; c = *ptr; -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ if (type == NLTYPE_ANYCRLF) switch(c) { @@ -172,7 +172,7 @@ PRIV(was_newline)(PCRE2_SPTR ptr, uint32_t type, PCRE2_SPTR startptr, uint32_t c; ptr--; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { BACKCHAR(ptr); @@ -182,7 +182,7 @@ else c = *ptr; #else (void)utf; c = *ptr; -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ if (type == NLTYPE_ANYCRLF) switch(c) { diff --git a/src/pcre2_ord2utf.c b/src/pcre2_ord2utf.c index 1dc5b14..d268e94 100644 --- a/src/pcre2_ord2utf.c +++ b/src/pcre2_ord2utf.c @@ -50,10 +50,11 @@ into a UTF string. The behaviour is different for each code unit width. */ #include "pcre2_internal.h" -/* If SUPPORT_UTF is not defined, this function will never be called. Supply a -dummy function because some compilers do not like empty source modules. */ +/* If SUPPORT_UNICODE is not defined, this function will never be called. +Supply a dummy function because some compilers do not like empty source +modules. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE unsigned int PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer) { @@ -61,7 +62,7 @@ PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer) (void)(buffer); return 0; } -#else /* SUPPORT_UTF */ +#else /* SUPPORT_UNICODE */ /************************************************* @@ -114,6 +115,6 @@ return 2; return 1; #endif } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* End of pcre_ord2utf.c */ diff --git a/src/pcre2_pattern_info.c b/src/pcre2_pattern_info.c index 93d7dcd..0fe58bb 100644 --- a/src/pcre2_pattern_info.c +++ b/src/pcre2_pattern_info.c @@ -56,11 +56,9 @@ Arguments: what what information is required where where to put the information -Returns: 0 if data returned, negative on error +Returns: 0 if data returned, negative on error or unset value */ -/* FIXME: Remove BADENDIANNESS if saving/restoring is not to be implemented. */ - PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_pattern_info(const pcre2_code *code, uint32_t what, void *where) { @@ -69,13 +67,21 @@ const pcre2_real_code *re = (pcre2_real_code *)code; if (re == NULL || where == NULL) return PCRE2_ERROR_NULL; /* Check that the first field in the block is the magic number. If it is not, -return with PCRE2_ERROR_BADMAGIC. However, if the magic number is equal to -REVERSED_MAGIC_NUMBER we return with PCRE2_ERROR_BADENDIANNESS, which -means that the pattern is likely compiled with different endianness. */ +return with PCRE2_ERROR_BADMAGIC. */ + +if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; + +#ifdef FIXME +If saving restoring gets implemented, define PCRE2_ERROR_BADENDIANNESS, and add +this comment and code: + +/* However, if the magic number is equal to REVERSED_MAGIC_NUMBER we return +with PCRE2_ERROR_BADENDIANNESS, which means that the pattern is likely compiled +with different endianness. */ -if (re->magic_number != MAGIC_NUMBER) return re->magic_number == REVERSED_MAGIC_NUMBER? PCRE2_ERROR_BADENDIANNESS:PCRE2_ERROR_BADMAGIC; +#endif /* Check that this pattern was compiled in the correct bit mode */ @@ -151,6 +157,7 @@ switch(what) case PCRE2_INFO_MATCHLIMIT: *((uint32_t *)where) = re->limit_match; + if (re->limit_match == UINT32_MAX) return PCRE2_ERROR_UNSET; break; case PCRE2_INFO_MAXLOOKBEHIND: @@ -179,6 +186,7 @@ switch(what) case PCRE2_INFO_RECURSIONLIMIT: *((uint32_t *)where) = re->limit_recursion; + if (re->limit_recursion == UINT32_MAX) return PCRE2_ERROR_UNSET; break; case PCRE2_INFO_SIZE: diff --git a/src/pcre2_printint.c b/src/pcre2_printint.c index 3067b38..0ad7dbf 100644 --- a/src/pcre2_printint.c +++ b/src/pcre2_printint.c @@ -94,7 +94,7 @@ BOOL one_code_unit = !utf; /* If UTF is supported and requested, check for a valid single code unit. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { #if PCRE2_CODE_UNIT_WIDTH == 8 @@ -105,7 +105,7 @@ if (utf) one_code_unit = (c & 0xfffff800u) != 0xd800u; #endif /* CODE_UNIT_WIDTH */ } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* Handle a valid one-code-unit character at any width. */ @@ -121,7 +121,7 @@ if (one_code_unit) for each width. If UTF is not supported, control should never get here, but we need a return statement to keep the compiler happy. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE return 0; #else @@ -178,7 +178,7 @@ as an indication. */ fprintf(f, "\\X{%x}", c); return 0; #endif /* PCRE2_CODE_UNIT_WIDTH == 32 */ -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ } @@ -221,7 +221,7 @@ into the main code, however, we just put one into this function. */ static const char * get_ucpname(unsigned int ptype, unsigned int pvalue) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE int i; for (i = utt_size - 1; i >= 0; i--) { @@ -233,7 +233,7 @@ return (i >= 0)? utt_names + utt[i].name_offset : "??"; (void)ptype; (void)pvalue; return "??"; -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ } diff --git a/src/pcre2_study.c b/src/pcre2_study.c index 8bd18b4..2e673c3 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c @@ -228,7 +228,7 @@ for (;;) case OP_NOTPOSPLUSI: branchlength++; cc += 2; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); #endif break; @@ -249,7 +249,7 @@ for (;;) case OP_NOTEXACTI: branchlength += GET2(cc,1); cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); #endif break; @@ -297,7 +297,7 @@ for (;;) appear, but leave the code, just in case.) */ case OP_ANYBYTE: -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) return -1; #endif branchlength++; @@ -536,7 +536,7 @@ for (;;) case OP_NOTPOSQUERYI: cc += PRIV(OP_lengths)[op]; -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); #endif break; @@ -608,7 +608,7 @@ SET_BIT(c); /* In UTF-8 or UTF-16 mode, pick up the remaining code units in order to find the end of the character, even when caseless. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { #if PCRE2_CODE_UNIT_WIDTH == 8 @@ -617,7 +617,7 @@ if (utf) if ((c & 0xfc00) == 0xd800) GETUTF16INC(c, p); #endif } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* If caseless, handle the other case of the character. */ @@ -671,7 +671,7 @@ set_type_bits(pcre2_real_code *re, int cbit_type, unsigned int table_limit) register uint32_t c; for (c = 0; c < table_limit; c++) re->start_bitmap[c] |= re->tables[c+cbits_offset+cbit_type]; -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 if (table_limit == 32) return; for (c = 128; c < 256; c++) { @@ -712,7 +712,7 @@ set_nottype_bits(pcre2_real_code *re, int cbit_type, unsigned int table_limit) register uint32_t c; for (c = 0; c < table_limit; c++) re->start_bitmap[c] |= ~(re->tables[c+cbits_offset+cbit_type]); -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 if (table_limit != 32) for (c = 24; c < 32; c++) re->start_bitmap[c] = 0xff; #endif } @@ -752,7 +752,7 @@ set_start_bits(pcre2_real_code *re, PCRE2_SPTR code, BOOL utf) register uint32_t c; int yield = SSB_DONE; -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 int table_limit = utf? 16:32; #else int table_limit = 32; @@ -866,7 +866,7 @@ do const uint32_t *p = PRIV(ucd_caseless_sets) + tcode[2]; while ((c = *p++) < NOTACHAR) { -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 if (utf) { PCRE2_UCHAR buff[6]; @@ -1042,7 +1042,7 @@ do /* For the 8-bit library in UTF-8 mode, set the bits for the first code units of horizontal space characters. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { SET_BIT(0xC2); /* For U+00A0 */ @@ -1081,7 +1081,7 @@ do /* For the 8-bit library in UTF-8 mode, set the bits for the first code units of vertical space characters. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { SET_BIT(0xC2); /* For U+0085 (NEL) */ @@ -1181,7 +1181,7 @@ do /* For the 8-bit library in UTF-8 mode, set the bits for the first code units of horizontal space characters. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { SET_BIT(0xC2); /* For U+00A0 */ @@ -1218,7 +1218,7 @@ do /* For the 8-bit library in UTF-8 mode, set the bits for the first code units of vertical space characters. */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { SET_BIT(0xC2); /* For U+0085 (NEL) */ @@ -1287,7 +1287,7 @@ do character modes, set the 0xFF bit to indicate code units >= 255. */ case OP_NCLASS: -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 if (utf) { re->start_bitmap[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ @@ -1318,7 +1318,7 @@ do if (classmap != NULL) { -#if defined SUPPORT_UTF && PCRE2_CODE_UNIT_WIDTH == 8 +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 if (utf) { for (c = 0; c < 16; c++) re->start_bitmap[c] |= classmap[c]; diff --git a/src/pcre2_substring.c b/src/pcre2_substring.c index bbaf47e..9e737e6 100644 --- a/src/pcre2_substring.c +++ b/src/pcre2_substring.c @@ -108,8 +108,8 @@ Returns: if successful: 0 */ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_copy_bynumber(pcre2_match_data *match_data, int stringnumber, - PCRE2_UCHAR *buffer, PCRE2_SIZE *sizeptr) +pcre2_substring_copy_bynumber(pcre2_match_data *match_data, + unsigned int stringnumber, PCRE2_UCHAR *buffer, PCRE2_SIZE *sizeptr) { PCRE2_SIZE left, right; PCRE2_SIZE p = 0; @@ -189,8 +189,8 @@ Returns: if successful: zero */ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_substring_get_bynumber(pcre2_match_data *match_data, int stringnumber, - PCRE2_UCHAR **stringptr, PCRE2_SIZE *sizeptr) +pcre2_substring_get_bynumber(pcre2_match_data *match_data, + unsigned int stringnumber, PCRE2_UCHAR **stringptr, PCRE2_SIZE *sizeptr) { PCRE2_SIZE left, right; PCRE2_SIZE p = 0; @@ -288,7 +288,7 @@ Returns: 0 if successful, else a negative error number PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_substring_length_bynumber(pcre2_match_data *match_data, - int stringnumber, PCRE2_SIZE *sizeptr) + unsigned int stringnumber, PCRE2_SIZE *sizeptr) { if (stringnumber >= match_data->oveccount || stringnumber > match_data->code->top_bracket || diff --git a/src/pcre2_tables.c b/src/pcre2_tables.c index d9ed1d1..af1c7f0 100644 --- a/src/pcre2_tables.c +++ b/src/pcre2_tables.c @@ -76,7 +76,7 @@ as for the library in 8-bit mode, because pcre2test uses UTF-8 internally for handling wide characters. */ #if defined PCRE2_PCRE2TEST || \ - (defined SUPPORT_UTF && \ + (defined SUPPORT_UNICODE && \ defined PCRE2_CODE_UNIT_WIDTH && \ PCRE2_CODE_UNIT_WIDTH == 8) @@ -106,7 +106,7 @@ const uint8_t PRIV(utf8_table4)[] = { #endif /* UTF-8 support needed */ -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE /* Table to translate from particular type value to the general value. */ @@ -728,6 +728,6 @@ const ucp_type_table PRIV(utt)[] = { const size_t PRIV(utt_size) = sizeof(PRIV(utt)) / sizeof(ucp_type_table); -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* End of pcre2_tables.c */ diff --git a/src/pcre2_ucd.c b/src/pcre2_ucd.c index 11b6fb5..7199cbd 100644 --- a/src/pcre2_ucd.c +++ b/src/pcre2_ucd.c @@ -32,7 +32,7 @@ condition to cut out the tables when not needed. But don't leave a totally empty module because some compilers barf at that. Instead, just supply small dummy tables. */ -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE const ucd_record PRIV(ucd_records)[] = {{0,0,0,0,0 }}; const uint8_t PRIV(ucd_stage1)[] = {0}; const uint16_t PRIV(ucd_stage2)[] = {0}; @@ -3628,6 +3628,6 @@ const uint16_t PRIV(ucd_stage2)[] = { /* 58112 bytes, block = 128 */ #if UCD_BLOCK_SIZE != 128 #error Please correct UCD_BLOCK_SIZE in pcre2_internal.h #endif -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ #endif /* PCRE2_PCRE2TEST */ diff --git a/src/pcre2_valid_utf.c b/src/pcre2_valid_utf.c index d7c22ca..267dc66 100644 --- a/src/pcre2_valid_utf.c +++ b/src/pcre2_valid_utf.c @@ -50,12 +50,12 @@ strings. */ #include "pcre2_internal.h" -#ifndef SUPPORT_UTF +#ifndef SUPPORT_UNICODE /************************************************* -* Dummy function when UTF not supported * +* Dummy function when Unicode is not supported * *************************************************/ -/* This function should never be called when UTF is not supported. */ +/* This function should never be called when Unicode is not supported. */ int PRIV(valid_utf)(PCRE2_SPTR string, PCRE2_SIZE length, PCRE2_SIZE *erroroffset) @@ -388,6 +388,6 @@ for (p = string; length-- > 0; p++) return 0; #endif /* CODE_UNIT_WIDTH */ } -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ /* End of pcre2_valid_utf.c */ diff --git a/src/pcre2_xclass.c b/src/pcre2_xclass.c index 9f29b92..2deb428 100644 --- a/src/pcre2_xclass.c +++ b/src/pcre2_xclass.c @@ -103,7 +103,7 @@ while ((t = *data++) != XCL_END) uint32_t x, y; if (t == XCL_SINGLE) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { GETCHARINC(x, data); /* macro generates multiple statements */ @@ -115,7 +115,7 @@ while ((t = *data++) != XCL_END) } else if (t == XCL_RANGE) { -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE if (utf) { GETCHARINC(x, data); /* macro generates multiple statements */ @@ -130,7 +130,7 @@ while ((t = *data++) != XCL_END) if (c >= x && c <= y) return !negated; } -#ifdef SUPPORT_UTF +#ifdef SUPPORT_UNICODE else /* XCL_PROP & XCL_NOTPROP */ { const ucd_record *prop = GET_UCD(c); @@ -262,7 +262,7 @@ while ((t = *data++) != XCL_END) } #else (void)utf; /* Avoid compiler warning */ -#endif /* SUPPORT_UTF */ +#endif /* SUPPORT_UNICODE */ } return negated; /* char did not match */ diff --git a/src/pcre2test.c b/src/pcre2test.c index 954407a..3cd3438 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -196,6 +196,7 @@ so that the PCRE2_EXP_xxx macros get set appropriately for an application, not for building the library. */ #define PRIV(name) name +#define PCRE2_CODE_UNIT_WIDTH 0 #include "pcre2.h" #include "pcre2posix.h" #include "pcre2_internal.h" @@ -208,16 +209,17 @@ of PRIV avoids name clashes. */ #include "pcre2_tables.c" #include "pcre2_ucd.c" -/* When PCRE2_CODE_UNIT_WIDTH is unset, pcre2_internal.h does not include +/* When PCRE2_CODE_UNIT_WIDTH is zero, pcre2_internal.h does not include pcre2_intmodedep.h, which is where mode-dependent macros and structures are defined. We can now include it for each supported code unit width. Because -PCRE2_CODE_UNIT_WIDTH was not defined before including pcre2.h, it will have -left PCRE2_SUFFIX defined as a no-op. We must re-define it appropriately while -including these files, and then restore it to a no-op. Because LINK_SIZE may be -changed in 16-bit mode and forced to 1 in 32-bit mode, the order of these -inclusions should not be changed. */ +PCRE2_CODE_UNIT_WIDTH was defined as zero before including pcre2.h, it will +have left PCRE2_SUFFIX defined as a no-op. We must re-define it appropriately +while including these files, and then restore it to a no-op. Because LINK_SIZE +may be changed in 16-bit mode and forced to 1 in 32-bit mode, the order of +these inclusions should not be changed. */ #undef PCRE2_SUFFIX +#undef PCRE2_CODE_UNIT_WIDTH #ifdef SUPPORT_PCRE8 #define PCRE2_CODE_UNIT_WIDTH 8 @@ -576,7 +578,7 @@ static coptstruct coptlist[] = { { "pcre16", CONF_FIX, SUPPORT_16 }, { "pcre32", CONF_FIX, SUPPORT_32 }, { "pcre8", CONF_FIX, SUPPORT_8 }, - { "utf", CONF_INT, PCRE2_CONFIG_UTF } + { "unicode", CONF_INT, PCRE2_CONFIG_UNICODE } }; #define COPTLISTCOUNT sizeof(coptlist)/sizeof(coptstruct) @@ -2815,22 +2817,26 @@ pattern. Arguments: what code for the required information where where to put the answer + unsetok PCRE2_ERROR_UNSET is an "expected" result Returns: the return from pcre2_pattern_info() */ static int -pattern_info(int what, void *where) +pattern_info(int what, void *where, BOOL unsetok) { int rc; PCRE2_PATTERN_INFO(rc, compiled_code, what, where); if (rc >= 0) return 0; -fprintf(outfile, "Error %d from pcre2_pattern_info_%d(%d)\n", rc, test_mode, - what); -if (rc == PCRE2_ERROR_BADMODE) - fprintf(outfile, "Running in %d-bit mode but pattern was compiled in " - "%d-bit mode\n", test_mode, - 8 * (FLD(compiled_code, flags) & PCRE2_MODE_MASK)); +if (rc != PCRE2_ERROR_UNSET || !unsetok) + { + fprintf(outfile, "Error %d from pcre2_pattern_info_%d(%d)\n", rc, test_mode, + what); + if (rc == PCRE2_ERROR_BADMODE) + fprintf(outfile, "Running in %d-bit mode but pattern was compiled in " + "%d-bit mode\n", test_mode, + 8 * (FLD(compiled_code, flags) & PCRE2_MODE_MASK)); + } return rc; } @@ -3026,32 +3032,61 @@ if ((pat_patctl.control & CTL_INFO) != 0) { const void *nametable; const uint8_t *start_bits; + BOOL match_limit_set, recursion_limit_set; uint32_t backrefmax, bsr_convention, capture_count, first_ctype, first_cunit, hascrorlf, jchanged, last_ctype, last_cunit, match_empty, match_limit, maxlookbehind, minlength, nameentrysize, namecount, newline_convention, recursion_limit; + + /* These info requests may return PCRE2_ERROR_UNSET. */ + + switch(pattern_info(PCRE2_INFO_MATCHLIMIT, &match_limit, TRUE)) + { + case 0: + match_limit_set = TRUE; + break; + + case PCRE2_ERROR_UNSET: + match_limit_set = FALSE; + break; + + default: + return PR_ABEND; + } + + switch(pattern_info(PCRE2_INFO_RECURSIONLIMIT, &recursion_limit, TRUE)) + { + case 0: + recursion_limit_set = TRUE; + break; + + case PCRE2_ERROR_UNSET: + recursion_limit_set = FALSE; + break; + + default: + return PR_ABEND; + } /* These info requests should always succeed. */ - if (pattern_info(PCRE2_INFO_BACKREFMAX, &backrefmax) + - pattern_info(PCRE2_INFO_BSR, &bsr_convention) + - pattern_info(PCRE2_INFO_CAPTURECOUNT, &capture_count) + - pattern_info(PCRE2_INFO_FIRSTBITMAP, &start_bits) + - pattern_info(PCRE2_INFO_FIRSTCODEUNIT, &first_cunit) + - pattern_info(PCRE2_INFO_FIRSTCODETYPE, &first_ctype) + - pattern_info(PCRE2_INFO_HASCRORLF, &hascrorlf) + - pattern_info(PCRE2_INFO_JCHANGED, &jchanged) + - pattern_info(PCRE2_INFO_LASTCODEUNIT, &last_cunit) + - pattern_info(PCRE2_INFO_LASTCODETYPE, &last_ctype) + - pattern_info(PCRE2_INFO_MATCHEMPTY, &match_empty) + - pattern_info(PCRE2_INFO_MATCHLIMIT, &match_limit) + - pattern_info(PCRE2_INFO_MAXLOOKBEHIND, &maxlookbehind) + - pattern_info(PCRE2_INFO_MINLENGTH, &minlength) + - pattern_info(PCRE2_INFO_NAMECOUNT, &namecount) + - pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &nameentrysize) + - pattern_info(PCRE2_INFO_NAMETABLE, &nametable) + - pattern_info(PCRE2_INFO_NEWLINE, &newline_convention) + - pattern_info(PCRE2_INFO_RECURSIONLIMIT, &recursion_limit) + if (pattern_info(PCRE2_INFO_BACKREFMAX, &backrefmax, FALSE) + + pattern_info(PCRE2_INFO_BSR, &bsr_convention, FALSE) + + pattern_info(PCRE2_INFO_CAPTURECOUNT, &capture_count, FALSE) + + pattern_info(PCRE2_INFO_FIRSTBITMAP, &start_bits, FALSE) + + pattern_info(PCRE2_INFO_FIRSTCODEUNIT, &first_cunit, FALSE) + + pattern_info(PCRE2_INFO_FIRSTCODETYPE, &first_ctype, FALSE) + + pattern_info(PCRE2_INFO_HASCRORLF, &hascrorlf, FALSE) + + pattern_info(PCRE2_INFO_JCHANGED, &jchanged, FALSE) + + pattern_info(PCRE2_INFO_LASTCODEUNIT, &last_cunit, FALSE) + + pattern_info(PCRE2_INFO_LASTCODETYPE, &last_ctype, FALSE) + + pattern_info(PCRE2_INFO_MATCHEMPTY, &match_empty, FALSE) + + pattern_info(PCRE2_INFO_MAXLOOKBEHIND, &maxlookbehind, FALSE) + + pattern_info(PCRE2_INFO_MINLENGTH, &minlength, FALSE) + + pattern_info(PCRE2_INFO_NAMECOUNT, &namecount, FALSE) + + pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &nameentrysize, FALSE) + + pattern_info(PCRE2_INFO_NAMETABLE, &nametable, FALSE) + + pattern_info(PCRE2_INFO_NEWLINE, &newline_convention, FALSE) != 0) return PR_ABEND; @@ -3062,11 +3097,11 @@ if ((pat_patctl.control & CTL_INFO) != 0) if (maxlookbehind > 0) fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind); - - if (match_limit != UINT32_MAX) + + if (match_limit_set) fprintf(outfile, "Match limit = %u\n", match_limit); - if (recursion_limit != UINT32_MAX) + if (recursion_limit_set) fprintf(outfile, "Recursion limit = %u\n", recursion_limit); if (namecount > 0) @@ -3099,8 +3134,8 @@ if ((pat_patctl.control & CTL_INFO) != 0) if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n"); if (match_empty) fprintf(outfile, "May match empty string\n"); - pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options); - pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options); + pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options, FALSE); + pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options, FALSE); /* Remove UTF/UCP if they were there only because of forbid_utf. This saves cluttering up the verification output of non-UTF test files. */ @@ -3234,7 +3269,7 @@ if ((pat_patctl.control & CTL_INFO) != 0) if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0) { size_t jitsize; - if (pattern_info(PCRE2_INFO_JITSIZE, &jitsize) == 0) + if (pattern_info(PCRE2_INFO_JITSIZE, &jitsize, FALSE) == 0) { if (jitsize > 0) fprintf(outfile, "JIT compilation was successful\n"); @@ -3625,14 +3660,14 @@ if ((pat_patctl.control & CTL_MEMORY) != 0) if (test_mode == 32) cblock_size = sizeof(pcre2_real_code_32); #endif - (void)pattern_info(PCRE2_INFO_SIZE, &size); - (void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count); - (void)pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size); + (void)pattern_info(PCRE2_INFO_SIZE, &size, FALSE); + (void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count, FALSE); + (void)pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size, FALSE); fprintf(outfile, "Memory allocation (code space): %d\n", (int)(size - name_count*name_entry_size*code_unit_size - cblock_size)); if (pat_patctl.jit != 0) { - (void)pattern_info(PCRE2_INFO_JITSIZE, &size); + (void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE); fprintf(outfile, "Memory allocation (JIT code): %d\n", (int)size); } } @@ -4452,7 +4487,7 @@ for (gmatched = 0;; gmatched++) if ((dat_datctl.control & CTL_ALLCAPTURES) != 0) { uint32_t maxcapcount; - if (pattern_info(PCRE2_INFO_CAPTURECOUNT, &maxcapcount) < 0) + if (pattern_info(PCRE2_INFO_CAPTURECOUNT, &maxcapcount, FALSE) < 0) return PR_SKIP; capcount = maxcapcount + 1; /* Allow for full match */ if (capcount > (int)dat_datctl.oveccount) capcount = dat_datctl.oveccount; @@ -4943,7 +4978,7 @@ printf(" newline newline type [CR, LF, CRLF, ANYCRLF, ANY]\n"); printf(" pcre8 8 bit library support enabled [0, 1]\n"); printf(" pcre16 16 bit library support enabled [0, 1]\n"); printf(" pcre32 32 bit library support enabled [0, 1]\n"); -printf(" utf Unicode Transformation Format supported [0, 1]\n"); +printf(" unicode Unicode and UTF support enabled [0, 1]\n"); printf(" -d set default pattern control 'debug'\n"); printf(" -dfa set default subject control 'dfa'\n"); printf(" -help show usage information\n"); @@ -5057,7 +5092,7 @@ printf(" 16-bit support\n"); printf(" 32-bit support\n"); #endif -(void)PCRE2_CONFIG(PCRE2_CONFIG_UTF, &rc, sizeof(rc)); +(void)PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, &rc, sizeof(rc)); if (rc != 0) printf(" UTF support (Unicode version %s)\n", uversion); else diff --git a/testdata/grepoutput b/testdata/grepoutput index b69ce03..f8b029f 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -384,15 +384,15 @@ aaaaa2 010203040506 RC=0 ======== STDERR ======== -pcre2grep: pcre2_match() gave error -47 while matching this text: +pcre2grep: pcre2_match() gave error -45 while matching this text: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -pcre2grep: pcre2_match() gave error -47 while matching this text: +pcre2grep: pcre2_match() gave error -45 while matching this text: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -pcre2grep: Error -46, -47 or -52 means that a resource limit was exceeded. +pcre2grep: Error -44, -45 or -50 means that a resource limit was exceeded. pcre2grep: Check your regex for nested unlimited loops. ---------------------------- Test 38 ------------------------------ This line contains a binary zero here >< for testing. @@ -510,23 +510,23 @@ In the middle of a line, PATTERN appears. Check up on PATTERN near the end. RC=0 ---------------------------- Test 62 ----------------------------- -pcre2grep: pcre2_match() gave error -47 while matching text that starts: +pcre2grep: pcre2_match() gave error -45 while matching text that starts: This is a file of miscellaneous text that is used as test data for checking that the pcregrep command is working correctly. The file must be more than 24K long so that it needs more than a single read -pcre2grep: Error -46, -47 or -52 means that a resource limit was exceeded. +pcre2grep: Error -44, -45 or -50 means that a resource limit was exceeded. pcre2grep: Check your regex for nested unlimited loops. RC=1 ---------------------------- Test 63 ----------------------------- -pcre2grep: pcre2_match() gave error -52 while matching text that starts: +pcre2grep: pcre2_match() gave error -50 while matching text that starts: This is a file of miscellaneous text that is used as test data for checking that the pcregrep command is working correctly. The file must be more than 24K long so that it needs more than a single read -pcre2grep: Error -46, -47 or -52 means that a resource limit was exceeded. +pcre2grep: Error -44, -45 or -50 means that a resource limit was exceeded. pcre2grep: Check your regex for nested unlimited loops. RC=1 ---------------------------- Test 64 ------------------------------ diff --git a/testdata/testoutput10 b/testdata/testoutput10 index b1b5419..cc757d8 100644 --- a/testdata/testoutput10 +++ b/testdata/testoutput10 @@ -888,7 +888,7 @@ Subject length lower bound = 3 a\x{123}aa\=offset=1 0: aa a\x{123}aa\=offset=2 -Error -36 (bad UTF-8 offset) +Error -35 (bad UTF-8 offset) a\x{123}aa\=offset=3 0: aa a\x{123}aa\=offset=4 @@ -896,7 +896,7 @@ Error -36 (bad UTF-8 offset) a\x{123}aa\=offset=5 No match a\x{123}aa\=offset=6 -Failed: error -34: bad offset value +Failed: error -33: bad offset value /\x{1234}+/Ii,utf Capturing subpattern count = 0 diff --git a/testdata/testoutput12-16 b/testdata/testoutput12-16 index f1ed11f..e18fa83 100644 --- a/testdata/testoutput12-16 +++ b/testdata/testoutput12-16 @@ -787,9 +787,9 @@ Subject length lower bound = 3 a\x{123}aa\=offset=4 No match a\x{123}aa\=offset=5 -Failed: error -34: bad offset value +Failed: error -33: bad offset value a\x{123}aa\=offset=6 -Failed: error -34: bad offset value +Failed: error -33: bad offset value /\x{1234}+/Ii,utf Capturing subpattern count = 0 @@ -851,9 +851,9 @@ Subject length lower bound = 1 /a/utf \x{10000}\=offset=1 -Error -36 (bad UTF-16 offset) +Error -35 (bad UTF-16 offset) \x{10000}ab\=offset=1 -Error -36 (bad UTF-16 offset) +Error -35 (bad UTF-16 offset) \x{10000}ab\=offset=2 0: a \x{10000}ab\=offset=3 @@ -861,7 +861,7 @@ No match \x{10000}ab\=offset=4 No match \x{10000}ab\=offset=5 -Failed: error -34: bad offset value +Failed: error -33: bad offset value /νΌ€/utf Failed: error -26 at offset 0: UTF-16 error: isolated low surrogate diff --git a/testdata/testoutput12-32 b/testdata/testoutput12-32 index 1e39d8b..62fd49e 100644 --- a/testdata/testoutput12-32 +++ b/testdata/testoutput12-32 @@ -779,9 +779,9 @@ Subject length lower bound = 3 a\x{123}aa\=offset=4 No match a\x{123}aa\=offset=5 -Failed: error -34: bad offset value +Failed: error -33: bad offset value a\x{123}aa\=offset=6 -Failed: error -34: bad offset value +Failed: error -33: bad offset value /\x{1234}+/Ii,utf Capturing subpattern count = 0 @@ -851,9 +851,9 @@ No match \x{10000}ab\=offset=3 No match \x{10000}ab\=offset=4 -Failed: error -34: bad offset value +Failed: error -33: bad offset value \x{10000}ab\=offset=5 -Failed: error -34: bad offset value +Failed: error -33: bad offset value /νΌ€/utf Failed: error -27 at offset 0: UTF-32 error: code points 0xd800-0xdfff are not defined diff --git a/testdata/testoutput2 b/testdata/testoutput2 index f913a35..8ab27aa 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -986,7 +986,7 @@ Subject length lower bound = 4 0: abcd 1: a 2: d -copy substring 5 failed (-49): unknown or unset substring +copy substring 5 failed (-47): unknown or unset substring /(.{20})/I Capturing subpattern count = 1 @@ -1040,9 +1040,9 @@ Subject length lower bound = 4 2: 3: f 1G a (1) -get substring 2 failed (-49): unknown or unset substring +get substring 2 failed (-47): unknown or unset substring 3G f (1) -get substring 4 failed (-49): unknown or unset substring +get substring 4 failed (-47): unknown or unset substring 0L adef 1L a 2L @@ -1055,7 +1055,7 @@ get substring 4 failed (-49): unknown or unset substring 1G bc (2) 2G bc (2) 3G f (1) -get substring 4 failed (-49): unknown or unset substring +get substring 4 failed (-47): unknown or unset substring 0L bcdef 1L bc 2L bc @@ -4370,7 +4370,7 @@ Subject length lower bound = 8 0: abcdefgh 1: cd 2: gh -copy substring 'three' failed (-49): unknown or unset substring +copy substring 'three' failed (-47): unknown or unset substring /(?P)(?P)/IB ------------------------------------------------------------------ @@ -5737,7 +5737,7 @@ No match 0: a1 1: a1 2: a1 -copy substring 'Z' failed (-49): unknown or unset substring +copy substring 'Z' failed (-47): unknown or unset substring C a1 (2) A /(?|(?)(?)(?)|(?)(?)(?))/I,dupnames @@ -5778,7 +5778,7 @@ Subject length lower bound = 2 C a (1) A cd\=copy=A 0: cd -copy substring 'A' failed (-49): unknown or unset substring +copy substring 'A' failed (-47): unknown or unset substring /^(?Pa)(?Pb)|cd(?Pef)(?Pgh)/I,dupnames Capturing subpattern count = 4 @@ -5822,7 +5822,7 @@ No match 0: a1 1: a1 2: a1 -get substring 'Z' failed (-49): unknown or unset substring +get substring 'Z' failed (-47): unknown or unset substring G a1 (2) A /^(?Pa)(?Pb)/I,dupnames @@ -5853,7 +5853,7 @@ Subject length lower bound = 2 G a (1) A cd\=get=A 0: cd -get substring 'A' failed (-49): unknown or unset substring +get substring 'A' failed (-47): unknown or unset substring /^(?Pa)(?Pb)|cd(?Pef)(?Pgh)/I,dupnames Capturing subpattern count = 4 @@ -10446,7 +10446,7 @@ Partial match: abc abc\=offset=3 No match abc\=offset=4 -Failed: error -34: bad offset value +Failed: error -33: bad offset value abc\=offset=-4 ** Invalid value in 'offset=-4' @@ -11129,15 +11129,15 @@ Matched, but too many substrings /((?2))((?1))/ abc -Failed: error -51: nested recursion at the same subject position +Failed: error -49: nested recursion at the same subject position /((?(R2)a+|(?1)b))/ aaaabcde -Failed: error -51: nested recursion at the same subject position +Failed: error -49: nested recursion at the same subject position /(?(R)a*(?1)|((?R))b)/ aaaabcde -Failed: error -51: nested recursion at the same subject position +Failed: error -49: nested recursion at the same subject position /(a+|(?R)b)/ Failed: error 140 at offset 7: recursion could loop indefinitely @@ -12129,11 +12129,11 @@ Subject length lower bound = 3 aaaaaaaaaaaaaz No match aaaaaaaaaaaaaz\=match_limit=3000 -Failed: error -47: match limit exceeded +Failed: error -45: match limit exceeded /(a+)*zz/ aaaaaaaaaaaaaz\=recursion_limit=10 -Failed: error -52: recursion limit exceeded +Failed: error -50: recursion limit exceeded /(*LIMIT_MATCH=3000)(a+)*zz/I Capturing subpattern count = 1 @@ -12142,9 +12142,9 @@ Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 aaaaaaaaaaaaaz -Failed: error -47: match limit exceeded +Failed: error -45: match limit exceeded aaaaaaaaaaaaaz\=match_limit=60000 -Failed: error -47: match limit exceeded +Failed: error -45: match limit exceeded /(*LIMIT_MATCH=60000)(*LIMIT_MATCH=3000)(a+)*zz/I Capturing subpattern count = 1 @@ -12153,7 +12153,7 @@ Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 aaaaaaaaaaaaaz -Failed: error -47: match limit exceeded +Failed: error -45: match limit exceeded /(*LIMIT_MATCH=60000)(a+)*zz/I Capturing subpattern count = 1 @@ -12164,7 +12164,7 @@ Subject length lower bound = 2 aaaaaaaaaaaaaz No match aaaaaaaaaaaaaz\=match_limit=3000 -Failed: error -47: match limit exceeded +Failed: error -45: match limit exceeded /(*LIMIT_RECURSION=10)(a+)*zz/I Capturing subpattern count = 1 @@ -12173,9 +12173,9 @@ Starting code units: a z Last code unit = 'z' Subject length lower bound = 2 aaaaaaaaaaaaaz -Failed: error -52: recursion limit exceeded +Failed: error -50: recursion limit exceeded aaaaaaaaaaaaaz\=recursion_limit=1000 -Failed: error -52: recursion limit exceeded +Failed: error -50: recursion limit exceeded /(*LIMIT_RECURSION=10)(*LIMIT_RECURSION=1000)(a+)*zz/I Capturing subpattern count = 1 @@ -12195,7 +12195,7 @@ Subject length lower bound = 2 aaaaaaaaaaaaaz No match aaaaaaaaaaaaaz\=recursion_limit=10 -Failed: error -52: recursion limit exceeded +Failed: error -50: recursion limit exceeded # This test causes a segfault with Perl 5.18.0 diff --git a/testdata/testoutput6 b/testdata/testoutput6 index 57e39c7..922185f 100644 --- a/testdata/testoutput6 +++ b/testdata/testoutput6 @@ -6132,7 +6132,7 @@ No match /^(?(2)a|(1)(2))+$/ 123a -Failed: error -40: backreference condition or recursion test not supported for DFA matching +Failed: error -39: backreference condition or recursion test not supported for DFA matching /(?<=a|bbbb)c/ ac @@ -7059,7 +7059,7 @@ Partial match: dogs /abc\K123/ xyzabc123pqr -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /(?<=abc)123/ xyzabc123pqr @@ -7185,29 +7185,29 @@ No match /^(?!a(*SKIP)b)/ ac -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /^(?=a(*SKIP)b|ac)/ ** Failers No match ac -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /^(?=a(*THEN)b|ac)/ ac -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /^(?=a(*PRUNE)b)/ ab -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching ** Failers No match ac -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /^(?(?!a(*SKIP)b))/ ac -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /(?<=abc)def/ abc\=ph @@ -7277,7 +7277,7 @@ Partial match: abc abc\=offset=3 No match abc\=offset=4 -Failed: error -34: bad offset value +Failed: error -33: bad offset value abc\=offset=-4 ** Invalid value in 'offset=-4' @@ -7403,7 +7403,7 @@ No match /((?2))((?1))/ abc -Failed: error -51: nested recursion at the same subject position +Failed: error -49: nested recursion at the same subject position /(?(R)a+|(?R)b)/ aaaabcde @@ -7419,11 +7419,11 @@ Failed: error -51: nested recursion at the same subject position /((?(R2)a+|(?1)b))/ aaaabcde -Failed: error -40: backreference condition or recursion test not supported for DFA matching +Failed: error -39: backreference condition or recursion test not supported for DFA matching /(?(R)a*(?1)|((?R))b)/ aaaabcde -Failed: error -51: nested recursion at the same subject position +Failed: error -49: nested recursion at the same subject position /(a+)/no_auto_possess aaaa\=ovector=3 @@ -7572,7 +7572,7 @@ Partial match: \x0d\x0d\x0d /abcdef/ abc\=dfa_restart -Failed: error -38: invalid data in workspace for DFA restart +Failed: error -37: invalid data in workspace for DFA restart /)(.)|(?R))++)*F>/ text text xxxxx text F> text2 more text. diff --git a/testdata/testoutput7 b/testdata/testoutput7 index 85c59b3..b3ebbb1 100644 --- a/testdata/testoutput7 +++ b/testdata/testoutput7 @@ -1230,7 +1230,7 @@ Partial match: the cat /ab\Cde/utf abXde -Failed: error -41: item unsupported for DFA matching +Failed: error -40: item unsupported for DFA matching /(?<=ab\Cde)X/utf Failed: error 136 at offset 10: \C is not allowed in a lookbehind assertion