sort: add locale-aware month sorting (-M)#11445
sort: add locale-aware month sorting (-M)#11445sylvestre wants to merge 2 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
3377348 to
aa3ca32
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
146a915 to
afbe750
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
| } | ||
| let text = String::from_utf8(output.stdout).ok()?; | ||
| let months: Vec<String> = text.trim().split(';').map(String::from).collect(); | ||
| if months.len() == 12 && months.iter().all(|m| !m.is_empty()) { |
There was a problem hiding this comment.
I would do the check for emptiness with a filter as part of the chain on the previous line.
| let expected = months.iter().fold(String::new(), |mut s, m| { | ||
| writeln!(s, "{m}").unwrap(); | ||
| s | ||
| }); |
There was a problem hiding this comment.
Using join might be easier to read:
| let expected = months.iter().fold(String::new(), |mut s, m| { | |
| writeln!(s, "{m}").unwrap(); | |
| s | |
| }); | |
| let expected = months.join("\n") + "\n"; |
There was a problem hiding this comment.
Just wondering: are those tests ever run in the CI?
| let initial_selection = &self.line[selection.clone()]; | ||
|
|
||
| let mut month_chars = initial_selection | ||
| let trimmed = initial_selection |
There was a problem hiding this comment.
The name trimmed is a bit misleading as it contains a position (and not a trimmed string).
| trimmed..trimmed | ||
| } else { | ||
| // We parsed a month. Match the first three non-whitespace characters, which must be the month we parsed. | ||
| month_chars.next().unwrap().0 | ||
| ..month_chars | ||
| .nth(2) | ||
| .map_or(initial_selection.len(), |(idx, _)| idx) | ||
| // We parsed a month. Use the actual match byte length. | ||
| trimmed..(trimmed + match_len) |
There was a problem hiding this comment.
It might make sense to set selection.start and selection.end directly in the if/else blocks instead of returning a range.
| /// Parse the beginning string into a Month, returning [`Month::Unknown`] on errors. | ||
| fn month_parse(line: &[u8]) -> Month { | ||
| /// Also returns the byte length consumed from the input (after leading blanks). | ||
| fn month_parse(line: &[u8]) -> (Month, usize) { |
There was a problem hiding this comment.
I think this function is not entirely correct.
Here is an example where I get a different output compared to GNU sort:
$ printf "juin\nav ril\nmars\nfevr." | LC_ALL=fr_FR.UTF-8 cargo run -q sort -M
fevr.
mars
av ril
juin
$ printf "juin\nav ril\nmars\nfevr." | LC_ALL=fr_FR.UTF-8 sort -M
av ril
fevr.
mars
juin
No description provided.