php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
pcre2_match_data.c
Go to the documentation of this file.
1/*************************************************
2* Perl-Compatible Regular Expressions *
3*************************************************/
4
5/* PCRE is a library of functions to support regular expressions whose syntax
6and semantics are as close as possible to those of the Perl 5 language.
7
8 Written by Philip Hazel
9 Original API code Copyright (c) 1997-2012 University of Cambridge
10 New API code Copyright (c) 2016-2022 University of Cambridge
11
12-----------------------------------------------------------------------------
13Redistribution and use in source and binary forms, with or without
14modification, are permitted provided that the following conditions are met:
15
16 * Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
18
19 * Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 * Neither the name of the University of Cambridge nor the names of its
24 contributors may be used to endorse or promote products derived from
25 this software without specific prior written permission.
26
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37POSSIBILITY OF SUCH DAMAGE.
38-----------------------------------------------------------------------------
39*/
40
41
42#ifdef HAVE_CONFIG_H
43#include "config.h"
44#endif
45
46#include "pcre2_internal.h"
47
48
49
50/*************************************************
51* Create a match data block given ovector size *
52*************************************************/
53
54/* A minimum of 1 is imposed on the number of ovector pairs. A maximum is also
55imposed because the oveccount field in a match data block is uintt6_t. */
56
58pcre2_match_data_create(uint32_t oveccount, pcre2_general_context *gcontext)
59{
60pcre2_match_data *yield;
61if (oveccount < 1) oveccount = 1;
62if (oveccount > UINT16_MAX) oveccount = UINT16_MAX;
63yield = PRIV(memctl_malloc)(
64 offsetof(pcre2_match_data, ovector) + 2*oveccount*sizeof(PCRE2_SIZE),
65 (pcre2_memctl *)gcontext);
66if (yield == NULL) return NULL;
67yield->oveccount = oveccount;
68yield->flags = 0;
69yield->heapframes = NULL;
70yield->heapframes_size = 0;
71return yield;
72}
73
74
75
76/*************************************************
77* Create a match data block using pattern data *
78*************************************************/
79
80/* If no context is supplied, use the memory allocator from the code. */
81
84 pcre2_general_context *gcontext)
85{
86if (gcontext == NULL) gcontext = (pcre2_general_context *)code;
87return pcre2_match_data_create(((pcre2_real_code *)code)->top_bracket + 1,
88 gcontext);
89}
90
91
92
93/*************************************************
94* Free a match data block *
95*************************************************/
96
99{
100if (match_data != NULL)
101 {
102 if (match_data->heapframes != NULL)
103 match_data->memctl.free(match_data->heapframes,
104 match_data->memctl.memory_data);
105 if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0)
106 match_data->memctl.free((void *)match_data->subject,
107 match_data->memctl.memory_data);
108 match_data->memctl.free(match_data, match_data->memctl.memory_data);
109 }
110}
111
112
113
114/*************************************************
115* Get last mark in match *
116*************************************************/
117
120{
121return match_data->mark;
122}
123
124
125
126/*************************************************
127* Get pointer to ovector *
128*************************************************/
129
132{
133return match_data->ovector;
134}
135
136
137
138/*************************************************
139* Get number of ovector slots *
140*************************************************/
141
144{
145return match_data->oveccount;
146}
147
148
149
150/*************************************************
151* Get starting code unit in match *
152*************************************************/
153
156{
157return match_data->startchar;
158}
159
160
161
162/*************************************************
163* Get size of match data block *
164*************************************************/
165
168{
169return offsetof(pcre2_match_data, ovector) +
170 2 * (match_data->oveccount) * sizeof(PCRE2_SIZE);
171}
172
173
174
175/*************************************************
176* Get heapframes size *
177*************************************************/
178
181{
182return match_data->heapframes_size;
183}
184
185/* End of pcre2_match_data.c */
#define NULL
Definition gdcache.h:45
#define pcre2_real_code
Definition pcre2.h:826
#define pcre2_match_data_create
Definition pcre2.h:885
#define pcre2_general_context
Definition pcre2.h:840
#define pcre2_code
Definition pcre2.h:822
#define pcre2_get_startchar
Definition pcre2.h:872
#define pcre2_get_ovector_pointer
Definition pcre2.h:870
#define pcre2_get_match_data_heapframes_size
Definition pcre2.h:868
#define PCRE2_SIZE
Definition pcre2.h:479
#define pcre2_match_data_create_from_pattern
Definition pcre2.h:886
#define PCRE2_SPTR
Definition pcre2.h:820
#define pcre2_match_data
Definition pcre2.h:844
#define pcre2_get_match_data_size
Definition pcre2.h:869
#define pcre2_get_mark
Definition pcre2.h:867
#define pcre2_match_data_free
Definition pcre2.h:887
#define PCRE2_CALL_CONVENTION
Definition pcre2.h:81
#define pcre2_get_ovector_count
Definition pcre2.h:871
void *PRIV memctl_malloc(size_t size, pcre2_memctl *memctl)
#define PCRE2_MD_COPIED_SUBJECT
#define PCRE2_EXP_DEFN
#define PRIV(name)
#define offsetof(STRUCTURE, FIELD)