|
6 | 6 | // spell-checker:ignore sysconf CTYPE |
7 | 7 | use crate::{wc_simd_allowed, word_count::WordCount}; |
8 | 8 | use uucore::hardware::SimdPolicy; |
| 9 | +use uucore::i18n::charmap::is_effective_ctype_c_or_posix; |
9 | 10 |
|
10 | 11 | use super::WordCountable; |
11 | 12 |
|
12 | | -/// Check if the current locale is C or POSIX (where characters == bytes). |
13 | | -/// This follows GNU coreutils behavior where MB_CUR_MAX == 1 in these locales. |
14 | | -pub(crate) fn is_c_or_posix_locale() -> bool { |
15 | | - // Check LC_ALL, LC_CTYPE, and LANG in order of precedence |
16 | | - let locale_val = ["LC_ALL", "LC_CTYPE", "LANG"] |
17 | | - .iter() |
18 | | - .find_map(|&var| std::env::var(var).ok().filter(|v| !v.is_empty())); |
19 | | - |
20 | | - if let Some(locale) = locale_val { |
21 | | - // Extract the base locale name (before any '.' or '@') |
22 | | - let base_locale = locale.split(&['.', '@']).next().unwrap_or(&locale); |
23 | | - base_locale == "C" || base_locale == "POSIX" |
24 | | - } else { |
25 | | - // No locale set, default to POSIX behavior (chars == bytes) |
26 | | - true |
27 | | - } |
28 | | -} |
29 | | - |
30 | 13 | use std::io::{self, ErrorKind, Read}; |
31 | 14 |
|
32 | 15 | #[cfg(unix)] |
@@ -242,7 +225,7 @@ pub(crate) fn count_bytes_chars_and_lines_fast< |
242 | 225 |
|
243 | 226 | // In C/POSIX locale, characters are equivalent to bytes (MB_CUR_MAX == 1). |
244 | 227 | // This follows GNU coreutils behavior. |
245 | | - let chars_are_bytes = is_c_or_posix_locale(); |
| 228 | + let chars_are_bytes = is_effective_ctype_c_or_posix(); |
246 | 229 |
|
247 | 230 | loop { |
248 | 231 | match handle.read(buf) { |
|
0 commit comments