mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Simplify valid_var_name
This commit is contained in:
parent
9dcb5abaf1
commit
2bf554ae5e
2 changed files with 3 additions and 12 deletions
|
@ -2414,21 +2414,13 @@ void redirect_tty_output() {
|
||||||
bool valid_var_name_char(wchar_t chr) { return fish_iswalnum(chr) || chr == L'_'; }
|
bool valid_var_name_char(wchar_t chr) { return fish_iswalnum(chr) || chr == L'_'; }
|
||||||
|
|
||||||
/// Test if the given string is a valid variable name.
|
/// Test if the given string is a valid variable name.
|
||||||
bool valid_var_name(const wchar_t *str) {
|
bool valid_var_name(const wcstring &str) {
|
||||||
if (str[0] == L'\0') return false;
|
return std::find_if(str.begin(), str.end(), valid_var_name_char) == str.end();
|
||||||
while (*str) {
|
|
||||||
if (!valid_var_name_char(*str)) return false;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the given string is a valid variable name.
|
|
||||||
bool valid_var_name(const wcstring &str) { return valid_var_name(str.c_str()); }
|
|
||||||
|
|
||||||
/// Test if the string is a valid function name.
|
/// Test if the string is a valid function name.
|
||||||
bool valid_func_name(const wcstring &str) {
|
bool valid_func_name(const wcstring &str) {
|
||||||
if (str.size() == 0) return false;
|
if (str.empty()) return false;
|
||||||
if (str.at(0) == L'-') return false;
|
if (str.at(0) == L'-') return false;
|
||||||
if (str.find_first_of(L'/') != wcstring::npos) return false;
|
if (str.find_first_of(L'/') != wcstring::npos) return false;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -971,7 +971,6 @@ void invalidate_termsize(bool invalidate_vars = false);
|
||||||
struct winsize get_current_winsize();
|
struct winsize get_current_winsize();
|
||||||
|
|
||||||
bool valid_var_name_char(wchar_t chr);
|
bool valid_var_name_char(wchar_t chr);
|
||||||
bool valid_var_name(const wchar_t *str);
|
|
||||||
bool valid_var_name(const wcstring &str);
|
bool valid_var_name(const wcstring &str);
|
||||||
bool valid_func_name(const wcstring &str);
|
bool valid_func_name(const wcstring &str);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue