add unicode-aware expand command
[hband-tools.git] / half-baked / expand
blobf190370dd77e8b7f05660b19879c8ffe5e247ec4
1 #!/usr/bin/env perl
3 # unicode-aware expand(1) replacement
5 use Encode;
6 binmode STDOUT, ":utf8";
8 $tabstop = 4;
9 $tabstopMinusOne = $tabstop - 1;
11 while(<STDIN>)
13 Encode::_utf8_on($_);
14 s/((?<A>[^\t]{0,$tabstopMinusOne})\t|(?<A>[^\t]{$tabstop}))/sprintf "%s%s", $+{A}, " " x ($tabstop - length $+{A})/ge;
15 print;