tdf#147021 avoid use of SAL_N_ELEMENTS macro

Replaced loops with std::find_if calls to avoid use of the
SAL_N_ELEMENTS macro in smmod.cxx.

Change-Id: I561d8a4ae66dc5ad342009ee8af3c9db87688d97
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182194
Tested-by: Jenkins
Reviewed-by: Hossein   <hossein@libreoffice.org>
This commit is contained in:
Simon Chenery 2025-02-25 20:08:11 +01:00 committed by Hossein
parent 1791a290a8
commit 1d78c4993c

View File

@ -43,68 +43,56 @@ OUString SmResId(TranslateId aId) { return Translate::get(aId, SmModule::get()->
OUString SmLocalizedSymbolData::GetUiSymbolName( std::u16string_view rExportName ) OUString SmLocalizedSymbolData::GetUiSymbolName( std::u16string_view rExportName )
{ {
OUString aRes; auto it = std::find_if(std::begin(RID_UI_SYMBOL_NAMES), std::end(RID_UI_SYMBOL_NAMES),
[&rExportName](const auto& rUISymbolTranslateId)
for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES); ++i) { return o3tl::equalsAscii(rExportName, rUISymbolTranslateId.getId()); });
if (it != std::end(RID_UI_SYMBOL_NAMES))
{ {
if (o3tl::equalsAscii(rExportName, RID_UI_SYMBOL_NAMES[i].getId())) return SmResId(*it);
{
aRes = SmResId(RID_UI_SYMBOL_NAMES[i]);
break;
}
} }
return aRes; return {};
} }
OUString SmLocalizedSymbolData::GetExportSymbolName( std::u16string_view rUiName ) OUString SmLocalizedSymbolData::GetExportSymbolName( std::u16string_view rUiName )
{ {
OUString aRes; auto it = std::find_if(std::begin(RID_UI_SYMBOL_NAMES), std::end(RID_UI_SYMBOL_NAMES),
[&rUiName](const auto& rUISymbolTranslateId)
for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES); ++i) { return rUiName == SmResId(rUISymbolTranslateId); });
if (it != std::end(RID_UI_SYMBOL_NAMES))
{ {
if (rUiName == SmResId(RID_UI_SYMBOL_NAMES[i])) const char *pKey = it->getId();
{ return OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
const char *pKey = RID_UI_SYMBOL_NAMES[i].getId();
aRes = OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
break;
}
} }
return aRes; return {};
} }
OUString SmLocalizedSymbolData::GetUiSymbolSetName( std::u16string_view rExportName ) OUString SmLocalizedSymbolData::GetUiSymbolSetName( std::u16string_view rExportName )
{ {
OUString aRes; auto it = std::find_if(std::begin(RID_UI_SYMBOLSET_NAMES), std::end(RID_UI_SYMBOLSET_NAMES),
[&rExportName](const auto& rUISymbolSetTranslateId)
for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES); ++i) { return o3tl::equalsAscii(rExportName, rUISymbolSetTranslateId.getId()); });
if (it != std::end(RID_UI_SYMBOLSET_NAMES))
{ {
if (o3tl::equalsAscii(rExportName, RID_UI_SYMBOLSET_NAMES[i].getId())) return SmResId(*it);
{
aRes = SmResId(RID_UI_SYMBOLSET_NAMES[i]);
break;
}
} }
return aRes; return {};
} }
OUString SmLocalizedSymbolData::GetExportSymbolSetName( std::u16string_view rUiName ) OUString SmLocalizedSymbolData::GetExportSymbolSetName( std::u16string_view rUiName )
{ {
OUString aRes; auto it = std::find_if(std::begin(RID_UI_SYMBOLSET_NAMES), std::end(RID_UI_SYMBOLSET_NAMES),
[&rUiName](const auto& rUISymbolSetTranslateId)
for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES); ++i) { return rUiName == SmResId(rUISymbolSetTranslateId); });
if (it != std::end(RID_UI_SYMBOLSET_NAMES))
{ {
if (rUiName == SmResId(RID_UI_SYMBOLSET_NAMES[i])) const char *pKey = it->getId();
{ return OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
const char *pKey = RID_UI_SYMBOLSET_NAMES[i].getId();
aRes = OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
break;
}
} }
return aRes; return {};
} }
SFX_IMPL_INTERFACE(SmModule, SfxModule) SFX_IMPL_INTERFACE(SmModule, SfxModule)