LCOV - code coverage report
Current view: top level - svtools/source/misc - langtab.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 63 17.5 %
Date: 2012-08-25 Functions: 3 8 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 73 5.5 %

           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                 :            : #include <boost/static_assert.hpp>
      30                 :            : 
      31                 :            : #include <tools/shl.hxx>
      32                 :            : 
      33                 :            : #include <com/sun/star/i18n/DirectionProperty.hpp>
      34                 :            : 
      35                 :            : #include <i18npool/lang.h>
      36                 :            : #include <i18npool/mslangid.hxx>
      37                 :            : 
      38                 :            : #include <svtools/svtools.hrc>
      39                 :            : #include <svtools/svtresid.hxx>
      40                 :            : #include <svtools/langtab.hxx>
      41                 :            : #include <unotools/syslocale.hxx>
      42                 :            : 
      43                 :            : 
      44                 :            : using namespace ::com::sun::star;
      45                 :            : 
      46                 :            : //------------------------------------------------------------------------
      47                 :            : 
      48                 :          0 : SVT_DLLPUBLIC const String ApplyLreOrRleEmbedding( const String &rText )
      49                 :            : {
      50                 :          0 :     const sal_uInt16 nLen = rText.Len();
      51         [ #  # ]:          0 :     if (nLen == 0)
      52         [ #  # ]:          0 :         return String();
      53                 :            : 
      54                 :          0 :     const sal_Unicode cLRE_Embedding  = 0x202A;      // the start char of an LRE embedding
      55                 :          0 :     const sal_Unicode cRLE_Embedding  = 0x202B;      // the start char of an RLE embedding
      56                 :          0 :     const sal_Unicode cPopDirectionalFormat = 0x202C;   // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
      57                 :            : 
      58                 :            :     // check if there are alreay embedding characters at the strings start
      59                 :            :     // if so change nothing
      60                 :          0 :     const sal_Unicode cChar = rText.GetBuffer()[0];
      61 [ #  # ][ #  # ]:          0 :     if (cChar == cLRE_Embedding || cChar == cRLE_Embedding)
      62         [ #  # ]:          0 :         return rText;
      63                 :            : 
      64                 :            :     // since we only call the function getCharacterDirection
      65                 :            :     // it does not matter which locale the CharClass is for.
      66                 :            :     // Thus we can readily make use of SvtSysLocale::GetCharClass()
      67                 :            :     // which should come at no cost...
      68         [ #  # ]:          0 :     SvtSysLocale aSysLocale;
      69         [ #  # ]:          0 :     const CharClass &rCharClass = aSysLocale.GetCharClass();
      70                 :            : 
      71                 :            :     // we should look for the first non-neutral LTR or RTL character
      72                 :            :     // and use that to determine the embedding of the whole text...
      73                 :            :     // Thus we can avoid to check every character of the text.
      74                 :          0 :     bool bFound     = false;
      75                 :          0 :     bool bIsRtlText = false;
      76 [ #  # ][ #  # ]:          0 :     for (sal_uInt16 i = 0;  i < nLen && !bFound;  ++i)
                 [ #  # ]
      77                 :            :     {
      78         [ #  # ]:          0 :         sal_Int16 nDirection = rCharClass.getCharacterDirection( rText, i );
      79      [ #  #  # ]:          0 :         switch (nDirection)
      80                 :            :         {
      81                 :            :             case i18n::DirectionProperty_LEFT_TO_RIGHT :
      82                 :            :             case i18n::DirectionProperty_LEFT_TO_RIGHT_EMBEDDING :
      83                 :            :             case i18n::DirectionProperty_LEFT_TO_RIGHT_OVERRIDE :
      84                 :            :             case i18n::DirectionProperty_EUROPEAN_NUMBER :
      85                 :            :             case i18n::DirectionProperty_ARABIC_NUMBER :        // yes! arabic numbers are written from left to right
      86                 :            :             {
      87                 :          0 :                 bIsRtlText  = false;
      88                 :          0 :                 bFound      = true;
      89                 :          0 :                 break;
      90                 :            :             }
      91                 :            : 
      92                 :            :             case i18n::DirectionProperty_RIGHT_TO_LEFT :
      93                 :            :             case i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC :
      94                 :            :             case i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING :
      95                 :            :             case i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE :
      96                 :            :             {
      97                 :          0 :                 bIsRtlText  = true;
      98                 :          0 :                 bFound      = true;
      99                 :          0 :                 break;
     100                 :            :             }
     101                 :            : 
     102                 :            :             default:
     103                 :            :             {
     104                 :            :                 // nothing to be done, character is considered to be neutral we need to look further ...
     105                 :            :             }
     106                 :            :         }
     107                 :            :     }
     108                 :            : 
     109                 :          0 :     sal_Unicode cStart  = cLRE_Embedding;   // default is to use LRE embedding characters
     110         [ #  # ]:          0 :     if (bIsRtlText)
     111                 :          0 :         cStart = cRLE_Embedding;            // then use RLE embedding
     112                 :            : 
     113                 :            :     // add embedding start and end chars to the text if the direction could be determined
     114         [ #  # ]:          0 :     String aRes( rText );
     115         [ #  # ]:          0 :     if (bFound)
     116                 :            :     {
     117         [ #  # ]:          0 :         aRes.Insert( cStart, 0 );
     118         [ #  # ]:          0 :         aRes.Insert( cPopDirectionalFormat );
     119                 :            :     }
     120                 :            : 
     121 [ #  # ][ #  # ]:          0 :     return aRes;
                 [ #  # ]
     122                 :            : }
     123                 :            : 
     124                 :            : //------------------------------------------------------------------------
     125                 :            : 
     126                 :            : namespace {
     127                 :            :     BOOST_STATIC_ASSERT(
     128                 :            :         16642 == STR_ARR_SVT_LANGUAGE_TABLE);
     129                 :            : //        "The value of STR_ARR_SVT_LANGUAGE_TABLE has changed. wizards/com/sun/star/wizards/letter/LocaleCodes.java has this value hard coded, please adapt it to your change."
     130                 :            : }
     131                 :            : 
     132                 :        598 : SvtLanguageTable::SvtLanguageTable() :
     133         [ +  - ]:        598 :     ResStringArray( SvtResId( STR_ARR_SVT_LANGUAGE_TABLE ) )
     134                 :            : {
     135                 :        598 : }
     136                 :            : 
     137                 :            : //------------------------------------------------------------------------
     138                 :            : 
     139                 :        598 : SvtLanguageTable::~SvtLanguageTable()
     140                 :            : {
     141                 :        598 : }
     142                 :            : 
     143                 :            : //------------------------------------------------------------------------
     144                 :            : 
     145                 :        598 : const rtl::OUString SvtLanguageTable::GetString( const LanguageType eType, bool bUserInterfaceSelection ) const
     146                 :            : {
     147                 :        598 :     LanguageType eLang = MsLangId::getReplacementForObsoleteLanguage( eType, bUserInterfaceSelection);
     148                 :        598 :     sal_uInt32 nPos = FindIndex( eLang );
     149                 :            : 
     150 [ +  - ][ +  - ]:        598 :     if ( RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count() )
                 [ +  - ]
     151                 :        598 :         return ResStringArray::GetString( nPos );
     152                 :            :     else
     153                 :            :     {
     154                 :            :         // If we knew what a simple "en" should alias to (en_US?) we could
     155                 :            :         // generally raise an error.
     156                 :            :         OSL_ENSURE(
     157                 :            :             eLang == LANGUAGE_ENGLISH, "language entry not found in resource" );
     158                 :            : 
     159                 :          0 :         nPos = FindIndex( LANGUAGE_DONTKNOW );
     160                 :            : 
     161 [ #  # ][ #  # ]:          0 :         if ( RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count() )
                 [ #  # ]
     162                 :          0 :             return ResStringArray::GetString( nPos );
     163                 :            :     }
     164                 :        598 :     return rtl::OUString();
     165                 :            : }
     166                 :            : 
     167                 :          0 : String SvtLanguageTable::GetLanguageString( const LanguageType eType )
     168                 :            : {
     169 [ #  # ][ #  # ]:          0 :     static const SvtLanguageTable aLangTable;
         [ #  # ][ #  # ]
     170         [ #  # ]:          0 :     return aLangTable.GetString( eType );
     171                 :            : }
     172                 :            : 
     173                 :            : //------------------------------------------------------------------------
     174                 :            : 
     175                 :          0 : LanguageType SvtLanguageTable::GetType( const String& rStr ) const
     176                 :            : {
     177                 :          0 :     LanguageType eType = LANGUAGE_DONTKNOW;
     178                 :          0 :     sal_uInt32 nCount = Count();
     179                 :            : 
     180         [ #  # ]:          0 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
     181                 :            :     {
     182 [ #  # ][ #  # ]:          0 :         if (ResStringArray::GetString( i ).equals(rStr))
     183                 :            :         {
     184                 :          0 :             eType = LanguageType( GetValue( i ) );
     185                 :          0 :             break;
     186                 :            :         }
     187                 :            :     }
     188                 :          0 :     return eType;
     189                 :            : }
     190                 :            : 
     191                 :            : //------------------------------------------------------------------------
     192                 :            : 
     193                 :          0 : sal_uInt32 SvtLanguageTable::GetEntryCount() const
     194                 :            : {
     195                 :          0 :     return Count();
     196                 :            : }
     197                 :            : 
     198                 :            : //------------------------------------------------------------------------
     199                 :            : 
     200                 :          0 : LanguageType SvtLanguageTable::GetTypeAtIndex( sal_uInt32 nIndex ) const
     201                 :            : {
     202                 :          0 :     LanguageType nType = LANGUAGE_DONTKNOW;
     203         [ #  # ]:          0 :     if (nIndex < Count())
     204                 :          0 :         nType = LanguageType( GetValue( nIndex ) );
     205                 :          0 :     return nType;
     206                 :            : }
     207                 :            : 
     208                 :            : //------------------------------------------------------------------------
     209                 :            : 
     210                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10