../3rdparty/pcre/pcre_newline.c

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
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 Copyright (c) 1997-2012 University of Cambridge -
10 -
11----------------------------------------------------------------------------- -
12Redistribution and use in source and binary forms, with or without -
13modification, are permitted provided that the following conditions are met: -
14 -
15 * Redistributions of source code must retain the above copyright notice, -
16 this list of conditions and the following disclaimer. -
17 -
18 * Redistributions in binary form must reproduce the above copyright -
19 notice, this list of conditions and the following disclaimer in the -
20 documentation and/or other materials provided with the distribution. -
21 -
22 * Neither the name of the University of Cambridge nor the names of its -
23 contributors may be used to endorse or promote products derived from -
24 this software without specific prior written permission. -
25 -
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -
36POSSIBILITY OF SUCH DAMAGE. -
37----------------------------------------------------------------------------- -
38*/ -
39 -
40 -
41/* This module contains internal functions for testing newlines when more than -
42one kind of newline is to be recognized. When a newline is found, its length is -
43returned. In principle, we could implement several newline "types", each -
44referring to a different set of newline characters. At present, PCRE supports -
45only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF, -
46and NLTYPE_ANY. The full list of Unicode newline characters is taken from -
47http://unicode.org/unicode/reports/tr18/. */ -
48 -
49 -
50#ifdef PCRE_HAVE_CONFIG_H -
51#include "config.h" -
52#endif -
53 -
54#include "pcre_internal.h" -
55 -
56 -
57 -
58/************************************************* -
59* Check for newline at given position * -
60*************************************************/ -
61 -
62/* It is guaranteed that the initial value of ptr is less than the end of the -
63string that is being processed. -
64 -
65Arguments: -
66 ptr pointer to possible newline -
67 type the newline type -
68 endptr pointer to the end of the string -
69 lenptr where to return the length -
70 utf TRUE if in utf mode -
71 -
72Returns: TRUE or FALSE -
73*/ -
74 -
75BOOL -
76PRIV(is_newline)(PCRE_PUCHAR ptr, int type, PCRE_PUCHAR endptr, int *lenptr, -
77 BOOL utf) -
78{ -
79int c;
executed (the execution status of this line is deduced): int c;
-
80(void)utf;
executed (the execution status of this line is deduced): (void)utf;
-
81#ifdef SUPPORT_UTF -
82if (utf)
partially evaluated: utf
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-29
83 { -
84 GETCHAR(c, ptr);
never executed: }
partially evaluated: (c & 0xfc00) == 0xd800
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
0-29
85 }
executed: }
Execution Count:29
29
86else -
87#endif /* SUPPORT_UTF */ -
88 c = *ptr;
never executed: c = *ptr;
0
89 -
90if (type == NLTYPE_ANYCRLF) switch(c)
partially evaluated: type == 2
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-29
91 { -
92 case 0x000a: *lenptr = 1; return TRUE; /* LF */
executed: return 1;
Execution Count:4
4
93 case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
partially evaluated: ptr < endptr - 1
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
evaluated: ptr[1] == 0x0a
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
0-8
94 return TRUE; /* CR */
executed: return 1;
Execution Count:8
8
95 default: return FALSE;
executed: return 0;
Execution Count:17
17
96 }
never executed: }
0
97 -
98/* NLTYPE_ANY */ -
99 -
100else switch(c) -
101 { -
102 case 0x000a: /* LF */ -
103 case 0x000b: /* VT */ -
104 case 0x000c: *lenptr = 1; return TRUE; /* FF */
never executed: return 1;
0
105 case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
never evaluated: ptr < endptr - 1
never evaluated: ptr[1] == 0x0a
0
106 return TRUE; /* CR */
never executed: return 1;
0
107#ifdef COMPILE_PCRE8 -
108 case 0x0085: *lenptr = utf? 2 : 1; return TRUE; /* NEL */ -
109 case 0x2028: /* LS */ -
110 case 0x2029: *lenptr = 3; return TRUE; /* PS */ -
111#else -
112 case 0x0085: /* NEL */ -
113 case 0x2028: /* LS */ -
114 case 0x2029: *lenptr = 1; return TRUE; /* PS */
never executed: return 1;
0
115#endif /* COMPILE_PCRE8 */ -
116 default: return FALSE;
never executed: return 0;
0
117 }
never executed: }
0
118} -
119 -
120 -
121 -
122/************************************************* -
123* Check for newline at previous position * -
124*************************************************/ -
125 -
126/* It is guaranteed that the initial value of ptr is greater than the start of -
127the string that is being processed. -
128 -
129Arguments: -
130 ptr pointer to possible newline -
131 type the newline type -
132 startptr pointer to the start of the string -
133 lenptr where to return the length -
134 utf TRUE if in utf mode -
135 -
136Returns: TRUE or FALSE -
137*/ -
138 -
139BOOL -
140PRIV(was_newline)(PCRE_PUCHAR ptr, int type, PCRE_PUCHAR startptr, int *lenptr, -
141 BOOL utf) -
142{ -
143int c;
never executed (the execution status of this line is deduced): int c;
-
144(void)utf;
never executed (the execution status of this line is deduced): (void)utf;
-
145ptr--;
never executed (the execution status of this line is deduced): ptr--;
-
146#ifdef SUPPORT_UTF -
147if (utf)
never evaluated: utf
0
148 { -
149 BACKCHAR(ptr);
never executed: ptr--;
never evaluated: (*ptr & 0xfc00) == 0xdc00
0
150 GETCHAR(c, ptr);
never executed: }
never evaluated: (c & 0xfc00) == 0xd800
0
151 }
never executed: }
0
152else -
153#endif /* SUPPORT_UTF */ -
154 c = *ptr;
never executed: c = *ptr;
0
155 -
156if (type == NLTYPE_ANYCRLF) switch(c)
never evaluated: type == 2
0
157 { -
158 case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
never evaluated: ptr > startptr
never evaluated: ptr[-1] == 0x0d
0
159 return TRUE; /* LF */
never executed: return 1;
0
160 case 0x000d: *lenptr = 1; return TRUE; /* CR */
never executed: return 1;
0
161 default: return FALSE;
never executed: return 0;
0
162 }
never executed: }
0
163 -
164else switch(c) -
165 { -
166 case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
never evaluated: ptr > startptr
never evaluated: ptr[-1] == 0x0d
0
167 return TRUE; /* LF */
never executed: return 1;
0
168 case 0x000b: /* VT */ -
169 case 0x000c: /* FF */ -
170 case 0x000d: *lenptr = 1; return TRUE; /* CR */
never executed: return 1;
0
171#ifdef COMPILE_PCRE8 -
172 case 0x0085: *lenptr = utf? 2 : 1; return TRUE; /* NEL */ -
173 case 0x2028: /* LS */ -
174 case 0x2029: *lenptr = 3; return TRUE; /* PS */ -
175#else -
176 case 0x0085: /* NEL */ -
177 case 0x2028: /* LS */ -
178 case 0x2029: *lenptr = 1; return TRUE; /* PS */
never executed: return 1;
0
179#endif /* COMPILE_PCRE8 */ -
180 default: return FALSE;
never executed: return 0;
0
181 }
never executed: }
0
182} -
183 -
184/* End of pcre_newline.c */ -
185 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial