wc: introduce IS_POSIXLY_CORRECT static (#11853)

This commit is contained in:
xtqqczze
2026-04-20 21:40:15 +01:00
committed by GitHub
parent dc18b54fb7
commit ab786f50ef
+8 -4
View File
@@ -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());