summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2007-08-30 22:23:08 (GMT)
committerEric Smith <eric@trueblade.com>2007-08-30 22:23:08 (GMT)
commit185e30cdf330b0c687a7afaf26b1eef761ff12ca (patch)
tree207ffc5193da7731b951d1e7e6819940517551f4 /Objects
parentbc3b345f8284620bba07e9c2ec4cd64553f2b983 (diff)
downloadcpython-185e30cdf330b0c687a7afaf26b1eef761ff12ca.zip
cpython-185e30cdf330b0c687a7afaf26b1eef761ff12ca.tar.gz
cpython-185e30cdf330b0c687a7afaf26b1eef761ff12ca.tar.bz2
Added format tests.
Fixed bug in alignment of negative numbers. Whitespace normalization.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringlib/formatter.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index c408350..8e2b8ef 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -145,8 +145,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
}
/* The special case for 0-padding (backwards compat) */
- if (format->fill_char == '\0' &&
- end-ptr >= 1 && ptr[0] == '0') {
+ if (format->fill_char == '\0' && end-ptr >= 1 && ptr[0] == '0') {
format->fill_char = '0';
if (format->align == '\0') {
format->align = '=';
@@ -298,9 +297,10 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
r->n_lpadding = padding / 2;
r->n_rpadding = padding - r->n_lpadding;
}
- else
- /* must be '=' */
+ else if (format->align == '=')
r->n_spadding = padding;
+ else
+ r->n_lpadding = padding;
}
}
r->n_total = r->n_lpadding + r->n_lsign + r->n_spadding +
@@ -603,7 +603,7 @@ strtounicode(Py_UNICODE *buffer, const char *charbuffer)
register Py_ssize_t i;
Py_ssize_t len = strlen(charbuffer);
for (i = len - 1; i >= 0; i--)
- buffer[i] = (Py_UNICODE) charbuffer[i];
+ buffer[i] = (Py_UNICODE) charbuffer[i];
return len;
}
@@ -641,14 +641,14 @@ _format_float(STRINGLIB_CHAR type, PyObject *value,
/* Worst case length calc to ensure no buffer overrun:
'g' formats:
- fmt = %#.<prec>g
- buf = '-' + [0-9]*prec + '.' + 'e+' + (longest exp
- for any double rep.)
- len = 1 + prec + 1 + 2 + 5 = 9 + prec
+ fmt = %#.<prec>g
+ buf = '-' + [0-9]*prec + '.' + 'e+' + (longest exp
+ for any double rep.)
+ len = 1 + prec + 1 + 2 + 5 = 9 + prec
'f' formats:
- buf = '-' + [0-9]*x + '.' + [0-9]*prec (with x < 50)
- len = 1 + 50 + 1 + prec = 52 + prec
+ buf = '-' + [0-9]*x + '.' + [0-9]*prec (with x < 50)
+ len = 1 + 50 + 1 + prec = 52 + prec
If prec=0 the effective precision is 1 (the leading digit is
always given), therefore increase the length by one.
@@ -678,7 +678,7 @@ _format_float(STRINGLIB_CHAR type, PyObject *value,
x = PyFloat_AsDouble(value);
if (x == -1.0 && PyErr_Occurred())
- goto done;
+ goto done;
if (type == '%') {
type = 'f';
@@ -687,9 +687,9 @@ _format_float(STRINGLIB_CHAR type, PyObject *value,
}
if (precision < 0)
- precision = 6;
+ precision = 6;
if (type == 'f' && (fabs(x) / 1e25) >= 1e25)
- type = 'g';
+ type = 'g';
/* cast "type", because if we're in unicode we need to pass a
8-bit char. this is safe, because we've restricted what "type"