summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2025-01-17 14:06:35 +0900
committerTomaž Vajngerl <quikee@gmail.com>2025-01-20 01:39:16 +0100
commit2990620e202eb59edce160264e25ca63ba4a93ba (patch)
treebc375ebd2ef5edd9cddf152085a658d311843acf /xmloff
parentb3601746facd15e6c54cb5061c77d6fbad6591cc (diff)
remove code duplication - conversion hex char to value
We use the same funciton all over the place, so create a common function in o3tl and use that in all instances where we duplicated the code. Change-Id: I74091fbbde8c2ba8c7e4ab30194ab53e2a338e52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180372 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmluconv.cxx16
-rw-r--r--xmloff/source/transform/TransformerBase.cxx19
2 files changed, 6 insertions, 29 deletions
diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx
index a99ddff236ef..abeb2c610bae 100644
--- a/xmloff/source/core/xmluconv.cxx
+++ b/xmloff/source/core/xmluconv.cxx
@@ -32,6 +32,7 @@
#include <xmloff/xmlement.hxx>
#include <xmloff/xmltoken.hxx>
#include <rtl/math.hxx>
+#include <o3tl/numeric.hxx>
#include <tools/date.hxx>
#include <tools/time.hxx>
@@ -314,18 +315,6 @@ bool SvXMLUnitConverter::convertEnumImpl(
return (eTok != XML_TOKEN_INVALID);
}
-static int lcl_gethex( int nChar )
-{
- if( nChar >= '0' && nChar <= '9' )
- return nChar - '0';
- else if( nChar >= 'a' && nChar <= 'f' )
- return nChar - 'a' + 10;
- else if( nChar >= 'A' && nChar <= 'F' )
- return nChar - 'A' + 10;
- else
- return 0;
-}
-
const char aHexTab[] = "0123456789abcdef";
@@ -950,8 +939,7 @@ bool SvXMLUnitConverter::convertHex( sal_uInt32& nVal, std::u16string_view rValu
nVal = 0;
for ( int i = 0; i < 8; i++ )
{
- nVal = ( nVal << 4 )
- | sal::static_int_cast< sal_uInt32 >( lcl_gethex( rValue[i] ) );
+ nVal = ( nVal << 4 ) | o3tl::convertToHex<sal_uInt32>(rValue[i]);
}
return true;
diff --git a/xmloff/source/transform/TransformerBase.cxx b/xmloff/source/transform/TransformerBase.cxx
index 7c2d0807a3c2..bc61f989a684 100644
--- a/xmloff/source/transform/TransformerBase.cxx
+++ b/xmloff/source/transform/TransformerBase.cxx
@@ -21,6 +21,7 @@
#include <rtl/ustrbuf.hxx>
#include <tools/UnitConversion.hxx>
#include <osl/diagnose.h>
+#include <o3tl/numeric.hxx>
#include <com/sun/star/i18n/CharacterClassification.hpp>
#include <com/sun/star/i18n/UnicodeType.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
@@ -1090,26 +1091,14 @@ bool XMLTransformerBase::DecodeStyleName( OUString& rName )
}
else if( bWithinHex )
{
- sal_Unicode cDigit;
- if( c >= '0' && c <= '9' )
- {
- cDigit = c - '0';
- }
- else if( c >= 'a' && c <= 'f' )
- {
- cDigit = c - 'a' + 10;
- }
- else if( c >= 'A' && c <= 'F' )
- {
- cDigit = c - 'A' + 10;
- }
- else
+ int nValue = o3tl::convertToHex<int>(c);
+ if (nValue == -1)
{
// error
bEncoded = false;
break;
}
- cEnc = (cEnc << 4) + cDigit;
+ cEnc = (cEnc << 4) + nValue;
}
else
{