From 5a9256368dfee7a64c811f557de1b8df86e05b07 Mon Sep 17 00:00:00 2001
From: Mike Gilbert <floppym@gentoo.org>
Date: Sun, 17 Jun 2018 11:14:43 -0400
Subject: [PATCH 15/24] Turkish locale

---
 Objects/stringobject.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index c47d32f406..7cd0d0e625 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1987,10 +1987,14 @@ PyDoc_STRVAR(lower__doc__,
 \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)
@@ -2010,7 +2014,7 @@ string_lower(PyStringObject *self)
     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;
@@ -2021,9 +2025,14 @@ PyDoc_STRVAR(upper__doc__,
 \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)
@@ -2043,7 +2052,7 @@ string_upper(PyStringObject *self)
     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;
@@ -2071,11 +2080,11 @@ string_title(PyStringObject *self)
         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;
@@ -2104,7 +2113,7 @@ string_capitalize(PyStringObject *self)
     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++;
@@ -2112,7 +2121,7 @@ string_capitalize(PyStringObject *self)
     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++;
@@ -2183,10 +2192,10 @@ string_swapcase(PyStringObject *self)
     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;
-- 
2.30.1

