intl/uconv/util/umap.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/uconv/util/umap.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,175 @@
     1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +/* #include "PRIntlpriv.h" */
     1.9 +#include "unicpriv.h" 
    1.10 +
    1.11 +
    1.12 +typedef uint16_t (* MapFormatFunc)(uint16_t in,const uTable *uT,const uMapCell *cell);
    1.13 +typedef int (* HitFormateFunc)(uint16_t in,const uMapCell *cell);
    1.14 +typedef void (* FillInfoFormateFunc)(const uTable *uT, const uMapCell *cell, uint32_t* info);
    1.15 +
    1.16 +
    1.17 +int uHitFormate0(uint16_t in,const uMapCell *cell);
    1.18 +int uHitFormate2(uint16_t in,const uMapCell *cell);
    1.19 +uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell);
    1.20 +uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell);
    1.21 +uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell);
    1.22 +void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
    1.23 +void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
    1.24 +void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* aInfo);
    1.25 +
    1.26 +
    1.27 +const uMapCell *uGetMapCell(const uTable *uT, int16_t item);
    1.28 +char uGetFormat(const uTable *uT, int16_t item);
    1.29 +
    1.30 +
    1.31 +/*=================================================================================
    1.32 +
    1.33 +=================================================================================*/
    1.34 +const MapFormatFunc m_map[uNumFormatTag] =
    1.35 +{
    1.36 +    uMapFormate0,
    1.37 +    uMapFormate1,
    1.38 +    uMapFormate2,
    1.39 +};
    1.40 +
    1.41 +/*=================================================================================
    1.42 +
    1.43 +=================================================================================*/
    1.44 +const FillInfoFormateFunc m_fillinfo[uNumFormatTag] =
    1.45 +{
    1.46 +    uFillInfoFormate0,
    1.47 +    uFillInfoFormate1,
    1.48 +    uFillInfoFormate2,
    1.49 +};
    1.50 +
    1.51 +/*=================================================================================
    1.52 +
    1.53 +=================================================================================*/
    1.54 +const HitFormateFunc m_hit[uNumFormatTag] =
    1.55 +{
    1.56 +    uHitFormate0,
    1.57 +    uHitFormate0,
    1.58 +    uHitFormate2,
    1.59 +};
    1.60 +
    1.61 +#define uHit(format,in,cell)   (* m_hit[(format)])((in),(cell))
    1.62 +#define uMap(format,in,uT,cell)  (* m_map[(format)])((in),(uT),(cell))
    1.63 +#define uGetMapCell(uT, item) ((uMapCell *)(((uint16_t *)uT) + (uT)->offsetToMapCellArray + (item)*(UMAPCELL_SIZE/sizeof(uint16_t))))
    1.64 +#define uGetFormat(uT, item) (((((uint16_t *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f)
    1.65 +
    1.66 +/*=================================================================================
    1.67 +
    1.68 +=================================================================================*/
    1.69 +int uMapCode(const uTable *uT, uint16_t in, uint16_t* out)
    1.70 +{
    1.71 +  int done = 0;
    1.72 +  uint16_t itemOfList = uT->itemOfList;
    1.73 +  uint16_t i;
    1.74 +  *out = NOMAPPING;
    1.75 +  for(i=0;i<itemOfList;i++)
    1.76 +  {
    1.77 +    const uMapCell* uCell;
    1.78 +    int8_t format = uGetFormat(uT,i);
    1.79 +    uCell = uGetMapCell(uT,i);
    1.80 +    if(uHit(format, in, uCell))
    1.81 +    {
    1.82 +      *out = uMap(format, in, uT,uCell);
    1.83 +      done = 1;
    1.84 +      break;
    1.85 +    }
    1.86 +  }
    1.87 +  return ( done && (*out != NOMAPPING));
    1.88 +}
    1.89 +
    1.90 +
    1.91 +/*
    1.92 +member function
    1.93 +*/
    1.94 +/*=================================================================================
    1.95 +
    1.96 +=================================================================================*/
    1.97 +int uHitFormate0(uint16_t in,const uMapCell *cell)
    1.98 +{
    1.99 +  return ( (in >= cell->fmt.format0.srcBegin) &&
   1.100 +    (in <= cell->fmt.format0.srcEnd) ) ;
   1.101 +}
   1.102 +/*=================================================================================
   1.103 +
   1.104 +=================================================================================*/
   1.105 +int uHitFormate2(uint16_t in,const uMapCell *cell)
   1.106 +{
   1.107 +  return (in == cell->fmt.format2.srcBegin);
   1.108 +}
   1.109 +/*=================================================================================
   1.110 +
   1.111 +=================================================================================*/
   1.112 +uint16_t uMapFormate0(uint16_t in,const uTable *uT,const uMapCell *cell)
   1.113 +{
   1.114 +  return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
   1.115 +}
   1.116 +/*=================================================================================
   1.117 +
   1.118 +=================================================================================*/
   1.119 +uint16_t uMapFormate1(uint16_t in,const uTable *uT,const uMapCell *cell)
   1.120 +{
   1.121 +  return (*(((uint16_t *)uT) + uT->offsetToMappingTable
   1.122 +    + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
   1.123 +}
   1.124 +/*=================================================================================
   1.125 +
   1.126 +=================================================================================*/
   1.127 +uint16_t uMapFormate2(uint16_t in,const uTable *uT,const uMapCell *cell)
   1.128 +{
   1.129 +  return (cell->fmt.format2.destBegin);
   1.130 +}
   1.131 +
   1.132 +#define SET_REPRESENTABLE(info, c)  (info)[(c) >> 5] |= (1L << ((c) & 0x1f))
   1.133 +/*=================================================================================
   1.134 +
   1.135 +=================================================================================*/
   1.136 +void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,uint32_t* info)
   1.137 +{
   1.138 +  uint16_t begin, end, i;
   1.139 +  begin = cell->fmt.format0.srcBegin;
   1.140 +  end = cell->fmt.format0.srcEnd;
   1.141 +  if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */
   1.142 +  {
   1.143 +    for(i = begin; i <= end; i++)
   1.144 +      SET_REPRESENTABLE(info, i);
   1.145 +  } 
   1.146 +  else {
   1.147 +    uint32_t b = begin >> 5;
   1.148 +    uint32_t e = end >> 5;
   1.149 +    info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); 
   1.150 +    info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f)));
   1.151 +    for(b++ ; b < e ; b++)
   1.152 +      info[b] |= 0xFFFFFFFFL;
   1.153 +  }
   1.154 +}
   1.155 +/*=================================================================================
   1.156 +
   1.157 +=================================================================================*/
   1.158 +void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,uint32_t* info)
   1.159 +{
   1.160 +  uint16_t begin, end, i;
   1.161 +  uint16_t *base;
   1.162 +  begin = cell->fmt.format0.srcBegin;
   1.163 +  end = cell->fmt.format0.srcEnd;
   1.164 +  base = (((uint16_t *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset);
   1.165 +  for(i = begin; i <= end; i++) 
   1.166 +  {
   1.167 +    if(0xFFFD != base[i - begin])  /* check every item */
   1.168 +      SET_REPRESENTABLE(info, i);
   1.169 +  }
   1.170 +}
   1.171 +/*=================================================================================
   1.172 +
   1.173 +=================================================================================*/
   1.174 +void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,uint32_t* info)
   1.175 +{
   1.176 +  SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin);
   1.177 +}
   1.178 +

mercurial