~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/pcre/ucp.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************
 
2
*     libucp - Unicode Property Table handler    *
 
3
*************************************************/
 
4
 
 
5
/* This function provides a fast way of obtaining the basic Unicode properties
 
6
of a character, using a compact binary tree that occupies less than 100K bytes.
 
7
 
 
8
           Copyright (c) 2004 University of Cambridge
 
9
 
 
10
-------------------------------------------------------------------------------
 
11
Redistribution and use in source and binary forms, with or without
 
12
modification, are permitted provided that the following conditions are met:
 
13
 
 
14
    * Redistributions of source code must retain the above copyright notice,
 
15
      this list of conditions and the following disclaimer.
 
16
 
 
17
    * Redistributions in binary form must reproduce the above copyright
 
18
      notice, this list of conditions and the following disclaimer in the
 
19
      documentation and/or other materials provided with the distribution.
 
20
 
 
21
    * Neither the name of the University of Cambridge nor the names of its
 
22
      contributors may be used to endorse or promote products derived from
 
23
      this software without specific prior written permission.
 
24
 
 
25
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
26
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
27
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
28
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
29
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
30
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
31
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
32
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
33
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
34
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
35
POSSIBILITY OF SUCH DAMAGE.
 
36
-------------------------------------------------------------------------------
 
37
*/
 
38
 
 
39
 
 
40
#include "ucp.h"               /* Exported interface */
 
41
#include "ucpinternal.h"       /* Internal table details */
 
42
#include "ucptable.c"          /* The table itself */
 
43
 
 
44
 
 
45
 
 
46
/*************************************************
 
47
*         Search table and return data           *
 
48
*************************************************/
 
49
 
 
50
/* Two values are returned: the category is ucp_C, ucp_L, etc. The detailed
 
51
character type is ucp_Lu, ucp_Nd, etc.
 
52
 
 
53
Arguments:
 
54
  c           the character value
 
55
  type_ptr    the detailed character type is returned here
 
56
  case_ptr    for letters, the opposite case is returned here, if there
 
57
                is one, else zero
 
58
 
 
59
Returns:      the character type category or -1 if not found
 
60
*/
 
61
 
 
62
static int
 
63
ucp_findchar(const int c, int *type_ptr, int *case_ptr)
 
64
{
 
65
cnode *node = ucp_table;
 
66
register int cc = c;
 
67
int case_offset;
 
68
 
 
69
for (;;)
 
70
  {
 
71
  register int d = node->f1 | ((node->f0 & f0_chhmask) << 16);
 
72
  if (cc == d) break;
 
73
  if (cc < d)
 
74
    {
 
75
    if ((node->f0 & f0_leftexists) == 0) return -1;
 
76
    node ++;
 
77
    }
 
78
  else
 
79
    {
 
80
    register int roffset = (node->f2 & f2_rightmask) >> f2_rightshift;
 
81
    if (roffset == 0) return -1;
 
82
    node += 1 << (roffset - 1);
 
83
    }
 
84
  }
 
85
 
 
86
switch ((*type_ptr = ((node->f0 & f0_typemask) >> f0_typeshift)))
 
87
  {
 
88
  case ucp_Cc:
 
89
  case ucp_Cf:
 
90
  case ucp_Cn:
 
91
  case ucp_Co:
 
92
  case ucp_Cs:
 
93
  return ucp_C;
 
94
  break;
 
95
 
 
96
  case ucp_Ll:
 
97
  case ucp_Lu:
 
98
  case_offset = node->f2 & f2_casemask;
 
99
  if ((case_offset & 0x0100) != 0) case_offset |= 0xfffff000;
 
100
  *case_ptr = (case_offset == 0)? 0 : cc + case_offset;
 
101
  return ucp_L;
 
102
 
 
103
  case ucp_Lm:
 
104
  case ucp_Lo:
 
105
  case ucp_Lt:
 
106
  *case_ptr = 0;
 
107
  return ucp_L;
 
108
  break;
 
109
 
 
110
  case ucp_Mc:
 
111
  case ucp_Me:
 
112
  case ucp_Mn:
 
113
  return ucp_M;
 
114
  break;
 
115
 
 
116
  case ucp_Nd:
 
117
  case ucp_Nl:
 
118
  case ucp_No:
 
119
  return ucp_N;
 
120
  break;
 
121
 
 
122
  case ucp_Pc:
 
123
  case ucp_Pd:
 
124
  case ucp_Pe:
 
125
  case ucp_Pf:
 
126
  case ucp_Pi:
 
127
  case ucp_Ps:
 
128
  case ucp_Po:
 
129
  return ucp_P;
 
130
  break;
 
131
 
 
132
  case ucp_Sc:
 
133
  case ucp_Sk:
 
134
  case ucp_Sm:
 
135
  case ucp_So:
 
136
  return ucp_S;
 
137
  break;
 
138
 
 
139
  case ucp_Zl:
 
140
  case ucp_Zp:
 
141
  case ucp_Zs:
 
142
  return ucp_Z;
 
143
  break;
 
144
 
 
145
  default:         /* "Should never happen" */
 
146
  return -1;
 
147
  break;
 
148
  }
 
149
}
 
150
 
 
151
/* End of ucp.c */