michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: /* #include "PRIntlpriv.h" */ michael@0: #include "unicpriv.h" michael@0: michael@0: michael@0: typedef uint16_t (* MapFormatFunc)(uint16_t in,const uTable *uT,const uMapCell *cell); michael@0: typedef int (* HitFormateFunc)(uint16_t in,const uMapCell *cell); michael@0: typedef void (* FillInfoFormateFunc)(const uTable *uT, const uMapCell *cell, uint32_t* info); michael@0: michael@0: michael@0: int uHitFormate0(uint16_t in,const uMapCell *cell); michael@0: int uHitFormate2(uint16_t in,const uMapCell *cell); michael@0: uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell); michael@0: uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell); michael@0: uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell); michael@0: void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* aInfo); michael@0: void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* aInfo); michael@0: void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* aInfo); michael@0: michael@0: michael@0: const uMapCell *uGetMapCell(const uTable *uT, int16_t item); michael@0: char uGetFormat(const uTable *uT, int16_t item); michael@0: michael@0: michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: const MapFormatFunc m_map[uNumFormatTag] = michael@0: { michael@0: uMapFormate0, michael@0: uMapFormate1, michael@0: uMapFormate2, michael@0: }; michael@0: michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: const FillInfoFormateFunc m_fillinfo[uNumFormatTag] = michael@0: { michael@0: uFillInfoFormate0, michael@0: uFillInfoFormate1, michael@0: uFillInfoFormate2, michael@0: }; michael@0: michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: const HitFormateFunc m_hit[uNumFormatTag] = michael@0: { michael@0: uHitFormate0, michael@0: uHitFormate0, michael@0: uHitFormate2, michael@0: }; michael@0: michael@0: #define uHit(format,in,cell) (* m_hit[(format)])((in),(cell)) michael@0: #define uMap(format,in,uT,cell) (* m_map[(format)])((in),(uT),(cell)) michael@0: #define uGetMapCell(uT, item) ((uMapCell *)(((uint16_t *)uT) + (uT)->offsetToMapCellArray + (item)*(UMAPCELL_SIZE/sizeof(uint16_t)))) michael@0: #define uGetFormat(uT, item) (((((uint16_t *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f) michael@0: michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: int uMapCode(const uTable *uT, uint16_t in, uint16_t* out) michael@0: { michael@0: int done = 0; michael@0: uint16_t itemOfList = uT->itemOfList; michael@0: uint16_t i; michael@0: *out = NOMAPPING; michael@0: for(i=0;i= cell->fmt.format0.srcBegin) && michael@0: (in <= cell->fmt.format0.srcEnd) ) ; michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: int uHitFormate2(uint16_t in,const uMapCell *cell) michael@0: { michael@0: return (in == cell->fmt.format2.srcBegin); michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell) michael@0: { michael@0: return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin); michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell) michael@0: { michael@0: return (*(((uint16_t *)uT) + uT->offsetToMappingTable michael@0: + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin)); michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell) michael@0: { michael@0: return (cell->fmt.format2.destBegin); michael@0: } michael@0: michael@0: #define SET_REPRESENTABLE(info, c) (info)[(c) >> 5] |= (1L << ((c) & 0x1f)) michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* info) michael@0: { michael@0: uint16_t begin, end, i; michael@0: begin = cell->fmt.format0.srcBegin; michael@0: end = cell->fmt.format0.srcEnd; michael@0: if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */ michael@0: { michael@0: for(i = begin; i <= end; i++) michael@0: SET_REPRESENTABLE(info, i); michael@0: } michael@0: else { michael@0: uint32_t b = begin >> 5; michael@0: uint32_t e = end >> 5; michael@0: info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); michael@0: info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f))); michael@0: for(b++ ; b < e ; b++) michael@0: info[b] |= 0xFFFFFFFFL; michael@0: } michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* info) michael@0: { michael@0: uint16_t begin, end, i; michael@0: uint16_t *base; michael@0: begin = cell->fmt.format0.srcBegin; michael@0: end = cell->fmt.format0.srcEnd; michael@0: base = (((uint16_t *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset); michael@0: for(i = begin; i <= end; i++) michael@0: { michael@0: if(0xFFFD != base[i - begin]) /* check every item */ michael@0: SET_REPRESENTABLE(info, i); michael@0: } michael@0: } michael@0: /*================================================================================= michael@0: michael@0: =================================================================================*/ michael@0: void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* info) michael@0: { michael@0: SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin); michael@0: } michael@0: