LCOV - code coverage report
Current view: top level - i18nutil/source/utility - oneToOneMapping.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 68 60.3 %
Date: 2012-08-25 Functions: 6 9 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 50 48.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <i18nutil/oneToOneMapping.hxx>
      21                 :            : 
      22                 :            : namespace com { namespace sun { namespace star { namespace i18n {
      23                 :            : 
      24                 :         90 : oneToOneMapping::oneToOneMapping( OneToOneMappingTable_t *rpTable, const size_t rnBytes, const size_t rnUnitSize )
      25                 :            :     : mpTable( rpTable ),
      26                 :         90 :       mnSize( rnBytes / rnUnitSize )
      27                 :            : {
      28                 :         90 : }
      29                 :            : 
      30                 :         90 : oneToOneMapping::~oneToOneMapping()
      31                 :            : {
      32         [ -  + ]:         90 : }
      33                 :            : 
      34                 :          0 : sal_Unicode oneToOneMapping::find(const sal_Unicode nKey) const
      35                 :            : {
      36         [ #  # ]:          0 :     if( mpTable )
      37                 :            :     {
      38                 :            :         // binary search
      39                 :          0 :         int bottom = 0;
      40                 :          0 :         int top = mnSize - 1;
      41                 :            :         int current;
      42                 :            : 
      43                 :          0 :         for (;;) {
      44                 :          0 :             current = (top + bottom) / 2;
      45         [ #  # ]:          0 :             if( nKey < mpTable[current].first )
      46                 :          0 :                 top = current - 1;
      47         [ #  # ]:          0 :             else if( nKey > mpTable[current].first )
      48                 :          0 :                 bottom = current + 1;
      49                 :            :             else
      50                 :          0 :                 return mpTable[current].second;
      51                 :            : 
      52         [ #  # ]:          0 :             if( bottom > top )
      53                 :          0 :                 return sal_Unicode( nKey );
      54                 :            :         }
      55                 :            :     }
      56                 :            :     else
      57                 :          0 :         return sal_Unicode( nKey );
      58                 :            : }
      59                 :            : 
      60                 :         90 : oneToOneMappingWithFlag::oneToOneMappingWithFlag( UnicodePairWithFlag *rpTableWF, const size_t rnSize, const UnicodePairFlag rnFlag )
      61                 :            :     : oneToOneMapping( NULL, rnSize, sizeof(UnicodePairWithFlag) ),
      62                 :            :       mpTableWF ( rpTableWF ),
      63                 :            :       mnFlag    ( rnFlag ),
      64                 :         90 :       mbHasIndex( sal_False )
      65                 :            : {
      66                 :         90 : }
      67                 :            : 
      68                 :         90 : oneToOneMappingWithFlag::~oneToOneMappingWithFlag()
      69                 :            : {
      70         [ +  - ]:         90 :     if( mbHasIndex )
      71         [ +  + ]:      23130 :         for( int i = 0; i < 256; i++ )
      72         [ +  + ]:      23040 :             if( mpIndex[i] )
      73         [ +  - ]:        270 :                 delete [] mpIndex[i];
      74         [ -  + ]:         90 : }
      75                 :            : 
      76                 :            : 
      77                 :         90 : void oneToOneMappingWithFlag::makeIndex()
      78                 :            : {
      79 [ +  - ][ +  - ]:         90 :     if( !mbHasIndex && mpTableWF )
      80                 :            :     {
      81                 :         90 :         int i, j, high, low, current = -1;
      82                 :            : 
      83         [ +  + ]:      23130 :         for( i = 0; i < 256; i++ )
      84                 :      23040 :             mpIndex[i] = NULL;
      85                 :            : 
      86         [ +  + ]:      20160 :         for( size_t k = 0; k < mnSize; k++ )
      87                 :            :         {
      88                 :      20070 :             high = (mpTableWF[k].first >> 8) & 0xFF;
      89                 :      20070 :             low  = (mpTableWF[k].first)      & 0xFF;
      90         [ +  + ]:      20070 :             if( high != current )
      91                 :            :             {
      92                 :        270 :                 current = high;
      93                 :        270 :                 mpIndex[high] = new UnicodePairWithFlag*[256];
      94                 :            : 
      95         [ +  + ]:      69390 :                 for( j = 0; j < 256; j++ )
      96                 :      69120 :                     mpIndex[high][j] = NULL;
      97                 :            :             }
      98                 :      20070 :             mpIndex[high][low] = &mpTableWF[k];
      99                 :            :         }
     100                 :            : 
     101                 :         90 :         mbHasIndex = sal_True;
     102                 :            :     }
     103                 :         90 : }
     104                 :            : 
     105                 :      25790 : sal_Unicode oneToOneMappingWithFlag::find( const sal_Unicode nKey ) const
     106                 :            : {
     107         [ +  - ]:      25790 :     if( mpTableWF )
     108                 :            :     {
     109         [ +  - ]:      25790 :         if( mbHasIndex )
     110                 :            :         {
     111                 :            :             // index search
     112                 :            :             int high, low;
     113                 :      25790 :             high = (nKey >> 8) & 0xFF;
     114                 :      25790 :             low = nKey & 0xFF;
     115 [ +  - ][ +  + ]:      25790 :             if( mpIndex[high] != NULL &&
                 [ +  - ]
     116                 :      25790 :                 mpIndex[high][low] != NULL &&
     117                 :      25766 :                 mpIndex[high][low]->flag & mnFlag )
     118                 :      25766 :                 return mpIndex[high][low]->second;
     119                 :            :             else
     120                 :         24 :                 return sal_Unicode( nKey );
     121                 :            :         }
     122                 :            :         else
     123                 :            :         {
     124                 :            :             // binary search
     125                 :          0 :             int bottom = 0;
     126                 :          0 :             int top = mnSize - 1;
     127                 :            :             int current;
     128                 :            : 
     129                 :          0 :             for (;;) {
     130                 :          0 :                 current = (top + bottom) / 2;
     131         [ #  # ]:          0 :                 if( nKey < mpTableWF[current].first )
     132                 :          0 :                     top = current - 1;
     133         [ #  # ]:          0 :                 else if( nKey > mpTableWF[current].first )
     134                 :          0 :                     bottom = current + 1;
     135                 :            :                 else
     136                 :            :                 {
     137         [ #  # ]:          0 :                     if( mpTableWF[current].flag & mnFlag )
     138                 :          0 :                         return mpTableWF[current].second;
     139                 :            :                     else
     140                 :          0 :                         return sal_Unicode( nKey );
     141                 :            :                 }
     142                 :            : 
     143         [ #  # ]:          0 :                 if( bottom > top )
     144                 :          0 :                     return sal_Unicode( nKey );
     145                 :            :             }
     146                 :            :         }
     147                 :            :     }
     148                 :            :     else
     149                 :      25790 :         return sal_Unicode( nKey );
     150                 :            : }
     151                 :            : 
     152                 :            : 
     153                 :            : } } } }
     154                 :            : 
     155                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10