mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-17 15:34:18 +08:00
Fix uutils UTF-8 locale handling on Redox
This commit is contained in:
parent
8a28ce8da2
commit
30fd08a340
@ -48,6 +48,66 @@ index fd1f30303..c508f6b9b 100644
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||||
|
diff --git a/src/uucore/src/lib/features/i18n/mod.rs b/src/uucore/src/lib/features/i18n/mod.rs
|
||||||
|
index 282baf2e7..a38ccb30e 100644
|
||||||
|
--- a/src/uucore/src/lib/features/i18n/mod.rs
|
||||||
|
+++ b/src/uucore/src/lib/features/i18n/mod.rs
|
||||||
|
@@ -45,8 +45,21 @@ pub fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
|
||||||
|
|
||||||
|
if let Some(simple) = split.next() {
|
||||||
|
// Handle explicit C and POSIX locales - these should always use byte comparison
|
||||||
|
+ let encoding = split.next();
|
||||||
|
+ let is_utf8 = encoding.is_some_and(|enc| {
|
||||||
|
+ let lower = enc.to_lowercase();
|
||||||
|
+ lower == "utf-8" || lower == "utf8"
|
||||||
|
+ });
|
||||||
|
+
|
||||||
|
if simple == "C" || simple == "POSIX" {
|
||||||
|
- return (DEFAULT_LOCALE, UEncoding::Ascii);
|
||||||
|
+ return (
|
||||||
|
+ DEFAULT_LOCALE,
|
||||||
|
+ if is_utf8 {
|
||||||
|
+ UEncoding::Utf8
|
||||||
|
+ } else {
|
||||||
|
+ UEncoding::Ascii
|
||||||
|
+ },
|
||||||
|
+ );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Naively convert the locale name to BCP47 tag format.
|
||||||
|
@@ -55,14 +68,9 @@ pub fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
|
||||||
|
let bcp47 = simple.replace('_', "-");
|
||||||
|
let locale = Locale::try_from_str(&bcp47).unwrap_or(DEFAULT_LOCALE);
|
||||||
|
|
||||||
|
- // If locale parsing failed, parse the encoding part of the
|
||||||
|
- // locale. Treat the special case of the given locale being "C"
|
||||||
|
- // which becomes the default locale.
|
||||||
|
- let encoding = if (locale != DEFAULT_LOCALE || bcp47 == "C")
|
||||||
|
- && split.next().is_some_and(|enc| {
|
||||||
|
- let lower = enc.to_lowercase();
|
||||||
|
- lower == "utf-8" || lower == "utf8"
|
||||||
|
- }) {
|
||||||
|
+ // If the locale name was parsed successfully, use the encoding suffix
|
||||||
|
+ // to decide whether filenames should be treated as UTF-8.
|
||||||
|
+ let encoding = if (locale != DEFAULT_LOCALE || bcp47 == "C") && is_utf8 {
|
||||||
|
UEncoding::Utf8
|
||||||
|
} else {
|
||||||
|
UEncoding::Ascii
|
||||||
|
@@ -70,8 +78,12 @@ pub fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
|
||||||
|
return (locale, encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- // Default POSIX locale representing LC_ALL=C
|
||||||
|
- (DEFAULT_LOCALE, UEncoding::Ascii)
|
||||||
|
+
|
||||||
|
+ #[cfg(target_os = "redox")]
|
||||||
|
+ return (DEFAULT_LOCALE, UEncoding::Utf8);
|
||||||
|
+
|
||||||
|
+ #[cfg(not(target_os = "redox"))]
|
||||||
|
+ return (DEFAULT_LOCALE, UEncoding::Ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the collating locale from the environment
|
||||||
diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs
|
diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs
|
||||||
index b670f8976..a4ff9f983 100644
|
index b670f8976..a4ff9f983 100644
|
||||||
--- a/src/uucore/src/lib/mods/locale.rs
|
--- a/src/uucore/src/lib/mods/locale.rs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user