unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: 24603@debbugs.gnu.org
Subject: bug#24603: [RFC 11/18] Implement casing rules for Lithuanian
Date: Tue,  4 Oct 2016 03:10:34 +0200	[thread overview]
Message-ID: <1475543441-10493-11-git-send-email-mina86@mina86.com> (raw)
In-Reply-To: <1475543441-10493-1-git-send-email-mina86@mina86.com>

In Lithuanian, tittle above lower case i and j are retained even if
there are other diacritics above present.  For that to work, an explicit
combining dot above must be added after i and j or otherwise the
rendering engine will remove the tittle.

* src/casefiddle.c (struct casing_context, prepare_casing_context): Add
lithuanian_tittle member to hold state of Lithuanian rules handling.
(case_lithuanian): New function which implements Lithuanian rules.
(case_characters): Make use of case_lithuanian.

* test/src/casefiddle-tests.el (casefiddle-tests-casing): Add test cases
for Lithuanian rules.
---
 src/casefiddle.c             | 149 +++++++++++++++++++++++++++++++++++++++++--
 test/src/casefiddle-tests.el |  27 +++++++-
 2 files changed, 170 insertions(+), 6 deletions(-)

diff --git a/src/casefiddle.c b/src/casefiddle.c
index 2a7aa64..0377fe6 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -56,6 +56,16 @@ struct casing_context {
   bool inword;
   /* Whether to apply Azeri/Turkish rules for dotted and dotless i. */
   bool treat_turkic_i;
+
+  /* Whether to use Lithuanian rules for i’s and j’s tittle. */
+  unsigned char lithuanian_tittle;
+#define LT_OFF 0  /* No */
+#define LT_ON 1  /* Yes */
+#define LT_DEL_DOT_ABOVE 2  /* Yes and look out for combining dot above to
+			       delete. */
+#define LT_INS_DOT_ABOVE 3  /* Yes and look out for diacritics combining above
+			       because we may need to inject dot above before
+			       them. */
 };
 
 /* Initialise CTX structure and prepares related global data for casing
@@ -64,7 +74,7 @@ static void
 prepare_casing_context (struct casing_context *ctx,
 			enum case_action flag, bool inbuffer)
 {
-  Lisp_Object lang, l, tr, az;
+  Lisp_Object lang, l, tr, az, lt;
 
   ctx->flag = flag;
   ctx->inbuffer = inbuffer;
@@ -74,6 +84,7 @@ prepare_casing_context (struct casing_context *ctx,
     : Qnil;
 
   ctx->treat_turkic_i = false;
+  ctx->lithuanian_tittle = LT_OFF;
 
   /* If the case table is flagged as modified, rescan it.  */
   if (NILP (XCHAR_TABLE (BVAR (current_buffer, downcase_table))->extras[1]))
@@ -86,6 +97,7 @@ prepare_casing_context (struct casing_context *ctx,
   lang = Vcurrent_iso639_language;
   tr = intern_c_string ("tr");
   az = intern_c_string ("az");
+  lt = intern_c_string ("lt");
   if (SYMBOLP (lang))
     {
       l = lang;
@@ -97,10 +109,9 @@ prepare_casing_context (struct casing_context *ctx,
       lang = XCDR (lang);
     check_language:
       if (EQ (l, tr) || EQ (l, az))
-       {
-         ctx->treat_turkic_i = true;
-         break;
-       }
+	ctx->treat_turkic_i = true;
+      else if (EQ (l, lt))
+	ctx->lithuanian_tittle = LT_ON;
     }
 }
 
@@ -199,6 +210,131 @@ case_character_impl (struct casing_str_buf *buf,
 #define CAPITAL_DOTTED_I    0x130
 #define SMALL_DOTLESS_I     0x131
 #define COMBINING_DOT_ABOVE 0x307
+
+/* Lithuanian retains tittle in lower case i and j when there are more
+   accents above those letters. */
+
+#define CAPITAL_I_WITH_GRAVE  0x0CC
+#define CAPITAL_I_WITH_ACUTE  0x0CD
+#define CAPITAL_I_WITH_TILDE  0x128
+#define CAPITAL_I_WITH_OGONEK 0x12E
+#define SMALL_I_WITH_OGONEK   0x12F
+#define COMBINING_GRAVE_ABOVE 0x300
+#define COMBINING_ACUTE_ABOVE 0x301
+#define COMBINING_TILDE_ABOVE 0x303
+#define COMBINING_OGONEK      0x328
+
+/* Attempt to case CH using rules for Lithuanian i and j.  Return true if
+   character has been cased (in which case it’s saved in BUF), false otherwise.
+   If CTX->lithuanian_tittle is LT_OFF, return false. */
+static bool
+case_lithuanian (struct casing_str_buf *buf, struct casing_context *ctx,
+		 enum case_action flag, int ch)
+{
+  switch (__builtin_expect(ctx->lithuanian_tittle, LT_OFF)) {
+  case LT_OFF:
+    return false;
+
+  case LT_DEL_DOT_ABOVE:
+    /* When upper-casing i or j, a combining dot above that follows it must be
+       removed.  This is true even if there’s a combining ogonek in between.
+       But, if there’s another character combining above in between, combining
+       dot needs to stay (since the dot will be rendered above the other
+       diacritic). */
+    switch (ch) {
+    case COMBINING_DOT_ABOVE:
+      buf->len_chars = buf->len_bytes = 0;
+      ctx->lithuanian_tittle = LT_ON;
+      return true;
+    case COMBINING_GRAVE_ABOVE:
+    case COMBINING_ACUTE_ABOVE:
+    case COMBINING_TILDE_ABOVE:
+      ctx->lithuanian_tittle = LT_ON;
+      return false;
+    case COMBINING_OGONEK:
+      return false;
+    default:
+      ctx->lithuanian_tittle = LT_ON;
+    }
+    break;
+
+  case LT_INS_DOT_ABOVE:
+    /* When lower-casing I or J, if the letter has any accents above,
+       a combining dot above must be added before them.  If we are here, it
+       means that we have lower cased I or J and we’re now on the lookout for
+       accents combining above. */
+    switch (ch) {
+    case COMBINING_GRAVE_ABOVE:
+    case COMBINING_ACUTE_ABOVE:
+    case COMBINING_TILDE_ABOVE:
+      buf->len_chars = 2;
+      buf->len_bytes = CHAR_STRING (COMBINING_DOT_ABOVE, buf->data);
+      buf->len_bytes += CHAR_STRING (ch, buf->data + buf->len_bytes);
+      ctx->lithuanian_tittle = LT_ON;
+      return true;
+    case COMBINING_OGONEK:
+      return false;
+    default:
+      ctx->lithuanian_tittle = LT_ON;
+    }
+    break;
+  }
+
+  switch (flag) {
+  case CASE_UP:
+  case CASE_CAPITALIZE:
+    if (ch == 'i' || ch == 'j')
+      {
+	buf->data[0] = ch ^ ('i' ^ 'I');
+	buf->len_bytes = 1;
+      }
+    else if (ch == SMALL_I_WITH_OGONEK)
+      buf->len_bytes = CHAR_STRING (CAPITAL_I_WITH_OGONEK, buf->data);
+    else
+      break;
+    buf->len_chars = 1;
+    /* Change the state so we’re on the lookout for combining dot above. */
+    ctx->lithuanian_tittle = LT_DEL_DOT_ABOVE;
+    return true;
+
+  case CASE_DOWN:
+    /* Turning I or J to lower case requires combining dot above to be included
+       IF there are any other characters combining above present.  This is so
+       that the tittle is preserved. */
+    switch (ch) {
+    case CAPITAL_I_WITH_GRAVE:
+      ch = 0x80;  /* U+300, "\xCC\x80", combining grave accent */
+      goto has_accent;
+    case CAPITAL_I_WITH_ACUTE:
+      ch = 0x81;  /* U+301, "\xCC \x81", combining acute accent */
+      goto has_accent;
+    case CAPITAL_I_WITH_TILDE:
+      ch = 0x83;  /* U+303, "\xCC\x83", combining tilde */
+    has_accent:
+      memcpy (buf->data, "i\xCC\x87\xCC", 4);
+      buf->data[4] = ch;
+      buf->len_chars = 3;
+      buf->len_bytes = 5;
+      return true;
+
+    case 'I':
+    case 'J':
+      buf->data[0] = ch ^ ('i' ^ 'I');
+      buf->len_bytes = 1;
+      if (false)
+    case CAPITAL_I_WITH_OGONEK:
+	buf->len_bytes = CHAR_STRING (SMALL_I_WITH_OGONEK, buf->data);
+      buf->len_chars = 1;
+      /* Change the state so we’re on the lookout for diacritics combining
+	 above.  If one is found, we need to add combining dot above. */
+      ctx->lithuanian_tittle = LT_INS_DOT_ABOVE;
+      return true;
+    }
+    break;
+  }
+
+  return false;
+}
 \f
 /* Based on CTX, case character CH accordingly.  Update CTX as necessary.
    Return cased character.
@@ -234,6 +370,9 @@ case_characters (struct casing_str_buf *buf, struct casing_context *ctx,
 {
   enum case_action flag = normalise_flag (ctx);
 
+  if (case_lithuanian (buf, ctx, flag, ch))
+    return 0;
+
   if (flag != CASE_NO_ACTION && __builtin_expect(ctx->treat_turkic_i, false))
     {
       bool dot_above = false;
diff --git a/test/src/casefiddle-tests.el b/test/src/casefiddle-tests.el
index 9f5e43f..bae4242 100644
--- a/test/src/casefiddle-tests.el
+++ b/test/src/casefiddle-tests.el
@@ -185,7 +185,32 @@ casefiddle-tests--characters
               ("I\u0307si\u0307s" "I\u0307Sİ\u0307S" "isi\u0307s"
                                   "I\u0307si\u0307s" "I\u0307si\u0307s" 'tr)
               ("I\u0307sI\u0307s" "I\u0307SI\u0307S" "isis"
-                                  "I\u0307sis" "I\u0307sI\u0307s" 'tr))
+                                  "I\u0307sis" "I\u0307sI\u0307s" 'tr)
+
+              ;; Test combining dot above in inserted when needed when lower
+              ;; casing I or J.
+              ("I\u0328\u0300"          ; I + ogonek + grave
+               "I\u0328\u0300" "i\u0328\u0307\u0300"
+               "I\u0328\u0300" "I\u0328\u0300" 'lt)
+
+              ("J\u0328\u0300"          ; J + ogonek + grave
+               "J\u0328\u0300" "j\u0328\u0307\u0300"
+               "J\u0328\u0300" "J\u0328\u0300" 'lt)
+
+              ("Į\u0300"          ; I-ogonek + grave
+               "Į\u0300" "į\u0307\u0300" "Į\u0300" "Į\u0300" 'lt)
+
+              ("Ì Í Ĩ"
+               "Ì Í Ĩ" "i\u0307\u0300 i\u0307\u0301 i\u0307\u0303"
+               "Ì Í Ĩ" "Ì Í Ĩ" 'lt)
+
+              ;; Test combining dot above in removed when upper casing i or j.
+              ("i\u0328\u0307"          ; i + ogonek + dot above
+               "I\u0328" "i\u0328\u0307" "I\u0328" "I\u0328" 'lt)
+              ("j\u0328\u0307"          ; j + ogonek + dot above
+               "J\u0328" "j\u0328\u0307" "J\u0328" "J\u0328" 'lt)
+              ("į\u0307"                ; i-ogonek + dot above
+               "Į" "į\u0307" "Į" "Į" 'lt))
             (nreverse errors))
          (let* ((input (string-to-multibyte (car test)))
                 (expected (cdr test))
-- 
2.8.0.rc3.226.g39d4020






  parent reply	other threads:[~2016-10-04  1:10 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04  1:05 bug#24603: [RFC 00/18] Improvement to casing Michal Nazarewicz
2016-10-04  1:10 ` bug#24603: [RFC 01/18] Add tests for casefiddle.c Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 02/18] Generate upcase and downcase tables from Unicode data Michal Nazarewicz
2016-10-04  7:27     ` Eli Zaretskii
2016-10-04 14:54       ` Michal Nazarewicz
2016-10-04 15:06         ` Eli Zaretskii
2016-10-04 16:57           ` Michal Nazarewicz
2016-10-04 17:27             ` Eli Zaretskii
2016-10-04 17:44               ` Eli Zaretskii
2016-10-06 20:29                 ` Michal Nazarewicz
2016-10-07  6:52                   ` Eli Zaretskii
2016-10-04  1:10   ` bug#24603: [RFC 03/18] Don’t assume character can be either upper- or lower-case when casing Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 04/18] Split casify_object into multiple functions Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 05/18] Introduce case_character function Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 06/18] Add support for title-casing letters Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 07/18] Split up casify_region function Michal Nazarewicz
2016-10-04  7:17     ` Eli Zaretskii
2016-10-18  2:27       ` Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 08/18] Support casing characters which map into multiple code points Michal Nazarewicz
2016-10-04  7:38     ` Eli Zaretskii
2016-10-06 21:40       ` Michal Nazarewicz
2016-10-07  7:46         ` Eli Zaretskii
2017-01-28 23:48           ` Michal Nazarewicz
2017-02-10  9:12             ` Eli Zaretskii
2016-10-04  1:10   ` bug#24603: [RFC 09/18] Implement special sigma casing rule Michal Nazarewicz
2016-10-04  7:22     ` Eli Zaretskii
2016-10-04  1:10   ` bug#24603: [RFC 10/18] Implement Turkic dotless and dotted i handling when casing strings Michal Nazarewicz
2016-10-04  7:12     ` Eli Zaretskii
2016-10-04  1:10   ` Michal Nazarewicz [this message]
2016-10-04  1:10   ` bug#24603: [RFC 12/18] Implement rules for title-casing Dutch ij ‘letter’ Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 13/18] Add some tricky Unicode characters to regex test Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 14/18] Factor out character category lookup to separate function Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 15/18] Base lower- and upper-case tests on Unicode properties Michal Nazarewicz
2016-10-04  6:54     ` Eli Zaretskii
2016-10-04  1:10   ` bug#24603: [RFC 16/18] Refactor character class checking; optimise ASCII case Michal Nazarewicz
2016-10-04  7:48     ` Eli Zaretskii
2016-10-17 13:22       ` Michal Nazarewicz
2016-11-06 19:26       ` Michal Nazarewicz
2016-11-06 19:44         ` Eli Zaretskii
2016-12-20 14:32           ` Michal Nazarewicz
2016-12-20 16:39             ` Eli Zaretskii
2016-12-22 14:02               ` Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 17/18] Optimise character class matching in regexes Michal Nazarewicz
2016-10-04  1:10   ` bug#24603: [RFC 18/18] Fix case-fold-search character class matching Michal Nazarewicz
2016-10-17 22:03 ` bug#24603: [PATCH 0/3] Case table updates Michal Nazarewicz
2016-10-17 22:03   ` bug#24603: [PATCH 1/3] Add tests for casefiddle.c Michal Nazarewicz
2016-10-17 22:03   ` bug#24603: [PATCH 2/3] Generate upcase and downcase tables from Unicode data Michal Nazarewicz
2016-10-17 22:03   ` bug#24603: [PATCH 3/3] Don’t generate ‘X maps to X’ entries in case tables Michal Nazarewicz
2016-10-18  6:36   ` bug#24603: [PATCH 0/3] Case table updates Eli Zaretskii
2016-10-24 15:11     ` Michal Nazarewicz
2016-10-24 15:33       ` Eli Zaretskii
2017-03-09 21:51 ` bug#24603: [PATCHv5 00/11] Casing improvements Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 01/11] Split casify_object into multiple functions Michal Nazarewicz
2017-03-10  9:00     ` Andreas Schwab
2017-03-09 21:51   ` bug#24603: [PATCHv5 02/11] Introduce case_character function Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 03/11] Add support for title-casing letters (bug#24603) Michal Nazarewicz
2017-03-11  9:03     ` Eli Zaretskii
2017-03-09 21:51   ` bug#24603: [PATCHv5 04/11] Split up casify_region function (bug#24603) Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 05/11] Support casing characters which map into multiple code points (bug#24603) Michal Nazarewicz
2017-03-11  9:14     ` Eli Zaretskii
2017-03-21  2:09       ` Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 06/11] Implement special sigma casing rule (bug#24603) Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 07/11] Introduce ‘buffer-language’ buffer-locar variable Michal Nazarewicz
2017-03-11  9:29     ` Eli Zaretskii
2017-03-09 21:51   ` bug#24603: [PATCHv5 08/11] Implement rules for title-casing Dutch ij ‘letter’ (bug#24603) Michal Nazarewicz
2017-03-11  9:40     ` Eli Zaretskii
2017-03-16 21:30       ` Michal Nazarewicz
2017-03-17 13:43         ` Eli Zaretskii
2017-03-09 21:51   ` bug#24603: [PATCHv5 09/11] Implement Turkic dotless and dotted i casing rules (bug#24603) Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 10/11] Implement casing rules for Lithuanian (bug#24603) Michal Nazarewicz
2017-03-09 21:51   ` bug#24603: [PATCHv5 11/11] Implement Irish casing rules (bug#24603) Michal Nazarewicz
2017-03-11  9:44     ` Eli Zaretskii
2017-03-16 22:16       ` Michal Nazarewicz
2017-03-17  8:20         ` Eli Zaretskii
2017-03-11 10:00   ` bug#24603: [PATCHv5 00/11] Casing improvements Eli Zaretskii
2017-03-21  1:27   ` bug#24603: [PATCHv6 0/6] Casing improvements, language-independent part Michal Nazarewicz
2017-03-21  1:27     ` bug#24603: [PATCHv6 1/6] Split casify_object into multiple functions Michal Nazarewicz
2017-03-21  1:27     ` bug#24603: [PATCHv6 2/6] Introduce case_character function Michal Nazarewicz
2017-03-21  1:27     ` bug#24603: [PATCHv6 3/6] Add support for title-casing letters (bug#24603) Michal Nazarewicz
2017-03-21  1:27     ` bug#24603: [PATCHv6 4/6] Split up casify_region function (bug#24603) Michal Nazarewicz
2017-03-21  1:27     ` bug#24603: [PATCHv6 5/6] Support casing characters which map into multiple code points (bug#24603) Michal Nazarewicz
2017-03-22 16:06       ` Eli Zaretskii
2017-04-03  9:01         ` Michal Nazarewicz
2017-04-03 14:52           ` Eli Zaretskii
2019-06-25  0:09           ` Lars Ingebrigtsen
2019-06-25  0:29             ` Michał Nazarewicz
2020-08-11 13:46               ` Lars Ingebrigtsen
2021-05-10 11:51                 ` bug#24603: [RFC 00/18] Improvement to casing Lars Ingebrigtsen
2017-03-21  1:27     ` bug#24603: [PATCHv6 6/6] Implement special sigma casing rule (bug#24603) Michal Nazarewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475543441-10493-11-git-send-email-mina86@mina86.com \
    --to=mina86@mina86.com \
    --cc=24603@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).