From 8b0bc70db73b48d833a3b5791e55921768cf6932 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 31 Mar 2025 08:33:08 -0500 Subject: Remove reinterpret_cast usage in favor of std::bit_cast. --- include/fud_c_string.hpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'include/fud_c_string.hpp') diff --git a/include/fud_c_string.hpp b/include/fud_c_string.hpp index a1ab51a..0632619 100644 --- a/include/fud_c_string.hpp +++ b/include/fud_c_string.hpp @@ -18,6 +18,7 @@ #ifndef FUD_C_STRING_HPP #define FUD_C_STRING_HPP +#include #include #include #include @@ -54,28 +55,12 @@ constexpr ssize_t cStringLength(const char* str) constexpr ssize_t cStringLength(const char8_t* str, size_t maxLength) { - // Cannot cast str to const char* without breaking constexpr - // return cStringLength(reinterpret_cast(str), maxLength); - if (str == nullptr || maxLength > MAX_C_STRING_LENGTH) { - return -1; - } - - ssize_t size = 0; - - while (str[size] != 0 && static_cast(size) < maxLength) { - size++; - } - - if (str[size] != 0 && static_cast(size) == maxLength) { - return static_cast(maxLength) + 1; - } - - return size; + return cStringLength(std::bit_cast(str), maxLength); } constexpr ssize_t cStringLength(const char8_t* str) { - return cStringLength(str, MAX_C_STRING_LENGTH); + return cStringLength(std::bit_cast(str), MAX_C_STRING_LENGTH); } } // namespace fud -- cgit v1.2.3