1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
--- Objects/stringobject.c
+++ Objects/stringobject.c
@@ -1975,10 +1975,14 @@
\n\
Return a copy of the string S converted to lowercase.");
-/* _tolower and _toupper are defined by SUSv2, but they're not ISO C */
-#ifndef _tolower
-#define _tolower tolower
-#endif
+static int
+tolower_C_locale(int c)
+{
+ if (c >= 'A' && c <= 'Z')
+ return c + 0x20;
+ else
+ return c;
+}
static PyObject *
string_lower(PyStringObject *self)
@@ -1998,7 +2002,7 @@
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
if (isupper(c))
- s[i] = _tolower(c);
+ s[i] = tolower_C_locale(c);
}
return newobj;
@@ -2009,9 +2013,14 @@
\n\
Return a copy of the string S converted to uppercase.");
-#ifndef _toupper
-#define _toupper toupper
-#endif
+static int
+toupper_C_locale(int c)
+{
+ if (c >= 'a' && c <= 'z')
+ return c - 0x20;
+ else
+ return c;
+}
static PyObject *
string_upper(PyStringObject *self)
@@ -2031,7 +2040,7 @@
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(s[i]);
if (islower(c))
- s[i] = _toupper(c);
+ s[i] = toupper_C_locale(c);
}
return newobj;
@@ -2059,11 +2068,11 @@
int c = Py_CHARMASK(*s++);
if (islower(c)) {
if (!previous_is_cased)
- c = toupper(c);
+ c = toupper_C_locale(c);
previous_is_cased = 1;
} else if (isupper(c)) {
if (previous_is_cased)
- c = tolower(c);
+ c = tolower_C_locale(c);
previous_is_cased = 1;
} else
previous_is_cased = 0;
@@ -2092,7 +2101,7 @@
if (0 < n) {
int c = Py_CHARMASK(*s++);
if (islower(c))
- *s_new = toupper(c);
+ *s_new = toupper_C_locale(c);
else
*s_new = c;
s_new++;
@@ -2100,7 +2109,7 @@
for (i = 1; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (isupper(c))
- *s_new = tolower(c);
+ *s_new = tolower_C_locale(c);
else
*s_new = c;
s_new++;
@@ -2171,10 +2180,10 @@
for (i = 0; i < n; i++) {
int c = Py_CHARMASK(*s++);
if (islower(c)) {
- *s_new = toupper(c);
+ *s_new = toupper_C_locale(c);
}
else if (isupper(c)) {
- *s_new = tolower(c);
+ *s_new = tolower_C_locale(c);
}
else
*s_new = c;
|