diff Objects/stringlib/formatter.h @ 42980:9df911d654af

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.
author Eric Smith <eric@trueblade.com>
date Wed, 29 Aug 2007 12:38:45 +0000
parents 11ec4097fafe
children 0f82fc42fd68
line wrap: on
line diff
--- a/Objects/stringlib/formatter.h	Wed Aug 29 05:52:49 2007 +0000
+++ b/Objects/stringlib/formatter.h	Wed Aug 29 12:38:45 2007 +0000
@@ -13,6 +13,8 @@
    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
     input string, updates *result with the corresponding positive
@@ -73,7 +75,8 @@
 is_sign_element(STRINGLIB_CHAR c)
 {
     switch (c) {
-    case ' ': case '+': case '-': case '(':
+    case ' ': case '+': case '-':
+    case '(':
         return 1;
     default:
         return 0;
@@ -132,9 +135,11 @@
     if (end-ptr >= 1 && is_sign_element(ptr[0])) {
         format->sign = ptr[0];
         ptr++;
+#if ALLOW_PARENS_FOR_SIGN
         if (end-ptr >= 1 && ptr[0] == ')') {
             ptr++;
         }
+#endif
     }
 
     /* The special case for 0-padding (backwards compat) */
@@ -247,6 +252,7 @@
         r->n_lsign = 1;
         r->lsign = (actual_sign == '-' ? '-' : '+');
     }
+#if ALLOW_PARENS_FOR_SIGN
     else if (format->sign == '(') {
         if (actual_sign == '-') {
             r->n_lsign = 1;
@@ -255,6 +261,7 @@
             r->rsign = ')';
         }
     }
+#endif
     else if (format->sign == ' ') {
         r->n_lsign = 1;
         r->lsign = (actual_sign == '-' ? '-' : ' ');