LCOV - code coverage report
Current view: top level - libreoffice/linguistic/source - hhconvdic.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 41 0.0 %
Date: 2012-12-27 Functions: 0 10 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             : #include <unicode/uscript.h>
      21             : #include <i18npool/lang.h>
      22             : #include <tools/fsys.hxx>
      23             : #include <tools/stream.hxx>
      24             : #include <tools/string.hxx>
      25             : #include <osl/mutex.hxx>
      26             : #include <ucbhelper/content.hxx>
      27             : 
      28             : #include <cppuhelper/factory.hxx>   // helper for factories
      29             : #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
      30             : #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
      31             : #include <com/sun/star/lang/Locale.hpp>
      32             : #include <com/sun/star/uno/Reference.h>
      33             : #include <com/sun/star/registry/XRegistryKey.hpp>
      34             : 
      35             : #include "hhconvdic.hxx"
      36             : #include "linguistic/misc.hxx"
      37             : #include "defs.hxx"
      38             : 
      39             : using namespace utl;
      40             : using namespace osl;
      41             : using namespace com::sun::star;
      42             : using namespace com::sun::star::lang;
      43             : using namespace com::sun::star::uno;
      44             : using namespace com::sun::star::linguistic2;
      45             : using namespace linguistic;
      46             : 
      47             : using ::rtl::OUString;
      48             : 
      49             : #define SN_HH_CONV_DICTIONARY   "com.sun.star.linguistic2.HangulHanjaConversionDictionary"
      50             : 
      51             : 
      52             : #include <i18nutil/unicode.hxx>
      53             : #include <com/sun/star/i18n/UnicodeScript.hpp>
      54             : 
      55             : using namespace i18n;
      56             : 
      57             : #define SCRIPT_OTHERS   0
      58             : #define SCRIPT_HANJA    1
      59             : #define SCRIPT_HANGUL   2
      60             : 
      61             : // from i18npool/source/textconversion/textconversion_ko.cxx
      62           0 : sal_Int16 SAL_CALL checkScriptType(sal_Unicode c) throw (RuntimeException)
      63             : {
      64           0 :   UErrorCode status = U_ZERO_ERROR;
      65             : 
      66           0 :   UScriptCode scriptCode = uscript_getScript(c, &status);
      67             : 
      68           0 :   if ( !U_SUCCESS(status) ) throw RuntimeException();
      69             : 
      70             :   return scriptCode == USCRIPT_HANGUL ? SCRIPT_HANGUL :
      71           0 :             scriptCode == USCRIPT_HAN ? SCRIPT_HANJA : SCRIPT_OTHERS;
      72             : }
      73             : 
      74             : 
      75             : 
      76           0 : sal_Bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType )
      77             : {
      78           0 :     sal_Bool bIsAll = sal_True;
      79           0 :     for (sal_Int32 i = 0;  i < rTxt.getLength() && bIsAll;  ++i)
      80             :     {
      81           0 :         if (checkScriptType( rTxt.getStr()[i]) != nScriptType)
      82           0 :             bIsAll = sal_False;
      83             :     }
      84           0 :     return bIsAll;
      85             : }
      86             : 
      87             : 
      88             : 
      89           0 : HHConvDic::HHConvDic( const String &rName, const String &rMainURL ) :
      90           0 :     ConvDic( rName, LANGUAGE_KOREAN, ConversionDictionaryType::HANGUL_HANJA, sal_True, rMainURL )
      91             : {
      92           0 : }
      93             : 
      94             : 
      95           0 : HHConvDic::~HHConvDic()
      96             : {
      97           0 : }
      98             : 
      99             : 
     100           0 : void SAL_CALL HHConvDic::addEntry(
     101             :         const OUString& aLeftText,
     102             :         const OUString& aRightText )
     103             :     throw (IllegalArgumentException, container::ElementExistException, RuntimeException)
     104             : {
     105           0 :     MutexGuard  aGuard( GetLinguMutex() );
     106             : 
     107           0 :     if ((aLeftText.getLength() != aRightText.getLength()) ||
     108           0 :         !TextIsAllScriptType( aLeftText,  SCRIPT_HANGUL ) ||
     109           0 :         !TextIsAllScriptType( aRightText, SCRIPT_HANJA ))
     110           0 :         throw IllegalArgumentException();
     111           0 :     ConvDic::addEntry( aLeftText, aRightText );
     112           0 : }
     113             : 
     114             : 
     115           0 : OUString SAL_CALL HHConvDic::getImplementationName(  )
     116             :     throw (RuntimeException)
     117             : {
     118           0 :     MutexGuard  aGuard( GetLinguMutex() );
     119           0 :     return getImplementationName_Static();
     120             : }
     121             : 
     122             : 
     123           0 : sal_Bool SAL_CALL HHConvDic::supportsService( const OUString& rServiceName )
     124             :     throw (RuntimeException)
     125             : {
     126           0 :     MutexGuard  aGuard( GetLinguMutex() );
     127           0 :     sal_Bool bRes = sal_False;
     128           0 :     if ( rServiceName == SN_CONV_DICTIONARY || rServiceName == SN_HH_CONV_DICTIONARY )
     129           0 :         bRes = sal_True;
     130           0 :     return bRes;
     131             : }
     132             : 
     133             : 
     134           0 : uno::Sequence< OUString > SAL_CALL HHConvDic::getSupportedServiceNames(  )
     135             :     throw (RuntimeException)
     136             : {
     137           0 :     MutexGuard  aGuard( GetLinguMutex() );
     138           0 :     return getSupportedServiceNames_Static();
     139             : }
     140             : 
     141             : 
     142           0 : uno::Sequence< OUString > HHConvDic::getSupportedServiceNames_Static()
     143             :     throw()
     144             : {
     145           0 :     uno::Sequence< OUString > aSNS( 2 );
     146           0 :     aSNS.getArray()[0] = A2OU( SN_CONV_DICTIONARY );
     147           0 :     aSNS.getArray()[1] = A2OU( SN_HH_CONV_DICTIONARY );
     148           0 :     return aSNS;
     149             : }
     150             : 
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10