mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 10:01:14 -03:00
Clean up env_var_table_t. Switch from storing var_uni_entry_t* to var_uni_entry_t. Various other cleanups.
This commit is contained in:
46
env.h
46
env.h
@@ -108,20 +108,31 @@ class env_var_t : public wcstring
|
||||
private:
|
||||
bool is_missing;
|
||||
public:
|
||||
static env_var_t missing_var(void);
|
||||
static env_var_t missing_var(void)
|
||||
{
|
||||
env_var_t result(L"");
|
||||
result.is_missing = true;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
env_var_t(const env_var_t &x) : wcstring(x), is_missing(x.is_missing) { }
|
||||
env_var_t(const wcstring & x) : wcstring(x), is_missing(false) { }
|
||||
env_var_t(const wchar_t *x) : wcstring(x), is_missing(false) { }
|
||||
env_var_t() : wcstring(L""), is_missing(false) { }
|
||||
|
||||
bool missing(void) const
|
||||
{
|
||||
return is_missing;
|
||||
}
|
||||
|
||||
bool missing_or_empty(void) const
|
||||
{
|
||||
return missing() || empty();
|
||||
}
|
||||
|
||||
const wchar_t *c_str(void) const;
|
||||
|
||||
env_var_t &operator=(const env_var_t &s)
|
||||
{
|
||||
is_missing = s.is_missing;
|
||||
@@ -131,14 +142,35 @@ class env_var_t : public wcstring
|
||||
|
||||
bool operator==(const env_var_t &s) const
|
||||
{
|
||||
if (is_missing && s.is_missing)
|
||||
return true;
|
||||
else if (s.is_missing || s.is_missing)
|
||||
return false;
|
||||
else
|
||||
return *static_cast<const wcstring *>(this) == *static_cast<const wcstring *>(&s);
|
||||
return is_missing == s.is_missing && static_cast<const wcstring &>(*this) == static_cast<const wcstring &>(s);
|
||||
}
|
||||
|
||||
bool operator==(const wcstring &s) const
|
||||
{
|
||||
return ! is_missing && static_cast<const wcstring &>(*this) == s;
|
||||
}
|
||||
|
||||
bool operator!=(const env_var_t &s) const
|
||||
{
|
||||
return !(*this == s);
|
||||
}
|
||||
|
||||
bool operator!=(const wcstring &s) const
|
||||
{
|
||||
return !(*this == s);
|
||||
}
|
||||
|
||||
bool operator==(const wchar_t *s) const
|
||||
{
|
||||
return ! is_missing && static_cast<const wcstring &>(*this) == s;
|
||||
}
|
||||
|
||||
bool operator!=(const wchar_t *s) const
|
||||
{
|
||||
return !(*this == s);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
/**
|
||||
Gets the variable with the specified name, or an empty string if it does not exist.
|
||||
|
||||
Reference in New Issue
Block a user