mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
wc: introduce IS_POSIXLY_CORRECT static (#11853)
This commit is contained in:
+8
-4
@@ -19,6 +19,7 @@ use std::{
|
||||
io::{self, Write, stderr},
|
||||
iter,
|
||||
path::{Path, PathBuf},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser};
|
||||
@@ -579,11 +580,11 @@ fn process_chunk<
|
||||
text: &str,
|
||||
current_len: &mut usize,
|
||||
in_word: &mut bool,
|
||||
posixly_correct: bool,
|
||||
is_posixly_correct: bool,
|
||||
) {
|
||||
for ch in text.chars() {
|
||||
if SHOW_WORDS {
|
||||
let is_space = if posixly_correct {
|
||||
let is_space = if is_posixly_correct {
|
||||
matches!(ch, '\t'..='\r' | ' ')
|
||||
} else {
|
||||
ch.is_whitespace()
|
||||
@@ -655,7 +656,7 @@ fn word_count_from_reader_specialized<
|
||||
let mut reader = BufReadDecoder::new(reader.buffered());
|
||||
let mut in_word = false;
|
||||
let mut current_len = 0;
|
||||
let posixly_correct = env::var_os("POSIXLY_CORRECT").is_some();
|
||||
let is_posixly_correct = *IS_POSIXLY_CORRECT;
|
||||
while let Some(chunk) = reader.next_strict() {
|
||||
match chunk {
|
||||
Ok(text) => {
|
||||
@@ -664,7 +665,7 @@ fn word_count_from_reader_specialized<
|
||||
text,
|
||||
&mut current_len,
|
||||
&mut in_word,
|
||||
posixly_correct,
|
||||
is_posixly_correct,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -1039,3 +1040,6 @@ fn print_stats(
|
||||
}
|
||||
writeln!(stdout)
|
||||
}
|
||||
|
||||
static IS_POSIXLY_CORRECT: LazyLock<bool> =
|
||||
LazyLock::new(|| env::var_os("POSIXLY_CORRECT").is_some());
|
||||
|
||||
Reference in New Issue
Block a user