1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
8 Written by Philip Hazel
9 Original API code Copyright (c) 1997-2012 University of Cambridge
10 New API code Copyright (c) 2016-2017 University of Cambridge
12 -----------------------------------------------------------------------------
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
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.
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.
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 -----------------------------------------------------------------------------
46 #include "pcre2_internal.h"
50 /*************************************************
51 * Create a match data block given ovector size *
52 *************************************************/
54 /* A minimum of 1 is imposed on the number of ovector pairs. */
56 PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION
57 pcre2_match_data_create(uint32_t oveccount, pcre2_general_context *gcontext)
59 pcre2_match_data *yield;
60 if (oveccount < 1) oveccount = 1;
61 yield = PRIV(memctl_malloc)(
62 offsetof(pcre2_match_data, ovector) + 2*oveccount*sizeof(PCRE2_SIZE),
63 (pcre2_memctl *)gcontext);
64 if (yield == NULL) return NULL;
65 yield->oveccount = oveccount;
71 /*************************************************
72 * Create a match data block using pattern data *
73 *************************************************/
75 /* If no context is supplied, use the memory allocator from the code. */
77 PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION
78 pcre2_match_data_create_from_pattern(const pcre2_code *code,
79 pcre2_general_context *gcontext)
81 if (gcontext == NULL) gcontext = (pcre2_general_context *)code;
82 return pcre2_match_data_create(((pcre2_real_code *)code)->top_bracket + 1,
88 /*************************************************
89 * Free a match data block *
90 *************************************************/
92 PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
93 pcre2_match_data_free(pcre2_match_data *match_data)
95 if (match_data != NULL)
96 match_data->memctl.free(match_data, match_data->memctl.memory_data);
101 /*************************************************
102 * Get last mark in match *
103 *************************************************/
105 PCRE2_EXP_DEFN PCRE2_SPTR PCRE2_CALL_CONVENTION
106 pcre2_get_mark(pcre2_match_data *match_data)
108 return match_data->mark;
113 /*************************************************
114 * Get pointer to ovector *
115 *************************************************/
117 PCRE2_EXP_DEFN PCRE2_SIZE * PCRE2_CALL_CONVENTION
118 pcre2_get_ovector_pointer(pcre2_match_data *match_data)
120 return match_data->ovector;
125 /*************************************************
126 * Get number of ovector slots *
127 *************************************************/
129 PCRE2_EXP_DEFN uint32_t PCRE2_CALL_CONVENTION
130 pcre2_get_ovector_count(pcre2_match_data *match_data)
132 return match_data->oveccount;
137 /*************************************************
138 * Get starting code unit in match *
139 *************************************************/
141 PCRE2_EXP_DEFN PCRE2_SIZE PCRE2_CALL_CONVENTION
142 pcre2_get_startchar(pcre2_match_data *match_data)
144 return match_data->startchar;
147 /* End of pcre2_match_data.c */