From 10791467d824b2af74c52caf6e4724c07427793c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 17 Nov 2023 14:57:42 +0100 Subject: [PATCH] string: add isblank Signed-off-by: Simon Rozman --- include/stdex/string.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index d78118087..fc6578c1d 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -252,6 +252,28 @@ namespace stdex /// const inline std::locale std_locale_C("C"); + /// + /// Checks if string contains all white-space + /// + /// \param[in] str String + /// \param[in] count Code unit count limit + /// + /// \return `true` if all characters are white-space or `false` when any non-white-space character is found in string. + /// + template + inline bool isblank( + _In_reads_or_z_opt_(count) const T* str, + _In_ size_t count, + _In_ const std::locale& locale) + { + _Assume_(str || !count); + const auto& ctype = std::use_facet>(locale); + for (size_t i = 0; i < count && str[i]; ++i) + if (!ctype.is(ctype.space, str[i])) + return false; + return true; + } + /// /// Find a code unit in a string case-insensitive ///