1 /* $NetBSD: urestubs.c,v 1.3 2021/08/14 16:14:57 christos Exp $ */
2
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 1998-2021 The OpenLDAP Foundation.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
12 *
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
16 */
17 /*
18 * Copyright 1997, 1998, 1999 Computing Research Labs,
19 * New Mexico State University
20 *
21 * Permission is hereby granted, free of charge, to any person obtaining a
22 * copy of this software and associated documentation files (the "Software"),
23 * to deal in the Software without restriction, including without limitation
24 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
25 * and/or sell copies of the Software, and to permit persons to whom the
26 * Software is furnished to do so, subject to the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be included in
29 * all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
35 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
36 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
37 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39 /* Id: urestubs.c,v 1.2 1999/09/21 15:47:44 mleisher Exp " */
40
41 #include <sys/cdefs.h>
42 __RCSID("$NetBSD: urestubs.c,v 1.3 2021/08/14 16:14:57 christos Exp $");
43
44 #include "portable.h"
45 #include <ac/bytes.h>
46
47 #include "ure.h"
48
49 #ifdef _MSC_VER
50 # include "../ucdata/ucdata.h"
51 #else
52 # include "ucdata.h"
53 #endif
54
55 /*
56 * This file contains stub routines needed by the URE package to test
57 * character properties and other Unicode implementation specific details.
58 */
59
60 /*
61 * This routine should return the lower case equivalent for the character or,
62 * if there is no lower case quivalent, the character itself.
63 */
_ure_tolower(ucs4_t c)64 ucs4_t _ure_tolower(ucs4_t c)
65 {
66 return uctoupper(c);
67 }
68
69 static struct ucmaskmap {
70 unsigned long mask1;
71 unsigned long mask2;
72 } masks[32] = {
73 { UC_MN, 0 }, /* _URE_NONSPACING */
74 { UC_MC, 0 }, /* _URE_COMBINING */
75 { UC_ND, 0 }, /* _URE_NUMDIGIT */
76 { UC_NL|UC_NO, 0 }, /* _URE_NUMOTHER */
77 { UC_ZS, 0 }, /* _URE_SPACESEP */
78 { UC_ZL, 0 }, /* _URE_LINESEP */
79 { UC_ZP, 0 }, /* _URE_PARASEP */
80 { UC_CC, 0 }, /* _URE_CNTRL */
81 { UC_CO, 0 }, /* _URE_PUA */
82
83 { UC_LU, 0 }, /* _URE_UPPER */
84 { UC_LL, 0 }, /* _URE_LOWER */
85 { UC_LT, 0 }, /* _URE_TITLE */
86 { UC_LM, 0 }, /* _URE_MODIFIER */
87 { UC_LO, 0 }, /* _URE_OTHERLETTER */
88 { UC_PD, 0 }, /* _URE_DASHPUNCT */
89 { UC_PS, 0 }, /* _URE_OPENPUNCT */
90 { UC_PC, 0 }, /* _URE_CLOSEPUNCT */
91 { UC_PO, 0 }, /* _URE_OTHERPUNCT */
92 { UC_SM, 0 }, /* _URE_MATHSYM */
93 { UC_SC, 0 }, /* _URE_CURRENCYSYM */
94 { UC_SO, 0 }, /* _URE_OTHERSYM */
95
96 { UC_L, 0 }, /* _URE_LTR */
97 { UC_R, 0 }, /* _URE_RTL */
98
99 { 0, UC_EN }, /* _URE_EURONUM */
100 { 0, UC_ES }, /* _URE_EURONUMSEP */
101 { 0, UC_ET }, /* _URE_EURONUMTERM */
102 { 0, UC_AN }, /* _URE_ARABNUM */
103 { 0, UC_CS }, /* _URE_COMMONSEP */
104
105 { 0, UC_B }, /* _URE_BLOCKSEP */
106 { 0, UC_S }, /* _URE_SEGMENTSEP */
107
108 { 0, UC_WS }, /* _URE_WHITESPACE */
109 { 0, UC_ON } /* _URE_OTHERNEUT */
110 };
111
112
113 /*
114 * This routine takes a set of URE character property flags (see ure.h) along
115 * with a character and tests to see if the character has one or more of those
116 * properties.
117 */
118 int
_ure_matches_properties(unsigned long props,ucs4_t c)119 _ure_matches_properties(unsigned long props, ucs4_t c)
120 {
121 int i;
122 unsigned long mask1=0, mask2=0;
123
124 for( i=0; i<32; i++ ) {
125 if( props & (1 << i) ) {
126 mask1 |= masks[i].mask1;
127 mask2 |= masks[i].mask2;
128 }
129 }
130
131 return ucisprop( c, mask1, mask2 );
132 }
133