A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
24
Task/Align-columns/Maple/align-columns-2.maple
Normal file
24
Task/Align-columns/Maple/align-columns-2.maple
Normal 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:
|
||||
Loading…
Add table
Add a link
Reference in a new issue