LCOV - code coverage report
Current view: top level - vcl/source/app - i18nhelp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 71 73.2 %
Date: 2014-04-11 Functions: 9 11 81.8 %
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 "comphelper/processfactory.hxx"
      21             : #include "unotools/localedatawrapper.hxx"
      22             : #include "unotools/transliterationwrapper.hxx"
      23             : 
      24             : #include "i18nlangtag/languagetag.hxx"
      25             : 
      26             : #include "rtl/ustrbuf.hxx"
      27             : 
      28             : #include "vcl/i18nhelp.hxx"
      29             : 
      30             : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      31             : #include "com/sun/star/i18n/TransliterationModules.hpp"
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35         103 : vcl::I18nHelper::I18nHelper(  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const LanguageTag& rLanguageTag )
      36             :     :
      37         103 :         maLanguageTag( rLanguageTag)
      38             : {
      39         103 :     m_xContext = rxContext;
      40         103 :     mpLocaleDataWrapper = NULL;
      41         103 :     mpTransliterationWrapper= NULL;
      42         103 :     mbTransliterateIgnoreCase = false;
      43         103 : }
      44             : 
      45         110 : vcl::I18nHelper::~I18nHelper()
      46             : {
      47          55 :     ImplDestroyWrappers();
      48          55 : }
      49             : 
      50          55 : void vcl::I18nHelper::ImplDestroyWrappers()
      51             : {
      52          55 :     delete mpLocaleDataWrapper;
      53          55 :     mpLocaleDataWrapper = NULL;
      54             : 
      55          55 :     delete mpTransliterationWrapper;
      56          55 :     mpTransliterationWrapper= NULL;
      57          55 : }
      58             : 
      59       10360 : utl::TransliterationWrapper& vcl::I18nHelper::ImplGetTransliterationWrapper() const
      60             : {
      61       10360 :     if ( !mpTransliterationWrapper )
      62             :     {
      63          47 :         sal_Int32 nModules = i18n::TransliterationModules_IGNORE_WIDTH;
      64          47 :         if ( mbTransliterateIgnoreCase )
      65          47 :             nModules |= i18n::TransliterationModules_IGNORE_CASE;
      66             : 
      67          47 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = new utl::TransliterationWrapper( m_xContext, (i18n::TransliterationModules)nModules );
      68          47 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper->loadModuleIfNeeded( maLanguageTag.getLanguageType() );
      69             :     }
      70       10360 :     return *mpTransliterationWrapper;
      71             : }
      72             : 
      73        1731 : LocaleDataWrapper& vcl::I18nHelper::ImplGetLocaleDataWrapper() const
      74             : {
      75        1731 :     if ( !mpLocaleDataWrapper )
      76             :     {
      77          37 :         ((vcl::I18nHelper*)this)->mpLocaleDataWrapper = new LocaleDataWrapper( m_xContext, maLanguageTag );
      78             :     }
      79        1731 :     return *mpLocaleDataWrapper;
      80             : }
      81             : 
      82      546515 : inline bool is_formatting_mark( sal_Unicode c )
      83             : {
      84      546515 :     if( (c >= 0x200B) && (c <= 0x200F) )    // BiDi and zero-width-markers
      85           0 :         return true;
      86      546515 :     if( (c >= 0x2028) && (c <= 0x202E) )    // BiDi and paragraph-markers
      87           0 :         return true;
      88      546515 :     return false;
      89             : }
      90             : 
      91             : /* #i100057# filter formatting marks out of strings before passing them to
      92             :    the transliteration. The real solution would have been an additional TransliterationModule
      93             :    to ignore these marks during transliteration; however changin the code in i18npool that actually
      94             :    implements this could produce unwanted side effects.
      95             : 
      96             :    Of course this copying around is not really good, but looking at i18npool, one more time
      97             :    will not hurt.
      98             : */
      99       96493 : OUString vcl::I18nHelper::filterFormattingChars( const OUString& rStr )
     100             : {
     101       96493 :     sal_Int32 nUnicodes = rStr.getLength();
     102       96493 :     OUStringBuffer aBuf( nUnicodes );
     103       96493 :     const sal_Unicode* pStr = rStr.getStr();
     104      739501 :     while( nUnicodes-- )
     105             :     {
     106      546515 :         if( ! is_formatting_mark( *pStr ) )
     107      546515 :             aBuf.append( *pStr );
     108      546515 :         pStr++;
     109             :     }
     110       96493 :     return aBuf.makeStringAndClear();
     111             : }
     112             : 
     113           0 : sal_Int32 vcl::I18nHelper::CompareString( const OUString& rStr1, const OUString& rStr2 ) const
     114             : {
     115           0 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     116             : 
     117           0 :     if ( mbTransliterateIgnoreCase )
     118             :     {
     119             :         // Change mbTransliterateIgnoreCase and destroy the warpper, next call to
     120             :         // ImplGetTransliterationWrapper() will create a wrapper with the correct bIgnoreCase
     121           0 :         ((vcl::I18nHelper*)this)->mbTransliterateIgnoreCase = false;
     122           0 :         delete ((vcl::I18nHelper*)this)->mpTransliterationWrapper;
     123           0 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = NULL;
     124             :     }
     125             : 
     126           0 :     OUString aStr1( filterFormattingChars(rStr1) );
     127           0 :     OUString aStr2( filterFormattingChars(rStr2) );
     128           0 :     return ImplGetTransliterationWrapper().compareString( aStr1, aStr2 );
     129             : }
     130             : 
     131       10360 : bool vcl::I18nHelper::MatchString( const OUString& rStr1, const OUString& rStr2 ) const
     132             : {
     133       10360 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     134             : 
     135       10360 :     if ( !mbTransliterateIgnoreCase )
     136             :     {
     137             :         // Change mbTransliterateIgnoreCase and destroy the warpper, next call to
     138             :         // ImplGetTransliterationWrapper() will create a wrapper with the correct bIgnoreCase
     139          47 :         ((vcl::I18nHelper*)this)->mbTransliterateIgnoreCase = true;
     140          47 :         delete ((vcl::I18nHelper*)this)->mpTransliterationWrapper;
     141          47 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = NULL;
     142             :     }
     143             : 
     144       20720 :     OUString aStr1( filterFormattingChars(rStr1) );
     145       20720 :     OUString aStr2( filterFormattingChars(rStr2) );
     146       20720 :     return ImplGetTransliterationWrapper().isMatch( aStr1, aStr2 );
     147             : }
     148             : 
     149           0 : bool vcl::I18nHelper::MatchMnemonic( const OUString& rString, sal_Unicode cMnemonicChar ) const
     150             : {
     151           0 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     152             : 
     153           0 :     bool bEqual = false;
     154           0 :     sal_Int32 n = rString.indexOf( '~' );
     155           0 :     if ( n != -1 )
     156             :     {
     157           0 :         OUString aMatchStr = rString.copy( n+1 );   // not only one char, because of transliteration...
     158           0 :         bEqual = MatchString( OUString(cMnemonicChar), aMatchStr );
     159             :     }
     160           0 :     return bEqual;
     161             : }
     162             : 
     163        1731 : OUString vcl::I18nHelper::GetNum( long nNumber, sal_uInt16 nDecimals, bool bUseThousandSep, bool bTrailingZeros ) const
     164             : {
     165        1731 :     return ImplGetLocaleDataWrapper().getNum( nNumber, nDecimals, bUseThousandSep, bTrailingZeros );
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10