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)); }