summaryrefslogtreecommitdiffstats
path: root/Python/mystrtoul.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/mystrtoul.c')
-rw-r--r--Python/mystrtoul.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c
index 52502cb..c35be81 100644
--- a/Python/mystrtoul.c
+++ b/Python/mystrtoul.c
@@ -83,9 +83,9 @@ static int digitlimit[] = {
** This is a general purpose routine for converting
** an ascii string to an integer in an arbitrary base.
** Leading white space is ignored. If 'base' is zero
-** it looks for a leading 0b, 0o or 0x to tell which
-** base. If these are absent it defaults to 10.
-** Base must be 0 or between 2 and 36 (inclusive).
+** it looks for a leading 0, 0b, 0B, 0o, 0O, 0x or 0X
+** to tell which base. If these are absent it defaults
+** to 10. Base must be 0 or between 2 and 36 (inclusive).
** If 'ptr' is non-NULL it will contain a pointer to
** the end of the scan.
** Errors due to bad pointers will probably result in
@@ -102,9 +102,9 @@ PyOS_strtoul(register char *str, char **ptr, int base)
while (*str && isspace(Py_CHARMASK(*str)))
++str;
- /* check for leading 0b, 0o or 0x for auto-base or base 16 */
+ /* check for leading 0 or 0x for auto-base or base 16 */
switch (base) {
- case 0: /* look for leading 0b, 0o or 0x */
+ case 0: /* look for leading 0, 0b, 0o or 0x */
if (*str == '0') {
++str;
if (*str == 'x' || *str == 'X') {
@@ -135,27 +135,19 @@ PyOS_strtoul(register char *str, char **ptr, int base)
++str;
base = 2;
} else {
- /* skip all zeroes... */
- while (*str == '0')
- ++str;
- while (isspace(Py_CHARMASK(*str)))
- ++str;
- if (ptr)
- *ptr = str;
- return 0;
+ base = 8;
}
}
else
base = 10;
break;
- /* even with explicit base, skip leading 0? prefix */
- case 16:
+ case 2: /* skip leading 0b or 0B */
if (*str == '0') {
++str;
- if (*str == 'x' || *str == 'X') {
- /* there must be at least one digit after 0x */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
+ if (*str == 'b' || *str == 'B') {
+ /* there must be at least one digit after 0b */
+ if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
if (ptr)
*ptr = str;
return 0;
@@ -164,7 +156,8 @@ PyOS_strtoul(register char *str, char **ptr, int base)
}
}
break;
- case 8:
+
+ case 8: /* skip leading 0o or 0O */
if (*str == '0') {
++str;
if (*str == 'o' || *str == 'O') {
@@ -178,12 +171,13 @@ PyOS_strtoul(register char *str, char **ptr, int base)
}
}
break;
- case 2:
- if(*str == '0') {
+
+ case 16: /* skip leading 0x or 0X */
+ if (*str == '0') {
++str;
- if (*str == 'b' || *str == 'B') {
- /* there must be at least one digit after 0b */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
+ if (*str == 'x' || *str == 'X') {
+ /* there must be at least one digit after 0x */
+ if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
if (ptr)
*ptr = str;
return 0;