diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-08 14:05:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-08 20:44:43 +0200 |
commit | 3e7679738413054c7e6ce973380eac501bf41cf2 (patch) | |
tree | ad80f5bd2f11020fa864488792b6cc0e98a00207 /include | |
parent | 3bfac2a7fad9737f31443292699bd6fee6ac3a6f (diff) |
move comphelper::string::toInt32 to o3tl
so we can use it in places where we cannot include comphelper
Change-Id: Iba0ba3e4c0dcf0f9d1f09092a77c3b2010ec4f6d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132732
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/string.hxx | 58 | ||||
-rw-r--r-- | include/o3tl/string_view.hxx | 26 |
2 files changed, 26 insertions, 58 deletions
diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx index 8bf0456e0e33..82815c0e5bc6 100644 --- a/include/comphelper/string.hxx +++ b/include/comphelper/string.hxx @@ -359,64 +359,6 @@ COMPHELPER_DLLPUBLIC bool isdigitAsciiString(std::string_view rString); */ COMPHELPER_DLLPUBLIC bool isdigitAsciiString(std::u16string_view rString); -/** Interpret a string as a long integer. - - This function cannot be used for language-specific conversion. - - @param str - a string. - - @param radix - the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX - (36), inclusive. - - @param nStrLength - number of chars to process - - @return - the long integer value represented by the string, or 0 if the string does - not represent a long integer. -*/ -inline sal_Int64 toInt64(std::u16string_view str, sal_Int16 radix = 10 ) -{ - return rtl_ustr_toInt64_WithLength(str.data(), radix, str.size()); -} -inline sal_Int64 toInt64(std::string_view str, sal_Int16 radix = 10 ) -{ - return rtl_str_toInt64_WithLength(str.data(), radix, str.size()); -} - -/** Interpret a string as an integer. - - This function cannot be used for language-specific conversion. - - @param radix - the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX - (36), inclusive. - - @param nStrLength - number of chars to process - - @return - the integer value represented by the string, or 0 if the string does not - represent an integer. - */ -inline sal_Int32 toInt32( std::u16string_view str, sal_Int16 radix = 10 ) -{ - sal_Int64 n = rtl_ustr_toInt64_WithLength(str.data(), radix, str.size()); - if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) - n = 0; - return n; -} -inline sal_Int32 toInt32( std::string_view str, sal_Int16 radix = 10 ) -{ - sal_Int64 n = rtl_str_toInt64_WithLength(str.data(), radix, str.size()); - if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) - n = 0; - return n; -} - - } // namespace comphelper::string /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index c62fa5f23283..b14258c14d39 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -304,6 +304,32 @@ inline std::string_view trim(std::string_view str) return std::string_view{ str.data() + nPreSpaces, static_cast<size_t>(nLen - nPostSpaces - nPreSpaces) }; } + +// Like OString::toInt32, but for std::string_view: +inline sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix = 10) +{ + sal_Int64 n = rtl_ustr_toInt64_WithLength(str.data(), radix, str.size()); + if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) + n = 0; + return n; +} +inline sal_Int32 toInt32(std::string_view str, sal_Int16 radix = 10) +{ + sal_Int64 n = rtl_str_toInt64_WithLength(str.data(), radix, str.size()); + if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) + n = 0; + return n; +} + +// Like OString::toInt64, but for std::string_view: +inline sal_Int64 toInt64(std::u16string_view str, sal_Int16 radix = 10) +{ + return rtl_ustr_toInt64_WithLength(str.data(), radix, str.size()); +} +inline sal_Int64 toInt64(std::string_view str, sal_Int16 radix = 10) +{ + return rtl_str_toInt64_WithLength(str.data(), radix, str.size()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |