Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,65 +0,0 @@
|
|||
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Strings_Edit; use Strings_Edit;
|
||||
|
||||
procedure Column_Aligner is
|
||||
Text : constant String :=
|
||||
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$" & NUL &
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program" & NUL &
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$" & NUL &
|
||||
"column$are$separated$by$at$least$one$space." & NUL &
|
||||
"Further,$allow$for$each$word$in$a$column$to$be$either$left$" & NUL &
|
||||
"justified,$right$justified,$or$center$justified$within$its$column." & NUL;
|
||||
File : File_Type;
|
||||
Width : array (1..1_000) of Natural := (others => 0);
|
||||
Line : String (1..200);
|
||||
Column : Positive := 1;
|
||||
Start : Positive := 1;
|
||||
Pointer : Positive;
|
||||
begin
|
||||
Create (File, Out_File, "columned.txt");
|
||||
-- Determining the widths of columns
|
||||
for I in Text'Range loop
|
||||
case Text (I) is
|
||||
when '$' | NUL =>
|
||||
Width (Column) := Natural'Max (Width (Column), I - Start + 1);
|
||||
Start := I + 1;
|
||||
if Text (I) = NUL then
|
||||
Column := 1;
|
||||
else
|
||||
Column := Column + 1;
|
||||
end if;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end loop;
|
||||
-- Formatting
|
||||
for Align in Alignment loop
|
||||
Column := 1;
|
||||
Start := 1;
|
||||
Pointer := 1;
|
||||
for I in Text'Range loop
|
||||
case Text (I) is
|
||||
when '$' | NUL =>
|
||||
Put -- Formatted output of a word
|
||||
( Destination => Line,
|
||||
Pointer => Pointer,
|
||||
Value => Text (Start..I - 1),
|
||||
Field => Width (Column),
|
||||
Justify => Align
|
||||
);
|
||||
Start := I + 1;
|
||||
if Text (I) = NUL then
|
||||
Put_Line (File, Line (1..Pointer - 1));
|
||||
Pointer := 1;
|
||||
Column := 1;
|
||||
else
|
||||
Column := Column + 1;
|
||||
end if;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end loop;
|
||||
end loop;
|
||||
Close (File);
|
||||
end Column_Aligner;
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
; == If the given text is in an file, it will read with:
|
||||
#include <File.au3>
|
||||
Global $aRead
|
||||
_FileReadToArray($sPath, $aRead) ; == $aRead[0] includes count of lines, every line stored in one item (without linebreak)
|
||||
|
||||
; == For example we get the same result with StringSplit()
|
||||
Global $sText = _
|
||||
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$" & @CRLF & _
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program" & @CRLF & _
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$" & @CRLF & _
|
||||
"column$are$separated$by$at$least$one$space." & @CRLF & _
|
||||
"Further,$allow$for$each$word$in$a$column$to$be$either$left$" & @CRLF & _
|
||||
"justified,$right$justified,$or$center$justified$within$its$column." & @CRLF
|
||||
|
||||
$aRead = StringSplit($sText, @CRLF, 1)
|
||||
|
||||
; == strip leading and trailing "$" and trailing spaces, count remaining "$" to get max column number
|
||||
Global $iMaxColumn = 0, $iLines = 0
|
||||
For $i = 1 To $aRead[0]
|
||||
If $aRead[$i] = '' Then ContinueLoop ; skip empty lines
|
||||
$iLines += 1
|
||||
$aRead[$i] = StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($aRead[$i], '^\$', ''), '\$$', ''), '\s*$', '')
|
||||
StringReplace($aRead[$i], '$', '$')
|
||||
If @extended +1 > $iMaxColumn Then $iMaxColumn = @extended +1
|
||||
Next
|
||||
|
||||
; == build array to store all fields and length of every item
|
||||
Global $aFields[$iLines][$iMaxColumn +1][2]
|
||||
; == and store the max. length of item in columns
|
||||
Global $aColLen[$iMaxColumn]
|
||||
|
||||
; == fill the array
|
||||
Global $aSplitLine
|
||||
$iLines = 0
|
||||
For $i = 1 To $aRead[0]
|
||||
If $aRead[$i] = '' Then ContinueLoop ; skip empty lines
|
||||
$iMaxColLen = 0
|
||||
$aSplitLine = StringSplit($aRead[$i], '$')
|
||||
For $j = 1 To $aSplitLine[0]
|
||||
$aFields[$iLines][$j-1][0] = $aSplitLine[$j]
|
||||
$aFields[$iLines][$j-1][1] = StringLen($aSplitLine[$j])
|
||||
If $aFields[$iLines][$j-1][1] > $aColLen[$j-1] Then $aColLen[$j-1] = $aFields[$iLines][$j-1][1]
|
||||
Next
|
||||
$iLines += 1
|
||||
Next
|
||||
|
||||
; == let the user select the alignment for every column
|
||||
$sAlign = InputBox('Column alignment', 'There are ' & $iMaxColumn & ' columns.' & @LF & '0 = left 1 = center 2 = right' & @LF & _
|
||||
'Input alignment for all columns without delimiters.' & @LF & 'Let it empty, to align all left.')
|
||||
If $sAlign = '' Then
|
||||
For $i = 1 To $iMaxColumn
|
||||
$sAlign &= '0'
|
||||
Next
|
||||
EndIf
|
||||
Global $aAlignment = StringSplit($sAlign, '', 2)
|
||||
|
||||
; == output all to console
|
||||
Global $sLineOut
|
||||
For $i = 0 To UBound($aFields) -1
|
||||
$sLineOut = ''
|
||||
For $j = 0 To $iMaxColumn -1
|
||||
If $aFields[$i][$j][0] = '' Then ContinueLoop
|
||||
$sLineOut &= _GetAligned($aFields[$i][$j][0], $aFields[$i][$j][1], $aAlignment[$j], $aColLen[$j])
|
||||
Next
|
||||
ConsoleWrite(StringTrimRight($sLineOut, 1) & @LF)
|
||||
Next
|
||||
|
||||
Func _GetAligned($_sString, $_iLen, $_iAlign, $_iMaxLen)
|
||||
Local $sSpace = ''
|
||||
For $i = 1 To $_iMaxLen
|
||||
$sSpace &= ' '
|
||||
Next
|
||||
Switch $_iAlign
|
||||
Case 0
|
||||
Return $_sString & StringLeft($sSpace, $_iMaxLen - $_iLen +1)
|
||||
Case 1
|
||||
Local $iLenLeft = Int(($_iMaxLen - $_iLen)/2)
|
||||
Local $iLenRight = $_iMaxLen - $iLenLeft - $_iLen
|
||||
Return StringLeft($sSpace, $iLenLeft) & $_sString & StringLeft($sSpace, $iLenRight) & ' '
|
||||
Case 2
|
||||
Return StringLeft($sSpace, $_iMaxLen - $_iLen) & $_sString & ' '
|
||||
EndSwitch
|
||||
EndFunc ;==>_GetAligned
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
identification division.
|
||||
program-id. AlignColumns.
|
||||
|
||||
data division.
|
||||
working-storage section.
|
||||
*>-> Constants
|
||||
78 MAX-LINES value 6.
|
||||
78 MAX-LINE-SIZE value 66.
|
||||
78 MAX-COLUMNS value 12.
|
||||
78 MAX-COLUMN-SIZE value 16.
|
||||
*>-> Indexes
|
||||
01 w-idx pic is 9(2).
|
||||
01 w-idy pic is 9(2).
|
||||
01 w-pos pic is 9(3).
|
||||
*>-> Data structures
|
||||
01 w-lines.
|
||||
05 w-line pic is x(MAX-LINE-SIZE) occurs MAX-LINES.
|
||||
01 w-column-sizes.
|
||||
05 w-column-size pic is 99 occurs MAX-COLUMNS value zeros.
|
||||
01 w-matrix.
|
||||
05 filler occurs MAX-LINES.
|
||||
10 filler occurs MAX-COLUMNS.
|
||||
15 w-content pic is x(MAX-COLUMN-SIZE).
|
||||
*>-> Output
|
||||
01 w-line-out pic is x(120).
|
||||
*>-> Data alignment
|
||||
01 w-alignment pic is x(1).
|
||||
88 alignment-left value is "L".
|
||||
88 alignment-center value is "C".
|
||||
88 alignment-right value is "R".
|
||||
|
||||
procedure division.
|
||||
main.
|
||||
move "Given$a$text$file$of$many$lines,$where$fields$within$a$line$" to w-line(1)
|
||||
move "are$delineated$by$a$single$'dollar'$character,$write$a$program" to w-line(2)
|
||||
move "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$" to w-line(3)
|
||||
move "column$are$separated$by$at$least$one$space." to w-line(4)
|
||||
move "Further,$allow$for$each$word$in$a$column$to$be$either$left$" to w-line(5)
|
||||
move "justified,$right$justified,$or$center$justified$within$its$column." to w-line(6)
|
||||
perform calculate-size-columns
|
||||
set alignment-left to true
|
||||
perform show-content
|
||||
set alignment-center to true
|
||||
perform show-content
|
||||
set alignment-right to true
|
||||
perform show-content
|
||||
goback
|
||||
.
|
||||
calculate-size-columns.
|
||||
perform
|
||||
varying w-idx from 1 by 1
|
||||
until w-idx > MAX-LINES
|
||||
unstring w-line(w-idx) delimited by "$" into w-content(w-idx, 1), w-content(w-idx, 2),
|
||||
w-content(w-idx, 3), w-content(w-idx, 4), w-content(w-idx, 5), w-content(w-idx, 6),
|
||||
w-content(w-idx, 7), w-content(w-idx, 8), w-content(w-idx, 9), w-content(w-idx, 10),
|
||||
w-content(w-idx, 11), w-content(w-idx, 12),
|
||||
perform
|
||||
varying w-idy from 1 by 1
|
||||
until w-idy > MAX-COLUMNS
|
||||
if function stored-char-length(w-content(w-idx, w-idy)) > w-column-size(w-idy)
|
||||
move function stored-char-length(w-content(w-idx, w-idy)) to w-column-size(w-idy)
|
||||
end-if
|
||||
end-perform
|
||||
end-perform
|
||||
.
|
||||
show-content.
|
||||
move all "-" to w-line-out
|
||||
display w-line-out
|
||||
perform
|
||||
varying w-idx from 1 by 1
|
||||
until w-idx > MAX-LINES
|
||||
move spaces to w-line-out
|
||||
move 1 to w-pos
|
||||
perform
|
||||
varying w-idy from 1 by 1
|
||||
until w-idy > MAX-COLUMNS
|
||||
call "C$JUSTIFY" using w-content(w-idx, w-idy)(1:w-column-size(w-idy)), w-alignment
|
||||
move w-content(w-idx, w-idy) to w-line-out(w-pos:w-column-size(w-idy))
|
||||
compute w-pos = w-pos + w-column-size(w-idy) + 1
|
||||
end-perform
|
||||
display w-line-out
|
||||
end-perform
|
||||
.
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
------------------------------------------------------------------------------------------------------------------------
|
||||
Given a text file of many lines, where fields within a line
|
||||
are delineated by a single 'dollar' character, write a program
|
||||
that aligns each column of fields by ensuring that words in each
|
||||
column are separated by at least one space.
|
||||
Further, allow for each word in a column to be either left
|
||||
justified, right justified, or center justified within its column.
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
Given a text file of many lines, where fields within a line
|
||||
are delineated by a single 'dollar' character, write a program
|
||||
that aligns each column of fields by ensuring that words in each
|
||||
column are separated by at least one space.
|
||||
Further, allow for each word in a column to be either left
|
||||
justified, right justified, or center justified within its column.
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
Given a text file of many lines, where fields within a line
|
||||
are delineated by a single 'dollar' character, write a program
|
||||
that aligns each column of fields by ensuring that words in each
|
||||
column are separated by at least one space.
|
||||
Further, allow for each word in a column to be either left
|
||||
justified, right justified, or center justified within its column.
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
(defun prepare-data ()
|
||||
"Process data into list of lists."
|
||||
(let ((all-lines)
|
||||
(processed-line))
|
||||
(dolist (one-line (split-string "Given$a$text$file$of$many$lines,$where$fields$within$a$line$
|
||||
are$delineated$by$a$single$'dollar'$character,$write$a$program
|
||||
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
|
||||
column$are$separated$by$at$least$one$space.
|
||||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified,$or$center$justified$within$its$column." "[\n\r]" :OMIT-NULLS))
|
||||
(dolist (one-word (split-string one-line "\\$"))
|
||||
(push one-word processed-line))
|
||||
(push (nreverse processed-line) all-lines)
|
||||
(setq processed-line nil))
|
||||
(nreverse all-lines)))
|
||||
|
||||
(defun get-column (column-number data)
|
||||
"Get words from COLUMN-NUMBER column in DATA."
|
||||
(let ((column-result))
|
||||
(setq column-number (- column-number 1))
|
||||
(dolist (line data)
|
||||
(if (nth column-number line)
|
||||
(push (nth column-number line) column-result)
|
||||
(push "" column-result)))
|
||||
column-result))
|
||||
|
||||
(defun calc-column-width (column-number data)
|
||||
"Calculate padded width for COLUMN-NUMBER in DATA."
|
||||
(let ((column-words (get-column column-number data)))
|
||||
(+ 2 (apply #'max (mapcar #'length column-words)))))
|
||||
|
||||
(defun get-last-column (data)
|
||||
"Find the last column in DATA."
|
||||
(apply #'max (mapcar #'length data)))
|
||||
|
||||
(defun get-column-widths (data)
|
||||
"Get a list of column widths from DATA."
|
||||
(let ((current-column 1)
|
||||
(last-column (get-last-column data))
|
||||
(column-widths))
|
||||
(while (<= current-column last-column)
|
||||
(push (calc-column-width current-column data) column-widths)
|
||||
(setq current-column (1+ current-column)))
|
||||
(nreverse column-widths)))
|
||||
|
||||
(defun get-one-column-width (column-number data)
|
||||
"Get column width of COLUMN-NUMBER from DATA."
|
||||
(let ((column-widths (get-column-widths data)))
|
||||
(nth (- column-number 1) column-widths)))
|
||||
|
||||
(defun center-align-one-word (word column-width)
|
||||
"Center align WORD in space of COLUMN-WIDTH."
|
||||
(let* ((word-width (length word))
|
||||
(total-padding (- column-width word-width))
|
||||
(pre-padding-length (/ total-padding 2))
|
||||
(post-padding-length (- column-width (+ pre-padding-length word-width)))
|
||||
(pre-padding (make-string pre-padding-length ? ))
|
||||
(post-padding (make-string post-padding-length ? )))
|
||||
(insert (format "%s%s%s" pre-padding word post-padding))))
|
||||
|
||||
(defun center-align-one-line (one-line column-widths)
|
||||
"Center align ONE-LINE using COLUMN-WIDTHS."
|
||||
(let ((word-position 0))
|
||||
(dolist (word one-line)
|
||||
(center-align-one-word word (nth word-position column-widths))
|
||||
(setq word-position (1+ word-position)))))
|
||||
|
||||
(defun center-align-lines (data)
|
||||
"Center align columns of words in DATA."
|
||||
(let ((column-widths (get-column-widths data)))
|
||||
(dolist (one-line data)
|
||||
(center-align-one-line one-line column-widths)
|
||||
(insert (format "%s" "\n")))))
|
||||
|
||||
(defun left-align-one-word (word column-width)
|
||||
"Left align WORD in space of COLUMN-WIDTH."
|
||||
(let* ((word-width (length word))
|
||||
(total-padding (- column-width word-width))
|
||||
(pre-padding-length 1)
|
||||
(post-padding-length (- column-width (+ pre-padding-length word-width)))
|
||||
(pre-padding (make-string pre-padding-length ? ))
|
||||
(post-padding (make-string post-padding-length ? )))
|
||||
(insert (format "%s%s%s" pre-padding word post-padding))))
|
||||
|
||||
(defun left-align-one-line (one-line column-widths)
|
||||
"Left align ONE-LINE using COLUMN-WIDTHS."
|
||||
(let ((word-position 0))
|
||||
(dolist (word one-line)
|
||||
(left-align-one-word word (nth word-position column-widths))
|
||||
(setq word-position (1+ word-position)))))
|
||||
|
||||
(defun left-align-lines (data)
|
||||
"Left align columns of words in DATA."
|
||||
(let ((column-widths (get-column-widths data)))
|
||||
(dolist (one-line data)
|
||||
(left-align-one-line one-line column-widths)
|
||||
(insert (format "%s" "\n")))))
|
||||
|
||||
(defun right-align-one-word (word column-width)
|
||||
"Right align WORD in space of COLUMN-WIDTH."
|
||||
(let* ((word-width (length word))
|
||||
(total-padding (- column-width word-width))
|
||||
(post-padding-length 1)
|
||||
(pre-padding-length (- column-width (+ post-padding-length word-width)))
|
||||
(pre-padding (make-string pre-padding-length ? ))
|
||||
(post-padding (make-string post-padding-length ? )))
|
||||
(insert (format "%s%s%s" pre-padding word post-padding))))
|
||||
|
||||
(defun right-align-one-line (one-line column-widths)
|
||||
"Right align ONE-LINE using COLUMN-WIDTHS."
|
||||
(let ((word-position 0))
|
||||
(dolist (word one-line)
|
||||
(right-align-one-word word (nth word-position column-widths))
|
||||
(setq word-position (1+ word-position)))))
|
||||
|
||||
(defun right-align-lines (data)
|
||||
"Right align columns of words in DATA."
|
||||
(let ((column-widths (get-column-widths data)))
|
||||
(dolist (one-line data)
|
||||
(right-align-one-line one-line column-widths)
|
||||
(insert (format "%s" "\n")))))
|
||||
|
||||
(defun align-lines (alignment data)
|
||||
"Write DATA with given ALIGNMENT.
|
||||
DATA consists of a list of lists. Each internal list conists of a list
|
||||
of words."
|
||||
(let ((align-function (pcase alignment
|
||||
('left 'left-align-lines)
|
||||
("left" 'left-align-lines)
|
||||
('center 'center-align-lines)
|
||||
("center" 'center-align-lines)
|
||||
('right 'right-align-lines)
|
||||
("right" 'right-align-lines))))
|
||||
(funcall align-function data)))
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
constant data = {
|
||||
"Given$a$text$file$of$many$lines,$where$fields$within$a$line$",
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program",
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$",
|
||||
"column$are$separated$by$at$least$one$space.",
|
||||
"Further,$allow$for$each$word$in$a$column$to$be$either$left$",
|
||||
"justified,$right$justified,$or$center$justified$within$its$column."
|
||||
}
|
||||
|
||||
function split(sequence s, integer c)
|
||||
sequence out
|
||||
integer first, delim
|
||||
out = {}
|
||||
first = 1
|
||||
while first<=length(s) do
|
||||
delim = find_from(c,s,first)
|
||||
if delim = 0 then
|
||||
delim = length(s)+1
|
||||
end if
|
||||
out = append(out,s[first..delim-1])
|
||||
first = delim + 1
|
||||
end while
|
||||
return out
|
||||
end function
|
||||
|
||||
function align(sequence s, integer width, integer alignment)
|
||||
integer n
|
||||
n = width - length(s)
|
||||
if n <= 0 then
|
||||
return s
|
||||
elsif alignment < 0 then
|
||||
return s & repeat(' ', n)
|
||||
elsif alignment > 0 then
|
||||
return repeat(' ', n) & s
|
||||
else
|
||||
return repeat(' ', floor(n/2)) & s & repeat(' ', floor(n/2+0.5))
|
||||
end if
|
||||
end function
|
||||
|
||||
integer maxlen
|
||||
sequence lines
|
||||
maxlen = 0
|
||||
lines = repeat(0,length(data))
|
||||
for i = 1 to length(data) do
|
||||
lines[i] = split(data[i],'$')
|
||||
for j = 1 to length(lines[i]) do
|
||||
if length(lines[i][j]) > maxlen then
|
||||
maxlen = length(lines[i][j])
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
|
||||
for a = -1 to 1 do
|
||||
for i = 1 to length(lines) do
|
||||
for j = 1 to length(lines[i]) do
|
||||
puts(1, align(lines[i][j],maxlen,a) & ' ')
|
||||
end for
|
||||
puts(1,'\n')
|
||||
end for
|
||||
puts(1,'\n')
|
||||
end for
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
$file =
|
||||
@'
|
||||
Given$a$text$file$of$many$lines,$where$fields$within$a$line$
|
||||
are$delineated$by$a$single$'dollar'$character,$write$a$program
|
||||
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
|
||||
column$are$separated$by$at$least$one$space.
|
||||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified,$or$center$justified$within$its$column.
|
||||
'@.Split("`n")
|
||||
|
||||
$arr = @()
|
||||
$file | foreach {
|
||||
$line = $_
|
||||
$i = 0
|
||||
$hash = [ordered]@{}
|
||||
$line.split('$') | foreach{
|
||||
$hash["$i"] = "$_"
|
||||
$i++
|
||||
}
|
||||
$arr += @([pscustomobject]$hash)
|
||||
}
|
||||
$arr | Format-Table -HideTableHeaders -Wrap *
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
REBOL [
|
||||
Title: "Align Columns"
|
||||
URL: http://rosettacode.org/wiki/Align_columns
|
||||
]
|
||||
|
||||
specimen: {Given$a$text$file$of$many$lines,$where$fields$within$a$line$
|
||||
are$delineated$by$a$single$'dollar'$character,$write$a$program
|
||||
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
|
||||
column$are$separated$by$at$least$one$space.
|
||||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified,$or$center$justified$within$its$column.}
|
||||
|
||||
; Parse specimen into data grid.
|
||||
|
||||
data: copy []
|
||||
foreach line parse specimen to-string lf [ ; Break into lines.
|
||||
append/only data parse line "$" ; Break into columns.
|
||||
]
|
||||
|
||||
; Compute independent widths for each column.
|
||||
|
||||
widths: copy [] insert/dup widths 0 length? data/1
|
||||
foreach line data [
|
||||
forall line [
|
||||
i: index? line
|
||||
widths/:i: max widths/:i length? line/1
|
||||
]
|
||||
]
|
||||
|
||||
pad: func [n /local x][x: copy "" insert/dup x " " n x]
|
||||
|
||||
; These formatting functions are passed as arguments to entable.
|
||||
|
||||
right: func [n s][rejoin [pad n - length? s s]]
|
||||
|
||||
left: func [n s][rejoin [s pad n - length? s]]
|
||||
|
||||
centre: func [n s /local h][
|
||||
h: round/down (n - length? s) / 2
|
||||
rejoin [pad h s pad n - h - length? s]
|
||||
]
|
||||
|
||||
; Display data as table.
|
||||
|
||||
entable: func [data format] [
|
||||
foreach line data [
|
||||
forall line [
|
||||
prin rejoin [format pick widths index? line line/1 " "]
|
||||
]
|
||||
print ""
|
||||
]
|
||||
]
|
||||
|
||||
; Format data table.
|
||||
|
||||
foreach i [left centre right] [
|
||||
print ["^/Align" i "...^/"] entable data get i]
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
' Align columns - RC - VBScript
|
||||
Const nr=16, nc=16
|
||||
ReDim d(nc),t(nr), wor(nr,nc)
|
||||
i=i+1: t(i) = "Given$a$text$file$of$many$lines,$where$fields$within$a$line$"
|
||||
i=i+1: t(i) = "are$delineated$by$a$single$'dollar'$character,$write$a$program"
|
||||
i=i+1: t(i) = "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$"
|
||||
i=i+1: t(i) = "column$are$separated$by$at$least$one$space."
|
||||
i=i+1: t(i) = "Further,$allow$for$each$word$in$a$column$To$be$either$left$"
|
||||
i=i+1: t(i) = "justified,$right$justified,$or$center$justified$within$its$column."
|
||||
For r=1 to nr
|
||||
If t(r)="" Then Exit For
|
||||
w=xRTrim(t(r),"$")
|
||||
m=Split(w,"$")
|
||||
For c=1 To UBound(m)+1
|
||||
wor(r,c)=m(c-1)
|
||||
If Len(wor(r,c))>d(c) Then d(c)=Len(wor(r,c))
|
||||
Next 'c
|
||||
If c>cols Then cols=c
|
||||
Next 'r
|
||||
rows=r-1
|
||||
tt=Array("Left","Right","Center")
|
||||
For n=1 To 3
|
||||
Wscript.Echo
|
||||
Wscript.Echo "*****" & tt(n-1) & "*****"
|
||||
For r=1 To rows
|
||||
w=""
|
||||
For c=1 To cols
|
||||
x=wor(r,c): s=Space(d(c))
|
||||
Select Case n
|
||||
Case 1: w=w &" "& Left (x & s,d(c))
|
||||
Case 2: w=w &" "& Right (s & x,d(c))
|
||||
Case 3: w=w &" "& xCentre(x,d(c)," ")
|
||||
End Select 'n
|
||||
Next 'c
|
||||
Wscript.Echo Mid(w,2)
|
||||
Next 'r
|
||||
Next 'n
|
||||
|
||||
Function xCentre(c, n, Pad)
|
||||
Dim j
|
||||
If n > Len(c) Then
|
||||
j = (n - Len(c)) \ 2
|
||||
If (n - Len(c)) Mod 2 <> 0 Then j = j + 1
|
||||
xCentre = Mid(String(j, Pad) & c & String(j, Pad), 1, n)
|
||||
Else
|
||||
xCentre = c
|
||||
End If
|
||||
End Function 'xCentre
|
||||
|
||||
Function xRTrim(c, Pad)
|
||||
Dim i2, l, cc
|
||||
cc = "": l = Len(c)
|
||||
If l > 0 Then
|
||||
i2 = l
|
||||
Do While (Mid(c, i2, 1) = Pad And i2 > 1)
|
||||
i2 = i2 - 1
|
||||
Loop
|
||||
If i2 = 1 And Mid(c, i2, 1) = Pad Then i2 = 0
|
||||
If i2 > 0 Then cc = Mid(c, 1, i2)
|
||||
End If
|
||||
xRTrim = cc
|
||||
End Function 'xRTrim
|
||||
Loading…
Add table
Add a link
Reference in a new issue