LCOV - code coverage report
Current view: top level - i18npool/source/breakiterator - breakiterator_th.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 44 13.6 %
Date: 2012-08-25 Functions: 3 6 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 52 1.9 %

           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 <breakiterator_th.hxx>
      21                 :            : #include <wtt.h>
      22                 :            : 
      23                 :            : #include <string.h> // for memset
      24                 :            : 
      25                 :            : using namespace ::com::sun::star::uno;
      26                 :            : using namespace ::com::sun::star::lang;
      27                 :            : using namespace ::rtl;
      28                 :            : 
      29                 :            : namespace com { namespace sun { namespace star { namespace i18n {
      30                 :            : 
      31                 :            : //  ----------------------------------------------------
      32                 :            : //  class Breakiterator_th
      33                 :            : //  ----------------------------------------------------;
      34                 :          3 : BreakIterator_th::BreakIterator_th()
      35                 :            : {
      36                 :          3 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_th";
      37                 :          3 :     wordRule=lineRule=NULL;
      38                 :          3 : }
      39                 :            : 
      40                 :          3 : BreakIterator_th::~BreakIterator_th()
      41                 :            : {
      42         [ -  + ]:          6 : }
      43                 :            : 
      44                 :            : #define SARA_AM 0x0E33
      45                 :            : 
      46                 :            : /*
      47                 :            :  * cell composition states
      48                 :            :  */
      49                 :            : 
      50                 :            : #define ST_COM  1   // Compose the following character with leading char and display in the same cell
      51                 :            : #define ST_NXT  2   // display the following character in the next cell
      52                 :            : #define ST_NDP  3   // non-display
      53                 :            : 
      54                 :            : static const sal_Int16 thaiCompRel[MAX_CT][MAX_CT] = {
      55                 :            :     //  C  N  C  L  F  F  F  B  B  B  T  A  A  A  A  A  A
      56                 :            :     //  T  O  O  V  V  V  V  V  V  D  O  D  D  D  V  V  V
      57                 :            :     //  R  N  N     1  2  3  1  2     N  1  2  3  1  2  3
      58                 :            :     //  L     S                       E
      59                 :            :     //  0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
      60                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // CTRL 0
      61                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // NON  1
      62                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM, ST_COM   }, // CONS 2
      63                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // LV   3
      64                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // FV1  4
      65                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // FV2  5
      66                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // FV3  6
      67                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_COM, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // BV1  7
      68                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // BV2  8
      69                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // BD   9
      70                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // TONE 10
      71                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // AD1  11
      72                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // AD2  12
      73                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // AD3  13
      74                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_COM, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // AV1  14
      75                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT   }, // AV2  15
      76                 :            :     {   ST_NDP, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_NXT, ST_COM, ST_NXT, ST_COM, ST_NXT, ST_NXT, ST_NXT, ST_NXT   } // AV3  16
      77                 :            : 
      78                 :            : };
      79                 :            : 
      80                 :            : const sal_uInt32 is_ST_COM = (1<<CT_CTRL)|(1<<CT_NON)|(1<<CT_CONS)|(1<<CT_TONE);
      81                 :            : 
      82                 :          0 : static sal_uInt16 SAL_CALL getCombState(const sal_Unicode *text, sal_Int32 pos)
      83                 :            : {
      84 [ #  # ][ #  # ]:          0 :     sal_uInt16 ch1 = getCharType(text[pos]);
      85 [ #  # ][ #  # ]:          0 :     sal_uInt16 ch2 = getCharType(text[pos+1]);
      86                 :            : 
      87         [ #  # ]:          0 :     if (text[pos+1] == SARA_AM) {
      88         [ #  # ]:          0 :         if ((1 << ch1) & is_ST_COM)
      89                 :          0 :         return  ST_COM;
      90                 :            :         else
      91                 :          0 :         ch2 = CT_AD1;
      92                 :            :     }
      93                 :            : 
      94                 :          0 :     return thaiCompRel[ch1][ch2];
      95                 :            : }
      96                 :            : 
      97                 :            : 
      98                 :          0 : static sal_Int32 SAL_CALL getACell(const sal_Unicode *text, sal_Int32 pos, sal_Int32 len)
      99                 :            : {
     100                 :          0 :     sal_uInt32 curr = 1;
     101 [ #  # ][ #  # ]:          0 :     for (; pos + 1 < len && getCombState(text, pos) == ST_COM; curr++, pos++) {}
                 [ #  # ]
     102                 :          0 :     return curr;
     103                 :            : }
     104                 :            : 
     105                 :            : #define is_Thai(c)  (0x0e00 <= c && c <= 0x0e7f) // Unicode definition for Thai
     106                 :            : 
     107                 :          0 : void SAL_CALL BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 nStartPos)
     108                 :            :     throw(RuntimeException)
     109                 :            : {
     110         [ #  # ]:          0 :     if (Text != cachedText) {
     111                 :          0 :         cachedText = Text;
     112         [ #  # ]:          0 :         if (cellIndexSize < cachedText.getLength()) {
     113                 :          0 :         cellIndexSize = cachedText.getLength();
     114                 :          0 :         free(nextCellIndex);
     115                 :          0 :         free(previousCellIndex);
     116                 :          0 :         nextCellIndex = (sal_Int32*) calloc(cellIndexSize, sizeof(sal_Int32));
     117                 :          0 :         previousCellIndex = (sal_Int32*) calloc(cellIndexSize, sizeof(sal_Int32));
     118                 :            :         }
     119                 :            :         // reset nextCell for new Text
     120                 :          0 :         memset(nextCellIndex, 0, cellIndexSize * sizeof(sal_Int32));
     121                 :            :     }
     122 [ #  # ][ #  # ]:          0 :     else if (nextCellIndex[nStartPos] > 0 || ! is_Thai(Text[nStartPos]))
         [ #  # ][ #  # ]
     123                 :          0 :         return;
     124                 :            : 
     125                 :          0 :     const sal_Unicode* str = cachedText.getStr();
     126                 :          0 :     sal_Int32 len = cachedText.getLength(), startPos, endPos;
     127                 :            : 
     128                 :          0 :     startPos = nStartPos;
     129 [ #  # ][ #  # ]:          0 :     while (startPos > 0 && is_Thai(str[startPos-1])) startPos--;
         [ #  # ][ #  # ]
     130                 :          0 :     endPos = nStartPos+1;
     131 [ #  # ][ #  # ]:          0 :     while (endPos < len && is_Thai(str[endPos])) endPos++;
         [ #  # ][ #  # ]
     132                 :            : 
     133                 :            :     sal_Int32 start, end, pos;
     134                 :          0 :     pos = start = end = startPos;
     135                 :            : 
     136         [ #  # ]:          0 :     while (pos < endPos) {
     137                 :          0 :         end += getACell(str, start, endPos);
     138         [ #  # ]:          0 :         while (pos < end) {
     139                 :          0 :         nextCellIndex[pos] = end;
     140                 :          0 :         previousCellIndex[pos] = start;
     141                 :          0 :         pos++;
     142                 :            :         }
     143                 :          0 :         start = end;
     144                 :            :     }
     145                 :            : }
     146                 :            : 
     147                 :            : } } } }
     148                 :            : 
     149                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10