gmain: use Linux eventfd() for main context wake up
[glib.git] / glib / pcre / pcre_ucp_searchfuncs.c
blob36e90b5b99d523247cb0c5d6ace87d4bdba8de12
1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
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.
8 Written by Philip Hazel
9 Copyright (c) 1997-2006 University of Cambridge
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
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.
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.
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 -----------------------------------------------------------------------------
40 /* This file has been modified to use glib instead of the internal table
41 * in ucptable.c -- Marco Barisione */
43 /* This module contains code for searching the table of Unicode character
44 properties. */
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
50 #include "pcre_internal.h"
52 #include "ucp.h" /* Category definitions */
54 /* Table to translate from particular type value to the general value. */
56 #ifdef NOT_USED_IN_GLIB
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 */
71 /*************************************************
72 * Search table and return type *
73 *************************************************/
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.
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
83 Returns: the character type category
86 int
87 _pcre_ucp_findprop(const unsigned int c, int *type_ptr, int *script_ptr)
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];
97 #endif
101 /*************************************************
102 * Search table and return other case *
103 *************************************************/
105 /* If the given character is a letter, and there is another case for the
106 letter, return the other case. Otherwise, return -1.
108 Arguments:
109 c the character value
111 Returns: the other case or NOTACHAR if none
114 unsigned int
115 _pcre_ucp_othercase(const unsigned int c)
117 int other_case = NOTACHAR;
119 if (g_unichar_islower(c))
120 other_case = g_unichar_toupper(c);
121 else if (g_unichar_isupper(c))
122 other_case = g_unichar_tolower(c);
124 if (other_case == c)
125 other_case = NOTACHAR;
127 return other_case;
131 /* End of pcre_ucp_searchfuncs.c */