Remove code clone in parse_util_locate_cmdsub

This commit is contained in:
Johannes Altmanninger
2025-05-02 06:38:20 +02:00
parent cb719cd418
commit bd178c8ba8

View File

@@ -230,7 +230,9 @@ fn process_opening_quote(
quote: char, quote: char,
) -> Option<usize> { ) -> Option<usize> {
let q_end = quote_end(input.into(), pos, quote)?; let q_end = quote_end(input.into(), pos, quote)?;
// Found a valid closing quote.
if input[q_end] == '$' { if input[q_end] == '$' {
// The closing quote is another quoted command substitution.
*last_dollar = Some(q_end); *last_dollar = Some(q_end);
quoted_cmdsubs.push(paran_count); quoted_cmdsubs.push(paran_count);
} }
@@ -310,21 +312,19 @@ fn process_opening_quote(
if quoted_cmdsubs.last() == Some(&paran_count) { if quoted_cmdsubs.last() == Some(&paran_count) {
quoted_cmdsubs.pop(); quoted_cmdsubs.pop();
// Quoted command substitutions temporarily close double quotes. // Quoted command substitutions temporarily close double quotes.
// In "foo$(bar)baz$(qux)" // In "foo$(bar)baz$(qux)", after the ), we need to act as if there was a double quote.
// We are here ^ match process_opening_quote(
// After the ) in a quoted command substitution, we need to act as if input,
// there was an invisible double quote. &mut inout_is_quoted,
match quote_end(input.into(), pos, '"') { paran_count,
Some(q_end) => { &mut quoted_cmdsubs,
// Found a valid closing quote. pos,
// Stop at $(qux), which is another quoted command substitution. &mut last_dollar,
if input[q_end] == '$' { '"',
quoted_cmdsubs.push(paran_count); ) {
} Some(q_end) => pos = q_end,
pos = q_end;
}
None => break, None => break,
}; }
} }
} }
is_token_begin = is_token_delimiter(c, input.get(pos + 1).copied()); is_token_begin = is_token_delimiter(c, input.get(pos + 1).copied());