diff options
author | Michael Stahl <mst@openoffice.org> | 2011-10-11 14:19:00 +0200 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-10-11 17:57:00 +0200 |
commit | 3ca2bef76886450058d1667703aeafe4c2e456c3 (patch) | |
tree | b18d70f79bfcfd2b2e34790e86edafb4c4337a80 /sax/source | |
parent | 02c32e0f0e75a9df80888051d1ec189fa14129bd (diff) |
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
Diffstat (limited to 'sax/source')
-rw-r--r-- | sax/source/tools/converter.cxx | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index 94faa49e257c..49263667ca84 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -68,7 +68,7 @@ bool Converter::convertMeasure( sal_Int32& rValue, double nVal = 0; sal_Int32 nPos = 0; - sal_Int32 nLen = rString.getLength(); + sal_Int32 const nLen = rString.getLength(); // skip white space while( (nPos < nLen) && (rString[nPos] <= sal_Unicode(' ')) ) @@ -577,11 +577,31 @@ bool Converter::convertNumber( sal_Int32& rValue, const OUString& rString, sal_Int32 nMin, sal_Int32 nMax ) { + rValue = 0; + sal_Int64 nNumber = 0; + sal_Bool bRet = convertNumber64(nNumber,rString,nMin,nMax); + if ( bRet ) + rValue = static_cast<sal_Int32>(nNumber); + return bRet; +} + +/** convert 64-bit number to string */ +void Converter::convertNumber64( OUStringBuffer& rBuffer, + sal_Int64 nNumber ) +{ + rBuffer.append( nNumber ); +} + +/** convert string to 64-bit number with optional min and max values */ +bool Converter::convertNumber64( sal_Int64& rValue, + const OUString& rString, + sal_Int64 nMin, sal_Int64 nMax ) +{ bool bNeg = false; rValue = 0; sal_Int32 nPos = 0; - sal_Int32 nLen = rString.getLength(); + sal_Int32 const nLen = rString.getLength(); // skip white space while( (nPos < nLen) && (rString[nPos] <= sal_Unicode(' ')) ) @@ -612,7 +632,7 @@ bool Converter::convertNumber( sal_Int32& rValue, else if( rValue > nMax ) rValue = nMax; - return nPos == nLen; + return ( nPos == nLen && rValue >= nMin && rValue <= nMax ); } /** convert double number to string (using ::rtl::math) */ @@ -666,7 +686,8 @@ bool Converter::convertDouble(double& rValue, if(eStatus == rtl_math_ConversionStatus_Ok) { OUStringBuffer sUnit; - double fFactor = GetConversionFactor(sUnit, nSourceUnit, nTargetUnit); + double const fFactor = + GetConversionFactor(sUnit, nSourceUnit, nTargetUnit); if(fFactor != 1.0 && fFactor != 0.0) rValue /= fFactor; } |