/[pcre]/code/tags/pcre-5.0/maketables.c
ViewVC logotype

Diff of /code/tags/pcre-5.0/maketables.c

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

revision 43 by nigel, Sat Feb 24 21:39:21 2007 UTC revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC
# Line 8  and semantics are as close as possible t Line 8  and semantics are as close as possible t
8    
9  Written by: Philip Hazel <ph10@cam.ac.uk>  Written by: Philip Hazel <ph10@cam.ac.uk>
10    
11             Copyright (c) 1997-2000 University of Cambridge             Copyright (c) 1997-2003 University of Cambridge
12    
13  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
14  Permission is granted to anyone to use this software for any purpose on any  Redistribution and use in source and binary forms, with or without
15  computer system, and to redistribute it freely, subject to the following  modification, are permitted provided that the following conditions are met:
16  restrictions:  
17        * Redistributions of source code must retain the above copyright notice,
18  1. This software is distributed in the hope that it will be useful,        this list of conditions and the following disclaimer.
    but WITHOUT ANY WARRANTY; without even the implied warranty of  
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
   
 2. The origin of this software must not be misrepresented, either by  
    explicit claim or by omission.  
   
 3. Altered versions must be plainly marked as such, and must not be  
    misrepresented as being the original software.  
   
 4. If PCRE is embedded in any software that is released under the GNU  
    General Purpose Licence (GPL), then the terms of that licence shall  
    supersede any condition above with which it is incompatible.  
 -----------------------------------------------------------------------------  
19    
20  See the file Tech.Notes for some information on the internals.      * Redistributions in binary form must reproduce the above copyright
21          notice, this list of conditions and the following disclaimer in the
22          documentation and/or other materials provided with the distribution.
23    
24        * Neither the name of the University of Cambridge nor the names of its
25          contributors may be used to endorse or promote products derived from
26          this software without specific prior written permission.
27    
28    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38    POSSIBILITY OF SUCH DAMAGE.
39    -----------------------------------------------------------------------------
40  */  */
41    
42    
# Line 58  Arguments:   none Line 64  Arguments:   none
64  Returns:     pointer to the contiguous block of data  Returns:     pointer to the contiguous block of data
65  */  */
66    
67  unsigned const char *  const unsigned char *
68  pcre_maketables(void)  pcre_maketables(void)
69  {  {
70  unsigned char *yield, *p;  unsigned char *yield, *p;
# Line 82  for (i = 0; i < 256; i++) *p++ = tolower Line 88  for (i = 0; i < 256; i++) *p++ = tolower
88  for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);  for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);
89    
90  /* Then the character class tables. Don't try to be clever and save effort  /* Then the character class tables. Don't try to be clever and save effort
91  on exclusive ones - in some locales things may be different. */  on exclusive ones - in some locales things may be different. Note that the
92    table for "space" includes everything "isspace" gives, including VT in the
93    default locale. This makes it work for the POSIX class [:space:]. */
94    
95  memset(p, 0, cbit_length);  memset(p, 0, cbit_length);
96  for (i = 0; i < 256; i++)  for (i = 0; i < 256; i++)
# Line 112  for (i = 0; i < 256; i++) Line 120  for (i = 0; i < 256; i++)
120    }    }
121  p += cbit_length;  p += cbit_length;
122    
123  /* Finally, the character type table */  /* Finally, the character type table. In this, we exclude VT from the white
124    space chars, because Perl doesn't recognize it as such for \s and for comments
125    within regexes. */
126    
127  for (i = 0; i < 256; i++)  for (i = 0; i < 256; i++)
128    {    {
129    int x = 0;    int x = 0;
130    if (isspace(i)) x += ctype_space;    if (i != 0x0b && isspace(i)) x += ctype_space;
131    if (isalpha(i)) x += ctype_letter;    if (isalpha(i)) x += ctype_letter;
132    if (isdigit(i)) x += ctype_digit;    if (isdigit(i)) x += ctype_digit;
133    if (isxdigit(i)) x += ctype_xdigit;    if (isxdigit(i)) x += ctype_xdigit;
134    if (isalnum(i) || i == '_') x += ctype_word;    if (isalnum(i) || i == '_') x += ctype_word;
135    if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;  
136    *p++ = x;    /* Note: strchr includes the terminating zero in the characters it considers.
137    }    In this instance, that is ok because we want binary zero to be flagged as a
138      meta-character, which in this sense is any character that terminates a run
139      of data characters. */
140    
141      if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta; *p++ = x; }
142    
143  return yield;  return yield;
144  }  }

Legend:
Removed from v.43  
changed lines
  Added in v.75

  ViewVC Help
Powered by ViewVC 1.1.5