Commit 6dc46f5e authored by Eric Smith's avatar Eric Smith

Merged revisions 72040 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72040 | eric.smith | 2009-04-27 15:04:37 -0400 (Mon, 27 Apr 2009) | 1 line

  Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
........
parent 249b898e
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
#include "compile.h" #include "compile.h"
#include "eval.h" #include "eval.h"
#include "pyctype.h"
#include "pystrtod.h" #include "pystrtod.h"
#include "pystrcmp.h" #include "pystrcmp.h"
#include "dtoa.h" #include "dtoa.h"
......
...@@ -38,23 +38,15 @@ extern const char _Py_capitalize__doc__[]; ...@@ -38,23 +38,15 @@ extern const char _Py_capitalize__doc__[];
extern const char _Py_swapcase__doc__[]; extern const char _Py_swapcase__doc__[];
extern const char _Py_maketrans__doc__[]; extern const char _Py_maketrans__doc__[];
#define FLAG_LOWER 0x01 /* These are left in for backward compatibility and will be removed
#define FLAG_UPPER 0x02 in 2.8/3.2 */
#define FLAG_ALPHA (FLAG_LOWER|FLAG_UPPER) #define ISLOWER(c) Py_ISLOWER(c)
#define FLAG_DIGIT 0x04 #define ISUPPER(c) Py_ISUPPER(c)
#define FLAG_ALNUM (FLAG_ALPHA|FLAG_DIGIT) #define ISALPHA(c) Py_ISALPHA(c)
#define FLAG_SPACE 0x08 #define ISDIGIT(c) Py_ISDIGIT(c)
#define FLAG_XDIGIT 0x10 #define ISXDIGIT(c) Py_ISXDIGIT(c)
#define ISALNUM(c) Py_ISALNUM(c)
extern const unsigned int _Py_ctype_table[256]; #define ISSPACE(c) Py_ISSPACE(c)
#define ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
#define ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
#define ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
#define ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
#define ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
#define ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
#define ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
#undef islower #undef islower
#define islower(c) undefined_islower(c) #define islower(c) undefined_islower(c)
...@@ -71,11 +63,10 @@ extern const unsigned int _Py_ctype_table[256]; ...@@ -71,11 +63,10 @@ extern const unsigned int _Py_ctype_table[256];
#undef isspace #undef isspace
#define isspace(c) undefined_isspace(c) #define isspace(c) undefined_isspace(c)
extern const unsigned char _Py_ctype_tolower[256]; /* These are left in for backward compatibility and will be removed
extern const unsigned char _Py_ctype_toupper[256]; in 2.8/3.2 */
#define TOLOWER(c) Py_TOLOWER(c)
#define TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)]) #define TOUPPER(c) Py_TOUPPER(c)
#define TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
#undef tolower #undef tolower
#define tolower(c) undefined_tolower(c) #define tolower(c) undefined_tolower(c)
......
...@@ -294,6 +294,7 @@ PYTHON_OBJS= \ ...@@ -294,6 +294,7 @@ PYTHON_OBJS= \
Python/mysnprintf.o \ Python/mysnprintf.o \
Python/peephole.o \ Python/peephole.o \
Python/pyarena.o \ Python/pyarena.o \
Python/pyctype.o \
Python/pyfpe.o \ Python/pyfpe.o \
Python/pymath.o \ Python/pymath.o \
Python/pystate.o \ Python/pystate.o \
...@@ -653,6 +654,7 @@ PYTHON_HEADERS= \ ...@@ -653,6 +654,7 @@ PYTHON_HEADERS= \
Include/pgen.h \ Include/pgen.h \
Include/pgenheaders.h \ Include/pgenheaders.h \
Include/pyarena.h \ Include/pyarena.h \
Include/pyctype.h \
Include/pydebug.h \ Include/pydebug.h \
Include/pyerrors.h \ Include/pyerrors.h \
Include/pyfpe.h \ Include/pyfpe.h \
......
...@@ -12,6 +12,9 @@ What's New in Python 3.1 beta 1? ...@@ -12,6 +12,9 @@ What's New in Python 3.1 beta 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #5793: Rationalize isdigit / isalpha / tolower, etc. Includes
new Py_ISDIGIT / Py_ISALPHA / Py_TOLOWER, etc. in pctypes.h.
- Issue #5835: Deprecate PyOS_ascii_formatd. - Issue #5835: Deprecate PyOS_ascii_formatd.
- Issue #4971: Fix titlecase for characters that are their own - Issue #4971: Fix titlecase for characters that are their own
......
...@@ -2176,16 +2176,16 @@ split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount) ...@@ -2176,16 +2176,16 @@ split_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
for (i = j = 0; i < len; ) { for (i = j = 0; i < len; ) {
/* find a token */ /* find a token */
while (i < len && ISSPACE(s[i])) while (i < len && Py_ISSPACE(s[i]))
i++; i++;
j = i; j = i;
while (i < len && !ISSPACE(s[i])) while (i < len && !Py_ISSPACE(s[i]))
i++; i++;
if (j < i) { if (j < i) {
if (maxcount-- <= 0) if (maxcount-- <= 0)
break; break;
SPLIT_ADD(s, j, i); SPLIT_ADD(s, j, i);
while (i < len && ISSPACE(s[i])) while (i < len && Py_ISSPACE(s[i]))
i++; i++;
j = i; j = i;
} }
...@@ -2410,16 +2410,16 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount) ...@@ -2410,16 +2410,16 @@ rsplit_whitespace(const char *s, Py_ssize_t len, Py_ssize_t maxcount)
for (i = j = len - 1; i >= 0; ) { for (i = j = len - 1; i >= 0; ) {
/* find a token */ /* find a token */
while (i >= 0 && ISSPACE(s[i])) while (i >= 0 && Py_ISSPACE(s[i]))
i--; i--;
j = i; j = i;
while (i >= 0 && !ISSPACE(s[i])) while (i >= 0 && !Py_ISSPACE(s[i]))
i--; i--;
if (j > i) { if (j > i) {
if (maxcount-- <= 0) if (maxcount-- <= 0)
break; break;
SPLIT_ADD(s, i + 1, j + 1); SPLIT_ADD(s, i + 1, j + 1);
while (i >= 0 && ISSPACE(s[i])) while (i >= 0 && Py_ISSPACE(s[i]))
i--; i--;
j = i; j = i;
} }
...@@ -2986,11 +2986,11 @@ hex_digit_to_int(Py_UNICODE c) ...@@ -2986,11 +2986,11 @@ hex_digit_to_int(Py_UNICODE c)
{ {
if (c >= 128) if (c >= 128)
return -1; return -1;
if (ISDIGIT(c)) if (Py_ISDIGIT(c))
return c - '0'; return c - '0';
else { else {
if (ISUPPER(c)) if (Py_ISUPPER(c))
c = TOLOWER(c); c = Py_TOLOWER(c);
if (c >= 'a' && c <= 'f') if (c >= 'a' && c <= 'f')
return c - 'a' + 10; return c - 'a' + 10;
} }
......
This diff is collapsed.
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#define STRINGLIB_EMPTY nullstring #define STRINGLIB_EMPTY nullstring
#define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9')) #define STRINGLIB_ISDECIMAL(x) ((x >= '0') && (x <= '9'))
#define STRINGLIB_TODECIMAL(x) (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1) #define STRINGLIB_TODECIMAL(x) (STRINGLIB_ISDECIMAL(x) ? (x - '0') : -1)
#define STRINGLIB_TOUPPER toupper #define STRINGLIB_TOUPPER Py_TOUPPER
#define STRINGLIB_TOLOWER tolower #define STRINGLIB_TOLOWER Py_TOLOWER
#define STRINGLIB_FILL memset #define STRINGLIB_FILL memset
#define STRINGLIB_STR PyBytes_AS_STRING #define STRINGLIB_STR PyBytes_AS_STRING
#define STRINGLIB_LEN PyBytes_GET_SIZE #define STRINGLIB_LEN PyBytes_GET_SIZE
......
...@@ -603,6 +603,10 @@ SOURCE=..\..\Python\pyarena.c ...@@ -603,6 +603,10 @@ SOURCE=..\..\Python\pyarena.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\Python\pyctype.c
# End Source File
# Begin Source File
SOURCE=..\..\Python\pyfpe.c SOURCE=..\..\Python\pyfpe.c
# End Source File # End Source File
# Begin Source File # Begin Source File
......
...@@ -720,6 +720,9 @@ ...@@ -720,6 +720,9 @@
<File <File
RelativePath="..\..\Python\pyarena.c"> RelativePath="..\..\Python\pyarena.c">
</File> </File>
<File
RelativePath="..\..\Python\pyctype.c">
</File>
<File <File
RelativePath="..\..\Python\pyfpe.c"> RelativePath="..\..\Python\pyfpe.c">
</File> </File>
......
...@@ -850,6 +850,10 @@ ...@@ -850,6 +850,10 @@
RelativePath="..\..\Include\pyarena.h" RelativePath="..\..\Include\pyarena.h"
> >
</File> </File>
<File
RelativePath="..\..\Include\pyctype.h"
>
</File>
<File <File
RelativePath="..\..\Include\pydebug.h" RelativePath="..\..\Include\pydebug.h"
> >
...@@ -1730,6 +1734,10 @@ ...@@ -1730,6 +1734,10 @@
RelativePath="..\..\Python\pyarena.c" RelativePath="..\..\Python\pyarena.c"
> >
</File> </File>
<File
RelativePath="..\..\Python\pyctype.c"
>
</File>
<File <File
RelativePath="..\..\Python\pyfpe.c" RelativePath="..\..\Python\pyfpe.c"
> >
......
...@@ -349,6 +349,7 @@ SRC.PYTHON= $(addprefix $(TOP), \ ...@@ -349,6 +349,7 @@ SRC.PYTHON= $(addprefix $(TOP), \
Python/mysnprintf.c \ Python/mysnprintf.c \
Python/mystrtoul.c \ Python/mystrtoul.c \
Python/pyarena.c \ Python/pyarena.c \
Python/pyctype.c \
Python/pyfpe.c \ Python/pyfpe.c \
Python/pystate.c \ Python/pystate.c \
Python/pystrtod.c \ Python/pystrtod.c \
......
...@@ -846,6 +846,10 @@ ...@@ -846,6 +846,10 @@
RelativePath="..\Include\pyarena.h" RelativePath="..\Include\pyarena.h"
> >
</File> </File>
<File
RelativePath="..\Include\pyctype.h"
>
</File>
<File <File
RelativePath="..\Include\pydebug.h" RelativePath="..\Include\pydebug.h"
> >
...@@ -1730,6 +1734,10 @@ ...@@ -1730,6 +1734,10 @@
RelativePath="..\Python\pyarena.c" RelativePath="..\Python\pyarena.c"
> >
</File> </File>
<File
RelativePath="..\Python\pyctype.c"
>
</File>
<File <File
RelativePath="..\Python\pyfpe.c" RelativePath="..\Python\pyfpe.c"
> >
......
...@@ -3,12 +3,6 @@ ...@@ -3,12 +3,6 @@
#include <Python.h> #include <Python.h>
#include <locale.h> #include <locale.h>
/* ascii character tests (as opposed to locale tests) */
#define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
(c) == '\r' || (c) == '\t' || (c) == '\v')
#define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
/** /**
* PyOS_ascii_strtod: * PyOS_ascii_strtod:
* @nptr: the string to convert to a numeric value. * @nptr: the string to convert to a numeric value.
...@@ -104,7 +98,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) ...@@ -104,7 +98,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
p = nptr; p = nptr;
/* Skip leading space */ /* Skip leading space */
while (ISSPACE(*p)) while (Py_ISSPACE(*p))
p++; p++;
/* Process leading sign, if present */ /* Process leading sign, if present */
...@@ -147,7 +141,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) ...@@ -147,7 +141,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
goto invalid_string; goto invalid_string;
/* Check that what's left begins with a digit or decimal point */ /* Check that what's left begins with a digit or decimal point */
if (!ISDIGIT(*p) && *p != '.') if (!Py_ISDIGIT(*p) && *p != '.')
goto invalid_string; goto invalid_string;
digits_pos = p; digits_pos = p;
...@@ -158,7 +152,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) ...@@ -158,7 +152,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
swapped for the current locale's decimal point before we swapped for the current locale's decimal point before we
call strtod. On the other hand, if we find the current call strtod. On the other hand, if we find the current
locale's decimal point then the input is invalid. */ locale's decimal point then the input is invalid. */
while (ISDIGIT(*p)) while (Py_ISDIGIT(*p))
p++; p++;
if (*p == '.') if (*p == '.')
...@@ -166,14 +160,14 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) ...@@ -166,14 +160,14 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
decimal_point_pos = p++; decimal_point_pos = p++;
/* locate end of number */ /* locate end of number */
while (ISDIGIT(*p)) while (Py_ISDIGIT(*p))
p++; p++;
if (*p == 'e' || *p == 'E') if (*p == 'e' || *p == 'E')
p++; p++;
if (*p == '+' || *p == '-') if (*p == '+' || *p == '-')
p++; p++;
while (ISDIGIT(*p)) while (Py_ISDIGIT(*p))
p++; p++;
end = p; end = p;
} }
...@@ -269,7 +263,7 @@ change_decimal_from_locale_to_dot(char* buffer) ...@@ -269,7 +263,7 @@ change_decimal_from_locale_to_dot(char* buffer)
if (*buffer == '+' || *buffer == '-') if (*buffer == '+' || *buffer == '-')
buffer++; buffer++;
while (isdigit(Py_CHARMASK(*buffer))) while (Py_ISDIGIT(*buffer))
buffer++; buffer++;
if (strncmp(buffer, decimal_point, decimal_point_len) == 0) { if (strncmp(buffer, decimal_point, decimal_point_len) == 0) {
*buffer = '.'; *buffer = '.';
...@@ -312,7 +306,7 @@ ensure_minimum_exponent_length(char* buffer, size_t buf_size) ...@@ -312,7 +306,7 @@ ensure_minimum_exponent_length(char* buffer, size_t buf_size)
/* Find the end of the exponent, keeping track of leading /* Find the end of the exponent, keeping track of leading
zeros. */ zeros. */
while (*p && isdigit(Py_CHARMASK(*p))) { while (*p && Py_ISDIGIT(*p)) {
if (in_leading_zeros && *p == '0') if (in_leading_zeros && *p == '0')
++leading_zero_cnt; ++leading_zero_cnt;
if (*p != '0') if (*p != '0')
...@@ -375,11 +369,11 @@ ensure_decimal_point(char* buffer, size_t buf_size) ...@@ -375,11 +369,11 @@ ensure_decimal_point(char* buffer, size_t buf_size)
/* Skip leading sign, if present. I think this could only /* Skip leading sign, if present. I think this could only
ever be '-', but it can't hurt to check for both. */ ever be '-', but it can't hurt to check for both. */
++p; ++p;
while (*p && isdigit(Py_CHARMASK(*p))) while (*p && Py_ISDIGIT(*p))
++p; ++p;
if (*p == '.') { if (*p == '.') {
if (isdigit(Py_CHARMASK(*(p+1)))) { if (Py_ISDIGIT(*(p+1))) {
/* Nothing to do, we already have a decimal /* Nothing to do, we already have a decimal
point and a digit after it */ point and a digit after it */
} }
......
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