Skip to content

Commit e7b4aa2

Browse files
committed
sort: use locale decimal separator for general numeric sort
1 parent 585f46a commit e7b4aa2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/uu/sort/src/sort.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use uucore::error::{FromIo, strip_errno};
4545
use uucore::error::{UError, UResult, USimpleError, UUsageError};
4646
use uucore::extendedbigdecimal::ExtendedBigDecimal;
4747
use uucore::format_usage;
48+
use uucore::i18n::decimal::locale_decimal_separator;
4849
use uucore::line_ending::LineEnding;
4950
use uucore::parser::num_parser::{ExtendedParser, ExtendedParserError};
5051
use uucore::parser::parse_size::{ParseSizeError, Parser};
@@ -111,8 +112,6 @@ mod options {
111112
pub const FILES: &str = "files";
112113
}
113114

114-
const DECIMAL_PT: u8 = b'.';
115-
116115
const NEGATIVE: &u8 = &b'-';
117116
const POSITIVE: &u8 = &b'+';
118117

@@ -2048,7 +2047,10 @@ fn get_leading_gen(inp: &[u8]) -> Range<usize> {
20482047
continue;
20492048
}
20502049

2051-
if c == DECIMAL_PT && !had_decimal_pt && !had_e_notation {
2050+
if locale_decimal_separator().as_bytes().first() == Some(&c)
2051+
&& !had_decimal_pt
2052+
&& !had_e_notation
2053+
{
20522054
had_decimal_pt = true;
20532055
continue;
20542056
}

src/uucore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ i18n-decimal = ["i18n-common", "icu_decimal", "icu_provider"]
150150
mode = ["libc"]
151151
perms = ["entries", "libc", "walkdir"]
152152
buf-copy = []
153-
parser-num = ["extendedbigdecimal", "num-traits"]
153+
parser-num = ["extendedbigdecimal", "num-traits", "i18n-decimal"]
154154
parser-size = ["parser-num", "procfs"]
155155
parser-glob = ["glob"]
156156
parser = ["parser-num", "parser-size", "parser-glob"]

src/uucore/src/lib/features/parser/num_parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use num_traits::ToPrimitive;
1818
use num_traits::Zero;
1919

2020
use crate::extendedbigdecimal::ExtendedBigDecimal;
21+
use crate::i18n::decimal::locale_decimal_separator;
2122

2223
/// Base for number parsing
2324
#[derive(Clone, Copy, PartialEq)]
@@ -291,9 +292,9 @@ fn parse_digits(base: Base, str: &str, fractional: bool) -> (Option<BigUint>, i6
291292
let (digits, rest) = base.parse_digits(str);
292293

293294
// If allowed, parse the fractional part of the number if there can be one and the
294-
// input contains a '.' decimal separator.
295+
// input contains the locale-specific decimal separator.
295296
if fractional {
296-
if let Some(rest) = rest.strip_prefix('.') {
297+
if let Some(rest) = rest.strip_prefix(locale_decimal_separator()) {
297298
return base.parse_digits_count(rest, digits);
298299
}
299300
}

0 commit comments

Comments
 (0)