Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{
io::{self, Write, stderr},
iter,
path::{Path, PathBuf},
sync::LazyLock,
};

use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser};
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) => {
Expand All @@ -664,7 +665,7 @@ fn word_count_from_reader_specialized<
text,
&mut current_len,
&mut in_word,
posixly_correct,
is_posixly_correct,
);
}
Err(e) => {
Expand Down Expand Up @@ -1039,3 +1040,6 @@ fn print_stats(
}
writeln!(stdout)
}

static IS_POSIXLY_CORRECT: LazyLock<bool> =
LazyLock::new(|| env::var_os("POSIXLY_CORRECT").is_some());
Loading