diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-06-10 07:43:39 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-06-10 07:43:39 -0700 |
commit | 6b66641f1b03b959f15c1c63f6dc055264809410 (patch) | |
tree | 3c6bf51c69b3a43075a7cb1e63d148fd3c1c4d91 | |
parent | 5761d2e6c82f5234d4e63a49bc0a59ab69bbf0ed (diff) | |
download | txr-6b66641f1b03b959f15c1c63f6dc055264809410.tar.gz txr-6b66641f1b03b959f15c1c63f6dc055264809410.tar.bz2 txr-6b66641f1b03b959f15c1c63f6dc055264809410.zip |
format: fix precision field leading zero problems.
* stream.c (formatv): Do not recognize multiple leading zeros
as a single one; once the zero flag is set, if another zero is
seen, it must be treated as one of the digits specifying the
precision value. New requirement: before processing a format
specifier, check for the situation that the leading zero
has been specified, but no precision. Convert this situation
to that of a precision of zero being given, with no leading
zero.
* txr.1: Document the ambiguity around the leading zero and
how it is being handled when only the leading zero flag is
given, and no actual precision. Add a note about what happens
when zero precision is specified in ~a in conjunction with
a floating-point value. Misspelled "pas" word fixed.
-rw-r--r-- | stream.c | 11 | ||||
-rw-r--r-- | txr.1 | 24 |
2 files changed, 27 insertions, 8 deletions
@@ -3337,8 +3337,11 @@ val formatv(val stream_in, val fmtstr, struct args *al) case vf_precision: switch (ch) { case '0': - zeropad = 1; - continue; + if (!zeropad) { + zeropad = 1; + continue; + } + /* fallthrough */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': saved_state = state; @@ -3404,6 +3407,10 @@ val formatv(val stream_in, val fmtstr, struct args *al) break; case vf_spec: state = vf_init; + if (zeropad && !precision_p) { + zeropad = precision = 0; + precision_p = 1; + } switch (ch) { case 'x': case 'X': obj = args_get_checked(self, al, &arg_ix); @@ -54517,17 +54517,26 @@ is being omitted; there is only a precision field. The precision specifier may begin with these optional characters: .RS .coIP 0 -(the "leading zero flag"), +(the "leading zero indicator"), .coIP + (print a sign for positive values") .IP space (print a space in place of a positive sign). .RE -The precision specifier itself is either a decimal integer that does not -begin with a zero digit, or the +The precision specifier itself follows: it must be either a decimal integer +or the .code * -character. +character indicating that the precision value comes from an integer argument. + +The leading zero indicator is only active if a precision specifier is +present. If no precision specifier is present, then the leading zero indicator +is interpreted as a specifier indicating a precision value of zero, rather +than requesting leading zeros. To request zero padding together with zero +precision, either two or more zero digits are required, or else the leading +zero indicator must be given together with the +.code * +specifier. The precision field's components have a meaning which depends on the type of object printed and the conversion specifier. @@ -54615,6 +54624,7 @@ the special variable, whose default value is the same as that of the .code flo-dig variable. + Floating point values which are integers are printed without a trailing .code .0 @@ -54627,7 +54637,9 @@ sign on nonnegative values. If a leading zero is specified in the precision, and a nonzero width is specified, then the printed value's integer part will be padded with leading zeros up to one less than the field width. These zeros are placed before the -sign. +sign. A precision value of zero imposed on floating-point values is +equivalent to a value of one; it is not possible to request zero significant +figures. .coIP s Prints any object in a standard way, as if by the @@ -54709,7 +54721,7 @@ precision of the number or its type. If it is omitted, then the value is obtained from the special variable .codn *print-flo-digits* , whose default value is three: three digits past the decimal point. A precision -of zero means no digits pas the decimal point, and in this case the decimal +of zero means no digits past the decimal point, and in this case the decimal point is suppressed (regardless of whether the numeric argument is floating-point or integer). |