summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2023-02-23 12:29:48 +0200
committerTor Lillqvist <tml@collabora.com>2023-02-23 13:47:56 +0000
commit6f29310fe83873c7d6844cf5e3089ca981e147db (patch)
treeb4bed03536f2b5493939ab9fec6cb6558c04e02b /cui
parentb352c9a79ce12daf8e38246993bc821944779b0a (diff)
Don't call CuiResId() in a global static variable initialiser
Instead, have a function that returns a reference to a local static variable. That local static is then initialised only when the function is called for the first time. Calling CuiResId() in a global initialiser is a bit questionable, and causes an uncaught exception when LO core is used in a WASM app. Possibly it would also have been problematic on other uncommon platforms. Change-Id: I4fd799ba3aa8d63fd3db1eb8cf6211aeed904ed2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147512 Tested-by: Tor Lillqvist <tml@collabora.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'cui')
-rw-r--r--cui/source/options/optcolor.cxx16
1 files changed, 10 insertions, 6 deletions
diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx
index 2cb20a2650fa..4ad5d2b5e93f 100644
--- a/cui/source/options/optcolor.cxx
+++ b/cui/source/options/optcolor.cxx
@@ -161,9 +161,13 @@ const vEntryInfo[] =
};
// Maps the names of default color schemes to the corresponding TranslateId
-std::map<OUString, OUString> const vColorSchemes = {
- {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)},
- {"COLOR_SCHEME_LIBREOFFICE_DARK", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)}
+const std::map<OUString, OUString> &getColorSchemes()
+{
+ static std::map<OUString, OUString> const vColorSchemes = {
+ {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)},
+ {"COLOR_SCHEME_LIBREOFFICE_DARK", CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)}
+ };
+ return vColorSchemes;
};
// If the color scheme name has a translated string, then return the translation
@@ -171,8 +175,8 @@ std::map<OUString, OUString> const vColorSchemes = {
// For non-translatable color schemes, the ID and the name are the same
OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId)
{
- auto it = vColorSchemes.find(sSchemeId);
- if (it != vColorSchemes.end())
+ auto it = getColorSchemes().find(sSchemeId);
+ if (it != getColorSchemes().end())
return it->second;
return sSchemeId;
}
@@ -181,7 +185,7 @@ OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId)
// For non-translatable color schemes, the ID and the name are the same
OUString lcl_TranslatedNameToSchemeId(const OUString& sName)
{
- for (auto it = vColorSchemes.begin(); it != vColorSchemes.end(); ++it)
+ for (auto it = getColorSchemes().begin(); it != getColorSchemes().end(); ++it)
if (it->second == sName)
return it->first;
return sName;