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

Diff of /code/trunk/pcre_newline.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 117 by ph10, Fri Mar 9 15:59:06 2007 UTC revision 150 by ph10, Tue Apr 17 08:22:40 2007 UTC
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  one kind of newline is to be recognized. When a newline is found, its length is  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  returned. In principle, we could implement several newline "types", each
44  referring to a different set of newline characters. At present, PCRE supports  referring to a different set of newline characters. At present, PCRE supports
45  only NLTYPE_FIXED, which gets handled without these functions, and NLTYPE_ALL,  only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF,
46  so for now the type isn't passed into the functions. It can easily be added  and NLTYPE_ANY. The full list of Unicode newline characters is taken from
 later if required. The full list of Unicode newline characters is taken from  
47  http://unicode.org/unicode/reports/tr18/. */  http://unicode.org/unicode/reports/tr18/. */
48    
49    
# Line 61  string that is being processed. Line 60  string that is being processed.
60    
61  Arguments:  Arguments:
62    ptr          pointer to possible newline    ptr          pointer to possible newline
63      type         the newline type
64    endptr       pointer to the end of the string    endptr       pointer to the end of the string
65    lenptr       where to return the length    lenptr       where to return the length
66    utf8         TRUE if in utf8 mode    utf8         TRUE if in utf8 mode
# Line 69  Returns: TRUE or FALSE Line 69  Returns: TRUE or FALSE
69  */  */
70    
71  BOOL  BOOL
72  _pcre_is_newline(const uschar *ptr, const uschar *endptr, int *lenptr,  _pcre_is_newline(const uschar *ptr, int type, const uschar *endptr,
73    BOOL utf8)    int *lenptr, BOOL utf8)
74  {  {
75  int c;  int c;
76  if (utf8) { GETCHAR(c, ptr); } else c = *ptr;  if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
77  switch(c)  
78    if (type == NLTYPE_ANYCRLF) switch(c)
79      {
80      case 0x000a: *lenptr = 1; return TRUE;             /* LF */
81      case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
82                   return TRUE;                          /* CR */
83      default: return FALSE;
84      }
85    
86    /* NLTYPE_ANY */
87    
88    else switch(c)
89    {    {
90    case 0x000a:                                       /* LF */    case 0x000a:                                       /* LF */
91    case 0x000b:                                       /* VT */    case 0x000b:                                       /* VT */
# Line 99  the string that is being processed. Line 110  the string that is being processed.
110    
111  Arguments:  Arguments:
112    ptr          pointer to possible newline    ptr          pointer to possible newline
113      type         the newline type
114    startptr     pointer to the start of the string    startptr     pointer to the start of the string
115    lenptr       where to return the length    lenptr       where to return the length
116    utf8         TRUE if in utf8 mode    utf8         TRUE if in utf8 mode
# Line 107  Returns: TRUE or FALSE Line 119  Returns: TRUE or FALSE
119  */  */
120    
121  BOOL  BOOL
122  _pcre_was_newline(const uschar *ptr, const uschar *startptr, int *lenptr,  _pcre_was_newline(const uschar *ptr, int type, const uschar *startptr,
123    BOOL utf8)    int *lenptr, BOOL utf8)
124  {  {
125  int c;  int c;
126  ptr--;  ptr--;
# Line 118  if (utf8) Line 130  if (utf8)
130    GETCHAR(c, ptr);    GETCHAR(c, ptr);
131    }    }
132  else c = *ptr;  else c = *ptr;
133  switch(c)  
134    if (type == NLTYPE_ANYCRLF) switch(c)
135      {
136      case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
137                   return TRUE;                         /* LF */
138      case 0x000d: *lenptr = 1; return TRUE;            /* CR */
139      default: return FALSE;
140      }
141    
142    else switch(c)
143    {    {
144    case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;    case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
145                 return TRUE;                         /* LF */                 return TRUE;                         /* LF */

Legend:
Removed from v.117  
changed lines
  Added in v.150

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12