| 38 |
*/ |
*/ |
| 39 |
|
|
| 40 |
|
|
| 41 |
/* This module contains internal functions for testing newlines when more than |
/* 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 |
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 |
|
|
| 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 |
| 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 */ |
| 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 |
| 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--; |
| 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 */ |