ljr/wcmtools/s2/S2/Indenter.pm

44 lines
718 B
Perl
Raw Normal View History

2019-02-05 21:49:12 +00:00
#!/usr/bin/perl
#
package S2::Indenter;
use strict;
sub new {
my ($class, $o, $tabsize) = @_;
my $this = {
'o' => $o,
'tabsize' => $tabsize,
'depth' => 0,
};
bless $this, $class;
}
sub write {
my ($this, $s) = @_;
$this->{'o'}->write($s);
}
sub writeln {
my ($this, $s) = @_;
$this->{'o'}->writeln($s);
}
sub tabwrite {
my ($this, $s) = @_;
$this->{'o'}->write(" "x($this->{'tabsize'}*$this->{'depth'}) . $s);
}
sub tabwriteln {
my ($this, $s) = @_;
$this->{'o'}->writeln(" "x($this->{'tabsize'}*$this->{'depth'}) . $s);
}
sub newline { shift->{'o'}->newline(); }
sub tabIn { shift->{'depth'}++; }
sub tabOut { shift->{'depth'}--; }
1;