bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#24603: [RFC 12/18] Implement rules for title-casing Dutch ij ‘letter


From: Michal Nazarewicz
Subject: bug#24603: [RFC 12/18] Implement rules for title-casing Dutch ij ‘letter’
Date: Tue, 4 Oct 2016 03:10:35 +0200

Dutch treats ‘ij’ as a single letter and when capitalising a word it
should be capitalised as a single letter (i.e. ‘ij’ becomes ‘IJ’).
Implement that.

* src/casefiddle.c (casify_context): Add treat_dutch_ij member for
determining whether special handling of ij is necessary.
(prepare_cosify_context): Set treat_dutch_ij to true when in Dutch
locale and capitalising.
(dutch_ij_p_impl, dutch_ij_p, handle_dutch_ij_impl,
handle_dutch_ij): New routines for detecting and handling when ‘ij’
must be upcased together.
(do_casify_multibyte_string, do_casify_unibyte_string,
do_casify_unibyte_region, do_casify_multibyte_region): Implement
handling of Dutch ij.
---
 src/casefiddle.c             | 49 +++++++++++++++++++++++++++++++++++++++++++-
 test/src/casefiddle-tests.el |  6 +++++-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/casefiddle.c b/src/casefiddle.c
index 0377fe6..0de7814 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -66,6 +66,27 @@ struct casing_context {
 #define LT_INS_DOT_ABOVE 3  /* Yes and look out for diacritics combining above
                               because we may need to inject dot above before
                               them. */
+
+  /* In Dutch, ‘ij’ is a digraph and when capitalised the whole thing is upper
+     cased.  Unicode has ‘ij’ and ‘IJ’ (with proper casing mappings) but they
+     aren’t always used so we cannot/should not rely on them.
+
+     Note that rule for capitalising ‘ij’ as a single letter is not present in
+     Unicode 9.0’s SpecialCasing.txt.  On the flip side, Firefox implements 
this
+     as well so we’re not completely alone.
+
+     There are words where ‘ij’ are two separate letters (such as bijectie or
+     bijoux) in which case the capitalisation rules do not apply.  I (mina86)
+     have googled this a little and couldn’t find a Dutch word which beings 
with
+     ‘ij’ that is not a digraph so we should be in the clear since we only care
+     about the initial. */
+
+  /* Whether to apply Dutch rules for title-casing ij as IJ.  Non-zero
+     value implies flag is CASE_CAPITALIZE or CASE_CAPITALIZE_UP. */
+  unsigned char treat_dutch_ij;
+#define NL_OFF 0  /* No */
+#define NL_ON 1  /* Yes */
+#define NL_UPCASE_J 2  /* Yes and the previous character was upcased ‘i’. */
 };
 
 /* Initialise CTX structure and prepares related global data for casing
@@ -74,7 +95,7 @@ static void
 prepare_casing_context (struct casing_context *ctx,
                        enum case_action flag, bool inbuffer)
 {
-  Lisp_Object lang, l, tr, az, lt;
+  Lisp_Object lang, l, tr, az, lt, nl;
 
   ctx->flag = flag;
   ctx->inbuffer = inbuffer;
@@ -85,6 +106,7 @@ prepare_casing_context (struct casing_context *ctx,
 
   ctx->treat_turkic_i = false;
   ctx->lithuanian_tittle = LT_OFF;
+  ctx->treat_dutch_ij = NL_OFF;
 
   /* If the case table is flagged as modified, rescan it.  */
   if (NILP (XCHAR_TABLE (BVAR (current_buffer, downcase_table))->extras[1]))
@@ -98,6 +120,7 @@ prepare_casing_context (struct casing_context *ctx,
   tr = intern_c_string ("tr");
   az = intern_c_string ("az");
   lt = intern_c_string ("lt");
+  nl = intern_c_string ("nl");
   if (SYMBOLP (lang))
     {
       l = lang;
@@ -112,6 +135,8 @@ prepare_casing_context (struct casing_context *ctx,
        ctx->treat_turkic_i = true;
       else if (EQ (l, lt))
        ctx->lithuanian_tittle = LT_ON;
+      else if (EQ (l, nl))
+       ctx->treat_dutch_ij = (int) flag >= (int) CASE_CAPITALIZE;
     }
 }
 
@@ -154,6 +179,28 @@ case_character_impl (struct casing_str_buf *buf,
   ctx->inword = SYNTAX (ch) == Sword &&
     (!ctx->inbuffer || ctx->inword || !syntax_prefix_flag_p (ch));
 
+  /* Handle dutch ij.  We need to do it here before the flag == CASE_NO_ACTION
+     check.  Note that non-zero treat_dutch_ij implies ctx->flag being ≥
+     CASE_CAPITALIZE. */
+  switch (__builtin_expect(ctx->treat_dutch_ij, NL_OFF)) {
+  case NL_ON:
+    if (ch == 'i' && flag == CASE_CAPITALIZE)
+      {
+       ctx->treat_dutch_ij = NL_UPCASE_J;
+       cased = 'I';
+       goto done;
+      }
+    break;
+  case NL_UPCASE_J:
+    ctx->treat_dutch_ij = NL_ON;
+    if (ch == 'j')
+      {
+       cased = 'J';
+       goto done;
+      }
+  }
+
+  /* We are inside of a word and capitalising initials only. */
   if (flag == CASE_NO_ACTION)
     {
       cased = ch;
diff --git a/test/src/casefiddle-tests.el b/test/src/casefiddle-tests.el
index bae4242..3857f08 100644
--- a/test/src/casefiddle-tests.el
+++ b/test/src/casefiddle-tests.el
@@ -210,7 +210,11 @@ casefiddle-tests--characters
               ("j\u0328\u0307"          ; j + ogonek + dot above
                "J\u0328" "j\u0328\u0307" "J\u0328" "J\u0328" 'lt)
               ("į\u0307"                ; i-ogonek + dot above
-               "Į" "į\u0307" "Į" "Į" 'lt))
+               "Į" "į\u0307" "Į" "Į" 'lt)
+
+              ;; Dutch 'ij' is capitalised as single digraph.
+              ("ijsland" "IJSLAND" "ijsland" "Ijsland" "Ijsland")
+              ("ijsland" "IJSLAND" "ijsland" "IJsland" "IJsland" 'nl))
             (nreverse errors))
          (let* ((input (string-to-multibyte (car test)))
                 (expected (cdr test))
-- 
2.8.0.rc3.226.g39d4020






reply via email to

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