From 489370d1500383f3b2760a50637f11a817870004 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 3 Feb 2025 03:18:25 -0500 Subject: bsgrep: use utf-8 when in utf-8 locale. --- bsgrep | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bsgrep') diff --git a/bsgrep b/bsgrep index 26f247e..d4ef311 100755 --- a/bsgrep +++ b/bsgrep @@ -73,6 +73,15 @@ sub handle_line { } ### main() +# TODO: do we need 'use locale'? +# also, why does reading iso-8859-1 text auto-convert to utf-8? +for (qw/LANG LC_CTYPE LC_ALL/) { + if(($ENV{$_} // "") =~ /utf-?8/i) { + binmode(\*STDIN, ':utf8'); + binmode(\*STDOUT, ':utf8'); + last; + } +} if(defined($ARGV[0])) { if($ARGV[0] =~ /-help/) { -- cgit v1.2.3