emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1fb8a15 2/2: Further fixes for Turkish case changes in unibyte st


From: Lars Ingebrigtsen
Subject: master 1fb8a15 2/2: Further fixes for Turkish case changes in unibyte strings
Date: Wed, 20 Oct 2021 03:38:54 -0400 (EDT)

branch: master
commit 1fb8a1569dab5a5cb99afad9678b3bebae1733c5
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Further fixes for Turkish case changes in unibyte strings
    
    * src/casefiddle.c (struct casing_context): Add new slot to keep
    track of what the previous operation was.
    (case_character_impl): Set it.
    (do_casify_unibyte_string): Use it to handle Turkish correctly.
---
 src/casefiddle.c             | 11 +++++++++--
 test/src/casefiddle-tests.el | 13 +++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/casefiddle.c b/src/casefiddle.c
index e41ada8..81e9ed1 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -54,6 +54,9 @@ struct casing_context
 
   /* Whether the context is within a word.  */
   bool inword;
+
+  /* What the last operation was.  */
+  bool downcase_last;
 };
 
 /* Initialize CTX structure for casing characters.  */
@@ -143,10 +146,14 @@ case_character_impl (struct casing_str_buf *buf,
 
   /* Handle simple, one-to-one case.  */
   if (flag == CASE_DOWN)
-    cased = downcase (ch);
+    {
+      cased = downcase (ch);
+      ctx->downcase_last = true;
+    }
   else
     {
       bool cased_is_set = false;
+      ctx->downcase_last = false;
       if (!NILP (ctx->titlecase_char_table))
        {
          prop = CHAR_TABLE_REF (ctx->titlecase_char_table, ch);
@@ -324,7 +331,7 @@ do_casify_unibyte_string (struct casing_context *ctx, 
Lisp_Object obj)
         character (this can happen in some locales, like the Turkish
         "I"), downcase using the ASCII char table.  */
       if (ASCII_CHAR_P (ch) && !SINGLE_BYTE_CHAR_P (cased))
-       cased = ascii_casify_character (ctx->flag == CASE_DOWN, ch);
+       cased = ascii_casify_character (ctx->downcase_last, ch);
       SSET (obj, i, make_char_unibyte (cased));
     }
   return obj;
diff --git a/test/src/casefiddle-tests.el b/test/src/casefiddle-tests.el
index 9fa54dc..164adbc 100644
--- a/test/src/casefiddle-tests.el
+++ b/test/src/casefiddle-tests.el
@@ -278,4 +278,17 @@
     (with-temp-buffer
       (should-error (upcase-region nil nil t)))))
 
+(ert-deftest casefiddle-turkish ()
+  (skip-unless (member "tr_TR.utf8" (get-locale-names)))
+  (with-locale-environment "tr_TR.utf8"
+    (should (string-equal (downcase "I ı") "ı ı"))
+    (should (string-equal (downcase "İ i") "i̇ i"))
+    (should (string-equal (downcase "I") "i"))
+    (should (string-equal (capitalize "bIte") "Bite"))
+    (should (string-equal (capitalize "bIté") "Bıté"))
+    (should (string-equal (capitalize "indIa") "India"))
+    ;; This does not work -- it produces "Indıa".
+    ;;(should (string-equal (capitalize "indIá") "İndıa"))
+    ))
+
 ;;; casefiddle-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]