This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,24 @@
AlignColumns := proc( txt, align :: { "left", "right", "centre" } := "centre" )
uses StringTools;
# Get a list of lists of fields
local A := map( Split, Split( txt ), "$" );
# Calculate the column width
local width := 1 + max( map( L -> max( map( length, L ) ), A ) );
# Add spacing according to the requested type of alignment
if align = "left" then
local J := map( line -> map( PadRight, line, width ), A )
elif align = "right" then
J := map( line -> map( PadLeft, line, width ), A )
else
J := map( line -> map( Center, line, width ), A )
end if;
# Join up the fields in each line.
J := map( cat@op, J );
# Re-assemble the lines into a single string.
Join( J, "\n" )
end proc: