[Libreoffice-commits] .: 2 commits - sal/inc sal/qa sal/rtl sal/util

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jan 28 09:32:27 PST 2013


 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/qa/rtl/strings/test_strings_valuex.cxx |   27 ---
 sal/rtl/source/strtmpl.cxx                 |   45 ++++++
 sal/util/sal.map                           |    2 
 7 files changed, 250 insertions(+), 270 deletions(-)

New commits:
commit 8666cdd95e2b0f8148f45860358ca3f85ad7b9a3
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Jan 28 18:19:19 2013 +0100

    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

diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h
index 26fa5c7..b24cc52 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 1048855..69592f9 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,60 +1552,27 @@ 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.
 
       This function can't be used for language specific conversion.
 
       @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 1ff75bd..ab2707d 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 f9a64d0..192ba2b 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,62 +2189,28 @@ 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.
 
       This function can't be used for language specific conversion.
 
       @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 505d5ab..619f64e 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 9d3f88b..1bebb0a 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 {
commit dba8280c5667cddfd71562dc603c46c34339e685
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Jan 18 16:49:46 2013 +0100

    consolidate the float number tests
    
    And remove some unneeded ones (the float actually didn't have
    the necessary precision on 32bit anyway).
    
    Change-Id: I52dd387fd319dd6a5b44333a71d012ebaaecbf18

diff --git a/sal/qa/rtl/strings/test_strings_valuex.cxx b/sal/qa/rtl/strings/test_strings_valuex.cxx
index 9573b19..cbd12c5 100644
--- a/sal/qa/rtl/strings/test_strings_valuex.cxx
+++ b/sal/qa/rtl/strings/test_strings_valuex.cxx
@@ -21,16 +21,12 @@ public:
     void testOInt();
     void testOUFloat();
     void testOFloat();
-    void testOUDouble();
-    void testODouble();
 
     CPPUNIT_TEST_SUITE(valueX);
     CPPUNIT_TEST(testOUInt);
     CPPUNIT_TEST(testOInt);
     CPPUNIT_TEST(testOUFloat);
     CPPUNIT_TEST(testOFloat);
-    CPPUNIT_TEST(testOUDouble);
-    CPPUNIT_TEST(testODouble);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -82,11 +78,9 @@ void test::strings::valueX::testOInt() {
 
 template< typename T >
 void testFloat() {
-    T val1 = T::valueOf( 30039062.0f );
-    T val2 = T::number( 30039062.0f );
-    CPPUNIT_ASSERT_EQUAL( val1, val2 );
-
     CPPUNIT_ASSERT_EQUAL( T( "39062.2" ), T::number( 39062.2f ));
+    CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
+    // long double not supported
 }
 
 void test::strings::valueX::testOUFloat() {
@@ -96,21 +90,4 @@ void test::strings::valueX::testOUFloat() {
 void test::strings::valueX::testOFloat() {
     testFloat<rtl::OString>();
 }
-
-template< typename T >
-void testDouble() {
-    T val1 = T::valueOf( 30039062.0 );
-    T val2 = T::number( 30039062.0 );
-    CPPUNIT_ASSERT_EQUAL( val1, val2 );
-
-    CPPUNIT_ASSERT_EQUAL( T( "30039062.2" ), T::number( 30039062.2 ));
-}
-
-void test::strings::valueX::testOUDouble() {
-    testDouble<rtl::OUString>();
-}
-
-void test::strings::valueX::testODouble() {
-    testDouble<rtl::OString>();
-}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list