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