LCOV - code coverage report
Current view: top level - libreoffice/i18npool/source/inputchecker - inputsequencechecker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-12-27 Functions: 0 11 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.hxx>
      22             : #include <com/sun/star/i18n/InputSequenceCheckMode.hpp>
      23             : #include <com/sun/star/i18n/UnicodeType.hpp>
      24             : #include <i18nutil/unicode.hxx>
      25             : #include <rtl/ustrbuf.hxx>
      26             : 
      27             : using namespace ::com::sun::star::uno;
      28             : using namespace ::com::sun::star::lang;
      29             : using namespace ::rtl;
      30             : 
      31             : namespace com { namespace sun { namespace star { namespace i18n {
      32             : 
      33           0 : InputSequenceCheckerImpl::InputSequenceCheckerImpl( const Reference < XMultiServiceFactory >& rxMSF ) : xMSF( rxMSF )
      34             : {
      35           0 :         serviceName = "com.sun.star.i18n.InputSequenceCheckerImpl";
      36           0 :         cachedItem = NULL;
      37           0 : }
      38             : 
      39           0 : InputSequenceCheckerImpl::InputSequenceCheckerImpl()
      40             : {
      41           0 : }
      42             : 
      43           0 : InputSequenceCheckerImpl::~InputSequenceCheckerImpl()
      44             : {
      45             :         // Clear lookuptable
      46           0 :         for (size_t l = 0; l < lookupTable.size(); l++)
      47           0 :             delete lookupTable[l];
      48             : 
      49           0 :         lookupTable.clear();
      50           0 : }
      51             : 
      52             : sal_Bool SAL_CALL
      53           0 : InputSequenceCheckerImpl::checkInputSequence(const OUString& Text, sal_Int32 nStartPos,
      54             :         sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(RuntimeException)
      55             : {
      56           0 :         if (inputCheckMode == InputSequenceCheckMode::PASSTHROUGH)
      57           0 :             return sal_True;
      58             : 
      59           0 :         sal_Char* language = getLanguageByScripType(Text[nStartPos], inputChar);
      60             : 
      61           0 :         if (language)
      62           0 :             return getInputSequenceChecker(language)->checkInputSequence(Text, nStartPos, inputChar, inputCheckMode);
      63             :         else
      64           0 :             return sal_True; // not a checkable languages.
      65             : }
      66             : 
      67             : sal_Int32 SAL_CALL
      68           0 : InputSequenceCheckerImpl::correctInputSequence(OUString& Text, sal_Int32 nStartPos,
      69             :         sal_Unicode inputChar, sal_Int16 inputCheckMode) throw(RuntimeException)
      70             : {
      71           0 :         if (inputCheckMode != InputSequenceCheckMode::PASSTHROUGH) {
      72           0 :             sal_Char* language = getLanguageByScripType(Text[nStartPos], inputChar);
      73             : 
      74           0 :             if (language)
      75           0 :                 return getInputSequenceChecker(language)->correctInputSequence(Text, nStartPos, inputChar, inputCheckMode);
      76             :         }
      77           0 :         Text = Text.replaceAt(++nStartPos, 0, OUString(inputChar));
      78           0 :         return nStartPos;
      79             : }
      80             : 
      81             : static ScriptTypeList typeList[] = {
      82             :         //{ UnicodeScript_kHebrew,              UnicodeScript_kHebrew },        // 10,
      83             :         //{ UnicodeScript_kArabic,              UnicodeScript_kArabic },        // 11,
      84             :         { UnicodeScript_kDevanagari,UnicodeScript_kDevanagari,          UnicodeScript_kDevanagari },    // 14,
      85             :         { UnicodeScript_kThai,  UnicodeScript_kThai,                  UnicodeScript_kThai },          // 24,
      86             : 
      87             :         { UnicodeScript_kScriptCount,   UnicodeScript_kScriptCount,           UnicodeScript_kScriptCount }    // 88
      88             : };
      89             : 
      90             : sal_Char* SAL_CALL
      91           0 : InputSequenceCheckerImpl::getLanguageByScripType(sal_Unicode cChar, sal_Unicode nChar)
      92             : {
      93           0 :     sal_Int16 type = unicode::getUnicodeScriptType( cChar, typeList, UnicodeScript_kScriptCount );
      94             : 
      95           0 :     if (type != UnicodeScript_kScriptCount &&
      96           0 :             type == unicode::getUnicodeScriptType( nChar, typeList, UnicodeScript_kScriptCount )) {
      97           0 :         switch(type) {
      98           0 :             case UnicodeScript_kThai:           return (sal_Char*)"th";
      99             :             //case UnicodeScript_kArabic:       return (sal_Char*)"ar";
     100             :             //case UnicodeScript_kHebrew:       return (sal_Char*)"he";
     101           0 :             case UnicodeScript_kDevanagari:   return (sal_Char*)"hi";
     102             :         }
     103             :     }
     104           0 :     return NULL;
     105             : }
     106             : 
     107             : Reference< XExtendedInputSequenceChecker >& SAL_CALL
     108           0 : InputSequenceCheckerImpl::getInputSequenceChecker(sal_Char* rLanguage) throw (RuntimeException)
     109             : {
     110           0 :         if (cachedItem && cachedItem->aLanguage == rLanguage) {
     111           0 :             return cachedItem->xISC;
     112             :         }
     113           0 :         else if (xMSF.is()) {
     114           0 :             for (size_t l = 0; l < lookupTable.size(); l++) {
     115           0 :                 cachedItem = lookupTable[l];
     116           0 :                 if (cachedItem->aLanguage == rLanguage)
     117           0 :                     return cachedItem->xISC;
     118             :             }
     119             : 
     120           0 :             Reference < uno::XInterface > xI = xMSF->createInstance(
     121             :                         OUString("com.sun.star.i18n.InputSequenceChecker_") +
     122           0 :                         OUString::createFromAscii(rLanguage));
     123             : 
     124           0 :             if ( xI.is() ) {
     125           0 :                 Reference< XExtendedInputSequenceChecker > xISC;
     126           0 :                 xI->queryInterface( getCppuType((const Reference< XExtendedInputSequenceChecker>*)0) ) >>= xISC;
     127           0 :                 if (xISC.is()) {
     128           0 :                     lookupTable.push_back(cachedItem = new lookupTableItem(rLanguage, xISC));
     129           0 :                     return cachedItem->xISC;
     130           0 :                 }
     131           0 :             }
     132             :         }
     133           0 :         throw RuntimeException();
     134             : }
     135             : 
     136             : OUString SAL_CALL
     137           0 : InputSequenceCheckerImpl::getImplementationName(void) throw( RuntimeException )
     138             : {
     139           0 :         return OUString::createFromAscii(serviceName);
     140             : }
     141             : 
     142             : sal_Bool SAL_CALL
     143           0 : InputSequenceCheckerImpl::supportsService(const OUString& rServiceName) throw( RuntimeException )
     144             : {
     145           0 :         return !rServiceName.compareToAscii(serviceName);
     146             : }
     147             : 
     148             : Sequence< OUString > SAL_CALL
     149           0 : InputSequenceCheckerImpl::getSupportedServiceNames(void) throw( RuntimeException )
     150             : {
     151           0 :         Sequence< OUString > aRet(1);
     152           0 :         aRet[0] = OUString::createFromAscii(serviceName);
     153           0 :         return aRet;
     154             : }
     155             : 
     156             : } } } }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10