Skip to content

Commit 334a917

Browse files
committed
fix versionsort chunk split on non-ASCII numerics
1 parent 0a32a02 commit 334a917

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

src/sort.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a> VersionChunkIter<'a> {
6565
break;
6666
}
6767

68-
if !c.is_numeric() {
68+
if !c.is_ascii_digit() {
6969
continue;
7070
}
7171

@@ -283,6 +283,10 @@ mod test {
283283
source: "009"
284284
})
285285
);
286+
287+
// '๙' = U+0E59 THAI DIGIT NINE, General Category Nd
288+
let mut iter = VersionChunkIter::new("x๙v");
289+
assert_eq!(iter.next(), Some(VersionChunk::Str("x๙v")));
286290
}
287291

288292
#[test]
@@ -297,6 +301,11 @@ mod test {
297301
input.sort_by(|a, b| version_sort(a, b));
298302
assert_eq!(input, expected);
299303

304+
let mut input = vec!["x๙x", "xéx", "x0x"];
305+
let expected = vec!["x0x", "xéx", "x๙x"];
306+
input.sort_by(|a, b| version_sort(a, b));
307+
assert_eq!(input, expected);
308+
300309
let mut input = vec!["applesauce", "apple"];
301310
let expected = vec!["apple", "applesauce"];
302311
input.sort_by(|a, b| version_sort(a, b));
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::cmp::Ordering;
2+
use print๙msg::print as first_print;
3+
use print0msg::print as second_print;
4+
use printémsg::print as third_print;
5+
6+
fn main() {
7+
first_print();
8+
second_print();
9+
third_print();
10+
11+
assert_eq!("print๙msg".cmp("printémsg"), Ordering::Greater);
12+
}
13+
14+
/// '๙' = 0E59;THAI DIGIT NINE;Nd;
15+
mod print๙msg {
16+
pub fn print() {
17+
println!("Non-ASCII Decimal_Number")
18+
}
19+
}
20+
21+
/// '0' = 0030;DIGIT ZERO;Nd;
22+
mod print0msg {
23+
pub fn print() {
24+
println!("ASCII Decimal_Number")
25+
}
26+
}
27+
28+
/// 'é' = 00E9;LATIN SMALL LETTER E WITH ACUTE;Ll;
29+
mod printémsg {
30+
pub fn print() {
31+
println!("Lowercase_Letter")
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use print0msg::print as second_print;
2+
use printémsg::print as third_print;
3+
use print๙msg::print as first_print;
4+
use std::cmp::Ordering;
5+
6+
fn main() {
7+
first_print();
8+
second_print();
9+
third_print();
10+
11+
assert_eq!("print๙msg".cmp("printémsg"), Ordering::Greater);
12+
}
13+
14+
/// '๙' = 0E59;THAI DIGIT NINE;Nd;
15+
mod print๙msg {
16+
pub fn print() {
17+
println!("Non-ASCII Decimal_Number")
18+
}
19+
}
20+
21+
/// '0' = 0030;DIGIT ZERO;Nd;
22+
mod print0msg {
23+
pub fn print() {
24+
println!("ASCII Decimal_Number")
25+
}
26+
}
27+
28+
/// 'é' = 00E9;LATIN SMALL LETTER E WITH ACUTE;Ll;
29+
mod printémsg {
30+
pub fn print() {
31+
println!("Lowercase_Letter")
32+
}
33+
}

0 commit comments

Comments
 (0)