Mercurial > cpython-lru_cache-weakref
diff Objects/longobject.c @ 45791:62ef0ea034f4 legacy-trunk
Finished backporting PEP 3127, Integer Literal Support and Syntax.
Added 0b and 0o literals to tokenizer.
Modified PyOS_strtoul to support 0b and 0o inputs.
Modified PyLong_FromString to support guessing 0b and 0o inputs.
Renamed test_hexoct.py to test_int_literal.py and added binary tests.
Added upper and lower case 0b, 0O, and 0X tests to test_int_literal.py
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Mon, 17 Mar 2008 17:32:20 +0000 |
| parents | b7231bf6bfb7 |
| children | 8a3fa86c30a6 |
line wrap: on
line diff
--- a/Objects/longobject.c Mon Mar 17 16:31:57 2008 +0000 +++ b/Objects/longobject.c Mon Mar 17 17:32:20 2008 +0000 @@ -1465,14 +1465,27 @@ while (*str != '\0' && isspace(Py_CHARMASK(*str))) str++; if (base == 0) { + /* No base given. Deduce the base from the contents + of the string */ if (str[0] != '0') base = 10; else if (str[1] == 'x' || str[1] == 'X') base = 16; + else if (str[1] == 'o' || str[1] == 'O') + base = 8; + else if (str[1] == 'b' || str[1] == 'B') + base = 2; else + /* "old" (C-style) octal literal, still valid in + 2.x, although illegal in 3.x */ base = 8; } - if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) + /* Whether or not we were deducing the base, skip leading chars + as needed */ + if (str[0] == '0' && + ((base == 16 && (str[1] == 'x' || str[1] == 'X')) || + (base == 8 && (str[1] == 'o' || str[1] == 'O')) || + (base == 2 && (str[1] == 'b' || str[1] == 'B')))) str += 2; start = str;
