From 216b038a7d16ef2b1bc2a96fc57b523bb330489b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Aug 2019 00:00:20 -0400 Subject: [PATCH] hecl/SystemChar: Unify StrLen implementations and make constexpr We can utilize std::char_traits to generically handle the defined character type. Since C++17, std::char_traits' length() function is constexpr, so we can also make StrLen constexpr. --- hecl/include/hecl/SystemChar.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hecl/include/hecl/SystemChar.hpp b/hecl/include/hecl/SystemChar.hpp index 426051dc1..124c28332 100644 --- a/hecl/include/hecl/SystemChar.hpp +++ b/hecl/include/hecl/SystemChar.hpp @@ -26,7 +26,6 @@ namespace hecl { #if HECL_UCS2 typedef wchar_t SystemChar; -static inline size_t StrLen(const SystemChar* str) { return wcslen(str); } typedef std::wstring SystemString; typedef std::wstring_view SystemStringView; static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } @@ -37,7 +36,6 @@ static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str. typedef struct _stat Sstat; #else typedef char SystemChar; -static inline size_t StrLen(const SystemChar* str) { return strlen(str); } typedef std::string SystemString; typedef std::string_view SystemStringView; static inline void ToLower(SystemString& str) { @@ -54,4 +52,6 @@ static inline void ToUpper(SystemString& str) { typedef struct stat Sstat; #endif +constexpr size_t StrLen(const SystemChar* str) { return std::char_traits::length(str); } + } // namespace hecl