comphelper : use more frozen map

Change-Id: Ie089de8952e951a098791b5d363c3b4deda3365d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182669
Tested-by: Jenkins
Reviewed-by: Arnaud Versini <arnaud.versini@pm.me>
This commit is contained in:
Arnaud VERSINI
2025-03-08 14:59:29 +01:00
committed by Arnaud Versini
parent 56bfdcdd0b
commit 5ff4c96de5
2 changed files with 28 additions and 21 deletions

View File

@ -34,6 +34,7 @@ $(eval $(call gb_Library_add_defs,comphelper,\
$(eval $(call gb_Library_use_externals,comphelper,\
gpgmepp \
boost_headers \
frozen \
icuuc \
icu_headers \
zlib \

View File

@ -33,6 +33,10 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <frozen/bits/defines.h>
#include <frozen/bits/elsa_std.h>
#include <frozen/unordered_map.h>
using namespace css;
using namespace css::beans;
using namespace css::graphic;
@ -43,29 +47,31 @@ namespace comphelper
{
OUString GraphicMimeTypeHelper::GetMimeTypeForExtension(std::string_view rExt)
{
struct XMLGraphicMimeTypeMapper
{
const char* pExt;
const char* pMimeType;
};
#if defined(_MSC_VER) && !defined(__clang__)
static const
#else
static constexpr
#endif
auto aMapper
= frozen::make_unordered_map<std::string_view, OUString>(
{ { "gif", u"image/gif"_ustr },
{ "png", u"image/png"_ustr },
{ "jpg", u"image/jpeg"_ustr },
{ "tif", u"image/tiff"_ustr },
{ "svg", u"image/svg+xml"_ustr },
{ "pdf", u"application/pdf"_ustr },
{ "wmf", u"image/x-wmf"_ustr },
{ "emf", u"image/x-emf"_ustr },
{ "eps", u"image/x-eps"_ustr },
{ "bmp", u"image/bmp"_ustr },
{ "pct", u"image/x-pict"_ustr },
{ "svm", u"image/x-svm"_ustr } });
static const XMLGraphicMimeTypeMapper aMapper[]
= { { "gif", "image/gif" }, { "png", "image/png" }, { "jpg", "image/jpeg" },
{ "tif", "image/tiff" }, { "svg", "image/svg+xml" }, { "pdf", "application/pdf" },
{ "wmf", "image/x-wmf" }, { "emf", "image/x-emf" }, { "eps", "image/x-eps" },
{ "bmp", "image/bmp" }, { "pct", "image/x-pict" }, { "svm", "image/x-svm" } };
auto iterator = aMapper.find(rExt);
if (iterator != aMapper.end())
return iterator->second;
OUString aMimeType;
size_t const nCount = std::size(aMapper);
for (size_t i = 0; (i < nCount) && aMimeType.isEmpty(); ++i)
{
if (rExt == aMapper[i].pExt)
aMimeType = OUString(aMapper[i].pMimeType, strlen(aMapper[i].pMimeType),
RTL_TEXTENCODING_ASCII_US);
}
return aMimeType;
return OUString();
}
OUString GraphicMimeTypeHelper::GetMimeTypeForXGraphic(const Reference<XGraphic>& xGraphic)