Add a feature_test() function

This is a convenience over fish_features().test()
This commit is contained in:
ridiculousfish 2018-05-05 19:44:57 -07:00
parent 762c31be87
commit 4194b4efee
7 changed files with 12 additions and 9 deletions

View file

@ -138,7 +138,7 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_opts_t &opts, status_c
/// Print the features and their values.
static void print_features(io_streams_t &streams) {
for (const auto &md : features_t::metadata) {
int set = fish_features().test(md.flag);
int set = feature_test(md.flag);
streams.out.append_format(L"%ls\t%s\t%ls\t%ls\n", md.name, set ? "on" : "off", md.groups,
md.description);
}
@ -339,7 +339,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (!metadata) {
retval = TEST_FEATURE_NOT_RECOGNIZED;
} else {
retval = fish_features().test(metadata->flag) ? TEST_FEATURE_ON : TEST_FEATURE_OFF;
retval = feature_test(metadata->flag) ? TEST_FEATURE_ON : TEST_FEATURE_OFF;
}
break;
}

View file

@ -932,8 +932,8 @@ static void escape_string_script(const wchar_t *orig_in, size_t in_len, wcstring
const bool escape_all = static_cast<bool>(flags & ESCAPE_ALL);
const bool no_quoted = static_cast<bool>(flags & ESCAPE_NO_QUOTED);
const bool no_tilde = static_cast<bool>(flags & ESCAPE_NO_TILDE);
const bool no_caret = fish_features().test(features_t::stderr_nocaret);
const bool no_qmark = fish_features().test(features_t::qmark_noglob);
const bool no_caret = feature_test(features_t::stderr_nocaret);
const bool no_qmark = feature_test(features_t::qmark_noglob);
int need_escape = 0;
int need_complex_escape = 0;
@ -1361,7 +1361,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
break;
}
case L'?': {
if (unescape_special && !fish_features().test(features_t::qmark_noglob)) {
if (unescape_special && !feature_test(features_t::qmark_noglob)) {
to_append_or_none = ANY_CHAR;
}
break;

View file

@ -68,6 +68,9 @@ public:
/// Return the global set of features for fish. This is const to prevent accidental mutation.
const features_t &fish_features();
/// Perform a feature test on the global set of features.
inline bool feature_test(features_t::flag_t f) { return fish_features().test(f); }
/// Return the global set of features for fish, but mutable. In general fish features should be set
/// at startup only.
features_t &mutable_fish_features();

View file

@ -550,7 +550,7 @@ static void color_argument_internal(const wcstring &buffstr,
break;
}
case L'?': {
if (!fish_features().test(features_t::qmark_noglob)) {
if (!feature_test(features_t::qmark_noglob)) {
colors[in_pos] = highlight_spec_operator;
}
break;

View file

@ -419,7 +419,7 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar
wcstring parse_util_unescape_wildcards(const wcstring &str) {
wcstring result;
result.reserve(str.size());
bool unesc_qmark = !fish_features().test(features_t::qmark_noglob);
bool unesc_qmark = !feature_test(features_t::qmark_noglob);
const wchar_t *const cs = str.c_str();
for (size_t i = 0; cs[i] != L'\0'; i++) {

View file

@ -36,7 +36,7 @@ const wchar_t *tokenizer_error::Message() const {
}
// Whether carets redirect stderr.
static bool caret_redirs() { return !fish_features().test(features_t::stderr_nocaret); }
static bool caret_redirs() { return !feature_test(features_t::stderr_nocaret); }
/// Return an error token and mark that we no longer have a next token.
tok_t tokenizer_t::call_error(tokenizer_error *error_type, const wchar_t *token_start,

View file

@ -62,7 +62,7 @@ static size_t wildcard_find(const wchar_t *wc) {
/// Implementation of wildcard_has. Needs to take the length to handle embedded nulls (issue #1631).
static bool wildcard_has_impl(const wchar_t *str, size_t len, bool internal) {
assert(str != NULL);
bool qmark_is_wild = !fish_features().test(features_t::qmark_noglob);
bool qmark_is_wild = !feature_test(features_t::qmark_noglob);
const wchar_t *end = str + len;
if (internal) {
for (; str < end; str++) {