LCOV - code coverage report
Current view: top level - svx/source/gallery2 - galini.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 36 100.0 %
Date: 2015-06-13 12:38:46 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             : 
      10             : /*
      11             :  * The world's quickest and lamest .desktop / .ini file parser.
      12             :  * Ideally the .thm file would move to a .desktop file in
      13             :  * future.
      14             :  */
      15             : 
      16             : #include <sal/config.h>
      17             : 
      18             : #include <unotools/streamwrap.hxx>
      19             : #include <unotools/ucbstreamhelper.hxx>
      20             : #include <unotools/tempfile.hxx>
      21             : #include <svx/gallery1.hxx>
      22             : #include <i18nlangtag/languagetag.hxx>
      23             : #include <unotools/syslocale.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include <boost/scoped_ptr.hpp>
      27             : 
      28          27 : OUString GalleryThemeEntry::ReadStrFromIni(const OUString &aKeyName )
      29             : {
      30             :     boost::scoped_ptr<SvStream> pStrm(::utl::UcbStreamHelper::CreateStream(
      31          27 :                                 GetStrURL().GetMainURL( INetURLObject::NO_DECODE ),
      32          27 :                                 StreamMode::READ ));
      33             : 
      34          27 :     const LanguageTag &rLangTag = Application::GetSettings().GetUILanguageTag();
      35             : 
      36          54 :     ::std::vector< OUString > aFallbacks = rLangTag.getFallbackStrings( true);
      37             : 
      38          27 :     OUString aResult;
      39          27 :     sal_Int32 nRank = 42;
      40             : 
      41          27 :     if( pStrm )
      42             :     {
      43          27 :         OString aLine;
      44          87 :         while( pStrm->ReadLine( aLine ) )
      45             :         {
      46          33 :             OUString aKey;
      47          55 :             OUString aLocale;
      48          55 :             OUString aValue;
      49             :             sal_Int32 n;
      50             : 
      51             :             // comments
      52          33 :             if( aLine.startsWith( "#" ) )
      53          11 :                 continue;
      54             : 
      55             :             // a[en_US] = Bob
      56          22 :             if( ( n = aLine.indexOf( '=' ) ) >= 1)
      57             :             {
      58          44 :                 aKey = OStringToOUString(
      59          22 :                     aLine.copy( 0, n ).trim(), RTL_TEXTENCODING_ASCII_US );
      60          44 :                 aValue = OStringToOUString(
      61          22 :                     aLine.copy( n + 1 ).trim(), RTL_TEXTENCODING_UTF8 );
      62             : 
      63          22 :                 if( ( n = aKey.indexOf( '[' ) ) >= 1 )
      64             :                 {
      65          11 :                     aLocale = aKey.copy( n + 1 ).trim();
      66          11 :                     aKey = aKey.copy( 0, n ).trim();
      67          11 :                     if( (n = aLocale.indexOf( ']' ) ) >= 1 )
      68          11 :                         aLocale = aLocale.copy( 0, n ).trim();
      69             :                 }
      70             :             }
      71             :             SAL_INFO("svx", "ini file has '" << aKey << "' [ '" << aLocale << "' ] = '" << aValue << "'");
      72             : 
      73             :             // grisly language matching, is this not available somewhere else?
      74          22 :             if( aKey == aKeyName )
      75             :             {
      76             :                 /* FIXME-BCP47: what is this supposed to do? */
      77          22 :                 n = 0;
      78          22 :                 OUString aLang = aLocale.replace('_','-');
      79         198 :                 for( std::vector< OUString >::const_iterator i = aFallbacks.begin();
      80         132 :                      i != aFallbacks.end(); ++i, ++n )
      81             :                 {
      82             :                     SAL_INFO( "svx", "compare '" << aLang << "' with '" << *i << "' rank " << nRank << " vs. " << n );
      83          44 :                     if( *i == aLang && n < nRank ) {
      84          11 :                         nRank = n; // try to get the most accurate match
      85          11 :                         aResult = aValue;
      86             :                     }
      87          22 :                 }
      88             :             }
      89          49 :         }
      90             :     }
      91             : 
      92             :     SAL_INFO( "svx", "readStrFromIni returns '" << aResult << "'");
      93          54 :     return aResult;
      94             : }
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11