From 0b96b516d58534c2b6c643e0cd45a268fb730e16 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 12 Mar 2018 08:06:50 -0500 Subject: [PATCH] Improve and expand is_whitespace helper functions --- src/common.cpp | 13 +++++++++++-- src/common.h | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index f3c91df30..fbee108ff 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -75,11 +75,20 @@ static volatile bool termsize_valid = false; static char *wcs2str_internal(const wchar_t *in, char *out); static void debug_shared(const wchar_t msg_level, const wcstring &msg); -const wchar_t *whitespace = L" \t\r\n\v"; +const wcstring whitespace = L" \t\r\n\v"; const char *whitespace_narrow = " \t\r\n\v"; +bool is_whitespace(const wchar_t input) { + for (auto c : whitespace) { + if (c == input) { + return true; + } + } + return false; +} + bool is_whitespace(const wcstring &input) { - return input.find_first_not_of(whitespace); + return input.find_first_not_of(whitespace) == wcstring::npos; } bool has_working_tty_timestamps = true; diff --git a/src/common.h b/src/common.h index 8047018b5..9b84f7625 100644 --- a/src/common.h +++ b/src/common.h @@ -206,9 +206,10 @@ extern const wchar_t *program_name; extern bool has_working_tty_timestamps; /// A list of all whitespace characters -extern const wchar_t *whitespace; +extern const wcstring whitespace; extern const char *whitespace_narrow; +bool is_whitespace(const wchar_t input); bool is_whitespace(const wcstring &input); inline bool is_whitespace(const wchar_t *input) { return is_whitespace(wcstring(input)); }