Simplify valid_var_name

This commit is contained in:
Aaron Gyes 2019-03-14 10:28:48 -07:00
parent 9dcb5abaf1
commit 2bf554ae5e
2 changed files with 3 additions and 12 deletions

View file

@ -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;

View file

@ -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);