diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-03-08 23:31:11 +0100 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-03-09 19:19:04 +0100 |
commit | 3ba85b7786663da4f2de1a3c2fe7ee9a27657293 (patch) | |
tree | 31052009f6f30e919d7220b07d8b2bc84074e327 | |
parent | 959b30841ae9c5cc1f43928f5e7780abaab4a087 (diff) |
Support o3tl::iterateCodePoints with both sal_Int32 and std::size_t
...and clean up the most gross casting offenses
Change-Id: If0d646fb3e73e71a9a2735569395034973563a1f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164602
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
-rw-r--r-- | comphelper/source/misc/string.cxx | 2 | ||||
-rw-r--r-- | configmgr/source/access.cxx | 3 | ||||
-rw-r--r-- | include/o3tl/string_view.hxx | 6 | ||||
-rw-r--r-- | tools/source/misc/json_writer.cxx | 5 |
4 files changed, 10 insertions, 6 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 1b9137e473c0..446e500e0250 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -266,7 +266,7 @@ sal_Int32 getTokenCount(std::u16string_view rIn, sal_Unicode cTok) sal_uInt32 decimalStringToNumber(std::u16string_view str) { sal_uInt32 result = 0; - for( sal_Int32 i = 0; i < static_cast<sal_Int32>(str.size()); ) + for( std::size_t i = 0; i < str.size(); ) { sal_uInt32 c = o3tl::iterateCodePoints(str, &i); sal_uInt32 value = 0; diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx index c25cf73aaef0..44a47e74b331 100644 --- a/configmgr/source/access.cxx +++ b/configmgr/source/access.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <cassert> +#include <cstddef> #include <cstdlib> #include <utility> #include <vector> @@ -111,7 +112,7 @@ namespace { // surrogates, even though they should not appear in well-formed UNO OUString // instances anyway), or is a slash (as it causes problems in path syntax): bool isValidName(std::u16string_view name, bool setMember) { - for (sal_Int32 i = 0; i != static_cast<sal_Int32>(name.size());) { + for (std::size_t i = 0; i != name.size();) { sal_uInt32 c = o3tl::iterateCodePoints(name, &i); if ((c < 0x20 && !(c == 0x09 || c == 0x0A || c == 0x0D)) || rtl::isSurrogate(c) || c == 0xFFFE || c == 0xFFFF diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index 1e5db5eb0227..0fe51fd98eda 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -15,6 +15,7 @@ #include <cstddef> #include <string> #include <string_view> +#include <type_traits> #include <o3tl/intcmp.hxx> #include <rtl/character.hxx> @@ -509,8 +510,9 @@ inline double toDouble(std::string_view str) } // Like OUString::iterateCodePoints, but for std::string_view: -inline sal_uInt32 iterateCodePoints(std::u16string_view string, sal_Int32* indexUtf16, - sal_Int32 incrementCodePoints = 1) +template <typename T> +requires(std::is_same_v<T, sal_Int32> || std::is_same_v<T, std::size_t>) sal_uInt32 + iterateCodePoints(std::u16string_view string, T* indexUtf16, sal_Int32 incrementCodePoints = 1) { std::size_t n; char16_t cu; diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index 0ffc5cb903f9..b9f62d2b4b60 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -10,6 +10,7 @@ #include <tools/json_writer.hxx> #include <o3tl/string_view.hxx> #include <stdio.h> +#include <cstddef> #include <cstring> #include <rtl/math.hxx> @@ -137,8 +138,8 @@ void JsonWriter::writeEscapedOUString(std::u16string_view rPropVal) ++mPos; // Convert from UTF-16 to UTF-8 and perform escaping - sal_Int32 i = 0; - while (i < static_cast<sal_Int32>(rPropVal.size())) + std::size_t i = 0; + while (i < rPropVal.size()) { sal_uInt32 ch = o3tl::iterateCodePoints(rPropVal, &i); if (writeEscapedSequence(ch, mPos)) |