Skip to content

Commit

Permalink
fix: replaceInPlace() std::wstring #4713
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Sep 28, 2024
1 parent a525065 commit a5d6034
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Foundation/include/Poco/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,48 @@
#include "Poco/Foundation.h"
#include "Poco/Ascii.h"
#include <cstring>
#include <cwchar>
#include <algorithm>


// 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 <typename C>
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 <class S>
S trimLeft(const S& str)
/// Returns a copy of str with all leading
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit a5d6034

Please sign in to comment.