/[pcre]/code/trunk/pcre_newline.c
ViewVC logotype

Contents of /code/trunk/pcre_newline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1221 - (hide annotations) (download)
Sun Nov 11 20:27:03 2012 UTC (22 months, 2 weeks ago) by ph10
File MIME type: text/plain
File size: 6164 byte(s)
File tidies, preparing for 8.32-RC1.

1 nigel 93 /*************************************************
2     * Perl-Compatible Regular Expressions *
3     *************************************************/
4    
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.
7    
8     Written by Philip Hazel
9 ph10 836 Copyright (c) 1997-2012 University of Cambridge
10 nigel 93
11     -----------------------------------------------------------------------------
12     Redistribution and use in source and binary forms, with or without
13     modification, 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    
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     -----------------------------------------------------------------------------
38     */
39    
40    
41 ph10 150 /* This module contains internal functions for testing newlines when more than
42 nigel 93 one kind of newline is to be recognized. When a newline is found, its length is
43 ph10 150 returned. In principle, we could implement several newline "types", each
44     referring to a different set of newline characters. At present, PCRE supports
45 ph10 149 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 nigel 93 http://unicode.org/unicode/reports/tr18/. */
48    
49    
50 ph10 200 #ifdef HAVE_CONFIG_H
51 ph10 236 #include "config.h"
52 ph10 200 #endif
53 ph10 199
54 nigel 93 #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
63 ph10 1221 string that is being processed.
64 nigel 93
65     Arguments:
66     ptr pointer to possible newline
67 ph10 149 type the newline type
68 nigel 93 endptr pointer to the end of the string
69     lenptr where to return the length
70 ph10 836 utf TRUE if in utf mode
71 nigel 93
72     Returns: TRUE or FALSE
73     */
74    
75     BOOL
76 ph10 836 PRIV(is_newline)(PCRE_PUCHAR ptr, int type, PCRE_PUCHAR endptr, int *lenptr,
77     BOOL utf)
78 nigel 93 {
79 chpe 1093 pcre_uint32 c;
80 ph10 836 (void)utf;
81     #ifdef SUPPORT_UTF
82     if (utf)
83     {
84     GETCHAR(c, ptr);
85     }
86     else
87     #endif /* SUPPORT_UTF */
88     c = *ptr;
89 ph10 149
90 ph10 1221 /* Note that this function is called only for ANY or ANYCRLF. */
91    
92 ph10 149 if (type == NLTYPE_ANYCRLF) switch(c)
93 nigel 93 {
94 ph10 1033 case CHAR_LF: *lenptr = 1; return TRUE;
95     case CHAR_CR: *lenptr = (ptr < endptr - 1 && ptr[1] == CHAR_LF)? 2 : 1;
96     return TRUE;
97 ph10 149 default: return FALSE;
98     }
99    
100     /* NLTYPE_ANY */
101    
102     else switch(c)
103     {
104 ph10 1033 #ifdef EBCDIC
105     case CHAR_NEL:
106 ph10 1221 #endif
107 ph10 1033 case CHAR_LF:
108     case CHAR_VT:
109     case CHAR_FF: *lenptr = 1; return TRUE;
110    
111 ph10 1221 case CHAR_CR:
112 ph10 1033 *lenptr = (ptr < endptr - 1 && ptr[1] == CHAR_LF)? 2 : 1;
113     return TRUE;
114    
115     #ifndef EBCDIC
116 ph10 836 #ifdef COMPILE_PCRE8
117 ph10 1033 case CHAR_NEL: *lenptr = utf? 2 : 1; return TRUE;
118 nigel 93 case 0x2028: /* LS */
119     case 0x2029: *lenptr = 3; return TRUE; /* PS */
120 chpe 1055 #else /* COMPILE_PCRE16 || COMPILE_PCRE32 */
121 ph10 1033 case CHAR_NEL:
122 ph10 836 case 0x2028: /* LS */
123     case 0x2029: *lenptr = 1; return TRUE; /* PS */
124 ph10 1033 #endif /* COMPILE_PCRE8 */
125     #endif /* Not EBCDIC */
126    
127 nigel 93 default: return FALSE;
128     }
129     }
130    
131    
132    
133     /*************************************************
134     * Check for newline at previous position *
135     *************************************************/
136    
137     /* It is guaranteed that the initial value of ptr is greater than the start of
138     the string that is being processed.
139    
140     Arguments:
141     ptr pointer to possible newline
142 ph10 149 type the newline type
143 nigel 93 startptr pointer to the start of the string
144     lenptr where to return the length
145 ph10 836 utf TRUE if in utf mode
146 nigel 93
147     Returns: TRUE or FALSE
148     */
149    
150     BOOL
151 ph10 836 PRIV(was_newline)(PCRE_PUCHAR ptr, int type, PCRE_PUCHAR startptr, int *lenptr,
152     BOOL utf)
153 nigel 93 {
154 chpe 1093 pcre_uint32 c;
155 ph10 836 (void)utf;
156 nigel 93 ptr--;
157 ph10 836 #ifdef SUPPORT_UTF
158     if (utf)
159 nigel 93 {
160     BACKCHAR(ptr);
161     GETCHAR(c, ptr);
162     }
163 ph10 836 else
164     #endif /* SUPPORT_UTF */
165     c = *ptr;
166 ph10 149
167 ph10 1221 /* Note that this function is called only for ANY or ANYCRLF. */
168 ph10 1033
169 ph10 149 if (type == NLTYPE_ANYCRLF) switch(c)
170 nigel 93 {
171 ph10 1221 case CHAR_LF:
172 ph10 1033 *lenptr = (ptr > startptr && ptr[-1] == CHAR_CR)? 2 : 1;
173     return TRUE;
174 ph10 1221
175 ph10 1033 case CHAR_CR: *lenptr = 1; return TRUE;
176 ph10 149 default: return FALSE;
177     }
178    
179 ph10 1033 /* NLTYPE_ANY */
180    
181 ph10 149 else switch(c)
182     {
183 ph10 1221 case CHAR_LF:
184 ph10 1033 *lenptr = (ptr > startptr && ptr[-1] == CHAR_CR)? 2 : 1;
185     return TRUE;
186 ph10 1221
187 ph10 1033 #ifdef EBCDIC
188     case CHAR_NEL:
189 ph10 1221 #endif
190 ph10 1033 case CHAR_VT:
191     case CHAR_FF:
192     case CHAR_CR: *lenptr = 1; return TRUE;
193 ph10 1221
194     #ifndef EBCDIC
195 ph10 836 #ifdef COMPILE_PCRE8
196 ph10 1033 case CHAR_NEL: *lenptr = utf? 2 : 1; return TRUE;
197     case 0x2028: /* LS */
198     case 0x2029: *lenptr = 3; return TRUE; /* PS */
199 chpe 1055 #else /* COMPILE_PCRE16 || COMPILE_PCRE32 */
200 ph10 1033 case CHAR_NEL:
201 ph10 836 case 0x2028: /* LS */
202     case 0x2029: *lenptr = 1; return TRUE; /* PS */
203 ph10 1033 #endif /* COMPILE_PCRE8 */
204     #endif /* NotEBCDIC */
205    
206 nigel 93 default: return FALSE;
207     }
208     }
209    
210     /* End of pcre_newline.c */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12