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

Diff of /code/trunk/pcre_compile.c

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

revision 1047 by zherczeg, Fri Sep 28 15:06:38 2012 UTC revision 1069 by chpe, Tue Oct 16 15:54:29 2012 UTC
# Line 53  supporting internal functions that are n Line 53  supporting internal functions that are n
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    
56  /* When PCRE_DEBUG is defined, we need the pcre(16)_printint() function, which  /* When PCRE_DEBUG is defined, we need the pcre(16|32)_printint() function, which
57  is also used by pcretest. PCRE_DEBUG is not defined when building a production  is also used by pcretest. PCRE_DEBUG is not defined when building a production
58  library. We do not need to select pcre16_printint.c specially, because the  library. We do not need to select pcre16_printint.c specially, because the
59  COMPILE_PCREx macro will already be appropriately set. */  COMPILE_PCREx macro will already be appropriately set. */
# Line 123  overrun before it actually does run off Line 123  overrun before it actually does run off
123    
124  #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */  #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */
125  #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */  #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */
126    #define REQ_MASK       (REQ_CASELESS | REQ_VARY)
127    
128  /* Repeated character flags. */  /* Repeated character flags. */
129    
# Line 503  static const char error_texts[] = Line 504  static const char error_texts[] =
504    /* 75 */    /* 75 */
505    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
506    "character value in \\u.... sequence is too large\0"    "character value in \\u.... sequence is too large\0"
507      "invalid UTF-32 string\0"
508    ;    ;
509    
510  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 747  return (*p == CHAR_RIGHT_CURLY_BRACKET); Line 749  return (*p == CHAR_RIGHT_CURLY_BRACKET);
749  *************************************************/  *************************************************/
750    
751  /* This function is called when a \ has been encountered. It either returns a  /* This function is called when a \ has been encountered. It either returns a
752  positive value for a simple escape such as \n, or a negative value which  positive value for a simple escape such as \n, or 0 for a data character
753  encodes one of the more complicated things such as \d. A backreference to group  which will be placed in chptr. A backreference to group n is returned as
754  n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When  negative n. When UTF-8 is enabled, a positive value greater than 255 may
755  UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,  be returned in chptr.
756  ptr is pointing at the \. On exit, it is on the final character of the escape  On entry,ptr is pointing at the \. On exit, it is on the final character of the
757  sequence.  escape sequence.
758    
759  Arguments:  Arguments:
760    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
761      chptr          points to the data character
762    errorcodeptr   points to the errorcode variable    errorcodeptr   points to the errorcode variable
763    bracount       number of previous extracting brackets    bracount       number of previous extracting brackets
764    options        the options bits    options        the options bits
765    isclass        TRUE if inside a character class    isclass        TRUE if inside a character class
766    
767  Returns:         zero or positive => a data character  Returns:         zero => a data character
768                   negative => a special escape sequence                   positive => a special escape sequence
769                     negative => a back reference
770                   on error, errorcodeptr is set                   on error, errorcodeptr is set
771  */  */
772    
773  static int  static int
774  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
775    int options, BOOL isclass)    int bracount, int options, BOOL isclass)
776  {  {
777  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
778  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
779  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
780  pcre_int32 c;  pcre_uint32 c;
781    int escape = 0;
782  int i;  int i;
783    
784  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
# Line 790  Otherwise further processing may be requ Line 795  Otherwise further processing may be requ
795  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
796  /* Not alphanumeric */  /* Not alphanumeric */
797  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
798  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
799    
800  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
801  /* Not alphanumeric */  /* Not alphanumeric */
802  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
803  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
804  #endif  #endif
805    
806  /* Escapes that need further processing, or are illegal. */  /* Escapes that need further processing, or are illegal. */
# Line 803  else if ((i = escapes[c - 0x48]) != 0) Line 808  else if ((i = escapes[c - 0x48]) != 0)
808  else  else
809    {    {
810    const pcre_uchar *oldptr;    const pcre_uchar *oldptr;
811    BOOL braced, negated;    BOOL braced, negated, overflow;
812      int s;
813    
814    switch (c)    switch (c)
815      {      {
# Line 828  else Line 834  else
834          c = 0;          c = 0;
835          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
836            {            {
837            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
838  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
839            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
840            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 838  else Line 844  else
844  #endif  #endif
845            }            }
846    
847  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
848          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffff : 0xff))
849  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
850          if (c > (utf ? 0x10ffff : 0xffff))          if (c > (utf ? 0x10ffff : 0xffff))
851  #endif  #elif defined COMPILE_PCRE32
852            if (utf && c > 0x10ffff)
853  #endif  #endif
854            {            {
855            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 875  else Line 881  else
881      (3) For Oniguruma compatibility we also support \g followed by a name or a      (3) For Oniguruma compatibility we also support \g followed by a name or a
882      number either in angle brackets or in single quotes. However, these are      number either in angle brackets or in single quotes. However, these are
883      (possibly recursive) subroutine calls, _not_ backreferences. Just return      (possibly recursive) subroutine calls, _not_ backreferences. Just return
884      the -ESC_g code (cf \k). */      the ESC_g code (cf \k). */
885    
886      case CHAR_g:      case CHAR_g:
887      if (isclass) break;      if (isclass) break;
888      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
889        {        {
890        c = -ESC_g;        escape = ESC_g;
891        break;        break;
892        }        }
893    
# Line 894  else Line 900  else
900          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
901        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
902          {          {
903          c = -ESC_k;          escape = ESC_k;
904          break;          break;
905          }          }
906        braced = TRUE;        braced = TRUE;
# Line 910  else Line 916  else
916      else negated = FALSE;      else negated = FALSE;
917    
918      /* The integer range is limited by the machine's int representation. */      /* The integer range is limited by the machine's int representation. */
919      c = 0;      s = 0;
920        overflow = FALSE;
921      while (IS_DIGIT(ptr[1]))      while (IS_DIGIT(ptr[1]))
922        {        {
923        if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */        if (s > INT_MAX / 10 - 1) /* Integer overflow */
924          {          {
925          c = -1;          overflow = TRUE;
926          break;          break;
927          }          }
928        c = c * 10 + *(++ptr) - CHAR_0;        s = s * 10 + (int)(*(++ptr) - CHAR_0);
929        }        }
930      if (((unsigned int)c) > INT_MAX) /* Integer overflow */      if (overflow) /* Integer overflow */
931        {        {
932        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
933          ptr++;          ptr++;
# Line 934  else Line 941  else
941        break;        break;
942        }        }
943    
944      if (c == 0)      if (s == 0)
945        {        {
946        *errorcodeptr = ERR58;        *errorcodeptr = ERR58;
947        break;        break;
# Line 942  else Line 949  else
949    
950      if (negated)      if (negated)
951        {        {
952        if (c > bracount)        if (s > bracount)
953          {          {
954          *errorcodeptr = ERR15;          *errorcodeptr = ERR15;
955          break;          break;
956          }          }
957        c = bracount - (c - 1);        s = bracount - (s - 1);
958        }        }
959    
960      c = -(ESC_REF + c);      escape = -s;
961      break;      break;
962    
963      /* The handling of escape sequences consisting of a string of digits      /* The handling of escape sequences consisting of a string of digits
# Line 972  else Line 979  else
979        {        {
980        oldptr = ptr;        oldptr = ptr;
981        /* The integer range is limited by the machine's int representation. */        /* The integer range is limited by the machine's int representation. */
982        c -= CHAR_0;        s = (int)(c -CHAR_0);
983          overflow = FALSE;
984        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
985          {          {
986          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */          if (s > INT_MAX / 10 - 1) /* Integer overflow */
987            {            {
988            c = -1;            overflow = TRUE;
989            break;            break;
990            }            }
991          c = c * 10 + *(++ptr) - CHAR_0;          s = s * 10 + (int)(*(++ptr) - CHAR_0);
992          }          }
993        if (((unsigned int)c) > INT_MAX) /* Integer overflow */        if (overflow) /* Integer overflow */
994          {          {
995          while (IS_DIGIT(ptr[1]))          while (IS_DIGIT(ptr[1]))
996            ptr++;            ptr++;
997          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
998          break;          break;
999          }          }
1000        if (c < 10 || c <= bracount)        if (s < 10 || s <= bracount)
1001          {          {
1002          c = -(ESC_REF + c);          escape = -s;
1003          break;          break;
1004          }          }
1005        ptr = oldptr;      /* Put the pointer back and fall through */        ptr = oldptr;      /* Put the pointer back and fall through */
# Line 1038  else Line 1046  else
1046          c = 0;          c = 0;
1047          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
1048            {            {
1049            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
1050  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1051            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1052            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1056  else Line 1064  else
1064        const pcre_uchar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
1065    
1066        c = 0;        c = 0;
1067          overflow = FALSE;
1068        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
1069          {          {
1070          register int cc = *pt++;          register pcre_uint32 cc = *pt++;
1071          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
1072    
1073    #ifdef COMPILE_PCRE32
1074            if (c >= 0x10000000l) { overflow = TRUE; break; }
1075    #endif
1076    
1077  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1078          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1079          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1069  else Line 1082  else
1082          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
1083  #endif  #endif
1084    
1085  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
1086          if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }          if (c > (utf ? 0x10ffff : 0xff)) { overflow = TRUE; break; }
1087  #else  #elif defined COMPILE_PCRE16
1088  #ifdef COMPILE_PCRE16          if (c > (utf ? 0x10ffff : 0xffff)) { overflow = TRUE; break; }
1089          if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }  #elif defined COMPILE_PCRE32
1090  #endif          if (utf && c > 0x10ffff) { overflow = TRUE; break; }
1091  #endif  #endif
1092          }          }
1093    
1094        if (c < 0)        if (overflow)
1095          {          {
1096          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1097          *errorcodeptr = ERR34;          *errorcodeptr = ERR34;
# Line 1100  else Line 1113  else
1113      c = 0;      c = 0;
1114      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1115        {        {
1116        int cc;                                  /* Some compilers don't like */        pcre_uint32 cc;                          /* Some compilers don't like */
1117        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
1118  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1119        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */
# Line 1159  else Line 1172  else
1172  newline". PCRE does not support \N{name}. However, it does support  newline". PCRE does not support \N{name}. However, it does support
1173  quantification such as \N{2,3}. */  quantification such as \N{2,3}. */
1174    
1175  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&  if (escape == ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1176       !is_counted_repeat(ptr+2))       !is_counted_repeat(ptr+2))
1177    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1178    
1179  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
1180    
1181  if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)  if ((options & PCRE_UCP) != 0 && escape >= ESC_D && escape <= ESC_w)
1182    c -= (ESC_DU - ESC_D);    escape += (ESC_DU - ESC_D);
1183    
1184  /* Set the pointer to the final character before returning. */  /* Set the pointer to the final character before returning. */
1185    
1186  *ptrptr = ptr;  *ptrptr = ptr;
1187  return c;  *chptr = c;
1188    return escape;
1189  }  }
1190    
   
   
1191  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1192  /*************************************************  /*************************************************
1193  *               Handle \P and \p                 *  *               Handle \P and \p                 *
# Line 1198  Returns:         type value from ucp_typ Line 1210  Returns:         type value from ucp_typ
1210  static int  static int
1211  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)
1212  {  {
1213  int c, i, bot, top;  pcre_uchar c;
1214    int i, bot, top;
1215  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
1216  pcre_uchar name[32];  pcre_uchar name[32];
1217    
# Line 1245  top = PRIV(utt_size); Line 1258  top = PRIV(utt_size);
1258    
1259  while (bot < top)  while (bot < top)
1260    {    {
1261      int r;
1262    i = (bot + top) >> 1;    i = (bot + top) >> 1;
1263    c = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);    r = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);
1264    if (c == 0)    if (r == 0)
1265      {      {
1266      *dptr = PRIV(utt)[i].value;      *dptr = PRIV(utt)[i].value;
1267      return PRIV(utt)[i].type;      return PRIV(utt)[i].type;
1268      }      }
1269    if (c > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1270    }    }
1271    
1272  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
# Line 1297  int max = -1; Line 1311  int max = -1;
1311  /* Read the minimum value and do a paranoid check: a negative value indicates  /* Read the minimum value and do a paranoid check: a negative value indicates
1312  an integer overflow. */  an integer overflow. */
1313    
1314  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + (int)(*p++ - CHAR_0);
1315  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1316    {    {
1317    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1312  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1326  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1326    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1327      {      {
1328      max = 0;      max = 0;
1329      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + (int)(*p++ - CHAR_0);
1330      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1331        {        {
1332        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1367  Arguments: Line 1381  Arguments:
1381    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1382    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1383    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1384    utf          TRUE if we are in UTF-8 / UTF-16 mode    utf          TRUE if we are in UTF-8 / UTF-16 / UTF-32 mode
1385    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1386    
1387  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
# Line 1443  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1457  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1457      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&
1458          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1459        {        {
1460        int term;        pcre_uchar term;
1461        const pcre_uchar *thisname;        const pcre_uchar *thisname;
1462        *count += 1;        *count += 1;
1463        if (name == NULL && *count == lorn) return *count;        if (name == NULL && *count == lorn) return *count;
# Line 1451  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1465  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1465        if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;        if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;
1466        thisname = ptr;        thisname = ptr;
1467        while (*ptr != term) ptr++;        while (*ptr != term) ptr++;
1468        if (name != NULL && lorn == ptr - thisname &&        if (name != NULL && lorn == (int)(ptr - thisname) &&
1469            STRNCMP_UC_UC(name, thisname, lorn) == 0)            STRNCMP_UC_UC(name, thisname, (unsigned int)lorn) == 0)
1470          return *count;          return *count;
1471        term++;        term++;
1472        }        }
# Line 1601  Arguments: Line 1615  Arguments:
1615    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1616    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1617    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1618    utf          TRUE if we are in UTF-8 / UTF-16 mode    utf          TRUE if we are in UTF-8 / UTF-16 / UTF-32 mode
1619    
1620  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1621  */  */
# Line 1704  and doing the check at the end; a flag s Line 1718  and doing the check at the end; a flag s
1718    
1719  Arguments:  Arguments:
1720    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1721    utf      TRUE in UTF-8 / UTF-16 mode    utf      TRUE in UTF-8 / UTF-16 / UTF-32 mode
1722    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1723    cd       the "compile data" structure    cd       the "compile data" structure
1724    
# Line 1730  for (;;) Line 1744  for (;;)
1744    {    {
1745    int d;    int d;
1746    pcre_uchar *ce, *cs;    pcre_uchar *ce, *cs;
1747    register int op = *cc;    register pcre_uchar op = *cc;
1748    
1749    switch (op)    switch (op)
1750      {      {
# Line 1838  for (;;) Line 1852  for (;;)
1852      case OP_NOTI:      case OP_NOTI:
1853      branchlength++;      branchlength++;
1854      cc += 2;      cc += 2;
1855  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
1856      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1857  #endif  #endif
1858      break;      break;
# Line 1850  for (;;) Line 1864  for (;;)
1864      case OP_EXACTI:      case OP_EXACTI:
1865      case OP_NOTEXACT:      case OP_NOTEXACT:
1866      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1867      branchlength += GET2(cc,1);      branchlength += (int)GET2(cc,1);
1868      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1869  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
1870      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1871  #endif  #endif
1872      break;      break;
# Line 1895  for (;;) Line 1909  for (;;)
1909    
1910      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1911    
1912  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1913      case OP_XCLASS:      case OP_XCLASS:
1914      cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];      cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];
1915      /* Fall through */      /* Fall through */
# Line 1918  for (;;) Line 1932  for (;;)
1932        case OP_CRRANGE:        case OP_CRRANGE:
1933        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1934        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1935        branchlength += GET2(cc,1);        branchlength += (int)GET2(cc,1);
1936        cc += 1 + 2 * IMM2_SIZE;        cc += 1 + 2 * IMM2_SIZE;
1937        break;        break;
1938    
# Line 2034  length. Line 2048  length.
2048    
2049  Arguments:  Arguments:
2050    code        points to start of expression    code        points to start of expression
2051    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
2052    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
2053    
2054  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
# Line 2045  PRIV(find_bracket)(const pcre_uchar *cod Line 2059  PRIV(find_bracket)(const pcre_uchar *cod
2059  {  {
2060  for (;;)  for (;;)
2061    {    {
2062    register int c = *code;    register pcre_uchar c = *code;
2063    
2064    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
2065    
# Line 2068  for (;;) Line 2082  for (;;)
2082    else if (c == OP_CBRA || c == OP_SCBRA ||    else if (c == OP_CBRA || c == OP_SCBRA ||
2083             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
2084      {      {
2085      int n = GET2(code, 1+LINK_SIZE);      int n = (int)GET2(code, 1+LINK_SIZE);
2086      if (n == number) return (pcre_uchar *)code;      if (n == number) return (pcre_uchar *)code;
2087      code += PRIV(OP_lengths)[c];      code += PRIV(OP_lengths)[c];
2088      }      }
# Line 2121  for (;;) Line 2135  for (;;)
2135    a multi-byte character. The length in the table is a minimum, so we have to    a multi-byte character. The length in the table is a minimum, so we have to
2136    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
2137    
2138  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2139      if (utf) switch(c)      if (utf) switch(c)
2140        {        {
2141        case OP_CHAR:        case OP_CHAR:
# Line 2173  instance of OP_RECURSE. Line 2187  instance of OP_RECURSE.
2187    
2188  Arguments:  Arguments:
2189    code        points to start of expression    code        points to start of expression
2190    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
2191    
2192  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found
2193  */  */
# Line 2241  for (;;) Line 2255  for (;;)
2255      by a multi-byte character. The length in the table is a minimum, so we have      by a multi-byte character. The length in the table is a minimum, so we have
2256      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
2257    
2258  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2259      if (utf) switch(c)      if (utf) switch(c)
2260        {        {
2261        case OP_CHAR:        case OP_CHAR:
# Line 2327  bracket whose current branch will alread Line 2341  bracket whose current branch will alread
2341  Arguments:  Arguments:
2342    code        points to start of search    code        points to start of search
2343    endcode     points to where to stop    endcode     points to where to stop
2344    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2345    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2346    
2347  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2560  for (code = first_significant_code(code Line 2574  for (code = first_significant_code(code
2574      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
2575      MINUPTO, and POSUPTO may be followed by a multibyte character */      MINUPTO, and POSUPTO may be followed by a multibyte character */
2576    
2577  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2578      case OP_STAR:      case OP_STAR:
2579      case OP_STARI:      case OP_STARI:
2580      case OP_MINSTAR:      case OP_MINSTAR:
# Line 2626  Arguments: Line 2640  Arguments:
2640    code        points to start of the recursion    code        points to start of the recursion
2641    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2642    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2643    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2644    cd          pointers to tables etc    cd          pointers to tables etc
2645    
2646  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2773  value in the reference (which is a group Line 2787  value in the reference (which is a group
2787  Arguments:  Arguments:
2788    group      points to the start of the group    group      points to the start of the group
2789    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2790    utf        TRUE in UTF-8 / UTF-16 mode    utf        TRUE in UTF-8 / UTF-16 / UTF-32 mode
2791    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2792    save_hwm   the hwm forward reference pointer at the start of the group    save_hwm   the hwm forward reference pointer at the start of the group
2793    
# Line 2895  Yield:        -1 when no more Line 2909  Yield:        -1 when no more
2909  */  */
2910    
2911  static int  static int
2912  get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,  get_othercase_range(pcre_uint32 *cptr, pcre_uint32 d, pcre_uint32 *ocptr,
2913    unsigned int *odptr)    pcre_uint32 *odptr)
2914  {  {
2915  unsigned int c, othercase, next;  pcre_uint32 c, othercase, next;
2916  int co;  int co;
2917    
2918  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
# Line 2950  Returns:       TRUE if auto-possessifyin Line 2964  Returns:       TRUE if auto-possessifyin
2964  */  */
2965    
2966  static BOOL  static BOOL
2967  check_char_prop(int c, int ptype, int pdata, BOOL negated)  check_char_prop(pcre_uint32 c, int ptype, int pdata, BOOL negated)
2968  {  {
2969  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2970  const pcre_uint32 *p;  const pcre_uint32 *p;
# Line 3024  sense to automatically possessify the re Line 3038  sense to automatically possessify the re
3038    
3039  Arguments:  Arguments:
3040    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
3041    utf           TRUE in UTF-8 / UTF-16 mode    utf           TRUE in UTF-8 / UTF-16 / UTF-32 mode
3042    ptr           next character in pattern    ptr           next character in pattern
3043    options       options bits    options       options bits
3044    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 3036  static BOOL Line 3050  static BOOL
3050  check_auto_possessive(const pcre_uchar *previous, BOOL utf,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
3051    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
3052  {  {
3053  pcre_int32 c, next;  pcre_uint32 c = NOTACHAR;
3054    pcre_uint32 next;
3055    int escape;
3056  int op_code = *previous++;  int op_code = *previous++;
3057    
3058  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 3068  value is a character, a negative value i Line 3084  value is a character, a negative value i
3084  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3085    {    {
3086    int temperrorcode = 0;    int temperrorcode = 0;
3087    next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);
3088    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3089    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3090    }    }
3091  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
3092    {    {
3093      escape = 0;
3094  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3095    if (utf) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
3096  #endif  #endif
# Line 3114  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3131  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3131    
3132  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3133      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
3134      //if (escape == 0) switch(op_code)
3135    {    {
3136  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3137    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3123  if (op_code == OP_CHAR || op_code == OP_ Line 3141  if (op_code == OP_CHAR || op_code == OP_
3141    }    }
3142    
3143  /* Now compare the next item with the previous opcode. First, handle cases when  /* Now compare the next item with the previous opcode. First, handle cases when
3144  the next item is a character. For a caseless UTF match, the next character may  the next item is a character. */
 have more than one other case; convert this to a special property. */  
3145    
3146  if (next >= 0)  if (escape == 0)
3147    {    {
3148      /* For a caseless UTF match, the next character may have more than one other
3149      case, which maps to the special PT_CLIST property. Check this first. */
3150    
3151  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3152    if (utf && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3153      {      {
3154      int ocs = UCD_CASESET(next);      int ocs = UCD_CASESET(next);
3155      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, FALSE);      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);
3156      }      }
3157  #endif  #endif
3158    
# Line 3151  if (next >= 0) Line 3171  if (next >= 0)
3171  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3172      if (utf)      if (utf)
3173        {        {
3174        unsigned int othercase;        pcre_uint32 othercase;
3175        if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3176  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3177        othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3178  #else  #else
3179        othercase = NOTACHAR;        othercase = NOTACHAR;
3180  #endif  #endif
3181        return (unsigned int)c != othercase;        return c != othercase;
3182        }        }
3183      else      else
3184  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3185      return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3186    
3187      case OP_NOT:      case OP_NOT:
3188      return c == next;      return c == next;
# Line 3172  if (next >= 0) Line 3192  if (next >= 0)
3192  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3193      if (utf)      if (utf)
3194        {        {
3195        unsigned int othercase;        pcre_uint32 othercase;
3196        if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3197  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3198        othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3199  #else  #else
3200        othercase = NOTACHAR;        othercase = NOTACHAR;
3201  #endif  #endif
3202        return (unsigned int)c == othercase;        return c == othercase;
3203        }        }
3204      else      else
3205  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3206      return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Not UTF */      return (c == TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3207    
3208      /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.      /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
3209      When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */      When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
# Line 3252  switch(op_code) Line 3272  switch(op_code)
3272    {    {
3273    case OP_CHAR:    case OP_CHAR:
3274    case OP_CHARI:    case OP_CHARI:
3275    switch(-next)    switch(escape)
3276      {      {
3277      case ESC_d:      case ESC_d:
3278      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;
# Line 3277  switch(op_code) Line 3297  switch(op_code)
3297      switch(c)      switch(c)
3298        {        {
3299        HSPACE_CASES:        HSPACE_CASES:
3300        return -next != ESC_h;        return escape != ESC_h;
3301    
3302        default:        default:
3303        return -next == ESC_h;        return escape == ESC_h;
3304        }        }
3305    
3306      case ESC_v:      case ESC_v:
# Line 3288  switch(op_code) Line 3308  switch(op_code)
3308      switch(c)      switch(c)
3309        {        {
3310        VSPACE_CASES:        VSPACE_CASES:
3311        return -next != ESC_v;        return escape != ESC_v;
3312    
3313        default:        default:
3314        return -next == ESC_v;        return escape == ESC_v;
3315        }        }
3316    
3317      /* When PCRE_UCP is set, these values get generated for \d etc. Find      /* When PCRE_UCP is set, these values get generated for \d etc. Find
3318      their substitutions and process them. The result will always be either      their substitutions and process them. The result will always be either
3319      -ESC_p or -ESC_P. Then fall through to process those values. */      ESC_p or ESC_P. Then fall through to process those values. */
3320    
3321  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3322      case ESC_du:      case ESC_du:
# Line 3307  switch(op_code) Line 3327  switch(op_code)
3327      case ESC_SU:      case ESC_SU:
3328        {        {
3329        int temperrorcode = 0;        int temperrorcode = 0;
3330        ptr = substitutes[-next - ESC_DU];        ptr = substitutes[escape - ESC_DU];
3331        next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);        escape = check_escape(&ptr, &next, &temperrorcode, 0, options, FALSE);
3332        if (temperrorcode != 0) return FALSE;        if (temperrorcode != 0) return FALSE;
3333        ptr++;    /* For compatibility */        ptr++;    /* For compatibility */
3334        }        }
# Line 3335  switch(op_code) Line 3355  switch(op_code)
3355    
3356        /* Do the property check. */        /* Do the property check. */
3357    
3358        return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);        return check_char_prop(c, ptype, pdata, (escape == ESC_P) != negated);
3359        }        }
3360  #endif  #endif
3361    
# Line 3350  switch(op_code) Line 3370  switch(op_code)
3370    these op-codes are never generated.) */    these op-codes are never generated.) */
3371    
3372    case OP_DIGIT:    case OP_DIGIT:
3373    return next == -ESC_D || next == -ESC_s || next == -ESC_W ||    return escape == ESC_D || escape == ESC_s || escape == ESC_W ||
3374           next == -ESC_h || next == -ESC_v || next == -ESC_R;           escape == ESC_h || escape == ESC_v || escape == ESC_R;
3375    
3376    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3377    return next == -ESC_d;    return escape == ESC_d;
3378    
3379    case OP_WHITESPACE:    case OP_WHITESPACE:
3380    return next == -ESC_S || next == -ESC_d || next == -ESC_w;    return escape == ESC_S || escape == ESC_d || escape == ESC_w;
3381    
3382    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3383    return next == -ESC_s || next == -ESC_h || next == -ESC_v || next == -ESC_R;    return escape == ESC_s || escape == ESC_h || escape == ESC_v || escape == ESC_R;
3384    
3385    case OP_HSPACE:    case OP_HSPACE:
3386    return next == -ESC_S || next == -ESC_H || next == -ESC_d ||    return escape == ESC_S || escape == ESC_H || escape == ESC_d ||
3387           next == -ESC_w || next == -ESC_v || next == -ESC_R;           escape == ESC_w || escape == ESC_v || escape == ESC_R;
3388    
3389    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3390    return next == -ESC_h;    return escape == ESC_h;
3391    
3392    /* Can't have \S in here because VT matches \S (Perl anomaly) */    /* Can't have \S in here because VT matches \S (Perl anomaly) */
3393    case OP_ANYNL:    case OP_ANYNL:
3394    case OP_VSPACE:    case OP_VSPACE:
3395    return next == -ESC_V || next == -ESC_d || next == -ESC_w;    return escape == ESC_V || escape == ESC_d || escape == ESC_w;
3396    
3397    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3398    return next == -ESC_v || next == -ESC_R;    return escape == ESC_v || escape == ESC_R;
3399    
3400    case OP_WORDCHAR:    case OP_WORDCHAR:
3401    return next == -ESC_W || next == -ESC_s || next == -ESC_h ||    return escape == ESC_W || escape == ESC_s || escape == ESC_h ||
3402           next == -ESC_v || next == -ESC_R;           escape == ESC_v || escape == ESC_R;
3403    
3404    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3405    return next == -ESC_w || next == -ESC_d;    return escape == ESC_w || escape == ESC_d;
3406    
3407    default:    default:
3408    return FALSE;    return FALSE;
# Line 3416  Returns:        the number of < 256 char Line 3436  Returns:        the number of < 256 char
3436    
3437  static int  static int
3438  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3439    compile_data *cd, unsigned int start, unsigned int end)    compile_data *cd, pcre_uint32 start, pcre_uint32 end)
3440  {  {
3441  unsigned int c;  pcre_uint32 c;
3442  int n8 = 0;  int n8 = 0;
3443    
3444  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
# Line 3432  if ((options & PCRE_CASELESS) != 0) Line 3452  if ((options & PCRE_CASELESS) != 0)
3452    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3453      {      {
3454      int rc;      int rc;
3455      unsigned int oc, od;      pcre_uint32 oc, od;
3456    
3457      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3458      c = start;      c = start;
# Line 3473  if ((options & PCRE_CASELESS) != 0) Line 3493  if ((options & PCRE_CASELESS) != 0)
3493  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3494  in all cases. */  in all cases. */
3495    
3496  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3497  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3498    if ((options & PCRE_UTF8) == 0)    if ((options & PCRE_UTF8) == 0)
3499  #endif  #endif
3500    if (end > 0xff) end = 0xff;    if (end > 0xff) end = 0xff;
 #endif  
3501    
3502  #ifdef COMPILE_PCRE16  #elif defined COMPILE_PCRE16
3503  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3504    if ((options & PCRE_UTF16) == 0)    if ((options & PCRE_UTF16) == 0)
3505  #endif  #endif
3506    if (end > 0xffff) end = 0xffff;    if (end > 0xffff) end = 0xffff;
3507  #endif  
3508    #endif /* COMPILE_PCRE[8|16] */
3509    
3510  /* If all characters are less than 256, use the bit map. Otherwise use extra  /* If all characters are less than 256, use the bit map. Otherwise use extra
3511  data. */  data. */
# Line 3615  static int Line 3635  static int
3635  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3636    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3637  {  {
3638    BOOL utf = (options & PCRE_UTF8) != 0;
3639  int n8 = 0;  int n8 = 0;
3640  if (p[0] > 0)  if (p[0] > 0)
3641    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3642  while (p[0] < NOTACHAR)  while (p[0] < NOTACHAR)
3643    {    {
3644    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3645    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3646      (p[1] == NOTACHAR)? 0x10ffff : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3647    p++;    p++;
3648    }    }
3649  return n8;  return n8;
# Line 3673  pcre_int32 req_caseopt, reqvary, tempreq Line 3694  pcre_int32 req_caseopt, reqvary, tempreq
3694  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3695  int after_manual_callout = 0;  int after_manual_callout = 0;
3696  int length_prevgroup = 0;  int length_prevgroup = 0;
3697  register int c;  register pcre_uint32 c;
3698    int escape;
3699  register pcre_uchar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3700  pcre_uchar *last_code = code;  pcre_uchar *last_code = code;
3701  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
# Line 3693  must not do this for other options (e.g. Line 3715  must not do this for other options (e.g.
3715  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3716    
3717  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3718  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3719  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3720  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3721  #else  #else
# Line 3761  for (;; ptr++) Line 3783  for (;; ptr++)
3783    int terminator;    int terminator;
3784    int mclength;    int mclength;
3785    int tempbracount;    int tempbracount;
3786      int ec; // FIXMEchpe pcre_uint32
3787    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3788    
3789    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 4078  for (;; ptr++) Line 4101  for (;; ptr++)
4101        {        {
4102        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
4103    
4104  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4105        if (utf && HAS_EXTRALEN(c))        if (utf && HAS_EXTRALEN(c))
4106          {                           /* Braces are required because the */          {                           /* Braces are required because the */
4107          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
# Line 4230  for (;; ptr++) Line 4253  for (;; ptr++)
4253    
4254        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4255          {          {
4256          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);
4257    
4258          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4259    
4260          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          if (escape == 0)
4261          else if (-c == ESC_N)            /* \N is not supported in a class */            c = ec;
4262            else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4263            else if (escape == ESC_N)            /* \N is not supported in a class */
4264            {            {
4265            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4266            goto FAILED;            goto FAILED;
4267            }            }
4268          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (escape == ESC_Q)            /* Handle start of quoted string */
4269            {            {
4270            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
4271              {              {
# Line 4248  for (;; ptr++) Line 4274  for (;; ptr++)
4274            else inescq = TRUE;            else inescq = TRUE;
4275            continue;            continue;
4276            }            }
4277          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (escape == ESC_E) continue;  /* Ignore orphan \E */
4278    
4279          if (c < 0)          else
4280            {            {
4281            register const pcre_uint8 *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
4282            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
# Line 4258  for (;; ptr++) Line 4284  for (;; ptr++)
4284            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4285            class_one_char += 2;            class_one_char += 2;
4286    
4287            switch (-c)            switch (escape)
4288              {              {
4289  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4290              case ESC_du:     /* These are the values given for \d etc */              case ESC_du:     /* These are the values given for \d etc */
# Line 4268  for (;; ptr++) Line 4294  for (;; ptr++)
4294              case ESC_su:     /* of the default ASCII testing. */              case ESC_su:     /* of the default ASCII testing. */
4295              case ESC_SU:              case ESC_SU:
4296              nestptr = ptr;              nestptr = ptr;
4297              ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */              ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
4298              class_has_8bitchar--;                /* Undo! */              class_has_8bitchar--;                /* Undo! */
4299              continue;              continue;
4300  #endif  #endif
# Line 4337  for (;; ptr++) Line 4363  for (;; ptr++)
4363                int pdata;                int pdata;
4364                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4365                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
4366                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4367                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4368                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
4369                *class_uchardata++ = pdata;                *class_uchardata++ = pdata;
# Line 4365  for (;; ptr++) Line 4391  for (;; ptr++)
4391          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4392          This may be greater than 256. */          This may be greater than 256. */
4393    
4394            escape = 0;
4395    
4396          }   /* End of backslash handling */          }   /* End of backslash handling */
4397    
4398        /* A character may be followed by '-' to form a range. However, Perl does        /* A character may be followed by '-' to form a range. However, Perl does
# Line 4430  for (;; ptr++) Line 4458  for (;; ptr++)
4458    
4459          if (!inescq && d == CHAR_BACKSLASH)          if (!inescq && d == CHAR_BACKSLASH)
4460            {            {
4461            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            int descape;
4462              descape = check_escape(&ptr, &d, errorcodeptr, cd->bracount, options, TRUE);
4463            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4464    
4465            /* \b is backspace; any other special means the '-' was literal. */            /* \b is backspace; any other special means the '-' was literal. */
4466    
4467            if (d < 0)            if (descape != 0)
4468              {              {
4469              if (d == -ESC_b) d = CHAR_BS; else              if (descape == ESC_b) d = CHAR_BS; else
4470                {                {
4471                ptr = oldptr;                ptr = oldptr;
4472                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
# Line 4497  for (;; ptr++) Line 4526  for (;; ptr++)
4526          if (negate_class)          if (negate_class)
4527            {            {
4528  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4529                // FIXMEchpe pcreuint32?
4530            int d;            int d;
4531  #endif  #endif
4532            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 4520  for (;; ptr++) Line 4550  for (;; ptr++)
4550    
4551              {              {
4552              *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;              *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4553  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4554              if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)              if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4555                code += PRIV(ord2utf)(c, code);                code += PRIV(ord2utf)(c, code);
4556              else              else
# Line 4536  for (;; ptr++) Line 4566  for (;; ptr++)
4566          /* For a single, positive character, get the value into mcbuffer, and          /* For a single, positive character, get the value into mcbuffer, and
4567          then we can handle this with the normal one-character code. */          then we can handle this with the normal one-character code. */
4568    
4569  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4570          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4571            mclength = PRIV(ord2utf)(c, mcbuffer);            mclength = PRIV(ord2utf)(c, mcbuffer);
4572          else          else
# Line 4771  for (;; ptr++) Line 4801  for (;; ptr++)
4801        hold the length of the character in bytes, plus UTF_LENGTH to flag that        hold the length of the character in bytes, plus UTF_LENGTH to flag that
4802        it's a length rather than a small character. */        it's a length rather than a small character. */
4803    
4804  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4805        if (utf && NOT_FIRSTCHAR(code[-1]))        if (utf && NOT_FIRSTCHAR(code[-1]))
4806          {          {
4807          pcre_uchar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
# Line 4907  for (;; ptr++) Line 4937  for (;; ptr++)
4937    
4938          if (repeat_max < 0)          if (repeat_max < 0)
4939            {            {
4940  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4941            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4942              {              {
4943              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4932  for (;; ptr++) Line 4962  for (;; ptr++)
4962    
4963          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4964            {            {
4965  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4966            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4967              {              {
4968              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4962  for (;; ptr++) Line 4992  for (;; ptr++)
4992    
4993        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4994    
4995  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4996        if (utf && (c & UTF_LENGTH) != 0)        if (utf && (c & UTF_LENGTH) != 0)
4997          {          {
4998          memcpy(code, utf_chars, IN_UCHARS(c & 7));          memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 5449  for (;; ptr++) Line 5479  for (;; ptr++)
5479        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5480          {          {
5481          tempcode += PRIV(OP_lengths)[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5482  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
5483          if (utf && HAS_EXTRALEN(tempcode[-1]))          if (utf && HAS_EXTRALEN(tempcode[-1]))
5484            tempcode += GET_EXTRALEN(tempcode[-1]);            tempcode += GET_EXTRALEN(tempcode[-1]);
5485  #endif  #endif
# Line 5547  for (;; ptr++) Line 5577  for (;; ptr++)
5577          arg = ++ptr;          arg = ++ptr;
5578          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5579          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5580          if (arglen > (int)MAX_MARK)          if ((unsigned int)arglen > MAX_MARK)
5581            {            {
5582            *errorcodeptr = ERR75;            *errorcodeptr = ERR75;
5583            goto FAILED;            goto FAILED;
# Line 6648  for (;; ptr++) Line 6678  for (;; ptr++)
6678      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
6679      are arranged to be the negation of the corresponding OP_values in the      are arranged to be the negation of the corresponding OP_values in the
6680      default case when PCRE_UCP is not set. For the back references, the values      default case when PCRE_UCP is not set. For the back references, the values
6681      are ESC_REF plus the reference number. Only back references and those types      are negative the reference number. Only back references and those types
6682      that consume a character may be repeated. We can test for values between      that consume a character may be repeated. We can test for values between
6683      ESC_b and ESC_Z for the latter; this may have to change if any new ones are      ESC_b and ESC_Z for the latter; this may have to change if any new ones are
6684      ever created. */      ever created. */
6685    
6686      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6687      tempptr = ptr;      tempptr = ptr;
6688      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
6689    
6690      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6691    
6692      if (c < 0)      if (escape == 0)
6693          c = ec;
6694        else
6695        {        {
6696        if (-c == ESC_Q)            /* Handle start of quoted string */        if (escape == ESC_Q)            /* Handle start of quoted string */
6697          {          {
6698          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
6699            ptr += 2;               /* avoid empty string */            ptr += 2;               /* avoid empty string */
# Line 6668  for (;; ptr++) Line 6701  for (;; ptr++)
6701          continue;          continue;
6702          }          }
6703    
6704        if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */        if (escape == ESC_E) continue;  /* Perl ignores an orphan \E */
6705    
6706        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6707        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6708    
6709        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6710          firstchar = REQ_NONE;          firstchar = REQ_NONE;
6711    
6712        /* Set values to reset to if this is followed by a zero repeat. */        /* Set values to reset to if this is followed by a zero repeat. */
# Line 6683  for (;; ptr++) Line 6716  for (;; ptr++)
6716    
6717        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
6718        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
6719        -ESC_g is returned only for these cases. So we don't need to check for <        ESC_g is returned only for these cases. So we don't need to check for <
6720        or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is        or ' if the value is ESC_g. For the Perl syntax \g{n} the value is
6721        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as        -n, and for the Perl syntax \g{name} the result is ESC_k (as
6722        that is a synonym for a named back reference). */        that is a synonym for a named back reference). */
6723    
6724        if (-c == ESC_g)        if (escape == ESC_g)
6725          {          {
6726          const pcre_uchar *p;          const pcre_uchar *p;
6727          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
# Line 6744  for (;; ptr++) Line 6777  for (;; ptr++)
6777        /* \k<name> or \k'name' is a back reference by name (Perl syntax).        /* \k<name> or \k'name' is a back reference by name (Perl syntax).
6778        We also support \k{name} (.NET syntax).  */        We also support \k{name} (.NET syntax).  */
6779    
6780        if (-c == ESC_k)        if (escape == ESC_k)
6781          {          {
6782          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
6783            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
# Line 6763  for (;; ptr++) Line 6796  for (;; ptr++)
6796        not set to cope with cases like (?=(\w+))\1: which would otherwise set        not set to cope with cases like (?=(\w+))\1: which would otherwise set
6797        ':' later. */        ':' later. */
6798    
6799        if (-c >= ESC_REF)        if (escape < 0)
6800          {          {
6801          open_capitem *oc;          open_capitem *oc;
6802          recno = -c - ESC_REF;          recno = -escape;
6803    
6804          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6805          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
# Line 6793  for (;; ptr++) Line 6826  for (;; ptr++)
6826        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
6827    
6828  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6829        else if (-c == ESC_P || -c == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6830          {          {
6831          BOOL negated;          BOOL negated;
6832          int pdata;          int pdata;
6833          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
6834          if (ptype < 0) goto FAILED;          if (ptype < 0) goto FAILED;
6835          previous = code;          previous = code;
6836          *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6837          *code++ = ptype;          *code++ = ptype;
6838          *code++ = pdata;          *code++ = pdata;
6839          }          }
# Line 6809  for (;; ptr++) Line 6842  for (;; ptr++)
6842        /* If Unicode properties are not supported, \X, \P, and \p are not        /* If Unicode properties are not supported, \X, \P, and \p are not
6843        allowed. */        allowed. */
6844    
6845        else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)        else if (escape == ESC_X || escape == ESC_P || escape == ESC_p)
6846          {          {
6847          *errorcodeptr = ERR45;          *errorcodeptr = ERR45;
6848          goto FAILED;          goto FAILED;
# Line 6824  for (;; ptr++) Line 6857  for (;; ptr++)
6857    
6858        else        else
6859          {          {
6860          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)
6861            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6862  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6863          if (-c >= ESC_DU && -c <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
6864            {            {
6865            nestptr = ptr + 1;                   /* Where to resume */            nestptr = ptr + 1;                   /* Where to resume */
6866            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */            ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
6867            }            }
6868          else          else
6869  #endif  #endif
# Line 6838  for (;; ptr++) Line 6871  for (;; ptr++)
6871          so that it works in DFA mode and in lookbehinds. */          so that it works in DFA mode and in lookbehinds. */
6872    
6873            {            {
6874            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (escape > ESC_b && escape < ESC_Z)? code : NULL;
6875            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && escape == ESC_C)? OP_ALLANY : escape;
6876            }            }
6877          }          }
6878        continue;        continue;
# Line 6849  for (;; ptr++) Line 6882  for (;; ptr++)
6882      a value > 127. We set its representation in the length/buffer, and then      a value > 127. We set its representation in the length/buffer, and then
6883      handle it as a data character. */      handle it as a data character. */
6884    
6885  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
6886      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
6887        mclength = PRIV(ord2utf)(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6888      else      else
# Line 6872  for (;; ptr++) Line 6905  for (;; ptr++)
6905      mclength = 1;      mclength = 1;
6906      mcbuffer[0] = c;      mcbuffer[0] = c;
6907    
6908  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
6909      if (utf && HAS_EXTRALEN(c))      if (utf && HAS_EXTRALEN(c))
6910        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));
6911  #endif  #endif
# Line 7603  Returns:        pointer to compiled data Line 7636  Returns:        pointer to compiled data
7636                  with errorptr and erroroffset set                  with errorptr and erroroffset set
7637  */  */
7638    
7639  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7640  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7641  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
7642    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7643  #else  #elif defined COMPILE_PCRE16
7644  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7645  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,
7646    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7647    #elif defined COMPILE_PCRE32
7648    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7649    pcre32_compile(PCRE_SPTR32 pattern, int options, const char **errorptr,
7650      int *erroroffset, const unsigned char *tables)
7651  #endif  #endif
7652  {  {
7653  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7654  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7655  #else  #elif defined COMPILE_PCRE16
7656  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7657    #elif defined COMPILE_PCRE32
7658    return pcre32_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7659  #endif  #endif
7660  }  }
7661    
7662    
7663  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7664  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7665  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
7666    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7667  #else  #elif defined COMPILE_PCRE16
7668  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7669  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,
7670    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7671    #elif defined COMPILE_PCRE32
7672    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7673    pcre32_compile2(PCRE_SPTR32 pattern, int options, int *errorcodeptr,
7674      const char **errorptr, int *erroroffset, const unsigned char *tables)
7675  #endif  #endif
7676  {  {
7677  REAL_PCRE *re;  REAL_PCRE *re;
# Line 7714  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7757  while (ptr[skipatstart] == CHAR_LEFT_PAR
7757    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)
7758      { skipatstart += 8; options |= PCRE_UTF16; continue; }      { skipatstart += 8; options |= PCRE_UTF16; continue; }
7759  #endif  #endif
7760    #ifdef COMPILE_PCRE32
7761      if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)
7762        { skipatstart += 8; options |= PCRE_UTF32; continue; }
7763    #endif
7764    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7765      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7766    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
# Line 7742  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7789  while (ptr[skipatstart] == CHAR_LEFT_PAR
7789    else break;    else break;
7790    }    }
7791    
7792  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
7793  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
7794    
7795  /* Can't support UTF unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
# Line 7754  not used here. */ Line 7801  not used here. */
7801  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&
7802       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)
7803    {    {
7804  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7805    errorcode = ERR44;    errorcode = ERR44;
7806  #else  #elif defined COMPILE_PCRE16
7807    errorcode = ERR74;    errorcode = ERR74;
7808    #elif defined COMPILE_PCRE32
7809      errorcode = ERR77;
7810  #endif  #endif
7811    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7812    }    }
# Line 7921  re->name_count = cd->names_found; Line 7970  re->name_count = cd->names_found;
7970  re->ref_count = 0;  re->ref_count = 0;
7971  re->tables = (tables == PRIV(default_tables))? NULL : tables;  re->tables = (tables == PRIV(default_tables))? NULL : tables;
7972  re->nullpad = NULL;  re->nullpad = NULL;
7973    #ifdef COMPILE_PCRE32
7974    re->dummy1 = re->dummy2 = 0;
7975    #endif
7976    
7977  /* The starting points of the name/number translation table and of the code are  /* The starting points of the name/number translation table and of the code are
7978  passed around in the compile data block. The start/end pattern and initial  passed around in the compile data block. The start/end pattern and initial
# Line 8083  if ((re->options & PCRE_ANCHORED) == 0) Line 8135  if ((re->options & PCRE_ANCHORED) == 0)
8135        firstchar = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, FALSE);
8136      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */
8137        {        {
8138  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8139        re->first_char = firstchar & 0xff;        re->first_char = firstchar & 0xff;
8140  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
8141        re->first_char = firstchar & 0xffff;        re->first_char = firstchar & 0xffff;
8142  #endif  #elif defined COMPILE_PCRE32
8143          re->first_char = firstchar & ~REQ_MASK;
8144  #endif  #endif
8145        if ((firstchar & REQ_CASELESS) != 0)        if ((firstchar & REQ_CASELESS) != 0)
8146          {          {
# Line 8125  bytes. */ Line 8177  bytes. */
8177  if (reqchar >= 0 &&  if (reqchar >= 0 &&
8178       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))
8179    {    {
8180  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8181    re->req_char = reqchar & 0xff;    re->req_char = reqchar & 0xff;
8182  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
8183    re->req_char = reqchar & 0xffff;    re->req_char = reqchar & 0xffff;
8184  #endif  #elif defined COMPILE_PCRE32
8185      re->req_char = reqchar & ~REQ_MASK;
8186  #endif  #endif
8187    if ((reqchar & REQ_CASELESS) != 0)    if ((reqchar & REQ_CASELESS) != 0)
8188      {      {
# Line 8182  if ((re->flags & PCRE_REQCHSET) != 0) Line 8234  if ((re->flags & PCRE_REQCHSET) != 0)
8234      else printf("Req char = \\x%02x%s\n", ch, caseless);      else printf("Req char = \\x%02x%s\n", ch, caseless);
8235    }    }
8236    
8237  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8238  pcre_printint((pcre *)re, stdout, TRUE);  pcre_printint((pcre *)re, stdout, TRUE);
8239  #else  #elif defined COMPILE_PCRE16
8240  pcre16_printint((pcre *)re, stdout, TRUE);  pcre16_printint((pcre *)re, stdout, TRUE);
8241    #elif defined COMPILE_PCRE32
8242    pcre32_printint((pcre *)re, stdout, TRUE);
8243  #endif  #endif
8244    
8245  /* This check is done here in the debugging case so that the code that  /* This check is done here in the debugging case so that the code that
# Line 8201  if (code - codestart > length) Line 8255  if (code - codestart > length)
8255    }    }
8256  #endif   /* PCRE_DEBUG */  #endif   /* PCRE_DEBUG */
8257    
8258  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8259  return (pcre *)re;  return (pcre *)re;
8260  #else  #elif defined COMPILE_PCRE16
8261  return (pcre16 *)re;  return (pcre16 *)re;
8262    #elif defined COMPILE_PCRE32
8263    return (pcre32 *)re;
8264  #endif  #endif
8265  }  }
8266    

Legend:
Removed from v.1047  
changed lines
  Added in v.1069

  ViewVC Help
Powered by ViewVC 1.1.5