LCOV - code coverage report
Current view: directory - intl/uconv/util - umap.c (source / functions) Found Hit Coverage
Test: app.info Lines: 48 24 50.0 %
Date: 2012-06-02 Functions: 9 6 66.7 %

       1                 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   jeroen.dobbelaere@acunia.com
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : /* #include "PRIntlpriv.h" */
      39                 : #include "unicpriv.h" 
      40                 : 
      41                 : 
      42                 : typedef PRUint16 (* MapFormatFunc)(PRUint16 in,const uTable *uT,const uMapCell *cell);
      43                 : typedef PRBool (* HitFormateFunc)(PRUint16 in,const uMapCell *cell);
      44                 : typedef void (* FillInfoFormateFunc)(const uTable *uT, const uMapCell *cell, PRUint32* info);
      45                 : 
      46                 : 
      47                 : PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell);
      48                 : PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell);
      49                 : PRIVATE PRUint16 uMapFormate0(PRUint16 in,const uTable *uT,const uMapCell *cell);
      50                 : PRIVATE PRUint16 uMapFormate1(PRUint16 in,const uTable *uT,const uMapCell *cell);
      51                 : PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell);
      52                 : PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
      53                 : PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
      54                 : PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
      55                 : 
      56                 : 
      57                 : PRIVATE const uMapCell *uGetMapCell(const uTable *uT, PRInt16 item);
      58                 : PRIVATE char uGetFormat(const uTable *uT, PRInt16 item);
      59                 : 
      60                 : 
      61                 : /*=================================================================================
      62                 : 
      63                 : =================================================================================*/
      64                 : PRIVATE const MapFormatFunc m_map[uNumFormatTag] =
      65                 : {
      66                 :     uMapFormate0,
      67                 :     uMapFormate1,
      68                 :     uMapFormate2,
      69                 : };
      70                 : 
      71                 : /*=================================================================================
      72                 : 
      73                 : =================================================================================*/
      74                 : PRIVATE const FillInfoFormateFunc m_fillinfo[uNumFormatTag] =
      75                 : {
      76                 :     uFillInfoFormate0,
      77                 :     uFillInfoFormate1,
      78                 :     uFillInfoFormate2,
      79                 : };
      80                 : 
      81                 : /*=================================================================================
      82                 : 
      83                 : =================================================================================*/
      84                 : PRIVATE const HitFormateFunc m_hit[uNumFormatTag] =
      85                 : {
      86                 :     uHitFormate0,
      87                 :     uHitFormate0,
      88                 :     uHitFormate2,
      89                 : };
      90                 : 
      91                 : #define uHit(format,in,cell)   (* m_hit[(format)])((in),(cell))
      92                 : #define uMap(format,in,uT,cell)  (* m_map[(format)])((in),(uT),(cell))
      93                 : #define uGetMapCell(uT, item) ((uMapCell *)(((PRUint16 *)uT) + (uT)->offsetToMapCellArray + (item)*(UMAPCELL_SIZE/sizeof(PRUint16))))
      94                 : #define uGetFormat(uT, item) (((((PRUint16 *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f)
      95                 : 
      96                 : /*=================================================================================
      97                 : 
      98                 : =================================================================================*/
      99         2275399 : MODULE_PRIVATE PRBool uMapCode(const uTable *uT, PRUint16 in, PRUint16* out)
     100                 : {
     101         2275399 :   PRBool done = PR_FALSE;
     102         2275399 :   PRUint16 itemOfList = uT->itemOfList;
     103                 :   PRUint16 i;
     104         2275399 :   *out = NOMAPPING;
     105        51254869 :   for(i=0;i<itemOfList;i++)
     106                 :   {
     107                 :     const uMapCell* uCell;
     108        51151986 :     PRInt8 format = uGetFormat(uT,i);
     109        51151986 :     uCell = uGetMapCell(uT,i);
     110        51151986 :     if(uHit(format, in, uCell))
     111                 :     {
     112         2172516 :       *out = uMap(format, in, uT,uCell);
     113         2172516 :       done = PR_TRUE;
     114         2172516 :       break;
     115                 :     }
     116                 :   }
     117         2275399 :   return ( done && (*out != NOMAPPING));
     118                 : }
     119                 : 
     120                 : 
     121                 : /*
     122                 : member function
     123                 : */
     124                 : /*=================================================================================
     125                 : 
     126                 : =================================================================================*/
     127        49938553 : PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell)
     128                 : {
     129        84540439 :   return ( (in >= cell->fmt.format0.srcBegin) &&
     130        34601886 :     (in <= cell->fmt.format0.srcEnd) ) ;
     131                 : }
     132                 : /*=================================================================================
     133                 : 
     134                 : =================================================================================*/
     135         1213433 : PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell)
     136                 : {
     137         1213433 :   return (in == cell->fmt.format2.srcBegin);
     138                 : }
     139                 : /*=================================================================================
     140                 : 
     141                 : =================================================================================*/
     142         2024461 : PRIVATE PRUint16 uMapFormate0(PRUint16 in,const uTable *uT,const uMapCell *cell)
     143                 : {
     144         2024461 :   return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
     145                 : }
     146                 : /*=================================================================================
     147                 : 
     148                 : =================================================================================*/
     149          144103 : PRIVATE PRUint16 uMapFormate1(PRUint16 in,const uTable *uT,const uMapCell *cell)
     150                 : {
     151          288206 :   return (*(((PRUint16 *)uT) + uT->offsetToMappingTable
     152          144103 :     + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
     153                 : }
     154                 : /*=================================================================================
     155                 : 
     156                 : =================================================================================*/
     157            3952 : PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell)
     158                 : {
     159            3952 :   return (cell->fmt.format2.destBegin);
     160                 : }
     161                 : 
     162                 : #define SET_REPRESENTABLE(info, c)  (info)[(c) >> 5] |= (1L << ((c) & 0x1f))
     163                 : /*=================================================================================
     164                 : 
     165                 : =================================================================================*/
     166               0 : PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* info)
     167                 : {
     168                 :   PRUint16 begin, end, i;
     169               0 :   begin = cell->fmt.format0.srcBegin;
     170               0 :   end = cell->fmt.format0.srcEnd;
     171               0 :   if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */
     172                 :   {
     173               0 :     for(i = begin; i <= end; i++)
     174               0 :       SET_REPRESENTABLE(info, i);
     175                 :   } 
     176                 :   else {
     177               0 :     PRUint32 b = begin >> 5;
     178               0 :     PRUint32 e = end >> 5;
     179               0 :     info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); 
     180               0 :     info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f)));
     181               0 :     for(b++ ; b < e ; b++)
     182               0 :       info[b] |= 0xFFFFFFFFL;
     183                 :   }
     184               0 : }
     185                 : /*=================================================================================
     186                 : 
     187                 : =================================================================================*/
     188               0 : PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* info)
     189                 : {
     190                 :   PRUint16 begin, end, i;
     191                 :   PRUint16 *base;
     192               0 :   begin = cell->fmt.format0.srcBegin;
     193               0 :   end = cell->fmt.format0.srcEnd;
     194               0 :   base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset);
     195               0 :   for(i = begin; i <= end; i++) 
     196                 :   {
     197               0 :     if(0xFFFD != base[i - begin])  /* check every item */
     198               0 :       SET_REPRESENTABLE(info, i);
     199                 :   }
     200               0 : }
     201                 : /*=================================================================================
     202                 : 
     203                 : =================================================================================*/
     204               0 : PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* info)
     205                 : {
     206               0 :   SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin);
     207               0 : }
     208                 : 

Generated by: LCOV version 1.7