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

Diff of /code/trunk/pcretest.c

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

revision 1113 by chpe, Tue Oct 16 15:57:12 2012 UTC revision 1117 by chpe, Tue Oct 16 15:57:27 2012 UTC
# Line 399  argument, the casting might be incorrect Line 399  argument, the casting might be incorrect
399  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
400    
401  #define PCHARS32(lv, p, offset, len, f) \  #define PCHARS32(lv, p, offset, len, f) \
402    lv = pchars32((PCRE_SPTR32)(p) + offset, len, f)    lv = pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
403    
404  #define PCHARSV32(p, offset, len, f) \  #define PCHARSV32(p, offset, len, f)                \
405    (void)pchars32((PCRE_SPTR32)(p) + offset, len, f)    (void)pchars32((PCRE_SPTR32)(p) + offset, len, use_utf, f)
406    
407  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \  #define READ_CAPTURE_NAME32(p, cn8, cn16, cn32, re) \
408    p = read_capture_name32(p, cn32, re)    p = read_capture_name32(p, cn32, re)
# Line 1589  else Line 1589  else
1589  *pp = 0;  *pp = 0;
1590  return pp - buffer32;  return pp - buffer32;
1591  }  }
1592    
1593    /* Check that a 32-bit character string is valid UTF-32.
1594    
1595    Arguments:
1596      string       points to the string
1597      length       length of string, or -1 if the string is zero-terminated
1598    
1599    Returns:       TRUE  if the string is a valid UTF-32 string
1600                   FALSE otherwise
1601    */
1602    
1603    #ifdef SUPPORT_UTF
1604    static BOOL
1605    valid_utf32(pcre_uint32 *string, int length)
1606    {
1607    register pcre_uint32 *p;
1608    register pcre_uint32 c;
1609    
1610    for (p = string; length-- > 0; p++)
1611      {
1612      c = *p;
1613    
1614      if (c > 0x10ffffu)
1615        return FALSE;
1616    
1617      /* A surrogate */
1618      if ((c & 0xfffff800u) == 0xd800u)
1619        return FALSE;
1620    
1621      /* Non-character */
1622      if ((c & 0xfffeu) == 0xfffeu ||
1623          c >= 0xfdd0u && c <= 0xfdefu)
1624        return FALSE;
1625      }
1626    
1627    return TRUE;
1628    }
1629    #endif /* SUPPORT_UTF */
1630    
1631  #endif  #endif
1632    
1633  /*************************************************  /*************************************************
# Line 1874  return yield; Line 1913  return yield;
1913  /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.  /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
1914  If handed a NULL file, just counts chars without printing. */  If handed a NULL file, just counts chars without printing. */
1915    
1916  static int pchars32(PCRE_SPTR32 p, int length, FILE *f)  #define UTF32_MASK (0x1fffffu)
1917    
1918    static int pchars32(PCRE_SPTR32 p, int length, BOOL utf, FILE *f)
1919  {  {
1920  int yield = 0;  int yield = 0;
1921    
# Line 1883  if (length < 0) Line 1924  if (length < 0)
1924    
1925  while (length-- > 0)  while (length-- > 0)
1926    {    {
1927    pcre_uint32 c = *p++;    pcre_uint32 c = *p++;
1928      if (utf) c &= UTF32_MASK;
1929    yield += pchar(c, f);    yield += pchar(c, f);
1930    }    }
1931    
# Line 2714  int done = 0; Line 2756  int done = 0;
2756  int all_use_dfa = 0;  int all_use_dfa = 0;
2757  int verify_jit = 0;  int verify_jit = 0;
2758  int yield = 0;  int yield = 0;
2759    int mask_utf32 = 0;
2760  int stack_size;  int stack_size;
2761  pcre_uint8 *dbuffer = NULL;  pcre_uint8 *dbuffer = NULL;
2762  size_t dbuffer_size = 1u << 14;  size_t dbuffer_size = 1u << 14;
# Line 2825  while (argc > 1 && argv[op][0] == '-') Line 2868  while (argc > 1 && argv[op][0] == '-')
2868      exit(1);      exit(1);
2869  #endif  #endif
2870      }      }
2871    else if (strcmp(arg, "-32") == 0)    else if (strcmp(arg, "-32") == 0 || strcmp(arg, "-32+") == 0)
2872      {      {
2873  #ifdef SUPPORT_PCRE32  #ifdef SUPPORT_PCRE32
2874      pcre_mode = PCRE32_MODE;      pcre_mode = PCRE32_MODE;
2875        mask_utf32 = (strcmp(arg, "-32+") == 0);
2876  #else  #else
2877      printf("** This version of PCRE was built without 32-bit support\n");      printf("** This version of PCRE was built without 32-bit support\n");
2878      exit(1);      exit(1);
# Line 4573  while (!done) Line 4617  while (!done)
4617      }      }
4618  #endif  #endif
4619    
4620    #if defined SUPPORT_UTF && defined SUPPORT_PCRE32
4621        /* If we're requsted to test UTF-32 masking of high bits, change the data
4622        string to have high bits set, unless the string is invalid UTF-32.
4623        Since the JIT doesn't support this yet, only do it when not JITing. */
4624        if (use_utf && mask_utf32 && (study_options & PCRE_STUDY_ALLJIT) == 0 &&
4625            valid_utf32((pcre_uint32 *)dbuffer, len))
4626          {
4627          for (q32 = (pcre_uint32 *)dbuffer; *q32; q32++)
4628            *q32 |= ~(pcre_uint32)UTF32_MASK;
4629    
4630          options |= PCRE_NO_UTF32_CHECK;
4631          }
4632    #endif
4633    
4634      /* Move the data to the end of the buffer so that a read over the end of      /* Move the data to the end of the buffer so that a read over the end of
4635      the buffer will be seen by valgrind, even if it doesn't cause a crash. If      the buffer will be seen by valgrind, even if it doesn't cause a crash. If
4636      we are using the POSIX interface, we must include the terminating zero. */      we are using the POSIX interface, we must include the terminating zero. */

Legend:
Removed from v.1113  
changed lines
  Added in v.1117

  ViewVC Help
Powered by ViewVC 1.1.5