Commit b7f5ba16 authored by Eric Smith's avatar Eric Smith

Added conditional compilation for '()', which was an allowed sign code in a

previous version of PEP 3101.  It's currently not compiled in, but I want to
leave it because it might be useful in the future and it makes
calc_number_widths() clearer.  It justifies NumberFieldWidths.rsign
and .n__rsign.
parent 39dce30b
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
be. These are the only non-static functions defined here. be. These are the only non-static functions defined here.
*/ */
#define ALLOW_PARENS_FOR_SIGN 0
/* /*
get_integer consumes 0 or more decimal digit characters from an get_integer consumes 0 or more decimal digit characters from an
input string, updates *result with the corresponding positive input string, updates *result with the corresponding positive
...@@ -73,7 +75,8 @@ Py_LOCAL_INLINE(int) ...@@ -73,7 +75,8 @@ Py_LOCAL_INLINE(int)
is_sign_element(STRINGLIB_CHAR c) is_sign_element(STRINGLIB_CHAR c)
{ {
switch (c) { switch (c) {
case ' ': case '+': case '-': case '(': case ' ': case '+': case '-':
case '(':
return 1; return 1;
default: default:
return 0; return 0;
...@@ -132,9 +135,11 @@ parse_internal_render_format_spec(PyObject *format_spec, ...@@ -132,9 +135,11 @@ parse_internal_render_format_spec(PyObject *format_spec,
if (end-ptr >= 1 && is_sign_element(ptr[0])) { if (end-ptr >= 1 && is_sign_element(ptr[0])) {
format->sign = ptr[0]; format->sign = ptr[0];
ptr++; ptr++;
#if ALLOW_PARENS_FOR_SIGN
if (end-ptr >= 1 && ptr[0] == ')') { if (end-ptr >= 1 && ptr[0] == ')') {
ptr++; ptr++;
} }
#endif
} }
/* The special case for 0-padding (backwards compat) */ /* The special case for 0-padding (backwards compat) */
...@@ -247,6 +252,7 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign, ...@@ -247,6 +252,7 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
r->n_lsign = 1; r->n_lsign = 1;
r->lsign = (actual_sign == '-' ? '-' : '+'); r->lsign = (actual_sign == '-' ? '-' : '+');
} }
#if ALLOW_PARENS_FOR_SIGN
else if (format->sign == '(') { else if (format->sign == '(') {
if (actual_sign == '-') { if (actual_sign == '-') {
r->n_lsign = 1; r->n_lsign = 1;
...@@ -255,6 +261,7 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign, ...@@ -255,6 +261,7 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
r->rsign = ')'; r->rsign = ')';
} }
} }
#endif
else if (format->sign == ' ') { else if (format->sign == ' ') {
r->n_lsign = 1; r->n_lsign = 1;
r->lsign = (actual_sign == '-' ? '-' : ' '); r->lsign = (actual_sign == '-' ? '-' : ' ');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment