Fix span of multibyte short flags (#8866)

# Description

Follow up to #8849

Work for #8821
Should unblock work on #8808

Missing is a restriction to printables or identifiers according to
[UAX31](https://www.unicode.org/reports/tr31/)

# User-Facing Changes

Non ASCII characters should be allowed in shortflags.

# Tests + Formatting

Want to add some tests for the error reporting cases
This commit is contained in:
Stefan Holderbach 2023-04-14 18:53:14 +02:00 committed by GitHub
parent 8efbb48cb0
commit 6cedc05384
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -457,12 +457,12 @@ fn parse_short_flags(
let short_flags = &arg_contents_uft8_ref[1..]; let short_flags = &arg_contents_uft8_ref[1..];
let mut found_short_flags = vec![]; let mut found_short_flags = vec![];
let mut unmatched_short_flags = vec![]; let mut unmatched_short_flags = vec![];
for short_flag in short_flags.chars().enumerate() { for short_flag in short_flags.char_indices() {
let short_flag_char = short_flag.1; let short_flag_char = short_flag.1;
let orig = arg_span; let orig = arg_span;
let short_flag_span = Span::new( let short_flag_span = Span::new(
orig.start + 1 + short_flag.0, orig.start + 1 + short_flag.0,
orig.start + 1 + short_flag.0 + 1, orig.start + 1 + short_flag.0 + short_flag_char.len_utf8(),
); );
if let Some(flag) = sig.get_short_flag(short_flag_char) { if let Some(flag) = sig.get_short_flag(short_flag_char) {
// If we require an arg and are in a batch of short flags, error // If we require an arg and are in a batch of short flags, error