summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2011-10-11 14:19:00 +0200
committerMichael Stahl <mst@openoffice.org>2011-10-11 17:57:00 +0200
commit3ca2bef76886450058d1667703aeafe4c2e456c3 (patch)
treeb18d70f79bfcfd2b2e34790e86edafb4c4337a80 /sax
parent02c32e0f0e75a9df80888051d1ec189fa14129bd (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')
-rw-r--r--sax/inc/sax/tools/converter.hxx10
-rw-r--r--sax/source/tools/converter.cxx29
2 files changed, 35 insertions, 4 deletions
diff --git a/sax/inc/sax/tools/converter.hxx b/sax/inc/sax/tools/converter.hxx
index 13fb189d8429..20fe821d05bb 100644
--- a/sax/inc/sax/tools/converter.hxx
+++ b/sax/inc/sax/tools/converter.hxx
@@ -119,6 +119,16 @@ public:
sal_Int32 nMin = SAL_MIN_INT32,
sal_Int32 nMax = SAL_MAX_INT32 );
+ /** convert number to string */
+ static void convertNumber64(::rtl::OUStringBuffer& rBuffer,
+ sal_Int64 nNumber);
+
+ /** convert string to number with optional min and max values */
+ static bool convertNumber64(sal_Int64& rValue,
+ const ::rtl::OUString& rString,
+ sal_Int64 nMin = SAL_MIN_INT64,
+ sal_Int64 nMax = SAL_MAX_INT64);
+
/** convert double number to string (using ::rtl::math) and
DO convert from source unit to target unit */
static void convertDouble( ::rtl::OUStringBuffer& rBuffer,
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;
}