--- 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;