From 3c895c28391c2d7a037f3d83543d4c2444f7d1b5 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 6 Mar 2018 12:35:07 -0600 Subject: [PATCH] Add whitespace helpers to complete.h/cpp --- src/common.cpp | 7 +++++++ src/common.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/common.cpp b/src/common.cpp index 0c12b99ac..040a22d9d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -74,6 +74,13 @@ 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 char *whitespace_narrow = " \t\r\n\v"; + +bool is_whitespace(const wcstring &input) { + return input.find_first_not_of(whitespace); +} + bool has_working_tty_timestamps = true; /// Convert a character to its integer equivalent if it is a valid character for the requested base. diff --git a/src/common.h b/src/common.h index eec785c8d..9320c8e3d 100644 --- a/src/common.h +++ b/src/common.h @@ -203,6 +203,13 @@ extern const wchar_t *program_name; /// the tty. extern bool has_working_tty_timestamps; +/// A list of all whitespace characters +extern const wchar_t *whitespace; +extern const char *whitespace_narrow; + +bool is_whitespace(const wcstring &input); +inline bool is_whitespace(const wchar_t *input) { return is_whitespace(wcstring(input)); } + /// This macro is used to check that an argument is true. It is a bit like a non-fatal form of /// assert. Instead of exiting on failure, the current function is ended at once. The second /// parameter is the return value of the current function on failure.