intl/uconv/util/umap.c

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:358ce738cd10
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* #include "PRIntlpriv.h" */
6 #include "unicpriv.h"
7
8
9 typedef uint16_t (* MapFormatFunc)(uint16_t in,const uTable *uT,const uMapCell *cell);
10 typedef int (* HitFormateFunc)(uint16_t in,const uMapCell *cell);
11 typedef void (* FillInfoFormateFunc)(const uTable *uT, const uMapCell *cell, uint32_t* info);
12
13
14 int uHitFormate0(uint16_t in,const uMapCell *cell);
15 int uHitFormate2(uint16_t in,const uMapCell *cell);
16 uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell);
17 uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell);
18 uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell);
19 void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
20 void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
21 void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
22
23
24 const uMapCell *uGetMapCell(const uTable *uT, int16_t item);
25 char uGetFormat(const uTable *uT, int16_t item);
26
27
28 /*=================================================================================
29
30 =================================================================================*/
31 const MapFormatFunc m_map[uNumFormatTag] =
32 {
33 uMapFormate0,
34 uMapFormate1,
35 uMapFormate2,
36 };
37
38 /*=================================================================================
39
40 =================================================================================*/
41 const FillInfoFormateFunc m_fillinfo[uNumFormatTag] =
42 {
43 uFillInfoFormate0,
44 uFillInfoFormate1,
45 uFillInfoFormate2,
46 };
47
48 /*=================================================================================
49
50 =================================================================================*/
51 const HitFormateFunc m_hit[uNumFormatTag] =
52 {
53 uHitFormate0,
54 uHitFormate0,
55 uHitFormate2,
56 };
57
58 #define uHit(format,in,cell) (* m_hit[(format)])((in),(cell))
59 #define uMap(format,in,uT,cell) (* m_map[(format)])((in),(uT),(cell))
60 #define uGetMapCell(uT, item) ((uMapCell *)(((uint16_t *)uT) + (uT)->offsetToMapCellArray + (item)*(UMAPCELL_SIZE/sizeof(uint16_t))))
61 #define uGetFormat(uT, item) (((((uint16_t *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f)
62
63 /*=================================================================================
64
65 =================================================================================*/
66 int uMapCode(const uTable *uT, uint16_t in, uint16_t* out)
67 {
68 int done = 0;
69 uint16_t itemOfList = uT->itemOfList;
70 uint16_t i;
71 *out = NOMAPPING;
72 for(i=0;i<itemOfList;i++)
73 {
74 const uMapCell* uCell;
75 int8_t format = uGetFormat(uT,i);
76 uCell = uGetMapCell(uT,i);
77 if(uHit(format, in, uCell))
78 {
79 *out = uMap(format, in, uT,uCell);
80 done = 1;
81 break;
82 }
83 }
84 return ( done && (*out != NOMAPPING));
85 }
86
87
88 /*
89 member function
90 */
91 /*=================================================================================
92
93 =================================================================================*/
94 int uHitFormate0(uint16_t in,const uMapCell *cell)
95 {
96 return ( (in >= cell->fmt.format0.srcBegin) &&
97 (in <= cell->fmt.format0.srcEnd) ) ;
98 }
99 /*=================================================================================
100
101 =================================================================================*/
102 int uHitFormate2(uint16_t in,const uMapCell *cell)
103 {
104 return (in == cell->fmt.format2.srcBegin);
105 }
106 /*=================================================================================
107
108 =================================================================================*/
109 uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell)
110 {
111 return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
112 }
113 /*=================================================================================
114
115 =================================================================================*/
116 uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell)
117 {
118 return (*(((uint16_t *)uT) + uT->offsetToMappingTable
119 + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
120 }
121 /*=================================================================================
122
123 =================================================================================*/
124 uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell)
125 {
126 return (cell->fmt.format2.destBegin);
127 }
128
129 #define SET_REPRESENTABLE(info, c) (info)[(c) >> 5] |= (1L << ((c) & 0x1f))
130 /*=================================================================================
131
132 =================================================================================*/
133 void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* info)
134 {
135 uint16_t begin, end, i;
136 begin = cell->fmt.format0.srcBegin;
137 end = cell->fmt.format0.srcEnd;
138 if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */
139 {
140 for(i = begin; i <= end; i++)
141 SET_REPRESENTABLE(info, i);
142 }
143 else {
144 uint32_t b = begin >> 5;
145 uint32_t e = end >> 5;
146 info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f));
147 info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f)));
148 for(b++ ; b < e ; b++)
149 info[b] |= 0xFFFFFFFFL;
150 }
151 }
152 /*=================================================================================
153
154 =================================================================================*/
155 void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* info)
156 {
157 uint16_t begin, end, i;
158 uint16_t *base;
159 begin = cell->fmt.format0.srcBegin;
160 end = cell->fmt.format0.srcEnd;
161 base = (((uint16_t *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset);
162 for(i = begin; i <= end; i++)
163 {
164 if(0xFFFD != base[i - begin]) /* check every item */
165 SET_REPRESENTABLE(info, i);
166 }
167 }
168 /*=================================================================================
169
170 =================================================================================*/
171 void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* info)
172 {
173 SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin);
174 }
175

mercurial