diff options
-rw-r--r-- | stdlib/pic.tl | 5 | ||||
-rw-r--r-- | tests/018/format.tl | 8 | ||||
-rw-r--r-- | txr.1 | 24 |
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" @@ -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) |