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