<?php
class Indenter {
var $count, $step_size;
// can be activated in php5... but for now unused
function Indenter() {
$this->count = 0;
}
// static workaround!
function indent($str="", $action=NULL) {
static $count=0;
// do action if --; this should affect all INCLUDING THIS ONE
if ($action=="--") $count--;
// were we passed a string? if so, indent it and echo it.
if ($str) {
$spaces = "";
for ($i=0; $i<$count; $i++)
$spaces .= " ";
return ($spaces . $str);
}
// do action if ++; this should affect all LATER
if ($action=="++") $count++;
}
// can be activated in php5... but for now unused
function setStepSize($step_size) {
$this->step_size = round($step_size);
}
// can be activated in php5... but for now unused
function increase($step_size = 1) {
$this->count += $step_size;
}
// can be activated in php5... but for now unused
function decrease($step_size = 1) {
$this->count -= $step_size;
}
// can be activated in php5... but for now unused
function indentTEMP($str, $flag=NEWLINE_PREFIX) {
$spaces = "";
for ($i=0; $i<$this->count; $i++)
$spaces .= " ";
switch ($flag) {
case NEWLINE_PREFIX:
$str = "\n".$str;
break;
case NEWLINE_POSTFIX:
$str = $str ."\n";
break;
}
return $spaces . $str;
}
}
?>