summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-10-18 23:11:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-10-18 23:11:58 -0700
commit17c7372925bfab9b057b36f3d93da8a2e087c5d6 (patch)
treec8dbf0168c95a90b729a02b5486fc7ecba074800
parent20e06e1bf2b84c986fe43d9c709e175ed57b2745 (diff)
downloadtxr-17c7372925bfab9b057b36f3d93da8a2e087c5d6.tar.gz
txr-17c7372925bfab9b057b36f3d93da8a2e087c5d6.tar.bz2
txr-17c7372925bfab9b057b36f3d93da8a2e087c5d6.zip
pic: preserve decimal period in ### overflow fill.
* pic.tl (expand-pic-num): If the overflowing field specifies a decimal point other than in the rightmost position, then stick one into the fill pattern. The motivation for this is that it harmonizes with the digit separators. The new digit separator insertion logic will treat the # characters like digits, and requires the embedded decimal in order to work properly. Allowing digit separation to work in the fill pattern will make for better looking output in column displays. That's the same reason why we insert digit separators among leading zeros. * tests/018/format.tl: Overflow test cases updated in light of this requirement change. * txr.1: Documented.
-rw-r--r--stdlib/pic.tl5
-rw-r--r--tests/018/format.tl8
-rw-r--r--txr.124
3 files changed, 29 insertions, 8 deletions
diff --git a/stdlib/pic.tl b/stdlib/pic.tl
index 96e78f2a..70ddbedf 100644
--- a/stdlib/pic.tl
+++ b/stdlib/pic.tl
@@ -44,7 +44,10 @@
(with-gensyms (str)
^(let ((,str ,code))
(if (> (len ,str) ,(len fmt))
- ,(mkstring (len fmt) #\#)
+ ,(let ((fill (mkstring (len fmt) #\#)))
+ (if (plusp (len fra))
+ (set [fill dot] #\.))
+ fill)
,str)))
code))))
diff --git a/tests/018/format.tl b/tests/018/format.tl
index 0496d51f..307d4d96 100644
--- a/tests/018/format.tl
+++ b/tests/018/format.tl
@@ -200,15 +200,15 @@
(pic "-0#####.##" 1234.1) " 001234.10")
(mtest
- (pic "#!#" 1234) "###"
- (pic "#!#" 123) "###"
+ (pic "#!#" 1234) "#.#"
+ (pic "#!#" 123) "#.#"
(pic "#.#" 123) "123.0")
(mtest
(pic "-##!#" 12) " 12.0"
(pic "+##!#" 12) "+12.0"
- (pic "-##!#" -123) "#####"
- (pic "+##!#" 123) "#####")
+ (pic "-##!#" -123) "###.#"
+ (pic "+##!#" 123) "###.#")
(mtest
(pic "###!" 123) "123"
diff --git a/txr.1 b/txr.1
index 36deb601..b46bc722 100644
--- a/txr.1
+++ b/txr.1
@@ -56653,11 +56653,24 @@ versus the
character. The
.code !
character specifies that if the conversion of the numeric argument overflows
-the field, then instead of showing any digits, the field is filled with
+the field, then instead of showing any digits, the field is filled with a
+pattern consisting of
.code #
-(hash) characters. The
+(hash) characters, and possibly an embedded decimal point. In contrast, the
.code .
-character permits overflow.
+character permits the field's width to increase to accommodate overflowing
+output. If overflow takes place and the
+.code !
+character appears other than as the rightmost character of the pattern,
+then the decimal point character
+.code .
+character appears at the position indicated by that
+.code !
+character. If the
+.code !
+character is the rightmost character of the pattern, then, just as
+in the case of normal, non-overflowing output, it doesn't contribute to the
+width of the hash fill, and only hash characters appear.
If commas appear in the numeric pattern according to the more complex syntactic
rule, they count toward the field width and specify the insertion of
@@ -56677,6 +56690,11 @@ may not be the first character of a pattern. However, if a numeric pattern is
preceded or followed by a comma, those commas are ordinary characters which are
copied to the output.
+When, due to the presence of
+.codn ! ,
+an overflowing field is handled by the generation of a the hash character fill,
+the hash characters are treated as digits for the purpose of digit separation.
+
Escape patterns consist of a two-character sequence introduced by the
.code ~
(tilde)