77ec8d14b50e6927991666f79f711d28910d2da9
[platform/upstream/glib2.0.git] / glib / update-pcre / pcre_ucp_searchfuncs.c
1 /*************************************************
2 *      Perl-Compatible Regular Expressions       *
3 *************************************************/
4
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
7
8                        Written by Philip Hazel
9            Copyright (c) 1997-2006 University of Cambridge
10
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14
15     * Redistributions of source code must retain the above copyright notice,
16       this list of conditions and the following disclaimer.
17
18     * Redistributions in binary form must reproduce the above copyright
19       notice, this list of conditions and the following disclaimer in the
20       documentation and/or other materials provided with the distribution.
21
22     * Neither the name of the University of Cambridge nor the names of its
23       contributors may be used to endorse or promote products derived from
24       this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 -----------------------------------------------------------------------------
38 */
39
40 /* This file has been modified to use glib instead of the internal table
41  * in ucptable.c -- Marco Barisione */
42
43 /* This module contains code for searching the table of Unicode character
44 properties. */
45
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
49
50 #include "pcre_internal.h"
51
52 #include "ucp.h"               /* Category definitions */
53 #include "ucpinternal.h"       /* Internal table details */
54
55
56 /* Table to translate from particular type value to the general value. */
57
58 static int ucp_gentype[] = {
59   ucp_C, ucp_C, ucp_C, ucp_C, ucp_C,  /* Cc, Cf, Cn, Co, Cs */
60   ucp_L, ucp_L, ucp_L, ucp_L, ucp_L,  /* Ll, Lu, Lm, Lo, Lt */
61   ucp_M, ucp_M, ucp_M,                /* Mc, Me, Mn */
62   ucp_N, ucp_N, ucp_N,                /* Nd, Nl, No */
63   ucp_P, ucp_P, ucp_P, ucp_P, ucp_P,  /* Pc, Pd, Pe, Pf, Pi */
64   ucp_P, ucp_P,                       /* Ps, Po */
65   ucp_S, ucp_S, ucp_S, ucp_S,         /* Sc, Sk, Sm, So */
66   ucp_Z, ucp_Z, ucp_Z                 /* Zl, Zp, Zs */
67 };
68
69
70
71 /*************************************************
72 *         Search table and return type           *
73 *************************************************/
74
75 /* Three values are returned: the category is ucp_C, ucp_L, etc. The detailed
76 character type is ucp_Lu, ucp_Nd, etc. The script is ucp_Latin, etc.
77
78 Arguments:
79   c           the character value
80   type_ptr    the detailed character type is returned here
81   script_ptr  the script is returned here
82
83 Returns:      the character type category
84 */
85
86 int
87 _pcre_ucp_findprop(const unsigned int c, int *type_ptr, int *script_ptr)
88 {
89 /* Note that the Unicode types have the same values in glib and in
90  * PCRE, so ucp_Ll == G_UNICODE_LOWERCASE_LETTER,
91  * ucp_Zs == G_UNICODE_SPACE_SEPARATOR, and so on. */
92 *type_ptr = g_unichar_type(c);
93 *script_ptr = g_unichar_get_script(c);
94 return ucp_gentype[*type_ptr];
95 }
96
97
98
99
100 /*************************************************
101 *       Search table and return other case       *
102 *************************************************/
103
104 /* If the given character is a letter, and there is another case for the
105 letter, return the other case. Otherwise, return -1.
106
107 Arguments:
108   c           the character value
109
110 Returns:      the other case or NOTACHAR if none
111 */
112
113 unsigned int
114 _pcre_ucp_othercase(const unsigned int c)
115 {
116 int other_case = NOTACHAR;
117
118 if (g_unichar_islower(c))
119   other_case = g_unichar_toupper(c);
120 else if (g_unichar_isupper(c))
121   other_case = g_unichar_tolower(c);
122
123 if (other_case == c)
124   other_case = NOTACHAR;
125
126 return other_case;
127 }
128
129
130 /* End of pcre_ucp_searchfuncs.c */