summaryrefslogtreecommitdiffstats
path: root/forms/source/xforms/convert.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'forms/source/xforms/convert.cxx')
-rw-r--r--forms/source/xforms/convert.cxx55
1 files changed, 44 insertions, 11 deletions
diff --git a/forms/source/xforms/convert.cxx b/forms/source/xforms/convert.cxx
index 2dfab2d97eaa..0f7193422fa5 100644
--- a/forms/source/xforms/convert.cxx
+++ b/forms/source/xforms/convert.cxx
@@ -21,9 +21,11 @@
#include "convert.hxx"
#include <sstream>
+#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
#include <osl/diagnose.h>
#include <tools/date.hxx>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/uno/Type.hxx>
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/util/DateTime.hpp>
@@ -33,7 +35,6 @@
using xforms::Convert;
using com::sun::star::uno::Any;
-using com::sun::star::uno::makeAny;
using namespace utl;
Convert::Convert()
@@ -51,6 +52,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.replace(',','.'), '.', ',', &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 ) )
@@ -85,7 +116,7 @@ namespace
}
- css::util::Date lcl_toUNODate( const OUString& rString )
+ css::util::Date lcl_toUNODate( std::u16string_view rString )
{
css::util::Date aDate( 1, 1, 1900 );
@@ -103,7 +134,7 @@ namespace
// all okay?
if ( !bWellformed )
- return css::util::Date( 1, 1, 1900 );
+ throw com::sun::star::lang::IllegalArgumentException();
return aDate;
}
@@ -111,7 +142,7 @@ namespace
Any lcl_toAny_UNODate( const OUString& rString )
{
- return makeAny( lcl_toUNODate( rString ) );
+ return Any( lcl_toUNODate( rString ) );
}
@@ -132,7 +163,7 @@ namespace
ostr.fill('0');
ostr.width(9);
ostr << rTime.NanoSeconds;
- sInfo.append(OUString::createFromAscii(ostr.str().c_str()));
+ sInfo.appendAscii(ostr.str().c_str());
}
return sInfo.makeStringAndClear();
@@ -147,7 +178,7 @@ namespace
}
- css::util::Time lcl_toUNOTime( const OUString& rString )
+ css::util::Time lcl_toUNOTime( std::u16string_view rString )
{
css::util::Time aTime;
@@ -173,7 +204,7 @@ namespace
// all okay?
if ( !bWellformed )
- return css::util::Time();
+ throw com::sun::star::lang::IllegalArgumentException();
return aTime;
}
@@ -181,7 +212,7 @@ namespace
Any lcl_toAny_UNOTime( const OUString& rString )
{
- return makeAny( lcl_toUNOTime( rString ) );
+ return Any( lcl_toUNOTime( rString ) );
}
@@ -217,14 +248,14 @@ namespace
}
else
{
- aDate = lcl_toUNODate( rString.copy( 0, nDateTimeSep ) );
- aTime = lcl_toUNOTime( rString.copy( nDateTimeSep + 1 ) );
+ aDate = lcl_toUNODate( rString.subView( 0, nDateTimeSep ) );
+ aTime = lcl_toUNOTime( rString.subView( nDateTimeSep + 1 ) );
}
css::util::DateTime aDateTime(
aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours,
aDate.Day, aDate.Month, aDate.Year, aTime.IsUTC
);
- return makeAny( aDateTime );
+ return Any( aDateTime );
}
}
@@ -232,6 +263,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 );