; begin KiXgolfUDF ; ;! Function CIF($a, $y) Dim $,$s,$l,$e,$h,$z,$c $l=($a^)-1 Dim $w[$l] $c=@CRLF $y=Split($y,$c) ; ; LOOP 1 - pass through data and record longest entry in each column ; We also construct table top/botton/heading template as we go ; For Each $s in $y $h=@ For $=0 to $l $e=0^Split($s,"&")[$] If $w[$]<$e $w[$]=$e EndIf $h=Trim($h+" "+j($w[$],"<",@,"-")) Next Next ; ; LOOP 2 - Pass through data again, constructing table body ; For Each $s in $y $e=@ For $=0 to $l $e=$e+" | "+j($w[$],SubStr($a,$+1,1),Split($s,"&")[$]," ") ; Format data line Next $z=$z+"|"+SubStr($e,3)+" |"+$c +IIf($z=@,"|-"+Join(Split($h),"-+-")+"-|"+$c,@) ; IIf() the table is empty then this is the header line Next ; Add the header line to the top and bottom of the table $h="@-"+Join(Split($h),"---")+"-@" $CIF=$h+$c+$z+$h EndFunction ; Justification UDF ; $w=Width ; $t=Justification type ; $s=String to justify ; $c=Fill character ; Function j($w,$t,$s,$c) Dim $,$x If $t="=" $=$c EndIf ; Centre Justify, start on right while ($s^)<$w $s=Left($c,$t=">")+$j+$s+Left($c,$t="<")+$ $x=$ $=$j $j=$x ; Toggle centre justify RHS <-> LHS Loop $j=$s EndFunction ;! ;! ; end KiXgolfUDF ; vim:filetype=kix sw=4 ts=4
|