summaryrefslogtreecommitdiff
path: root/sal/rtl
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2010-08-27 12:22:23 +0200
committerMichael Stahl <mst@openoffice.org>2010-08-27 12:22:23 +0200
commit92dafe9862d693ce9d79269627c3e6832422874e (patch)
treeb0d16b8991fafa3715426fccc045653fc50a0be8 /sal/rtl
parent0f9a82f53bfb0f06bd592a462f16abdfe3200b51 (diff)
dba33h: #i112652#: rtl/math.h: string<->double conversion and XMLSchema-2:
rtl_math_doubleTo{,U}String produce XMLSchema-2 values "NaN", "INF", "-INF". rtl_math_stringToDouble and rtl_math_uStringToDouble support XMLSchema-2 values in addition to deprecated previously supported values.
Diffstat (limited to 'sal/rtl')
-rw-r--r--sal/rtl/source/math.cxx45
1 files changed, 30 insertions, 15 deletions
diff --git a/sal/rtl/source/math.cxx b/sal/rtl/source/math.cxx
index 83f34aa6acd1..d983c5726230 100644
--- a/sal/rtl/source/math.cxx
+++ b/sal/rtl/source/math.cxx
@@ -318,44 +318,37 @@ inline void doubleToString(StringT ** pResult,
if ( rtl::math::isNan( fValue ) )
{
- sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-1.#NAN");
+ // #i112652# XMLSchema-2
+ sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("NaN");
if (pResultCapacity == 0)
{
pResultCapacity = &nCapacity;
T::createBuffer(pResult, pResultCapacity);
nResultOffset = 0;
}
-
- if ( bSign )
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("-"));
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("1"));
- T::appendChar(pResult, pResultCapacity, &nResultOffset, cDecSeparator);
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("#NAN"));
+ RTL_CONSTASCII_STRINGPARAM("NaN"));
+
return;
}
bool bHuge = fValue == HUGE_VAL; // g++ 3.0.1 requires it this way...
if ( bHuge || rtl::math::isInf( fValue ) )
{
- sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-1.#INF");
+ // #i112652# XMLSchema-2
+ sal_Int32 nCapacity = RTL_CONSTASCII_LENGTH("-INF");
if (pResultCapacity == 0)
{
pResultCapacity = &nCapacity;
T::createBuffer(pResult, pResultCapacity);
nResultOffset = 0;
}
-
if ( bSign )
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
RTL_CONSTASCII_STRINGPARAM("-"));
T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("1"));
- T::appendChar(pResult, pResultCapacity, &nResultOffset, cDecSeparator);
- T::appendAscii(pResult, pResultCapacity, &nResultOffset,
- RTL_CONSTASCII_STRINGPARAM("#INF"));
+ RTL_CONSTASCII_STRINGPARAM("INF"));
+
return;
}
@@ -736,7 +729,29 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
++p0;
}
CharT const * p = p0;
+ bool bDone = false;
+
+ // #i112652# XMLSchema-2
+ if (3 >= (pEnd - p))
+ {
+ if ((CharT('N') == p[0]) && (CharT('a') == p[1])
+ && (CharT('N') == p[2]))
+ {
+ p += 3;
+ rtl::math::setNan( &fVal );
+ bDone = true;
+ }
+ else if ((CharT('I') == p[0]) && (CharT('N') == p[1])
+ && (CharT('F') == p[2]))
+ {
+ p += 3;
+ fVal = HUGE_VAL;
+ eStatus = rtl_math_ConversionStatus_OutOfRange;
+ bDone = true;
+ }
+ }
+ if (!bDone) // do not recognize e.g. NaN1.23
{
// leading zeros and group separators may be safely ignored
while (p != pEnd && (*p == CharT('0') || *p == cGroupSeparator))