mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-31 23:28:45 +00:00
Use maybe_t in unescape_string_internal
This commit is contained in:
parent
fa1dab040b
commit
8747018cbc
2 changed files with 17 additions and 15 deletions
|
@ -1480,8 +1480,8 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
|
|
||||||
for (size_t input_position = 0; input_position < input_len && !errored; input_position++) {
|
for (size_t input_position = 0; input_position < input_len && !errored; input_position++) {
|
||||||
const wchar_t c = input[input_position];
|
const wchar_t c = input[input_position];
|
||||||
// Here's the character we'll append to result, or NOT_A_WCHAR to suppress it.
|
// Here's the character we'll append to result, or none() to suppress it.
|
||||||
wint_t to_append_or_none = c;
|
maybe_t<wchar_t> to_append_or_none = c;
|
||||||
if (mode == mode_unquoted) {
|
if (mode == mode_unquoted) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case L'\\': {
|
case L'\\': {
|
||||||
|
@ -1499,7 +1499,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
input_position += *escape_chars - 1;
|
input_position += *escape_chars - 1;
|
||||||
}
|
}
|
||||||
// We've already appended, don't append anything else.
|
// We've already appended, don't append anything else.
|
||||||
to_append_or_none = NOT_A_WCHAR;
|
to_append_or_none = none();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'~': {
|
case L'~': {
|
||||||
|
@ -1602,18 +1602,21 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
case L'\t':
|
case L'\t':
|
||||||
case L' ': {
|
case L' ': {
|
||||||
if (unescape_special && brace_count > 0) {
|
if (unescape_special && brace_count > 0) {
|
||||||
to_append_or_none = brace_text_start ? wint_t(BRACE_SPACE) : NOT_A_WCHAR;
|
to_append_or_none =
|
||||||
|
brace_text_start ? maybe_t<wchar_t>(BRACE_SPACE) : none();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'\'': {
|
case L'\'': {
|
||||||
mode = mode_single_quotes;
|
mode = mode_single_quotes;
|
||||||
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
to_append_or_none =
|
||||||
|
unescape_special ? maybe_t<wchar_t>(INTERNAL_SEPARATOR) : none();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'\"': {
|
case L'\"': {
|
||||||
mode = mode_double_quotes;
|
mode = mode_double_quotes;
|
||||||
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
to_append_or_none =
|
||||||
|
unescape_special ? maybe_t<wchar_t>(INTERNAL_SEPARATOR) : none();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -1652,14 +1655,16 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (c == L'\'') {
|
} else if (c == L'\'') {
|
||||||
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
to_append_or_none =
|
||||||
|
unescape_special ? maybe_t<wchar_t>(INTERNAL_SEPARATOR) : none();
|
||||||
mode = mode_unquoted;
|
mode = mode_unquoted;
|
||||||
}
|
}
|
||||||
} else if (mode == mode_double_quotes) {
|
} else if (mode == mode_double_quotes) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case L'"': {
|
case L'"': {
|
||||||
mode = mode_unquoted;
|
mode = mode_unquoted;
|
||||||
to_append_or_none = unescape_special ? wint_t(INTERNAL_SEPARATOR) : NOT_A_WCHAR;
|
to_append_or_none =
|
||||||
|
unescape_special ? maybe_t<wchar_t>(INTERNAL_SEPARATOR) : none();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '\\': {
|
case '\\': {
|
||||||
|
@ -1681,7 +1686,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
}
|
}
|
||||||
case '\n': {
|
case '\n': {
|
||||||
/* Swallow newline */
|
/* Swallow newline */
|
||||||
to_append_or_none = NOT_A_WCHAR;
|
to_append_or_none = none();
|
||||||
input_position += 1; /* Skip over the backslash */
|
input_position += 1; /* Skip over the backslash */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1707,11 +1712,8 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now maybe append the char.
|
// Now maybe append the char.
|
||||||
if (to_append_or_none != NOT_A_WCHAR) {
|
if (to_append_or_none.has_value()) {
|
||||||
wchar_t to_append_char = static_cast<wchar_t>(to_append_or_none);
|
result.push_back(*to_append_or_none);
|
||||||
// If result_char is not NOT_A_WCHAR, it must be a valid wchar.
|
|
||||||
assert((wint_t)to_append_char == to_append_or_none);
|
|
||||||
result.push_back(to_append_char);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ using expand_flags_t = enum_set_t<expand_flag>;
|
||||||
|
|
||||||
class completion_t;
|
class completion_t;
|
||||||
|
|
||||||
enum {
|
enum : wchar_t {
|
||||||
/// Character representing a home directory.
|
/// Character representing a home directory.
|
||||||
HOME_DIRECTORY = EXPAND_RESERVED_BASE,
|
HOME_DIRECTORY = EXPAND_RESERVED_BASE,
|
||||||
/// Character representing process expansion for %self.
|
/// Character representing process expansion for %self.
|
||||||
|
|
Loading…
Reference in a new issue