File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,21 @@ collect: func [
393
393
either into [output] [head output]
394
394
]
395
395
396
+ pad : func [
397
+ "Pad a FORMed value on right side with spaces"
398
+ str "Value to pad, FORM it if not a string"
399
+ n [integer! ] "Total size (in characters) of the new string (pad on left side if negative)"
400
+ /with "Pad with char"
401
+ c [char! ]
402
+ return: [string! ] "Modified input string at head"
403
+ ] [
404
+ unless string? str [str: form str]
405
+ head insert /dup
406
+ any [all [n < 0 n: negate n str] tail str]
407
+ any [c #" " ]
408
+ (n - length? str)
409
+ ]
410
+
396
411
format : function [
397
412
"Format a string according to the format dialect."
398
413
rules {A block in the format dialect. E.g. [10 -10 #"-" 4 $32 "green" $0]}
Original file line number Diff line number Diff line change @@ -498,10 +498,18 @@ Rebol [
498
498
--test-- "SORT/reverse"
499
499
;@@ https://github.com/Oldes/Rebol-issues/issues/128
500
500
--assert [9 3 2 1 ] = sort/reverse [9 1 2 3 ]
501
+ ===end-group===
501
502
502
503
503
-
504
-
504
+ ===start-group=== "PAD"
505
+ --test-- "pad"
506
+ --assert "ab " = pad "ab" 4
507
+ --assert " ab" = pad "ab" -4
508
+ --assert "12 " = pad 12 4
509
+ --assert " 12" = pad 12 -4
510
+ --test-- "pad/with"
511
+ --assert "1200" = pad/with 12 4 #"0"
512
+ --assert "0012" = pad/with 12 -4 #"0"
505
513
===end-group===
506
514
507
515
You can’t perform that action at this time.
0 commit comments