intl/uconv/util/umap.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial