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

Generated by: LCOV version 1.10