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

Generated by: LCOV version 1.10