From a5d6034ab9cfc628c22d9e1939942314211346be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Sat, 28 Sep 2024 11:38:35 +0200 Subject: [PATCH] fix: replaceInPlace() std::wstring #4713 --- Foundation/include/Poco/String.h | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Foundation/include/Poco/String.h b/Foundation/include/Poco/String.h index acb4e9bb0c..4b68afbfce 100644 --- a/Foundation/include/Poco/String.h +++ b/Foundation/include/Poco/String.h @@ -21,17 +21,48 @@ #include "Poco/Foundation.h" #include "Poco/Ascii.h" #include +#include #include + // ignore loop unrolling warnings in this file #if defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 6)) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wpass-failed" #endif + namespace Poco { +template +std::size_t cstrlen(const C* str) + /// Returns the length of a zero-terminated C string. + /// For char and wchar_t based strings, overloads are + /// provided that call strlen() and wcslen(). +{ + const C* end = str; + while (*end) ++end; + return end - str; +} + + +inline std::size_t cstrlen(const char* str) + /// Returns the length of a zero-terminated C string. + /// This implementation calls std::strlen(). +{ + return std::strlen(str); +} + + +inline std::size_t cstrlen(const wchar_t* str) + /// Returns the length of a zero-terminated C string. + /// This implementation calls std::wcslen(). +{ + return std::wcslen(str); +} + + template S trimLeft(const S& str) /// Returns a copy of str with all leading @@ -494,7 +525,7 @@ S& replaceInPlace(S& str, const typename S::value_type* from, const typename S:: S result; typename S::size_type pos = 0; - typename S::size_type fromLen = std::strlen(from); + typename S::size_type fromLen = cstrlen(from); result.append(str, 0, start); do {