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
Copyright (c) 1997-2009 University of Cambridge
11
-----------------------------------------------------------------------------
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
15
* Redistributions of source code must retain the above copyright notice,
16
this list of conditions and the following disclaimer.
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.
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.
26
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
POSSIBILITY OF SUCH DAMAGE.
37
-----------------------------------------------------------------------------
41
/* This module contains internal functions for testing newlines when more than
42
one kind of newline is to be recognized. When a newline is found, its length is
43
returned. In principle, we could implement several newline "types", each
44
referring to a different set of newline characters. At present, PCRE supports
45
only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF,
46
and NLTYPE_ANY. The full list of Unicode newline characters is taken from
47
http://unicode.org/unicode/reports/tr18/. */
50
#if (defined(WIN64) || defined(WIN32))
51
# include "config_win.h"
52
#elif (defined(__APPLE__) || defined(OSMac_))
53
# include "config_mac.h"
54
#elif defined(__linux__) || defined(__linux)
55
# include "config_linux.h"
56
#elif defined(HAVE_CONFIG_H)
60
#include "pcre_internal.h"
64
/*************************************************
65
* Check for newline at given position *
66
*************************************************/
68
/* It is guaranteed that the initial value of ptr is less than the end of the
69
string that is being processed.
72
ptr pointer to possible newline
74
endptr pointer to the end of the string
75
lenptr where to return the length
76
utf8 TRUE if in utf8 mode
78
Returns: TRUE or FALSE
82
_pcre_is_newline(USPTR ptr, int type, USPTR endptr, int *lenptr, BOOL utf8)
85
if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
87
if (type == NLTYPE_ANYCRLF) switch(c)
89
case 0x000a: *lenptr = 1; return TRUE; /* LF */
90
case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
92
default: return FALSE;
100
case 0x000b: /* VT */
101
case 0x000c: *lenptr = 1; return TRUE; /* FF */
102
case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
103
return TRUE; /* CR */
104
case 0x0085: *lenptr = utf8? 2 : 1; return TRUE; /* NEL */
105
case 0x2028: /* LS */
106
case 0x2029: *lenptr = 3; return TRUE; /* PS */
107
default: return FALSE;
113
/*************************************************
114
* Check for newline at previous position *
115
*************************************************/
117
/* It is guaranteed that the initial value of ptr is greater than the start of
118
the string that is being processed.
121
ptr pointer to possible newline
122
type the newline type
123
startptr pointer to the start of the string
124
lenptr where to return the length
125
utf8 TRUE if in utf8 mode
127
Returns: TRUE or FALSE
131
_pcre_was_newline(USPTR ptr, int type, USPTR startptr, int *lenptr, BOOL utf8)
142
#else /* no UTF-8 support */
144
#endif /* SUPPORT_UTF8 */
146
if (type == NLTYPE_ANYCRLF) switch(c)
148
case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
149
return TRUE; /* LF */
150
case 0x000d: *lenptr = 1; return TRUE; /* CR */
151
default: return FALSE;
156
case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
157
return TRUE; /* LF */
158
case 0x000b: /* VT */
159
case 0x000c: /* FF */
160
case 0x000d: *lenptr = 1; return TRUE; /* CR */
161
case 0x0085: *lenptr = utf8? 2 : 1; return TRUE; /* NEL */
162
case 0x2028: /* LS */
163
case 0x2029: *lenptr = 3; return TRUE; /* PS */
164
default: return FALSE;
168
/* End of pcre_newline.c */