/[pcre]/code/tags/pcre-7.4/pcre_valid_utf8.c
ViewVC logotype

Diff of /code/tags/pcre-7.4/pcre_valid_utf8.c

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

revision 85 by nigel, Sat Feb 24 21:41:13 2007 UTC revision 117 by ph10, Fri Mar 9 15:59:06 2007 UTC
# Line 6  Line 6 
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
# Line 63  Returns:       < 0    if the string is a Line 63  Returns:       < 0    if the string is a
63                 >= 0   otherwise; the value is the offset of the bad byte                 >= 0   otherwise; the value is the offset of the bad byte
64  */  */
65    
66  PCRE_EXPORT int  int
67  _pcre_valid_utf8(const uschar *string, int length)  _pcre_valid_utf8(const uschar *string, int length)
68  {  {
69    #ifdef SUPPORT_UTF8
70  register const uschar *p;  register const uschar *p;
71    
72  if (length < 0)  if (length < 0)
# Line 79  for (p = string; length-- > 0; p++) Line 80  for (p = string; length-- > 0; p++)
80    register int ab;    register int ab;
81    register int c = *p;    register int c = *p;
82    if (c < 128) continue;    if (c < 128) continue;
83    if ((c & 0xc0) != 0xc0) return p - string;    if (c < 0xc0) return p - string;
84    ab = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */    ab = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */
85    if (length < ab) return p - string;    if (length < ab) return p - string;
86    length -= ab;    length -= ab;
# Line 123  for (p = string; length-- > 0; p++) Line 124  for (p = string; length-- > 0; p++)
124      if ((*(++p) & 0xc0) != 0x80) return p - string;      if ((*(++p) & 0xc0) != 0x80) return p - string;
125      }      }
126    }    }
127    #endif
128    
129  return -1;  return -1;
130  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5