LCOV - code coverage report
Current view: top level - vcl/source/app - i18nhelp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 71 64.8 %
Date: 2012-08-25 Functions: 7 11 63.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 114 28.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "unotools/localedatawrapper.hxx"
      31                 :            : #include "unotools/transliterationwrapper.hxx"
      32                 :            : 
      33                 :            : #include "i18npool/mslangid.hxx"
      34                 :            : 
      35                 :            : #include "rtl/ustrbuf.hxx"
      36                 :            : 
      37                 :            : #include "vcl/i18nhelp.hxx"
      38                 :            : 
      39                 :            : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      40                 :            : #include "com/sun/star/i18n/TransliterationModules.hpp"
      41                 :            : 
      42                 :            : using namespace ::com::sun::star;
      43                 :            : 
      44                 :        122 : vcl::I18nHelper::I18nHelper(  ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxMSF, const ::com::sun::star::lang::Locale& rLocale )
      45                 :            : {
      46         [ +  - ]:        122 :     mxMSF = rxMSF;
      47                 :        122 :     maLocale = rLocale;
      48                 :        122 :     mpLocaleDataWrapper = NULL;
      49                 :        122 :     mpTransliterationWrapper= NULL;
      50                 :        122 :     mbTransliterateIgnoreCase = sal_False;
      51                 :        122 : }
      52                 :            : 
      53                 :         96 : vcl::I18nHelper::~I18nHelper()
      54                 :            : {
      55         [ +  - ]:         96 :     ImplDestroyWrappers();
      56                 :         96 : }
      57                 :            : 
      58                 :         96 : void vcl::I18nHelper::ImplDestroyWrappers()
      59                 :            : {
      60         [ -  + ]:         96 :     delete mpLocaleDataWrapper;
      61                 :         96 :     mpLocaleDataWrapper = NULL;
      62                 :            : 
      63         [ +  + ]:         96 :     delete mpTransliterationWrapper;
      64                 :         96 :     mpTransliterationWrapper= NULL;
      65                 :         96 : }
      66                 :            : 
      67                 :       1100 : utl::TransliterationWrapper& vcl::I18nHelper::ImplGetTransliterationWrapper() const
      68                 :            : {
      69         [ +  + ]:       1100 :     if ( !mpTransliterationWrapper )
      70                 :            :     {
      71                 :         56 :         sal_Int32 nModules = i18n::TransliterationModules_IGNORE_WIDTH;
      72         [ +  - ]:         56 :         if ( mbTransliterateIgnoreCase )
      73                 :         56 :             nModules |= i18n::TransliterationModules_IGNORE_CASE;
      74                 :            : 
      75         [ +  - ]:         56 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = new utl::TransliterationWrapper( mxMSF, (i18n::TransliterationModules)nModules );
      76                 :         56 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper->loadModuleIfNeeded( MsLangId::convertLocaleToLanguage( maLocale ) );
      77                 :            :     }
      78                 :       1100 :     return *mpTransliterationWrapper;
      79                 :            : }
      80                 :            : 
      81                 :          0 : LocaleDataWrapper& vcl::I18nHelper::ImplGetLocaleDataWrapper() const
      82                 :            : {
      83         [ #  # ]:          0 :     if ( !mpLocaleDataWrapper )
      84                 :            :     {
      85         [ #  # ]:          0 :         ((vcl::I18nHelper*)this)->mpLocaleDataWrapper = new LocaleDataWrapper( mxMSF, maLocale );
      86                 :            :     }
      87                 :          0 :     return *mpLocaleDataWrapper;
      88                 :            : }
      89                 :            : 
      90                 :     208266 : inline bool is_formatting_mark( sal_Unicode c )
      91                 :            : {
      92 [ -  + ][ #  # ]:     208266 :     if( (c >= 0x200B) && (c <= 0x200F) )    // BiDi and zero-width-markers
      93                 :          0 :         return true;
      94 [ -  + ][ #  # ]:     208266 :     if( (c >= 0x2028) && (c <= 0x202E) )    // BiDi and paragraph-markers
      95                 :          0 :         return true;
      96                 :     208266 :     return false;
      97                 :            : }
      98                 :            : 
      99                 :            : /* #i100057# filter formatting marks out of strings before passing them to
     100                 :            :    the transliteration. The real solution would have been an additional TransliterationModule
     101                 :            :    to ignore these marks during transliteration; however changin the code in i18npool that actually
     102                 :            :    implements this could produce unwanted side effects.
     103                 :            : 
     104                 :            :    Of course this copying around is not really good, but looking at i18npool, one more time
     105                 :            :    will not hurt.
     106                 :            : */
     107                 :      31522 : String vcl::I18nHelper::filterFormattingChars( const String& rStr )
     108                 :            : {
     109                 :      31522 :     sal_Int32 nUnicodes = rStr.Len();
     110                 :      31522 :     rtl::OUStringBuffer aBuf( nUnicodes );
     111                 :      31522 :     const sal_Unicode* pStr = rStr.GetBuffer();
     112         [ +  + ]:     239788 :     while( nUnicodes-- )
     113                 :            :     {
     114         [ +  - ]:     208266 :         if( ! is_formatting_mark( *pStr ) )
     115         [ +  - ]:     208266 :             aBuf.append( *pStr );
     116                 :     208266 :         pStr++;
     117                 :            :     }
     118 [ +  - ][ +  - ]:      31522 :     return aBuf.makeStringAndClear();
     119                 :            : }
     120                 :            : 
     121                 :          0 : sal_Int32 vcl::I18nHelper::CompareString( const rtl::OUString& rStr1, const rtl::OUString& rStr2 ) const
     122                 :            : {
     123         [ #  # ]:          0 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     124                 :            : 
     125         [ #  # ]:          0 :     if ( mbTransliterateIgnoreCase )
     126                 :            :     {
     127                 :            :         // Change mbTransliterateIgnoreCase and destroy the warpper, next call to
     128                 :            :         // ImplGetTransliterationWrapper() will create a wrapper with the correct bIgnoreCase
     129                 :          0 :         ((vcl::I18nHelper*)this)->mbTransliterateIgnoreCase = sal_False;
     130 [ #  # ][ #  # ]:          0 :         delete ((vcl::I18nHelper*)this)->mpTransliterationWrapper;
     131                 :          0 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = NULL;
     132                 :            :     }
     133                 :            : 
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :     String aStr1( filterFormattingChars(rStr1) );
                 [ #  # ]
     136 [ #  # ][ #  # ]:          0 :     String aStr2( filterFormattingChars(rStr2) );
                 [ #  # ]
     137 [ #  # ][ #  # ]:          0 :     return ImplGetTransliterationWrapper().compareString( aStr1, aStr2 );
         [ #  # ][ #  # ]
                 [ #  # ]
     138                 :            : }
     139                 :            : 
     140                 :       1100 : sal_Bool vcl::I18nHelper::MatchString( const rtl::OUString& rStr1, const rtl::OUString& rStr2 ) const
     141                 :            : {
     142         [ +  - ]:       1100 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     143                 :            : 
     144         [ +  + ]:       1100 :     if ( !mbTransliterateIgnoreCase )
     145                 :            :     {
     146                 :            :         // Change mbTransliterateIgnoreCase and destroy the warpper, next call to
     147                 :            :         // ImplGetTransliterationWrapper() will create a wrapper with the correct bIgnoreCase
     148                 :         56 :         ((vcl::I18nHelper*)this)->mbTransliterateIgnoreCase = sal_True;
     149 [ -  + ][ #  # ]:         56 :         delete ((vcl::I18nHelper*)this)->mpTransliterationWrapper;
     150                 :         56 :         ((vcl::I18nHelper*)this)->mpTransliterationWrapper = NULL;
     151                 :            :     }
     152                 :            : 
     153 [ +  - ][ +  - ]:       1100 :     String aStr1( filterFormattingChars(rStr1) );
                 [ +  - ]
     154 [ +  - ][ +  - ]:       1100 :     String aStr2( filterFormattingChars(rStr2) );
                 [ +  - ]
     155 [ +  - ][ +  - ]:       1100 :     return ImplGetTransliterationWrapper().isMatch( aStr1, aStr2 );
         [ +  - ][ +  - ]
                 [ +  - ]
     156                 :            : }
     157                 :            : 
     158                 :          0 : sal_Bool vcl::I18nHelper::MatchMnemonic( const String& rString, sal_Unicode cMnemonicChar ) const
     159                 :            : {
     160         [ #  # ]:          0 :     ::osl::Guard< ::osl::Mutex > aGuard( ((vcl::I18nHelper*)this)->maMutex );
     161                 :            : 
     162                 :          0 :     sal_Bool bEqual = sal_False;
     163         [ #  # ]:          0 :     sal_uInt16 n = rString.Search( '~' );
     164         [ #  # ]:          0 :     if ( n != STRING_NOTFOUND )
     165                 :            :     {
     166         [ #  # ]:          0 :         String aMatchStr( rString, n+1, STRING_LEN );   // not only one char, because of transliteration...
     167 [ #  # ][ #  # ]:          0 :         bEqual = MatchString( rtl::OUString(cMnemonicChar), aMatchStr );
                 [ #  # ]
     168                 :            :     }
     169         [ #  # ]:          0 :     return bEqual;
     170                 :            : }
     171                 :            : 
     172                 :            : 
     173                 :          0 : String vcl::I18nHelper::GetNum( long nNumber, sal_uInt16 nDecimals, sal_Bool bUseThousandSep, sal_Bool bTrailingZeros ) const
     174                 :            : {
     175         [ #  # ]:          0 :     return ImplGetLocaleDataWrapper().getNum( nNumber, nDecimals, bUseThousandSep, bTrailingZeros );
     176                 :            : }
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10