mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Eliminate string_set_contains
This commit is contained in:
parent
1caf20f7c3
commit
3e14f96d40
1 changed files with 4 additions and 15 deletions
19
src/env.cpp
19
src/env.cpp
|
@ -216,25 +216,14 @@ static env_universal_t *uvars() { return s_universal_variables; }
|
||||||
// so we don't bother to sort them.
|
// so we don't bother to sort them.
|
||||||
using string_set_t = const wchar_t *const[];
|
using string_set_t = const wchar_t *const[];
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool string_set_contains(const T &set, const wchar_t *val) {
|
|
||||||
for (const wchar_t *entry : set) {
|
|
||||||
if (!std::wcscmp(val, entry)) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if a variable may not be set using the set command.
|
/// Check if a variable may not be set using the set command.
|
||||||
static bool is_read_only(const wchar_t *val) {
|
static bool is_read_only(const wcstring &key) {
|
||||||
const string_set_t env_read_only = {
|
static const string_set_t env_read_only = {
|
||||||
L"PWD", L"SHLVL", L"history", L"pipestatus", L"status", L"version",
|
L"PWD", L"SHLVL", L"history", L"pipestatus", L"status", L"version",
|
||||||
L"FISH_VERSION", L"fish_pid", L"hostname", L"_", L"fish_private_mode"};
|
L"FISH_VERSION", L"fish_pid", L"hostname", L"_", L"fish_private_mode"};
|
||||||
return string_set_contains(env_read_only, val) ||
|
return contains(env_read_only, key) || (in_private_mode() && key == L"fish_history");
|
||||||
(in_private_mode() && std::wcscmp(L"fish_history", val) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_read_only(const wcstring &val) { return is_read_only(val.c_str()); }
|
|
||||||
|
|
||||||
/// Return true if a variable should become a path variable by default. See #436.
|
/// Return true if a variable should become a path variable by default. See #436.
|
||||||
static bool variable_should_auto_pathvar(const wcstring &name) {
|
static bool variable_should_auto_pathvar(const wcstring &name) {
|
||||||
return string_suffixes_string(L"PATH", name);
|
return string_suffixes_string(L"PATH", name);
|
||||||
|
|
Loading…
Reference in a new issue