1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
11 * The world's quickest and lamest .desktop / .ini file parser.
12 * Ideally the .thm file would move to a .desktop file in
16 #include <sal/config.h>
17 #include <sal/log.hxx>
19 #include <unotools/ucbstreamhelper.hxx>
20 #include <galleryfilestorageentry.hxx>
21 #include <i18nlangtag/languagetag.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <o3tl/string_view.hxx>
27 OUString
GalleryFileStorageEntry::ReadStrFromIni(std::u16string_view aKeyName
) const
29 std::unique_ptr
<SvStream
> pStrm(::utl::UcbStreamHelper::CreateStream(
30 GetStrURL().GetMainURL( INetURLObject::DecodeMechanism::NONE
),
33 const LanguageTag
&rLangTag
= Application::GetSettings().GetUILanguageTag();
35 ::std::vector
< OUString
> aFallbacks
= rLangTag
.getFallbackStrings( true);
43 while( pStrm
->ReadLine( aLine
) )
51 if( aLine
.startsWith( "#" ) )
55 if( ( n
= aLine
.indexOf( '=' ) ) >= 1)
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
);
62 if( ( n
= aKey
.indexOf( '[' ) ) >= 1 )
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
));
70 SAL_INFO("svx", "ini file has '" << aKey
<< "' [ '" << aLocale
<< "' ] = '" << aValue
<< "'");
72 // grisly language matching, is this not available somewhere else?
73 if( aKey
== aKeyName
)
75 /* FIXME-BCP47: what is this supposed to do? */
77 OUString aLang
= aLocale
.replace('_','-');
78 for( const auto& rFallback
: aFallbacks
)
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
91 SAL_INFO( "svx", "readStrFromIni returns '" << aResult
<< "'");
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */