; -------------------------------------------------------------------------------------------------
; $pad(string, width, align, [pad_chr])
; align is assumed left if unspecified, otherwise use left,right,center
;
; exaple:
; /echo -a $pad(Name, 16, center) $pad(Mail, 32, center) $pad(url, 50, center)
; /echo -a $pad(KingTomato, 16) $pad(kingtomato@kingtomato.com, 32) $pad(www.kingtomato.com, 50)
;
; you can also use another pad character, other than character 160 (default) by specifying
; it after the alignment. This char can be either the numerical value for the character,
; the character itself, or a string of characters (such as doing [bold][space][bold])
;
; example:
; /echo -a $pad(Table Of Contents, 25) Page
; /echo -a $pad(Introduction, 25, left, .) 1
; /echo -a $pad(Chapter 1, 25, left, .) 4
; /echo -a $pad(Chapter 2, 25, left, .) 15
; -------------------------------------------------------------------------------------------------
/pad {
var %padChr = $iif($4, $iif($4 isnum, $chr($4), $4), $chr(160))
if ($2 <= $len($1)) return $1
if ($3 == right) return $+($str(%padChr,$calc($2 - $len($1))), $1)
else if ($3 == center) {
var %left = $int($calc(($2 - $len($1)) / 2))
return $+($str(%padChr,%left), $1, $str(%padChr,$calc(($2 - $len($1)) - %left)))
}
return $+($1, $str(%padChr,$calc($2 - $len($1))))
}
; eof - KingTomato
; -------------------------------------------------------------------------------------------------