Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5aa4744

Browse files
Issue #22584: Got rid of character tables in _sre.c and use standard macros
Py_TOLOWER, Py_ISSPACE, etc.
1 parent 7438e4b commit 5aa4744

1 file changed

Lines changed: 6 additions & 34 deletions

File tree

Modules/_sre.c

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -97,48 +97,20 @@ static char copyright[] =
9797
/* -------------------------------------------------------------------- */
9898
/* search engine state */
9999

100-
/* default character predicates (run sre_chars.py to regenerate tables) */
101-
102-
#define SRE_DIGIT_MASK 1
103-
#define SRE_SPACE_MASK 2
104-
#define SRE_LINEBREAK_MASK 4
105-
#define SRE_ALNUM_MASK 8
106-
#define SRE_WORD_MASK 16
107-
108-
/* FIXME: this assumes ASCII. create tables in init_sre() instead */
109-
110-
static char sre_char_info[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
111-
2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
112-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25,
113-
25, 25, 0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
114-
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0,
115-
0, 0, 16, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
116-
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 0, 0, 0 };
117-
118-
static char sre_char_lower[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
119-
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
120-
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
121-
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
122-
61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
123-
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
124-
122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
125-
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
126-
120, 121, 122, 123, 124, 125, 126, 127 };
127-
128100
#define SRE_IS_DIGIT(ch)\
129-
((ch) < 128 ? (sre_char_info[(ch)] & SRE_DIGIT_MASK) : 0)
101+
((ch) < 128 && Py_ISDIGIT(ch))
130102
#define SRE_IS_SPACE(ch)\
131-
((ch) < 128 ? (sre_char_info[(ch)] & SRE_SPACE_MASK) : 0)
103+
((ch) < 128 && Py_ISSPACE(ch))
132104
#define SRE_IS_LINEBREAK(ch)\
133-
((ch) < 128 ? (sre_char_info[(ch)] & SRE_LINEBREAK_MASK) : 0)
105+
((ch) == '\n')
134106
#define SRE_IS_ALNUM(ch)\
135-
((ch) < 128 ? (sre_char_info[(ch)] & SRE_ALNUM_MASK) : 0)
107+
((ch) < 128 && Py_ISALNUM(ch))
136108
#define SRE_IS_WORD(ch)\
137-
((ch) < 128 ? (sre_char_info[(ch)] & SRE_WORD_MASK) : 0)
109+
((ch) < 128 && (Py_ISALNUM(ch) || (ch) == '_'))
138110

139111
static unsigned int sre_lower(unsigned int ch)
140112
{
141-
return ((ch) < 128 ? (unsigned int)sre_char_lower[ch] : ch);
113+
return ((ch) < 128 ? Py_TOLOWER(ch) : ch);
142114
}
143115

144116
/* locale-specific character predicates */

0 commit comments

Comments
 (0)