/[pcre]/code/branches/pcre16/pcre_printint.src
ViewVC logotype

Diff of /code/branches/pcre16/pcre_printint.src

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

revision 781 by zherczeg, Mon Nov 28 20:39:30 2011 UTC revision 782 by zherczeg, Sat Dec 3 23:58:37 2011 UTC
# Line 72  static const char *OP_names[] = { OP_NAM Line 72  static const char *OP_names[] = { OP_NAM
72  *************************************************/  *************************************************/
73    
74  static int  static int
75  print_char(FILE *f, pcre_uchar *ptr, BOOL utf8)  print_char(FILE *f, pcre_uchar *ptr, BOOL utf)
76  {  {
77  int c = *ptr;  int c = *ptr;
78    
79  #ifndef SUPPORT_UTF8  #ifndef SUPPORT_UTF
80  (void)utf8;  /* Avoid compiler warning */  (void)utf;  /* Avoid compiler warning */
81  if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);  if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
82  return 0;  return 0;
83    
84  #else  #else
85  if (!utf8 || (c & 0xc0) != 0xc0)  
86    #ifdef COMPILE_PCRE8
87    
88    if (!utf || (c & 0xc0) != 0xc0)
89    {    {
90    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
91    return 0;    return 0;
# Line 110  else Line 113  else
113      s -= 6;      s -= 6;
114      c |= (ptr[i] & 0x3f) << s;      c |= (ptr[i] & 0x3f) << s;
115      }      }
116    if (c < 128) fprintf(f, "\\x%02x", c); else fprintf(f, "\\x{%x}", c);    fprintf(f, "\\x{%x}", c);
117    return a;    return a;
118    }    }
119  #endif  
120    #else
121    
122    #ifdef COMPILE_PCRE16
123    
124    if (!utf || (c & 0xfc00) != 0xd800)
125      {
126      if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
127      return 0;
128      }
129    else
130      {
131      /* This is a check for malformed UTF-16; it should only occur if the sanity
132      check has been turned off. Rather than swallow a low surrogate, just stop if
133      we hit a bad one. Print it with \X instead of \x as an indication. */
134    
135      if ((ptr[1] & 0xfc00) != 0xdc00)
136        {
137        fprintf(f, "\\X{%x}", c);
138        return 0;
139        }
140    
141      c = (((c & 0x3ff) << 10) | (ptr[1] & 0x3ff)) + 0x10000;
142      fprintf(f, "\\x{%x}", c);
143      return 1;
144      }
145    
146    #endif /* COMPILE_PCRE16 */
147    
148    #endif /* COMPILE_PCRE8 */
149    
150    #endif /* SUPPORT_UTF */
151  }  }
152    
153  /*************************************************  /*************************************************
154  *  Print uchar string (regardless of utf8)       *  *  Print uchar string (regardless of utf)        *
155  *************************************************/  *************************************************/
156    
157  static void  static void
# Line 168  pcre_printint(pcre *external_re, FILE *f Line 202  pcre_printint(pcre *external_re, FILE *f
202  {  {
203  real_pcre *re = (real_pcre *)external_re;  real_pcre *re = (real_pcre *)external_re;
204  pcre_uchar *codestart, *code;  pcre_uchar *codestart, *code;
205  BOOL utf8;  BOOL utf;
206    
207  unsigned int options = re->options;  unsigned int options = re->options;
208  int offset = re->name_table_offset;  int offset = re->name_table_offset;
# Line 187  if (re->magic_number != MAGIC_NUMBER) Line 221  if (re->magic_number != MAGIC_NUMBER)
221    }    }
222    
223  code = codestart = (pcre_uchar *)re + offset + count * size;  code = codestart = (pcre_uchar *)re + offset + count * size;
224  utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
225    utf = (options & PCRE_UTF8) != 0;
226    
227  for(;;)  for(;;)
228    {    {
# Line 232  for(;;) Line 267  for(;;)
267      do      do
268        {        {
269        code++;        code++;
270        code += 1 + print_char(f, code, utf8);        code += 1 + print_char(f, code, utf);
271        }        }
272      while (*code == OP_CHAR);      while (*code == OP_CHAR);
273      fprintf(f, "\n");      fprintf(f, "\n");
# Line 243  for(;;) Line 278  for(;;)
278      do      do
279        {        {
280        code++;        code++;
281        code += 1 + print_char(f, code, utf8);        code += 1 + print_char(f, code, utf);
282        }        }
283      while (*code == OP_CHARI);      while (*code == OP_CHARI);
284      fprintf(f, "\n");      fprintf(f, "\n");
# Line 349  for(;;) Line 384  for(;;)
384          extra = 2;          extra = 2;
385          }          }
386        }        }
387      else extra = print_char(f, code+1, utf8);      else extra = print_char(f, code+1, utf);
388      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
389      break;      break;
390    
# Line 364  for(;;) Line 399  for(;;)
399      case OP_MINUPTO:      case OP_MINUPTO:
400      case OP_POSUPTO:      case OP_POSUPTO:
401      fprintf(f, " %s ", flag);      fprintf(f, " %s ", flag);
402      extra = print_char(f, code + 1 + IMM2_SIZE, utf8);      extra = print_char(f, code + 1 + IMM2_SIZE, utf);
403      fprintf(f, "{");      fprintf(f, "{");
404      if (*code != OP_EXACT && *code != OP_EXACTI) fprintf(f, "0,");      if (*code != OP_EXACT && *code != OP_EXACTI) fprintf(f, "0,");
405      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
# Line 557  for(;;) Line 592  for(;;)
592            }            }
593          }          }
594    
595        /* Indicate a non-UTF8 class which was created by negation */        /* Indicate a non-UTF class which was created by negation */
596    
597        fprintf(f, "]%s", (*code == OP_NCLASS)? " (neg)" : "");        fprintf(f, "]%s", (*code == OP_NCLASS)? " (neg)" : "");
598    

Legend:
Removed from v.781  
changed lines
  Added in v.782

  ViewVC Help
Powered by ViewVC 1.1.5