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

Contents of /code/trunk/pcre_newline.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 836 - (hide annotations) (download)
Wed Dec 28 17:16:11 2011 UTC (2 years, 11 months ago) by ph10
File MIME type: text/plain
File size: 6278 byte(s)
Merging all the changes from the pcre16 branch into the trunk.

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     string that is being processed.
64    
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     int 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     if (type == NLTYPE_ANYCRLF) switch(c)
91 nigel 93 {
92 ph10 149 case 0x000a: *lenptr = 1; return TRUE; /* LF */
93     case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
94     return TRUE; /* CR */
95     default: return FALSE;
96     }
97    
98     /* NLTYPE_ANY */
99    
100     else switch(c)
101     {
102 nigel 93 case 0x000a: /* LF */
103     case 0x000b: /* VT */
104     case 0x000c: *lenptr = 1; return TRUE; /* FF */
105     case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
106     return TRUE; /* CR */
107 ph10 836 #ifdef COMPILE_PCRE8
108     case 0x0085: *lenptr = utf? 2 : 1; return TRUE; /* NEL */
109 nigel 93 case 0x2028: /* LS */
110     case 0x2029: *lenptr = 3; return TRUE; /* PS */
111 ph10 836 #else
112     case 0x0085: /* NEL */
113     case 0x2028: /* LS */
114     case 0x2029: *lenptr = 1; return TRUE; /* PS */
115     #endif /* COMPILE_PCRE8 */
116 nigel 93 default: return FALSE;
117     }
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
127     the string that is being processed.
128    
129     Arguments:
130     ptr pointer to possible newline
131 ph10 149 type the newline type
132 nigel 93 startptr pointer to the start of the string
133     lenptr where to return the length
134 ph10 836 utf TRUE if in utf mode
135 nigel 93
136     Returns: TRUE or FALSE
137     */
138    
139     BOOL
140 ph10 836 PRIV(was_newline)(PCRE_PUCHAR ptr, int type, PCRE_PUCHAR startptr, int *lenptr,
141     BOOL utf)
142 nigel 93 {
143     int c;
144 ph10 836 (void)utf;
145 nigel 93 ptr--;
146 ph10 836 #ifdef SUPPORT_UTF
147     if (utf)
148 nigel 93 {
149     BACKCHAR(ptr);
150     GETCHAR(c, ptr);
151     }
152 ph10 836 else
153     #endif /* SUPPORT_UTF */
154     c = *ptr;
155 ph10 149
156     if (type == NLTYPE_ANYCRLF) switch(c)
157 nigel 93 {
158     case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
159     return TRUE; /* LF */
160 ph10 149 case 0x000d: *lenptr = 1; return TRUE; /* CR */
161     default: return FALSE;
162     }
163    
164     else switch(c)
165     {
166     case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
167     return TRUE; /* LF */
168 nigel 93 case 0x000b: /* VT */
169     case 0x000c: /* FF */
170     case 0x000d: *lenptr = 1; return TRUE; /* CR */
171 ph10 836 #ifdef COMPILE_PCRE8
172     case 0x0085: *lenptr = utf? 2 : 1; return TRUE; /* NEL */
173 nigel 93 case 0x2028: /* LS */
174     case 0x2029: *lenptr = 3; return TRUE; /* PS */
175 ph10 836 #else
176     case 0x0085: /* NEL */
177     case 0x2028: /* LS */
178     case 0x2029: *lenptr = 1; return TRUE; /* PS */
179     #endif /* COMPILE_PCRE8 */
180 nigel 93 default: return FALSE;
181     }
182     }
183    
184     /* 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