-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
l10n: port stat for translation + use thiserror + add french #8243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- I had to update the logic to handle french accents (and other chars)
GNU testsuite comparison:
|
GNU testsuite comparison:
|
src/uu/stat/src/stat.rs
Outdated
/// Scans for a number at the beginning of the string | ||
/// Returns the parsed number and the character count (not byte count) | ||
/// This was updated to properly handle UTF-8 by tracking both character and byte counts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought a bit more about the changes made to this function and somehow it doesn't make much sense to have both character and byte counts. We only deal with ASCII characters (+
, -
, and 0
- 9
) and thus character count and byte count are the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good point!
GNU testsuite comparison:
|
let mut i = 0; | ||
let mut count = 0; | ||
|
||
match chars.next() { | ||
Some('-' | '+' | '0'..='9') => i += 1, | ||
Some('-' | '+' | '0'..='9') => { | ||
count += 1; | ||
} | ||
_ => return None, | ||
} | ||
for c in chars { | ||
match c { | ||
'0'..='9' => i += 1, | ||
_ => break, | ||
} | ||
|
||
for _ in chars.take_while(char::is_ascii_digit) { | ||
count += 1; | ||
} | ||
if i > 0 { | ||
F::from_str(&self[..i]).ok().map(|x| (x, i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can simplify it with something like:
let count = chars
.next()
.filter(|&c| c.is_ascii_digit() || c == '-' || c == '+')
.map(|_| 1 + chars.take_while(char::is_ascii_digit).count())
.unwrap_or(0);