From d9b8670548561f7f53a546b8fe53212c6b1ce26e Mon Sep 17 00:00:00 2001 From: Noel Date: Thu, 17 Dec 2020 16:23:57 +0200 Subject: use more string_view in convertEnum Change-Id: I859de4b908672722e1873c5b41cb456b42258ddd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107885 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/xmloff/xmltoken.hxx | 5 +++++ include/xmloff/xmluconv.hxx | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'include/xmloff') diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index e0f3ef898c65..0a8a12381240 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3410,6 +3410,11 @@ namespace xmloff::token { const OUString& rString, enum XMLTokenEnum eToken ); + /// compare eToken to the string + XMLOFF_DLLPUBLIC bool IsXMLToken( + std::string_view rString, + enum XMLTokenEnum eToken ); + XMLOFF_DLLPUBLIC bool IsXMLToken( const sax_fastparser::FastAttributeList::FastAttributeIter& aIter, enum XMLTokenEnum eToken ); diff --git a/include/xmloff/xmluconv.hxx b/include/xmloff/xmluconv.hxx index 3a9950edbd64..daca3b617f7f 100644 --- a/include/xmloff/xmluconv.hxx +++ b/include/xmloff/xmluconv.hxx @@ -147,6 +147,21 @@ public: return bRet; } + /** convert string to enum using given enum map, if the enum is + not found in the map, this method will return false */ + template + static bool convertEnum( EnumT& rEnum, + std::string_view rValue, + const SvXMLEnumMapEntry *pMap ) + { + sal_uInt16 nTmp; + bool bRet = convertEnumImpl(nTmp, rValue, + reinterpret_cast*>(pMap)); + if (bRet) + rEnum = static_cast(nTmp); + return bRet; + } + /** convert string to enum using given token map, if the enum is not found in the map, this method will return false */ template @@ -162,6 +177,21 @@ public: return bRet; } + /** convert string to enum using given token map, if the enum is + not found in the map, this method will return false */ + template + static bool convertEnum( EnumT& rEnum, + std::string_view rValue, + const SvXMLEnumStringMapEntry *pMap ) + { + sal_uInt16 nTmp; + bool bRet = convertEnumImpl(nTmp, rValue, + reinterpret_cast*>(pMap)); + if (bRet) + rEnum = static_cast(nTmp); + return bRet; + } + /** convert enum to string using given enum map with an optional default token. If the enum is not found in the map, this method will either use the given default or return @@ -268,6 +298,14 @@ private: std::u16string_view rValue, const SvXMLEnumStringMapEntry *pMap ); + static bool convertEnumImpl( sal_uInt16& rEnum, + std::string_view rValue, + const SvXMLEnumMapEntry *pMap ); + + static bool convertEnumImpl( sal_uInt16& rEnum, + std::string_view rValue, + const SvXMLEnumStringMapEntry *pMap ); + static bool convertEnumImpl( OUStringBuffer& rBuffer, sal_uInt16 nValue, const SvXMLEnumMapEntry *pMap, -- cgit