/[pcre]/code/branches/pcre16/pcre_get.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_get.c

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

revision 794 by ph10, Mon Nov 21 10:48:42 2011 UTC revision 795 by zherczeg, Sat Dec 10 02:20:06 2011 UTC
# Line 65  Returns:      the number of the named pa Line 65  Returns:      the number of the named pa
65                  (PCRE_ERROR_NOSUBSTRING) if not found                  (PCRE_ERROR_NOSUBSTRING) if not found
66  */  */
67    
68    #ifdef COMPILE_PCRE8
69  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
70  pcre_get_stringnumber(const pcre *code, const char *stringname)  pcre_get_stringnumber(const pcre *code, const char *stringname)
71    #else
72    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
73    pcre16_get_stringnumber(const pcre *code, PCRE_SPTR16 stringname)
74    #endif
75  {  {
76  int rc;  int rc;
77  int entrysize;  int entrysize;
# Line 87  while (top > bot) Line 92  while (top > bot)
92    {    {
93    int mid = (top + bot) / 2;    int mid = (top + bot) / 2;
94    pcre_uchar *entry = nametable + entrysize*mid;    pcre_uchar *entry = nametable + entrysize*mid;
95    int c = strcmp(stringname, (char *)(entry + 2));    int c = STRCMP_UC_UC((pcre_uchar *)stringname,
96        (pcre_uchar *)(entry + IMM2_SIZE));
97    if (c == 0) return (entry[0] << 8) + entry[1];    if (c == 0) return (entry[0] << 8) + entry[1];
98    if (c > 0) bot = mid + 1; else top = mid;    if (c > 0) bot = mid + 1; else top = mid;
99    }    }
# Line 114  Returns:      the length of each entry, Line 120  Returns:      the length of each entry,
120                  (PCRE_ERROR_NOSUBSTRING) if not found                  (PCRE_ERROR_NOSUBSTRING) if not found
121  */  */
122    
123    #ifdef COMPILE_PCRE8
124  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
125  pcre_get_stringtable_entries(const pcre *code, const char *stringname,  pcre_get_stringtable_entries(const pcre *code, const char *stringname,
126    char **firstptr, char **lastptr)    char **firstptr, char **lastptr)
127    #else
128    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
129    pcre16_get_stringtable_entries(const pcre *code, PCRE_SPTR16 stringname,
130      PCRE_SCHAR16 **firstptr, PCRE_SCHAR16 **lastptr)
131    #endif
132  {  {
133  int rc;  int rc;
134  int entrysize;  int entrysize;
# Line 138  while (top > bot) Line 150  while (top > bot)
150    {    {
151    int mid = (top + bot) / 2;    int mid = (top + bot) / 2;
152    pcre_uchar *entry = nametable + entrysize*mid;    pcre_uchar *entry = nametable + entrysize*mid;
153    int c = strcmp(stringname, (char *)(entry + 2));    int c = STRCMP_UC_UC((pcre_uchar *)stringname,
154        (pcre_uchar *)(entry + IMM2_SIZE));
155    if (c == 0)    if (c == 0)
156      {      {
157      pcre_uchar *first = entry;      pcre_uchar *first = entry;
158      pcre_uchar *last = entry;      pcre_uchar *last = entry;
159      while (first > nametable)      while (first > nametable)
160        {        {
161        if (strcmp(stringname, (char *)(first - entrysize + 2)) != 0) break;        if (STRCMP_UC_UC((pcre_uchar *)stringname,
162            (pcre_uchar *)(first - entrysize + IMM2_SIZE)) != 0) break;
163        first -= entrysize;        first -= entrysize;
164        }        }
165      while (last < lastentry)      while (last < lastentry)
166        {        {
167        if (strcmp(stringname, (char *)(last + entrysize + 2)) != 0) break;        if (STRCMP_UC_UC((pcre_uchar *)stringname,
168            (pcre_uchar *)(last + entrysize + IMM2_SIZE)) != 0) break;
169        last += entrysize;        last += entrysize;
170        }        }
171    #ifdef COMPILE_PCRE8
172      *firstptr = (char *)first;      *firstptr = (char *)first;
173      *lastptr = (char *)last;      *lastptr = (char *)last;
174    #else
175        *firstptr = (PCRE_SCHAR16 *)first;
176        *lastptr = (PCRE_SCHAR16 *)last;
177    #endif
178      return entrysize;      return entrysize;
179      }      }
180    if (c > 0) bot = mid + 1; else top = mid;    if (c > 0) bot = mid + 1; else top = mid;
# Line 182  Returns:       the number of the first t Line 202  Returns:       the number of the first t
202                 or a negative number on error                 or a negative number on error
203  */  */
204    
205    #ifdef COMPILE_PCRE8
206  static int  static int
207  get_first_set(const pcre *code, const char *stringname, int *ovector)  get_first_set(const pcre *code, const char *stringname, int *ovector)
208    #else
209    static int
210    get_first_set(const pcre *code, PCRE_SPTR16 stringname, int *ovector)
211    #endif
212  {  {
213  const real_pcre *re = (const real_pcre *)code;  const real_pcre *re = (const real_pcre *)code;
214  int entrysize;  int entrysize;
215  char *first, *last;  pcre_uchar *first, *last;
216  pcre_uchar *entry;  pcre_uchar *entry;
217    #ifdef COMPILE_PCRE8
218  if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0)  if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0)
219    return pcre_get_stringnumber(code, stringname);    return pcre_get_stringnumber(code, stringname);
220  entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last);  entrysize = pcre_get_stringtable_entries(code, stringname,
221      (char **)&first, (char **)&last);
222    #else
223    if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0)
224      return pcre16_get_stringnumber(code, stringname);
225    entrysize = pcre16_get_stringtable_entries(code, stringname,
226      (PCRE_SCHAR16 **)&first, (PCRE_SCHAR16 **)&last);
227    #endif
228  if (entrysize <= 0) return entrysize;  if (entrysize <= 0) return entrysize;
229  for (entry = (pcre_uchar *)first; entry <= (pcre_uchar *)last; entry += entrysize)  for (entry = (pcre_uchar *)first; entry <= (pcre_uchar *)last; entry += entrysize)
230    {    {
# Line 231  Returns:         if successful: Line 264  Returns:         if successful:
264                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
265  */  */
266    
267    #ifdef COMPILE_PCRE8
268  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
269  pcre_copy_substring(const char *subject, int *ovector, int stringcount,  pcre_copy_substring(const char *subject, int *ovector, int stringcount,
270    int stringnumber, char *buffer, int size)    int stringnumber, char *buffer, int size)
271    #else
272    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
273    pcre16_copy_substring(PCRE_SPTR16 subject, int *ovector, int stringcount,
274      int stringnumber, PCRE_SCHAR16 *buffer, int size)
275    #endif
276  {  {
277  int yield;  int yield;
278  if (stringnumber < 0 || stringnumber >= stringcount)  if (stringnumber < 0 || stringnumber >= stringcount)
# Line 241  if (stringnumber < 0 || stringnumber >= Line 280  if (stringnumber < 0 || stringnumber >=
280  stringnumber *= 2;  stringnumber *= 2;
281  yield = ovector[stringnumber+1] - ovector[stringnumber];  yield = ovector[stringnumber+1] - ovector[stringnumber];
282  if (size < yield + 1) return PCRE_ERROR_NOMEMORY;  if (size < yield + 1) return PCRE_ERROR_NOMEMORY;
283  memcpy(buffer, subject + ovector[stringnumber], yield);  memcpy(buffer, subject + ovector[stringnumber], IN_UCHARS(yield));
284  buffer[yield] = 0;  buffer[yield] = 0;
285  return yield;  return yield;
286  }  }
# Line 276  Returns:         if successful: Line 315  Returns:         if successful:
315                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
316  */  */
317    
318    #ifdef COMPILE_PCRE8
319  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
320  pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector,  pcre_copy_named_substring(const pcre *code, const char *subject, int *ovector,
321    int stringcount, const char *stringname, char *buffer, int size)    int stringcount, const char *stringname, char *buffer, int size)
322    #else
323    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
324    pcre16_copy_named_substring(const pcre *code, PCRE_SPTR16 subject, int *ovector,
325      int stringcount, PCRE_SPTR16 stringname, PCRE_SCHAR16 *buffer, int size)
326    #endif
327  {  {
328  int n = get_first_set(code, stringname, ovector);  int n = get_first_set(code, stringname, ovector);
329  if (n <= 0) return n;  if (n <= 0) return n;
330    #ifdef COMPILE_PCRE8
331  return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);  return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);
332    #else
333    return pcre16_copy_substring(subject, ovector, stringcount, n, buffer, size);
334    #endif
335  }  }
336    
337    
# Line 308  Returns:         if successful: 0 Line 357  Returns:         if successful: 0
357                     PCRE_ERROR_NOMEMORY (-6) failed to get store                     PCRE_ERROR_NOMEMORY (-6) failed to get store
358  */  */
359    
360    #ifdef COMPILE_PCRE8
361  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
362  pcre_get_substring_list(const char *subject, int *ovector, int stringcount,  pcre_get_substring_list(const char *subject, int *ovector, int stringcount,
363    const char ***listptr)    const char ***listptr)
364    #else
365    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
366    pcre16_get_substring_list(PCRE_SPTR16 subject, int *ovector, int stringcount,
367      PCRE_SPTR16 **listptr)
368    #endif
369  {  {
370  int i;  int i;
371  int size = sizeof(char *);  int size = sizeof(pcre_uchar *);
372  int double_count = stringcount * 2;  int double_count = stringcount * 2;
373  char **stringlist;  pcre_uchar **stringlist;
374  char *p;  pcre_uchar *p;
375    
376  for (i = 0; i < double_count; i += 2)  for (i = 0; i < double_count; i += 2)
377    size += sizeof(char *) + ovector[i+1] - ovector[i] + 1;    size += sizeof(pcre_uchar *) + IN_UCHARS(ovector[i+1] - ovector[i] + 1);
378    
379  stringlist = (char **)(pcre_malloc)(size);  stringlist = (pcre_uchar **)(pcre_malloc)(size);
380  if (stringlist == NULL) return PCRE_ERROR_NOMEMORY;  if (stringlist == NULL) return PCRE_ERROR_NOMEMORY;
381    
382    #ifdef COMPILE_PCRE8
383  *listptr = (const char **)stringlist;  *listptr = (const char **)stringlist;
384  p = (char *)(stringlist + stringcount + 1);  #else
385    *listptr = (PCRE_SPTR16 *)stringlist;
386    #endif
387    p = (pcre_uchar *)(stringlist + stringcount + 1);
388    
389  for (i = 0; i < double_count; i += 2)  for (i = 0; i < double_count; i += 2)
390    {    {
391    int len = ovector[i+1] - ovector[i];    int len = ovector[i+1] - ovector[i];
392    memcpy(p, subject + ovector[i], len);    memcpy(p, subject + ovector[i], IN_UCHARS(len));
393    *stringlist++ = p;    *stringlist++ = p;
394    p += len;    p += len;
395    *p++ = 0;    *p++ = 0;
# Line 353  Argument:   the result of a previous pcr Line 412  Argument:   the result of a previous pcr
412  Returns:    nothing  Returns:    nothing
413  */  */
414    
415    #ifdef COMPILE_PCRE8
416  PCRE_EXP_DEFN void PCRE_CALL_CONVENTION  PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
417  pcre_free_substring_list(const char **pointer)  pcre_free_substring_list(const char **pointer)
418    #else
419    PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
420    pcre16_free_substring_list(PCRE_SPTR16 *pointer)
421    #endif
422  {  {
423  (pcre_free)((void *)pointer);  (pcre_free)((void *)pointer);
424  }  }
# Line 386  Returns:         if successful: Line 450  Returns:         if successful:
450                     PCRE_ERROR_NOSUBSTRING (-7) substring not present                     PCRE_ERROR_NOSUBSTRING (-7) substring not present
451  */  */
452    
453    #ifdef COMPILE_PCRE8
454  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
455  pcre_get_substring(const char *subject, int *ovector, int stringcount,  pcre_get_substring(const char *subject, int *ovector, int stringcount,
456    int stringnumber, const char **stringptr)    int stringnumber, const char **stringptr)
457    #else
458    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
459    pcre16_get_substring(PCRE_SPTR16 subject, int *ovector, int stringcount,
460      int stringnumber, PCRE_SPTR16 *stringptr)
461    #endif
462  {  {
463  int yield;  int yield;
464  char *substring;  pcre_uchar *substring;
465  if (stringnumber < 0 || stringnumber >= stringcount)  if (stringnumber < 0 || stringnumber >= stringcount)
466    return PCRE_ERROR_NOSUBSTRING;    return PCRE_ERROR_NOSUBSTRING;
467  stringnumber *= 2;  stringnumber *= 2;
468  yield = ovector[stringnumber+1] - ovector[stringnumber];  yield = ovector[stringnumber+1] - ovector[stringnumber];
469  substring = (char *)(pcre_malloc)(yield + 1);  substring = (pcre_uchar *)(pcre_malloc)(IN_UCHARS(yield + 1));
470  if (substring == NULL) return PCRE_ERROR_NOMEMORY;  if (substring == NULL) return PCRE_ERROR_NOMEMORY;
471  memcpy(substring, subject + ovector[stringnumber], yield);  memcpy(substring, subject + ovector[stringnumber], IN_UCHARS(yield));
472  substring[yield] = 0;  substring[yield] = 0;
473  *stringptr = substring;  #ifdef COMPILE_PCRE8
474    *stringptr = (const char *)substring;
475    #else
476    *stringptr = (PCRE_SPTR16)substring;
477    #endif
478  return yield;  return yield;
479  }  }
480    
# Line 433  Returns:         if successful: Line 507  Returns:         if successful:
507                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring                     PCRE_ERROR_NOSUBSTRING (-7) no such captured substring
508  */  */
509    
510    #ifdef COMPILE_PCRE8
511  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
512  pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,  pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
513    int stringcount, const char *stringname, const char **stringptr)    int stringcount, const char *stringname, const char **stringptr)
514    #else
515    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
516    pcre16_get_named_substring(const pcre *code, PCRE_SPTR16 subject, int *ovector,
517      int stringcount, PCRE_SPTR16 stringname, PCRE_SPTR16 *stringptr)
518    #endif
519  {  {
520  int n = get_first_set(code, stringname, ovector);  int n = get_first_set(code, stringname, ovector);
521  if (n <= 0) return n;  if (n <= 0) return n;
522    #ifdef COMPILE_PCRE8
523  return pcre_get_substring(subject, ovector, stringcount, n, stringptr);  return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
524    #else
525    return pcre16_get_substring(subject, ovector, stringcount, n, stringptr);
526    #endif
527  }  }
528    
529    
# Line 456  Argument:   the result of a previous pcr Line 540  Argument:   the result of a previous pcr
540  Returns:    nothing  Returns:    nothing
541  */  */
542    
543    #ifdef COMPILE_PCRE8
544  PCRE_EXP_DEFN void PCRE_CALL_CONVENTION  PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
545  pcre_free_substring(const char *pointer)  pcre_free_substring(const char *pointer)
546    #else
547    PCRE_EXP_DEFN void PCRE_CALL_CONVENTION
548    pcre16_free_substring(PCRE_SPTR16 pointer)
549    #endif
550  {  {
551  (pcre_free)((void *)pointer);  (pcre_free)((void *)pointer);
552  }  }

Legend:
Removed from v.794  
changed lines
  Added in v.795

  ViewVC Help
Powered by ViewVC 1.1.5