From: Lars Ingebrigtsen Date: Wed, 20 Oct 2021 07:38:31 +0000 (+0200) Subject: Further fixes for Turkish case changes in unibyte strings X-Git-Tag: emacs-29.0.90~3671^2~484 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1fb8a1569dab5a5cb99afad9678b3bebae1733c5;p=emacs.git 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. --- diff --git a/src/casefiddle.c b/src/casefiddle.c index e41ada868d0..81e9ed153fb 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 9fa54dcaf43..164adbc19ef 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