Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorRoland Kaminski2022-10-03 19:38:04 +0200
committerMartin Hořeňovský2022-10-04 10:50:18 +0200
commit97313f9033cffde2002e4a377229559d360d7f73 (patch)
treea33488ec88a94dab87566098ef3ea5531d263ed6 /src/catch2
parent6a9bf2e0afe7eeece351777ae2f9b8e714ecd274 (diff)
downloadcatch3-97313f9033cffde2002e4a377229559d360d7f73.tar.gz
fix compilation on cygwin
Use std::char_traits<char>::find instead of strnlen for better portability.
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_tostring.hpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index 235dec3b..65c6c13e 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -13,7 +13,6 @@
#include <cstddef>
#include <type_traits>
#include <string>
-#include <string.h>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_config_wchar.hpp>
@@ -41,6 +40,13 @@ namespace Catch {
namespace Detail {
+ inline std::size_t catch_strnlen(const char *str, std::size_t n) {
+ auto ret = std::char_traits<char>::find(str, n, '\0');
+ if (ret != nullptr) {
+ return ret - str;
+ }
+ return n;
+ }
constexpr StringRef unprintableString = "{?}"_sr;
@@ -208,28 +214,24 @@ namespace Catch {
template<size_t SZ>
struct StringMaker<char[SZ]> {
static std::string convert(char const* str) {
- // Note that `strnlen` is not actually part of standard C++,
- // but both POSIX and Windows cstdlib provide it.
return Detail::convertIntoString(
- StringRef( str, strnlen( str, SZ ) ) );
+ StringRef( str, Detail::catch_strnlen( str, SZ ) ) );
}
};
template<size_t SZ>
struct StringMaker<signed char[SZ]> {
static std::string convert(signed char const* str) {
- // See the plain `char const*` overload
auto reinterpreted = reinterpret_cast<char const*>(str);
return Detail::convertIntoString(
- StringRef(reinterpreted, strnlen(reinterpreted, SZ)));
+ StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
}
};
template<size_t SZ>
struct StringMaker<unsigned char[SZ]> {
static std::string convert(unsigned char const* str) {
- // See the plain `char const*` overload
auto reinterpreted = reinterpret_cast<char const*>(str);
return Detail::convertIntoString(
- StringRef(reinterpreted, strnlen(reinterpreted, SZ)));
+ StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
}
};