| 6 |
and semantics are as close as possible to those of the Perl 5 language. |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
| 8 |
Written by Philip Hazel |
Written by Philip Hazel |
| 9 |
Copyright (c) 1997-2005 University of Cambridge |
Copyright (c) 1997-2007 University of Cambridge |
| 10 |
|
|
| 11 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 12 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 42 |
strings. */ |
strings. */ |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
#ifdef HAVE_CONFIG_H |
| 46 |
|
#include <config.h> |
| 47 |
|
#endif |
| 48 |
|
|
| 49 |
#include "pcre_internal.h" |
#include "pcre_internal.h" |
| 50 |
|
|
| 51 |
|
|
| 67 |
>= 0 otherwise; the value is the offset of the bad byte |
>= 0 otherwise; the value is the offset of the bad byte |
| 68 |
*/ |
*/ |
| 69 |
|
|
| 70 |
EXPORT int |
int |
| 71 |
_pcre_valid_utf8(const uschar *string, int length) |
_pcre_valid_utf8(const uschar *string, int length) |
| 72 |
{ |
{ |
| 73 |
|
#ifdef SUPPORT_UTF8 |
| 74 |
register const uschar *p; |
register const uschar *p; |
| 75 |
|
|
| 76 |
if (length < 0) |
if (length < 0) |
| 84 |
register int ab; |
register int ab; |
| 85 |
register int c = *p; |
register int c = *p; |
| 86 |
if (c < 128) continue; |
if (c < 128) continue; |
| 87 |
if ((c & 0xc0) != 0xc0) return p - string; |
if (c < 0xc0) return p - string; |
| 88 |
ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ |
ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ |
| 89 |
if (length < ab) return p - string; |
if (length < ab) return p - string; |
| 90 |
length -= ab; |
length -= ab; |
| 128 |
if ((*(++p) & 0xc0) != 0x80) return p - string; |
if ((*(++p) & 0xc0) != 0x80) return p - string; |
| 129 |
} |
} |
| 130 |
} |
} |
| 131 |
|
#endif |
| 132 |
|
|
| 133 |
return -1; |
return -1; |
| 134 |
} |
} |