LCOV - code coverage report
Current view: top level - include/unotools - transliterationwrapper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 1 100.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             : #include <unotools/unotoolsdllapi.h>
      20             : 
      21             : #ifndef INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
      22             : #define INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
      23             : 
      24             : #include <rtl/ustring.hxx>
      25             : #include <i18nlangtag/languagetag.hxx>
      26             : #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
      27             : 
      28             : namespace com { namespace sun { namespace star {
      29             :     namespace uno {
      30             :         class XComponentContext;
      31             :     }
      32             : }}}
      33             : 
      34             : namespace utl
      35             : {
      36             : 
      37             : class UNOTOOLS_DLLPUBLIC TransliterationWrapper
      38             : {
      39             :     ::com::sun::star::uno::Reference<
      40             :         ::com::sun::star::i18n::XExtendedTransliteration > xTrans;
      41             :     LanguageTag aLanguageTag;
      42             :     sal_uInt32 nType;
      43             :     mutable bool bFirstCall;
      44             : 
      45             :     TransliterationWrapper( const TransliterationWrapper& ) SAL_DELETED_FUNCTION;
      46             :     TransliterationWrapper& operator=( const TransliterationWrapper& ) SAL_DELETED_FUNCTION;
      47             : 
      48             :     void loadModuleImpl() const;
      49             :     void setLanguageLocaleImpl( sal_uInt16 nLang );
      50             : 
      51             : public:
      52             :     TransliterationWrapper( const ::com::sun::star::uno::Reference<
      53             :                     ::com::sun::star::uno::XComponentContext > & rxContext,
      54             :                     sal_uInt32 nType );
      55             : 
      56             :     ~TransliterationWrapper();
      57             : 
      58             :     // get current Locale / Language
      59             :     const ::com::sun::star::lang::Locale& getLocale() const { return aLanguageTag.getLocale();}
      60             :     sal_uInt16 getLanguage() const { return aLanguageTag.getLanguageType(); }
      61             : 
      62          11 :     sal_uInt32 getType() const { return nType; }
      63             : 
      64             :     bool needLanguageForTheMode() const;
      65             : 
      66             :     /** set a new language and load the corresponding transliteration module if
      67             :         needed for the mode set with nType in the ctor */
      68             :     void loadModuleIfNeeded( sal_uInt16 nLang );
      69             : 
      70             :     /** Load the transliteration module specified by rModuleName, which has to
      71             :         be the UNO service implementation name that is expanded to the full UNO
      72             :         service implementation name, for example, "NumToCharKanjiShort_ja_JP"
      73             :         expands to
      74             :         "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP".
      75             :         @ATTENTION!
      76             :         This method ignores the mode type set with the constructor and
      77             :         interferes with the loadModuleIfNeeded() method and the transliterate()
      78             :         method that gets a LanguageType passed as parameter.  Using one of
      79             :         those may load a different module and overwrite this setting. Only the
      80             :         transliterate() method that takes no LanguageType parameter may be used
      81             :         for a specific module loaded with this method.  */
      82             :     void loadModuleByImplName( const OUString& rModuleName, sal_uInt16 nLang );
      83             : 
      84             :     /** This transliteration method corresponds with the loadModuleByImplName()
      85             :         method. It relies on a module being loaded and does not try load one.
      86             :         If for any reason the string can't be transliterated the original
      87             :         string is returned.  */
      88             :     OUString transliterate( const OUString& rStr,
      89             :                         sal_Int32 nStart, sal_Int32 nLen,
      90             :                         ::com::sun::star::uno::Sequence <sal_Int32>* pOffset ) const;
      91             : 
      92             :     // Wrapper implementations of class Transliteration
      93             :     OUString transliterate( const OUString& rStr, sal_uInt16 nLanguage,
      94             :                         sal_Int32 nStart, sal_Int32 nLen,
      95             :                         ::com::sun::star::uno::Sequence <sal_Int32>* pOffset );
      96             : 
      97             :     /** If two strings are equal per this transliteration.
      98             :         Returns the number of matched code points in any case, even if strings
      99             :         are not equal, for example:
     100             :         equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 )
     101             :         returns false and nMatch:=1 and nMatch2:=1
     102             :         equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 )
     103             :         returns false and nMatch:=2 and nMatch2:=2
     104             :      */
     105             :     bool equals(
     106             :         const OUString& rStr1, sal_Int32 nPos1, sal_Int32 nCount1, sal_Int32& nMatch1,
     107             :         const OUString& rStr2, sal_Int32 nPos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) const;
     108             : 
     109             :     sal_Int32 compareString( const OUString& rStr1, const OUString& rStr2 ) const;
     110             : 
     111             :     // helpers
     112             : 
     113             :     /** If two strings are really equal as per this translation, and not just
     114             :         one string is matching the start of the other. Use this method instead
     115             :         of compareString()==0 because it is much faster.
     116             :      */
     117             :     bool isEqual( const OUString& rStr1, const OUString& rStr2 ) const;
     118             : 
     119             :     /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa"
     120             :      */
     121             :     bool isMatch( const OUString& rStr1, const OUString& rStr2 ) const;
     122             : 
     123             : };
     124             : 
     125             : }       // namespace utl
     126             : 
     127             : #endif
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11