diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-06-12 15:58:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-06-13 17:08:36 +0200 |
commit | 3af0114a295d2a6c600117adb5bcd6689c0c787e (patch) | |
tree | 262f32143b99a8754e517be454681267cadaa85f /include | |
parent | 4edbfa892bfe6ca81c88363b2249e0b7d5eef31f (diff) |
Introduce O[U]String::toUInt32
...which has become necessary since bd60d41176da540b01d7583cfe00637431967f39
"Handle oveflow in O(U)String::toInt() functions" reduces values in the range
(SAL_MAX_INT32 .. SAL_MAX_UINT32] to zero, but some calls of toInt32(16) relied
on getting a correct (unsigned) value for the whole input range ["0" ..
"FFFFFFFF"] (see libreoffice-4-1 commit 9bf6c83367cedb7be81bf67f30d2147d26c7a8c3
"Revert overflow checks in O[U]String::toInt{32,64} again").
Audited all uses of toInt32/64 with non-decimal radix. (There is still a TODO
comment in oox/source/helper/attributelist.cxx, and
stoc/source/typeconv/convert.cxx will still need some love and test code.)
Change-Id: Iadaca1c0e41dab553687d0ce41c20c10cd657a95
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/string.h | 21 | ||||
-rw-r--r-- | include/rtl/string.hxx | 17 | ||||
-rw-r--r-- | include/rtl/ustring.h | 21 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 17 |
4 files changed, 76 insertions, 0 deletions
diff --git a/include/rtl/string.h b/include/rtl/string.h index 9cd81aa1552f..28b089b7e16b 100644 --- a/include/rtl/string.h +++ b/include/rtl/string.h @@ -743,6 +743,27 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean( SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +/** Interpret a string as an unsigned integer. + + This function cannot be used for language-specific conversion. The string + must be null-terminated. + + @param str + a null-terminated string. + + @param radix + the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX + (36), inclusive. + + @return + the unsigned integer value represented by the string, or 0 if the string + does not represent an unsigned integer. + + @since LibreOffice 4.2 + */ +SAL_DLLPUBLIC sal_uInt32 SAL_CALL rtl_str_toUInt32( + const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); + /** Interpret a string as a long integer. This function cannot be used for language-specific conversion. The string diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 9432b7449562..c1cbba9b768c 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -1338,6 +1338,23 @@ public: } /** + Returns the uint32 value from this string. + + This function can't be used for language specific conversion. + + @param radix the radix (between 2 and 36) + @return the uint32 represented from this string. + 0 if this string represents no number or one of too large + magnitude. + + @since LibreOffice 4.2 + */ + sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const SAL_THROW(()) + { + return rtl_str_toUInt32( pData->buffer, radix ); + } + + /** Returns the int64 value from this string. This function can't be used for language specific conversion. diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h index da6720b3bcf6..8d206512904b 100644 --- a/include/rtl/ustring.h +++ b/include/rtl/ustring.h @@ -1073,6 +1073,27 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_ustr_toBoolean( SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_toInt32( const sal_Unicode * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +/** Interpret a string as an unsigned integer. + + This function cannot be used for language-specific conversion. The string + must be null-terminated. + + @param str + a null-terminated string. + + @param radix + the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX + (36), inclusive. + + @return + the unsigned integer value represented by the string, or 0 if the string + does not represent an unsigned integer. + + @since LibreOffice 4.2 + */ +SAL_DLLPUBLIC sal_uInt32 SAL_CALL rtl_ustr_toUInt32( + const sal_Unicode * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); + /** Interpret a string as a long integer. This function cannot be used for language-specific conversion. The string diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 112486d3bde2..fedd35ff6c6c 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -1799,6 +1799,23 @@ public: } /** + Returns the uint32 value from this string. + + This function can't be used for language specific conversion. + + @param radix the radix (between 2 and 36) + @return the uint32 represented from this string. + 0 if this string represents no number or one of too large + magnitude. + + @since LibreOffice 4.2 + */ + sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const SAL_THROW(()) + { + return rtl_ustr_toUInt32( pData->buffer, radix ); + } + + /** Returns the int64 value from this string. This function can't be used for language specific conversion. |