From b15ab697c2475b0e011cff6216f61f87a6614b1a Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 7 Dec 2023 12:25:35 +0100 Subject: [PATCH] string: add strnlen variant for known fixed-size buffers --- include/stdex/string.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index b79b581f5..af271c7e5 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -268,6 +268,19 @@ namespace stdex return i; } + /// + /// Calculate zero-terminated string length. + /// + /// \param[in] str String + /// + /// \return Number of code units excluding zero terminator in the string. + /// + template + inline size_t strnlen(_In_ const T (&str)[SIZE]) + { + return strnlen(str, SIZE); + } + constexpr auto npos{ static_cast(-1) }; ///