summaryrefslogtreecommitdiff
path: root/sal/inc/rtl
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-01-10 09:37:14 +0200
committerLuboš Luňák <l.lunak@suse.cz>2013-01-18 17:19:30 +0100
commit2b31e751db38e7ba0e2ec668520f50daf5eb25d5 (patch)
tree9f93c9eed71330e8fd2e6bfb234f0da340e3aeaf /sal/inc/rtl
parent6f6ed9c7e2212e5e7acb2c5b827e4e4f1e156ecd (diff)
Create OUString and OString number(*) methods.
API CHANGE: Adds new methods (several overloads) OString::number() OUString::number() and marks all of the existing fromValue() methods as deprecated. The purpose of this change is to clean up call sites by hiding the necessary casts. The casts are necessary because of overload resolution rules which are somewhat vague about which methods to choose when using integer types. See mailing list discussion here: http://nabble.documentfoundation.org/replacing-OUString-valueOf-static-cast-lt-sal-Int32-gt-td4027989.html Subject: "replacing OUString::valueOf(static_cast<sal_Int32>) ??" Change-Id: Id3d150a6525eb0334e41e2ec6640bb06cd790b43 Reviewed-on: https://gerrit.libreoffice.org/1625 Reviewed-by: Luboš Luňák <l.lunak@suse.cz> Tested-by: Luboš Luňák <l.lunak@suse.cz>
Diffstat (limited to 'sal/inc/rtl')
-rw-r--r--sal/inc/rtl/string.hxx138
-rw-r--r--sal/inc/rtl/ustring.hxx138
2 files changed, 264 insertions, 12 deletions
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 8e33973729d7..325fe28af239 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1399,8 +1399,9 @@ public:
@param b a sal_Bool.
@return a string with the string representation of the argument.
+ @deprecated there is no replacement, just code your own
*/
- static OString valueOf( sal_Bool b ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("just code your own") static OString valueOf( sal_Bool b ) SAL_THROW(())
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
rtl_String* pNewData = 0;
@@ -1413,8 +1414,9 @@ public:
@param c a character.
@return a string with the string representation of the argument.
+ @deprecated just use the "+" or "+=" operator
*/
- static OString valueOf( sal_Char c ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("use the + or += operator") static OString valueOf( sal_Char c ) SAL_THROW(())
{
return OString( &c, 1 );
}
@@ -1427,8 +1429,9 @@ public:
@param i a int32.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
+ @deprecated use number(sal_Int64,sal_Int16)
*/
- static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
rtl_String* pNewData = 0;
@@ -1437,15 +1440,67 @@ public:
}
/**
+ Returns the string representation of the int argument.
+
+ This function can't be used for language specific conversion.
+
+ @param i a int32.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ */
+ static OString number( int i, sal_Int16 radix = 10 )
+ {
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
+ rtl_String* pNewData = 0;
+ rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) );
+ return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
+ Returns the string representation of the int argument.
+
+ This function can't be used for language specific conversion.
+
+ @param i a int32.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ */
+ static OString number( unsigned int i, sal_Int16 radix = 10 )
+ {
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_String* pNewData = 0;
+ rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, i, radix ) );
+ return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
+ Returns the string representation of the long argument.
+
+ This function can't be used for language specific conversion.
+
+ @param ll a int64.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ @deprecated use number(sal_Int64,sal_Int16)
+ */
+ SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
+ {
+ return number( ll, radix );
+ }
+
+ /**
Returns the string representation of the long argument.
+ This is here because when choosing which conversion for overloaded
+ functions is better, the standard treats all integer conversions the same.
This function can't be used for language specific conversion.
@param ll a int64.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
+ @since LibreOffice 4.1
*/
- static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
+ static OString number( long ll, sal_Int16 radix = 10 )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
rtl_String* pNewData = 0;
@@ -1454,14 +1509,70 @@ public:
}
/**
+ Returns the string representation of the long argument.
+ This is here because when choosing which conversion for overloaded
+ functions is better, the standard treats all integer conversions the same.
+
+ This function can't be used for language specific conversion.
+
+ @param ll a int64.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ @since LibreOffice 4.1
+ */
+ static OString number( unsigned long ll, sal_Int16 radix = 10 )
+ {
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_String* pNewData = 0;
+ rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
+ return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /// @overload
+ /// @since LibreOffice 4.1
+ static OString number( long long ll, sal_Int16 radix = 10 )
+ {
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_String* pNewData = 0;
+ rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
+ return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /// @overload
+ /// @since LibreOffice 4.1
+ static OString number( unsigned long long ll, sal_Int16 radix = 10 )
+ {
+ assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit
+ sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_String* pNewData = 0;
+ rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
+ return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
+ Returns the string representation of the float argument.
+
+ This function can't be used for language specific conversion.
+
+ @param f a float.
+ @return a string with the string representation of the argument.
+ @deprecated use number(float)
+ */
+ SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( float f ) SAL_THROW(())
+ {
+ return number(f);
+ }
+
+ /**
Returns the string representation of the float argument.
This function can't be used for language specific conversion.
@param f a float.
@return a string with the string representation of the argument.
+ @since LibreOffice 4.1
*/
- static OString valueOf( float f ) SAL_THROW(())
+ static OString number( float f )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
rtl_String* pNewData = 0;
@@ -1476,8 +1587,23 @@ public:
@param d a double.
@return a string with the string representation of the argument.
+ @deprecated use number(double)
+ */
+ SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( double d ) SAL_THROW(())
+ {
+ return number(d);
+ }
+
+ /**
+ Returns the string representation of the double argument.
+
+ This function can't be used for language specific conversion.
+
+ @param d a double.
+ @return a string with the string representation of the argument.
+ @since LibreOffice 4.1
*/
- static OString valueOf( double d ) SAL_THROW(())
+ static OString number( double d )
{
sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
rtl_String* pNewData = 0;
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index c9fe25ec6131..c87978f4b067 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -2033,8 +2033,9 @@ public:
@param b a sal_Bool.
@return a string with the string representation of the argument.
+ @deprecated there is no replacement, just code your own
*/
- static OUString valueOf( sal_Bool b ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("just code your own") static OUString valueOf( sal_Bool b ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
rtl_uString* pNewData = 0;
@@ -2047,8 +2048,9 @@ public:
@param c a character.
@return a string with the string representation of the argument.
+ @deprecated just use the '+' or '+'; operator
*/
- static OUString valueOf( sal_Unicode c ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("just use the '+' or '+'; operator") static OUString valueOf( sal_Unicode c ) SAL_THROW(())
{
return OUString( &c, 1 );
}
@@ -2061,8 +2063,9 @@ public:
@param i a int32.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
+ @deprecated use number(sal_Int64,sal_Int16)
*/
- static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
rtl_uString* pNewData = 0;
@@ -2071,6 +2074,40 @@ public:
}
/**
+ Returns the string representation of the int argument.
+
+ This function can't be used for language specific conversion.
+
+ @param i a int32.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ */
+ static OUString number( int i, sal_Int16 radix = 10 )
+ {
+ sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
+ rtl_uString* pNewData = 0;
+ rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
+ return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
+ Returns the string representation of the int argument.
+
+ This function can't be used for language specific conversion.
+
+ @param i a int32.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ */
+ static OUString number( unsigned int i, sal_Int16 radix = 10 )
+ {
+ sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
+ rtl_uString* pNewData = 0;
+ rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, i, radix ) );
+ return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
Returns the string representation of the long argument.
This function can't be used for language specific conversion.
@@ -2078,8 +2115,26 @@ public:
@param ll a int64.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
+ @deprecated use number(sal_Int64,sal_Int16)
*/
- static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
+ SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
+ {
+ return number( ll, radix );
+ }
+
+ /**
+ Returns the string representation of the long argument.
+ This is here because when choosing which conversion for overloaded
+ functions is better, the standard treats all integer conversions the same.
+
+ This function can't be used for language specific conversion.
+
+ @param ll a int64.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ @since LibreOffice 4.1
+ */
+ static OUString number( long ll, sal_Int16 radix = 10)
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
rtl_uString* pNewData = 0;
@@ -2088,14 +2143,70 @@ public:
}
/**
+ Returns the string representation of the long argument.
+ This is here because when choosing which conversion for overloaded
+ functions is better, the standard treats all integer conversions the same.
+
+ This function can't be used for language specific conversion.
+
+ @param ll a int64.
+ @param radix the radix (between 2 and 36)
+ @return a string with the string representation of the argument.
+ @since LibreOffice 4.1
+ */
+ static OUString number( unsigned long ll, sal_Int16 radix = 10 )
+ {
+ sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_uString* pNewData = 0;
+ rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
+ return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /// @overload
+ /// @since LibreOffice 4.1
+ static OUString number( long long ll, sal_Int16 radix = 10 )
+ {
+ sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_uString* pNewData = 0;
+ rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
+ return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /// @overload
+ /// @since LibreOffice 4.1
+ static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
+ {
+ assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit
+ sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
+ rtl_uString* pNewData = 0;
+ rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
+ return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
+ }
+
+ /**
+ Returns the string representation of the float argument.
+
+ This function can't be used for language specific conversion.
+
+ @param f a float.
+ @return a string with the string representation of the argument.
+ @deprecated use number(float)
+ */
+ SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( float f ) SAL_THROW(())
+ {
+ return number(f);
+ }
+
+ /**
Returns the string representation of the float argument.
This function can't be used for language specific conversion.
@param f a float.
@return a string with the string representation of the argument.
+ @since LibreOffice 4.1
*/
- static OUString valueOf( float f ) SAL_THROW(())
+ static OUString number( float f )
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
rtl_uString* pNewData = 0;
@@ -2110,8 +2221,23 @@ public:
@param d a double.
@return a string with the string representation of the argument.
+ @deprecated use number(double)
+ */
+ SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( double d ) SAL_THROW(())
+ {
+ return number(d);
+ }
+
+ /**
+ Returns the string representation of the double argument.
+
+ This function can't be used for language specific conversion.
+
+ @param d a double.
+ @return a string with the string representation of the argument.
+ @since LibreOffice 4.1
*/
- static OUString valueOf( double d ) SAL_THROW(())
+ static OUString number( double d )
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
rtl_uString* pNewData = 0;