tdf#154658: XML Form Document: Fields doesnt calculate any more

Regression from 73334560b2dd2d60ac58d2cc2b1a5295490b03e1
author	Julien Nabet <serval2412@yahoo.fr>	2021-11-07 15:40:37 +0100
committer	Julien Nabet <serval2412@yahoo.fr>	2021-11-07 21:58:53 +0100
commit	73334560b2dd2d60ac58d2cc2b1a5295490b03e1 (patch)
tree	b5bc4f69dd8ed455c78ea05ab1c5e2f3c25b909e
parent	6be03ac71e0d4927612b4a57ead3d0b245c29c77 (diff)
Replace some macros in forms part 16

A big thank you to Raal for having spotted this!

Change-Id: Ib6f1878897b16b43df287702f82835824c1f766d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150174
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
(cherry picked from commit 26012007e4d20f47697d1336b725e60541df794a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150314
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/forms/source/xforms/convert.cxx b/forms/source/xforms/convert.cxx
index d3fbb07..28d3088 100644
--- a/forms/source/xforms/convert.cxx
+++ b/forms/source/xforms/convert.cxx
@@ -21,6 +21,7 @@
#include "convert.hxx"

#include <sstream>
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h>
#include <tools/date.hxx>
@@ -50,6 +51,36 @@ namespace
    Any lcl_toAny_OUString( const OUString& rStr )
    { return Any(rStr); }

    OUString lcl_toXSD_bool( const Any& rAny )
    { bool b = false; rAny >>= b; return b ? OUString("true") : OUString("false"); }

    Any lcl_toAny_bool( const OUString& rStr )
    {
        bool b = ( rStr == "true"  ||  rStr == "1" );
        return Any( b );
    }

    OUString lcl_toXSD_double( const Any& rAny )
    {
        double f = 0.0;
        rAny >>= f;

        return std::isfinite( f )
            ? rtl::math::doubleToUString( f, rtl_math_StringFormat_Automatic,
                                        rtl_math_DecimalPlaces_Max, '.',
                                        true )
            : OUString();
    }


    Any lcl_toAny_double( const OUString& rString )
    {
        rtl_math_ConversionStatus eStatus;
        double f = rtl::math::stringToDouble(
            rString, '.', ',', &eStatus );
        return ( eStatus == rtl_math_ConversionStatus_Ok ) ? Any( f ) : Any();
    }

    void lcl_appendInt32ToBuffer( const sal_Int32 _nValue, OUStringBuffer& _rBuffer, sal_Int16 _nMinDigits )
    {
        if ( ( _nMinDigits >= 4 ) && ( _nValue < 1000 ) )
@@ -231,6 +262,8 @@ namespace
void Convert::init()
{
    maMap[ cppu::UnoType<OUString>::get() ] = Convert_t(&lcl_toXSD_OUString, &lcl_toAny_OUString);
    maMap[ cppu::UnoType<bool>::get() ] = Convert_t(&lcl_toXSD_bool, &lcl_toAny_bool);
    maMap[ cppu::UnoType<double>::get() ] = Convert_t(&lcl_toXSD_double, &lcl_toAny_double);
    maMap[ cppu::UnoType<css::util::Date>::get() ] = Convert_t( &lcl_toXSD_UNODate, &lcl_toAny_UNODate );
    maMap[ cppu::UnoType<css::util::Time>::get() ] = Convert_t( &lcl_toXSD_UNOTime, &lcl_toAny_UNOTime );
    maMap[ cppu::UnoType<css::util::DateTime>::get() ] = Convert_t( &lcl_toXSD_UNODateTime, &lcl_toAny_UNODateTime );