$columns v2
Posted by poiuy_qwert
Friday, June 01, 2007
Description: poiuy_qwert

; $columns v2 by poiuy_qwert
;  Align text into columns using $chr(160) or supplied chr to indent.
;
; Fixed v2:
;   - Escaped special regex characters (^$/.[]()|?*+)
;   - Fixed example
;
; Usage:
;  $columns(text,collen1[,collenN])[.chr]
;   text              - Text to put in columns, use tab ($chr(9)) to seperate columns
;   collen1[,collenN] - The length of each column. If a column doesn't have a len it will use the previous len.
;   [.chr]            - If you supply an ASCII code it will use that instead of $chr(160)
;
; Example:
;  $columns($+(test,$chr(9),with,$chr(9),cols),40,20,3)  == test                                   with                col
;  $columns($+(this,$chr(9),is fun!),7).46 == this...is fun!
;  $columns($+(long tex,$chr(9),will be cut off    short,$chr(9),wont.),6) == long twill bshort wont.
;
; Note:
;  There is no error checking, please use valid column lengths and be aware there are chances of /set line to long errors.
;  Also, the examples only show instances using $chr(9), but you can hardcode the tab in if you want.

alias columns {
  var %a 1,%l $2,%p $iif($prop isnum 1-255,$prop,160),%t,%x
  while ($gettok($1,%a,9) != $!) {
    %x = $v1
    if (%a > 1) && ([ $ $+ [ $calc(%a +1) ] ] isnum 1-) %l = $v1
    var %t = %t $+ $left(%x,%l) $+ $str($chr(%p),$calc(%l -$len(%x)))
    inc %a
  }
  return $regsubex(%t,$+(/,$iif($chr(%p) isin ^$/.[]()|?*+,),$v1,+?$/),)
}
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world