LCOV - code coverage report
Current view: top level - libreoffice/i18npool/source/inputchecker - inputsequencechecker_th.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 37 0.0 %
Date: 2012-12-27 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          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             : 
      21             : #include <inputsequencechecker_th.hxx>
      22             : #include <wtt.h>
      23             : 
      24             : using ::rtl::OUString;
      25             : 
      26             : namespace com { namespace sun { namespace star { namespace i18n {
      27             : 
      28           0 : InputSequenceChecker_th::InputSequenceChecker_th()
      29             : {
      30           0 :     serviceName = "com.sun.star.i18n.InputSequenceChecker_th";
      31           0 : }
      32             : 
      33           0 : InputSequenceChecker_th::~InputSequenceChecker_th()
      34             : {
      35           0 : }
      36             : 
      37             : /* Table for Thai Cell Manipulation */
      38             : sal_Char _TAC_celltype_inputcheck[17][17] = {
      39             : /* Cn */ /*  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,   A,   B,   C,   D,   E,   F       */
      40             : /* Cn-1 00 */{  'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      41             :      /* 10 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      42             :      /* 20 */{  'X', 'A', 'A', 'A', 'A', 'S', 'A', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C' },
      43             :      /* 30 */{  'X', 'S', 'A', 'S', 'S', 'S', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      44             :      /* 40 */{  'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      45             :      /* 50 */{  'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      46             :      /* 60 */{  'X', 'A', 'A', 'A', 'S', 'A', 'S', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      47             :      /* 70 */{  'X', 'A', 'A', 'A', 'A', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' },
      48             :      /* 80 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' },
      49             :      /* 90 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      50             :      /* A0 */{  'X', 'A', 'A', 'A', 'A', 'A', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      51             :      /* B0 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      52             :      /* C0 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      53             :      /* D0 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R' },
      54             :      /* E0 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'C', 'R', 'R', 'R', 'R', 'R' },
      55             :      /* F0 */{  'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'R', 'R', 'R', 'R', 'R' },
      56             :          { 'X', 'A', 'A', 'A', 'S', 'S', 'A', 'R', 'R', 'R', 'C', 'R', 'C', 'R', 'R', 'R', 'R' }
      57             : };
      58             : 
      59             : sal_Bool _TAC_Composible[3][5] = {
      60             :         /*  'A',    'C',        'S',        'R',        'X'   */
      61             : /* Mode 0 */    {sal_True,  sal_True,   sal_True,   sal_True,   sal_True}, // PASSTHROUGH = 0
      62             : /* Mode 1 */    {sal_True,  sal_True,   sal_True,   sal_False,      sal_True}, // BASIC = 1
      63             : /* Mode 2 */    {sal_True,  sal_True,   sal_False,      sal_False,      sal_True}  // STRICT = 2
      64             : };
      65             : 
      66           0 : static sal_Bool SAL_CALL check(sal_Unicode ch1, sal_Unicode ch2, sal_Int16 inputCheckMode)
      67             : {
      68             :     sal_Int16  composible_class;
      69           0 :     switch (_TAC_celltype_inputcheck[getCharType(ch1)][getCharType(ch2)]) {
      70           0 :         case 'A': composible_class = 0; break;
      71           0 :         case 'C': composible_class = 1; break;
      72           0 :         case 'S': composible_class = 2; break;
      73           0 :         case 'R': composible_class = 3; break;
      74           0 :         case 'X': composible_class = 4; break;
      75           0 :         default:  composible_class = 0;
      76             :     }
      77           0 :     return (_TAC_Composible[inputCheckMode][composible_class]);
      78             : }
      79             : 
      80             : sal_Bool SAL_CALL
      81           0 : InputSequenceChecker_th::checkInputSequence(const OUString& Text, sal_Int32 nStartPos,
      82             :     sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(com::sun::star::uno::RuntimeException)
      83             : {
      84           0 :     return check(Text[nStartPos], inputChar, inputCheckMode);
      85             : }
      86             : 
      87             : sal_Int32 SAL_CALL
      88           0 : InputSequenceChecker_th::correctInputSequence(OUString& Text,
      89             :                                             sal_Int32       nStartPos,
      90             :                                             sal_Unicode     inputChar,
      91             :                                             sal_Int16       inputCheckMode)
      92             :   throw(com::sun::star::uno::RuntimeException)
      93             : {
      94             : /* 9 rules for input sequence correction, see issue i42661 for detail,
      95             : 
      96             : http://www.openoffice.org/issues/show_bug.cgi?id=42661
      97             : 
      98             : <abv> = <av1>|<av2>|<av3>|<bv1>|<bv2>
      99             : <abv1> = <av1>|<bv1>
     100             : <thanthakhat> = 0E4C (karan)
     101             : 
     102             : 1. <cons> <abv>_x + <abv>_y => <cons> <abv>_y (replace)
     103             : 2. <cons> <tone>_x + <tone>_y => <cons> <tone>_y (replace)
     104             : 3. <cons> <abv> <tone>_x + <tone>_y => <cons> <abv> <tone>_y (replace)
     105             : 4. <cons> <abv>_x <tone> + <abv>_y => <cons> <abv>_y <tone> (replace, reorder)
     106             : 5. <cons> <tone> + <abv> => <cons> <abv> <tone> (reorder)
     107             : 6. <cons> <fv1> + <tone> => <cons> <tone> <fv1> (reorder)
     108             : 7. <cons> <tone>_x <fv1> + <tone>_y => <cons> <tone>_y <fv1> (replace, reorder)
     109             : 8. <cons> <thanthakhat> + <abv1> => <cons> <abv1> <thanthakhat> (reorder)
     110             : 9. <cons> <abv1>_x <thanthakhat> + <abv1>_y => <cons> <abv1>_y <thanthakhat>(reorder, replace)
     111             : */
     112             : #define CT_ABV(t)  ( (t>=CT_AV1 && t<=CT_AV3) || t==CT_BV1 || t==CT_BV2)
     113             : #define CT_ABV1(t) (t==CT_AV1 || t==CT_BV1)
     114             : 
     115           0 :     if (check(Text[nStartPos], inputChar, inputCheckMode))
     116           0 :         Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
     117           0 :     else if (nStartPos > 0 && getCharType(Text[nStartPos-1]) == CT_CONS) {
     118           0 :         sal_uInt16 t1=getCharType(Text[nStartPos]), t2=getCharType(inputChar);
     119           0 :         if ( (CT_ABV(t1) && CT_ABV(t2)) || // 1.
     120             :                 (t1==CT_TONE && t2==CT_TONE) )// 2.
     121           0 :             Text = Text.replaceAt(nStartPos, 1, OUString(inputChar));
     122           0 :         else if ( (t1==CT_TONE && CT_ABV(t2)) ||  // 5.
     123             :                 (t1==CT_FV1 && t2==CT_TONE) ||  // 6.
     124           0 :                 (Text[nStartPos]==0x0E4C && CT_ABV1(t2)) ) // 8.
     125           0 :             Text = Text.replaceAt(nStartPos++, 0, OUString(inputChar));
     126             :         else
     127           0 :             nStartPos=Text.getLength();
     128           0 :     } else if (nStartPos > 1 && getCharType(Text[nStartPos-2]) == CT_CONS) {
     129           0 :         sal_uInt16 t1=getCharType(Text[nStartPos-1]), t2=getCharType(Text[nStartPos]), t3=getCharType(inputChar);
     130           0 :         if (CT_ABV(t1) && t2==CT_TONE && t3==CT_TONE) // 3.
     131           0 :             Text = Text.replaceAt(nStartPos, 1, OUString(inputChar));
     132           0 :         else if ( (CT_ABV(t1) && t2==CT_TONE && CT_ABV(t3)) || // 4.
     133             :                 (t1==CT_TONE && t2==CT_FV1 && t3==CT_TONE) || // 7.
     134           0 :                 (CT_ABV1(t1) && Text[nStartPos]==0x0E4C && CT_ABV1(t3)) ) // 9.
     135           0 :             Text = Text.replaceAt(nStartPos-1, 1, OUString(inputChar));
     136             :         else
     137           0 :             nStartPos=Text.getLength();
     138             :     } else
     139           0 :         nStartPos=Text.getLength();
     140             : 
     141           0 :     return nStartPos;
     142             : }
     143             : 
     144             : } } } }
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10