LibreOffice Module svx (master) 1
galini.cxx
Go to the documentation of this file.
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#include <sal/log.hxx>
18
22#include <vcl/svapp.hxx>
23#include <vcl/settings.hxx>
24#include <o3tl/string_view.hxx>
25#include <memory>
26
27OUString GalleryFileStorageEntry::ReadStrFromIni(std::u16string_view aKeyName ) const
28{
29 std::unique_ptr<SvStream> pStrm(::utl::UcbStreamHelper::CreateStream(
31 StreamMode::READ ));
32
34
35 ::std::vector< OUString > aFallbacks = rLangTag.getFallbackStrings( true);
36
37 OUString aResult;
38 sal_Int32 nRank = 42;
39
40 if( pStrm )
41 {
42 OString aLine;
43 while( pStrm->ReadLine( aLine ) )
44 {
45 OUString aKey;
46 OUString aLocale;
47 OUString aValue;
48 sal_Int32 n;
49
50 // comments
51 if( aLine.startsWith( "#" ) )
52 continue;
53
54 // a[en_US] = Bob
55 if( ( n = aLine.indexOf( '=' ) ) >= 1)
56 {
57 aKey = OStringToOUString(
58 o3tl::trim(aLine.subView( 0, n )), RTL_TEXTENCODING_ASCII_US );
59 aValue = OStringToOUString(
60 o3tl::trim(aLine.subView( n + 1 )), RTL_TEXTENCODING_UTF8 );
61
62 if( ( n = aKey.indexOf( '[' ) ) >= 1 )
63 {
64 aLocale = o3tl::trim(aKey.subView( n + 1 ));
65 aKey = o3tl::trim(aKey.subView( 0, n ));
66 if( (n = aLocale.indexOf( ']' ) ) >= 1 )
67 aLocale = o3tl::trim(aLocale.subView( 0, n ));
68 }
69 }
70 SAL_INFO("svx", "ini file has '" << aKey << "' [ '" << aLocale << "' ] = '" << aValue << "'");
71
72 // grisly language matching, is this not available somewhere else?
73 if( aKey == aKeyName )
74 {
75 /* FIXME-BCP47: what is this supposed to do? */
76 n = 0;
77 OUString aLang = aLocale.replace('_','-');
78 for( const auto& rFallback : aFallbacks )
79 {
80 SAL_INFO( "svx", "compare '" << aLang << "' with '" << rFallback << "' rank " << nRank << " vs. " << n );
81 if( rFallback == aLang && n < nRank ) {
82 nRank = n; // try to get the most accurate match
83 aResult = aValue;
84 }
85 ++n;
86 }
87 }
88 }
89 }
90
91 SAL_INFO( "svx", "readStrFromIni returns '" << aResult << "'");
92 return aResult;
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetUILanguageTag() const
static const AllSettings & GetSettings()
OUString ReadStrFromIni(std::u16string_view aKeyName) const
Definition: galini.cxx:27
const INetURLObject & GetStrURL() const
::std::vector< OUString > getFallbackStrings(bool bIncludeFullBcp47) const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
sal_Int64 n
#define SAL_INFO(area, stream)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)