7 @EXPORT = qw(expand unexpand $tabstop);
9 use vars qw($VERSION $tabstop $debug);
24 for (split(/^/m, $_, -1)) {
27 $pad = $tabstop - (pos() + $offs) % $tabstop;
35 return @l if wantarray;
48 @lines = split("\n", $x, -1);
50 $line = expand($line);
51 @e = split(/(.{$tabstop})/,$line,-1);
53 $lastbit = '' unless defined $lastbit;
55 if $lastbit eq " "x$tabstop;
60 print "sub on '$x'\n";
64 $line = join('',@e, $lastbit);
66 $x = join("\n", @lines);
68 return @l if wantarray;
79 1 while s/(^|\n)([^\t\n]*)(\t+)/
81 ($tabstop * length($3)
82 - (length($2) % $tabstop)))
85 return @l if wantarray;
92 Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1)
99 @lines_without_tabs = expand(@lines_with_tabs);
100 @lines_with_tabs = unexpand(@lines_without_tabs);
104 Text::Tabs does about what the unix utilities expand(1) and unexpand(1)
105 do. Given a line with tabs in it, expand will replace the tabs with
106 the appropriate number of spaces. Given a line with or without tabs in
107 it, unexpand will add tabs when it can save bytes by doing so. Invisible
108 compression with plain ascii!
112 expand doesn't handle newlines very quickly -- do not feed it an
113 entire document in one string. Instead feed it an array of lines.
117 Copyright (C) 1996-2002,2005 David Muir Sharnoff.
118 Copyright (C) 2005 Aristotle Pagaltzis
119 This module may be modified, used, copied, and redistributed at your own risk.
120 Publicly redistributed modified versions must use a different name.