From 8666cdd95e2b0f8148f45860358ca3f85ad7b9a3 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 28 Jan 2013 18:19:19 +0100 Subject: cleanups for number() string function - add sal_uInt64 valueOf helper to handle its full value range - group deprecated valueOf() together - forward to the number() taking the largest type instead of repeating the same code every time - various doc improvements: - add missing @since - do not refer to non-existent number() overloads in docs - "use number" - "huh, of course I use a number?" - "code your own" - my own function? why? - + or += operators are not, strictly speaking, replacements for valueOf() Change-Id: Ib138a06c4ac4365cfffc534e6ab115d55180a70d --- sal/inc/rtl/string.h | 23 ++++++ sal/inc/rtl/string.hxx | 198 +++++++++++++++++--------------------------- sal/inc/rtl/ustring.h | 23 ++++++ sal/inc/rtl/ustring.hxx | 202 ++++++++++++++++++--------------------------- sal/rtl/source/strtmpl.cxx | 45 ++++++++++ sal/util/sal.map | 2 + 6 files changed, 248 insertions(+), 245 deletions(-) diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h index 26fa5c728666..b24cc528dc55 100644 --- a/sal/inc/rtl/string.h +++ b/sal/inc/rtl/string.h @@ -649,6 +649,29 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_valueOfInt64( sal_Char * str, sal_Int64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C(); #define RTL_STR_MAX_VALUEOFINT64 65 +/** Create the string representation of an unsigned long integer. + + This function cannot be used for language-specific operations. + + @param str + a buffer that is big enough to hold the result and the terminating NUL + character. You should use the RTL_STR_MAX_VALUEOFUINT64 define to create a + buffer that is big enough. + + @param l + a long integer value. + + @param radix + the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX + (36), inclusive. + + @return + the length of the string. + */ +SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_valueOfUInt64( + sal_Char * str, sal_uInt64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +#define RTL_STR_MAX_VALUEOFUINT64 65 + /** Create the string representation of a float. This function cannot be used for language-specific conversion. diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx index 104885592986..69592f93e12d 100644 --- a/sal/inc/rtl/string.hxx +++ b/sal/inc/rtl/string.hxx @@ -1397,165 +1397,152 @@ public: } /** - Returns the string representation of the sal_Bool argument. + Returns the string representation of the integer argument. - If the sal_Bool is true, the string "true" is returned. - If the sal_Bool is false, the string "false" is returned. This function can't be used for language specific conversion. - @param b a sal_Bool. + @param i an integer value + @param radix the radix (between 2 and 36) @return a string with the string representation of the argument. - @deprecated there is no replacement, just code your own + @since LibreOffice 4.1 */ - SAL_DEPRECATED_INTERNAL("just code your own") static OString valueOf( sal_Bool b ) SAL_THROW(()) + static OString number( int i, sal_Int16 radix = 10 ) { - sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN]; + return number( static_cast< long long >( i ), radix ); + } + /// @overload + /// @since LibreOffice 4.1 + static OString number( unsigned int i, sal_Int16 radix = 10 ) + { + return number( static_cast< unsigned long long >( i ), radix ); + } + /// @overload + /// @since LibreOffice 4.1 + static OString number( long i, sal_Int16 radix = 10 ) + { + return number( static_cast< long long >( i ), radix ); + } + /// @overload + /// @since LibreOffice 4.1 + static OString number( unsigned long i, sal_Int16 radix = 10 ) + { + return number( static_cast< unsigned long long >( i ), radix ); + } + /// @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_valueOfBoolean( aBuf, b ) ); + 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 char argument. - - @param c a character. - @return a string with the string representation of the argument. - @deprecated just use the "+" or "+=" operator - */ - SAL_DEPRECATED_INTERNAL("use the + or += operator") static OString valueOf( sal_Char c ) SAL_THROW(()) + /// @overload + /// @since LibreOffice 4.1 + static OString number( unsigned long long ll, sal_Int16 radix = 10 ) { - return OString( &c, 1 ); + sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64]; + rtl_String* pNewData = 0; + rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfUInt64( aBuf, ll, radix ) ); + return OString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the float argument. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param f a float. @return a string with the string representation of the argument. - @deprecated use number(sal_Int64,sal_Int16) + @since LibreOffice 4.1 */ - SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) + static OString number( float f ) { - sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32]; + sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT]; rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) ); + rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) ); return OString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the double argument. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param d a double. @return a string with the string representation of the argument. + @since LibreOffice 4.1 */ - static OString number( int i, sal_Int16 radix = 10 ) + static OString number( double d ) { - sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32]; + sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE]; rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) ); + rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) ); return OString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the sal_Bool argument. + If the sal_Bool is true, the string "true" is returned. + If the sal_Bool is false, the string "false" is returned. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param b a sal_Bool. @return a string with the string representation of the argument. + @deprecated there is no replacement, use 'condition ? OString( "true" ) : OString( "false" )' */ - static OString number( unsigned int i, sal_Int16 radix = 10 ) + SAL_DEPRECATED_INTERNAL("write explicit code") static OString valueOf( sal_Bool b ) SAL_THROW(()) { - sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64]; + sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN]; rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, i, radix ) ); + rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) ); 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. + Returns the string representation of the char argument. - @param ll a int64. - @param radix the radix (between 2 and 36) + @param c a character. @return a string with the string representation of the argument. - @deprecated use number(sal_Int64,sal_Int16) + @deprecated use operator, function or constructor taking char or sal_Unicode argument */ - SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) + SAL_DEPRECATED_INTERNAL("convert to OString or use directly") static OString valueOf( sal_Char c ) SAL_THROW(()) { - return number( ll, radix ); + return OString( &c, 1 ); } /** - 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. + Returns the string representation of the int argument. This function can't be used for language specific conversion. - @param ll a int64. + @param i a int32. @param radix the radix (between 2 and 36) @return a string with the string representation of the argument. - @since LibreOffice 4.1 + @deprecated use number() */ - static OString number( long ll, sal_Int16 radix = 10 ) + SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) { - sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64]; + sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32]; rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) ); + 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 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 + @deprecated use number() */ - static OString number( unsigned long ll, sal_Int16 radix = 10 ) - { -#if SAL_TYPES_SIZEOFLONG == 8 - assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit -#endif - 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 ) + SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) { - 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 ); + return number( ll, radix ); } /** @@ -1565,30 +1552,13 @@ public: @param f a float. @return a string with the string representation of the argument. - @deprecated use number(float) + @deprecated use number() */ - SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( float f ) SAL_THROW(()) + 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 number( float f ) - { - sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT]; - rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) ); - return OString( pNewData, (DO_NOT_ACQUIRE*)0 ); - } - /** Returns the string representation of the double argument. @@ -1596,29 +1566,13 @@ public: @param d a double. @return a string with the string representation of the argument. - @deprecated use number(double) + @deprecated use number() */ - SAL_DEPRECATED_INTERNAL("use number") static OString valueOf( double d ) SAL_THROW(()) + 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 number( double d ) - { - sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE]; - rtl_String* pNewData = 0; - rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) ); - return OString( pNewData, (DO_NOT_ACQUIRE*)0 ); - } }; /* ======================================================================= */ diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h index 1ff75bdeb319..ab2707d00eb2 100644 --- a/sal/inc/rtl/ustring.h +++ b/sal/inc/rtl/ustring.h @@ -979,6 +979,29 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_valueOfInt64( sal_Unicode * str, sal_Int64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C(); #define RTL_USTR_MAX_VALUEOFINT64 RTL_STR_MAX_VALUEOFINT64 +/** Create the string representation of an unsigned long integer. + + This function cannot be used for language-specific operations. + + @param str + a buffer that is big enough to hold the result and the terminating NUL + character. You should use the RTL_USTR_MAX_VALUEOFUINT64 define to create + a buffer that is big enough. + + @param l + a long integer value. + + @param radix + the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX + (36), inclusive. + + @return + the length of the string. + */ +SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_valueOfUInt64( + sal_Unicode * str, sal_uInt64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +#define RTL_USTR_MAX_VALUEOFINT64 RTL_STR_MAX_VALUEOFINT64 + /** Create the string representation of a float. This function cannot be used for language-specific conversion. diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index f9a64d08aad6..192ba2bee0e2 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -2031,165 +2031,155 @@ public: } /** - Returns the string representation of the sal_Bool argument. + Returns the string representation of the integer argument. - If the sal_Bool is true, the string "true" is returned. - If the sal_Bool is false, the string "false" is returned. This function can't be used for language specific conversion. - @param b a sal_Bool. + @param i an integer value + @param radix the radix (between 2 and 36) @return a string with the string representation of the argument. - @deprecated there is no replacement, just code your own + @since LibreOffice 4.1 */ - SAL_DEPRECATED_INTERNAL("just code your own") static OUString valueOf( sal_Bool b ) SAL_THROW(()) + static OUString number( int i, sal_Int16 radix = 10 ) { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN]; + sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32]; rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) ); + 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 char argument. - - @param c a character. - @return a string with the string representation of the argument. - @deprecated just use the '+' or '+'; operator - */ - SAL_DEPRECATED_INTERNAL("just use the '+' or '+'; operator") static OUString valueOf( sal_Unicode c ) SAL_THROW(()) + /// @overload + /// @since LibreOffice 4.1 + static OUString number( unsigned int i, sal_Int16 radix = 10 ) { - return OUString( &c, 1 ); + return number( static_cast< unsigned long long >( i ), radix ); + } + /// @overload + /// @since LibreOffice 4.1 + static OUString number( long i, sal_Int16 radix = 10) + { + return number( static_cast< long long >( i ), radix ); + } + /// @overload + /// @since LibreOffice 4.1 + static OUString number( unsigned long i, sal_Int16 radix = 10 ) + { + return number( static_cast< unsigned long long >( i ), radix ); + } + /// @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 ) + { + sal_Unicode aBuf[RTL_STR_MAX_VALUEOFUINT64]; + rtl_uString* pNewData = 0; + rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfUInt64( aBuf, ll, radix ) ); + return OUString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the float argument. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param f a float. @return a string with the string representation of the argument. - @deprecated use number(sal_Int64,sal_Int16) + @since LibreOffice 4.1 */ - SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) + static OUString number( float f ) { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32]; + sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT]; rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) ); + rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) ); return OUString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the double argument. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param d a double. @return a string with the string representation of the argument. + @since LibreOffice 4.1 */ - static OUString number( int i, sal_Int16 radix = 10 ) + static OUString number( double d ) { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32]; + sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE]; rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) ); + rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) ); return OUString( pNewData, (DO_NOT_ACQUIRE*)0 ); } /** - Returns the string representation of the int argument. + Returns the string representation of the sal_Bool argument. + If the sal_Bool is true, the string "true" is returned. + If the sal_Bool is false, the string "false" is returned. This function can't be used for language specific conversion. - @param i a int32. - @param radix the radix (between 2 and 36) + @param b a sal_Bool. @return a string with the string representation of the argument. + @deprecated there is no replacement, use 'condition ? OString( "true" ) : OString( "false" )' */ - static OUString number( unsigned int i, sal_Int16 radix = 10 ) + SAL_DEPRECATED_INTERNAL("write explicit condition") static OUString valueOf( sal_Bool b ) SAL_THROW(()) { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64]; + sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN]; rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, i, radix ) ); + rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) ); 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. + Returns the string representation of the char argument. - @param ll a int64. - @param radix the radix (between 2 and 36) + @param c a character. @return a string with the string representation of the argument. - @deprecated use number(sal_Int64,sal_Int16) + @deprecated use operator, function or constructor taking char or sal_Unicode argument */ - SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) + SAL_DEPRECATED_INTERNAL("convert to OUString or use directly") static OUString valueOf( sal_Unicode c ) SAL_THROW(()) { - return number( ll, radix ); + return OUString( &c, 1 ); } /** - 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. + Returns the string representation of the int argument. This function can't be used for language specific conversion. - @param ll a int64. + @param i a int32. @param radix the radix (between 2 and 36) @return a string with the string representation of the argument. - @since LibreOffice 4.1 + @deprecated use number() */ - static OUString number( long ll, sal_Int16 radix = 10) + SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(()) { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64]; + sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32]; rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) ); + 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 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 + @deprecated use number() */ - static OUString number( unsigned long ll, sal_Int16 radix = 10 ) - { -#if SAL_TYPES_SIZEOFLONG == 8 - assert( ll <= SAL_MAX_INT64 ); // valueOfInt64 may not be able to handle the highest bit -#endif - 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 ) + SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(()) { - 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 ); + return number( ll, radix ); } /** @@ -2199,30 +2189,13 @@ public: @param f a float. @return a string with the string representation of the argument. - @deprecated use number(float) + @deprecated use number() */ - SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( float f ) SAL_THROW(()) + 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 number( float f ) - { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT]; - rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) ); - return OUString( pNewData, (DO_NOT_ACQUIRE*)0 ); - } - /** Returns the string representation of the double argument. @@ -2230,30 +2203,13 @@ public: @param d a double. @return a string with the string representation of the argument. - @deprecated use number(double) + @deprecated use number() */ - SAL_DEPRECATED_INTERNAL("use number") static OUString valueOf( double d ) SAL_THROW(()) + 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 number( double d ) - { - sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE]; - rtl_uString* pNewData = 0; - rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) ); - return OUString( pNewData, (DO_NOT_ACQUIRE*)0 ); - } - /** Returns a OUString copied without conversion from an ASCII character string. diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx index 505d5aba51fa..619f64e4a6ed 100644 --- a/sal/rtl/source/strtmpl.cxx +++ b/sal/rtl/source/strtmpl.cxx @@ -844,6 +844,51 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr, /* ----------------------------------------------------------------------- */ +sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfUInt64 )( IMPL_RTL_STRCODE* pStr, + sal_uInt64 n, + sal_Int16 nRadix ) + SAL_THROW_EXTERN_C() +{ + sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64]; + sal_Char* pBuf = aBuf; + sal_Int32 nLen = 0; + sal_uInt64 nValue; + + /* Radix must be valid */ + if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) ) + nRadix = 10; + + nValue = n; + + /* create a recursive buffer with all values, except the last one */ + do + { + sal_Char nDigit = (sal_Char)(nValue % nRadix); + nValue /= nRadix; + if ( nDigit > 9 ) + *pBuf = (nDigit-10) + 'a'; + else + *pBuf = (nDigit + '0' ); + pBuf++; + } + while ( nValue > 0 ); + + /* copy the values in the right direction into the destination buffer */ + do + { + pBuf--; + *pStr = *pBuf; + pStr++; + nLen++; + } + while ( pBuf != aBuf ); + *pStr = 0; + + return nLen; +} + +/* ----------------------------------------------------------------------- */ + sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr ) SAL_THROW_EXTERN_C() { diff --git a/sal/util/sal.map b/sal/util/sal.map index 9d3f88b44bd1..1bebb0aa0334 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -658,6 +658,8 @@ LIBO_UDK_4.1 { # symbols available in >= LibO 4.1 rtl_uString_ensureCapacity; rtl_string_alloc; rtl_uString_alloc; + rtl_str_valueOfUInt64; + rtl_ustr_valueOfUInt64; } LIBO_UDK_4.0; PRIVATE_1.0 { -- cgit