summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-09-25 12:16:36 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-09-26 07:38:09 +0200
commit186d36a7036462ae641b35004b4ffba3eeeca46f (patch)
tree7d511d4c6d4e6fa10be710d55aeba737b7662535
parentf5bbb2db98fe420174328e6c8e2f3d160a9b7758 (diff)
Simplify external implementations of O(U)String::number
Change-Id: I2e1b217d43806dd0f64239978211d5b17fcf311c Reviewed-on: https://gerrit.libreoffice.org/79518 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--include/rtl/string.hxx23
-rw-r--r--include/rtl/ustring.hxx28
2 files changed, 17 insertions, 34 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 68450da21fa9..a7a04f9d06e4 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1677,7 +1677,8 @@ public:
*/
static OString number( int i, sal_Int16 radix = 10 )
{
- return number( static_cast< long long >( i ), radix );
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
+ return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
}
/// @overload
/// @since LibreOffice 4.1
@@ -1702,18 +1703,14 @@ public:
static OString number( long long ll, sal_Int16 radix = 10 )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
- rtl_String* pNewData = NULL;
- rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
- return OString( pNewData, SAL_NO_ACQUIRE );
+ return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
}
/// @overload
/// @since LibreOffice 4.1
static OString number( unsigned long long ll, sal_Int16 radix = 10 )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64];
- rtl_String* pNewData = NULL;
- rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfUInt64( aBuf, ll, radix ) );
- return OString( pNewData, SAL_NO_ACQUIRE );
+ return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
}
/**
@@ -1722,15 +1719,13 @@ public:
This function can't be used for language specific conversion.
@param f a float.
- @return a string with the string representation of the argument.
+ @return a string with the decimal representation of the argument.
@since LibreOffice 4.1
*/
static OString number( float f )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
- rtl_String* pNewData = NULL;
- rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
- return OString( pNewData, SAL_NO_ACQUIRE );
+ return OString(aBuf, rtl_str_valueOfFloat(aBuf, f));
}
/**
@@ -1739,15 +1734,13 @@ public:
This function can't be used for language specific conversion.
@param d a double.
- @return a string with the string representation of the argument.
+ @return a string with the decimal representation of the argument.
@since LibreOffice 4.1
*/
static OString number( double d )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
- rtl_String* pNewData = NULL;
- rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
- return OString( pNewData, SAL_NO_ACQUIRE );
+ return OString(aBuf, rtl_str_valueOfDouble(aBuf, d));
}
#endif
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index a6d9e22c37b5..a974e3ac7a12 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3421,9 +3421,7 @@ public:
static OUString number( int i, sal_Int16 radix = 10 )
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
- rtl_uString* pNewData = NULL;
- rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
- return OUString( pNewData, SAL_NO_ACQUIRE );
+ return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
}
/// @overload
/// @since LibreOffice 4.1
@@ -3447,19 +3445,15 @@ public:
/// @since LibreOffice 4.1
static OUString number( long long ll, sal_Int16 radix = 10 )
{
- sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
- rtl_uString* pNewData = NULL;
- rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
- return OUString( pNewData, SAL_NO_ACQUIRE );
+ sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
+ return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
}
/// @overload
/// @since LibreOffice 4.1
static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
{
- sal_Unicode aBuf[RTL_STR_MAX_VALUEOFUINT64];
- rtl_uString* pNewData = NULL;
- rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfUInt64( aBuf, ll, radix ) );
- return OUString( pNewData, SAL_NO_ACQUIRE );
+ sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFUINT64];
+ return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
}
/**
@@ -3468,15 +3462,13 @@ public:
This function can't be used for language specific conversion.
@param f a float.
- @return a string with the string representation of the argument.
+ @return a string with the decimal representation of the argument.
@since LibreOffice 4.1
*/
static OUString number( float f )
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
- rtl_uString* pNewData = NULL;
- rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
- return OUString( pNewData, SAL_NO_ACQUIRE );
+ return OUString(aBuf, rtl_ustr_valueOfFloat(aBuf, f));
}
/**
@@ -3485,15 +3477,13 @@ public:
This function can't be used for language specific conversion.
@param d a double.
- @return a string with the string representation of the argument.
+ @return a string with the decimal representation of the argument.
@since LibreOffice 4.1
*/
static OUString number( double d )
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
- rtl_uString* pNewData = NULL;
- rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
- return OUString( pNewData, SAL_NO_ACQUIRE );
+ return OUString(aBuf, rtl_ustr_valueOfDouble(aBuf, d));
}
#endif