From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#24603: [RFC 09/18] Implement special sigma casing rule Date: Tue, 4 Oct 2016 03:10:32 +0200 Message-ID: <1475543441-10493-9-git-send-email-mina86@mina86.com> References: <1475543441-10493-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1475543665 15281 195.159.176.226 (4 Oct 2016 01:14:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Oct 2016 01:14:25 +0000 (UTC) To: 24603@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 04 03:14:21 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brEJG-000346-HP for geb-bug-gnu-emacs@m.gmane.org; Tue, 04 Oct 2016 03:14:18 +0200 Original-Received: from localhost ([::1]:39727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brEJH-0008G3-Tj for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Oct 2016 21:14:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brEHD-0006qB-Qh for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2016 21:12:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brEH8-0002WK-K5 for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2016 21:12:11 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brEH8-0002WC-HQ for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2016 21:12:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1brEH8-0006kA-Do for bug-gnu-emacs@gnu.org; Mon, 03 Oct 2016 21:12:06 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 04 Oct 2016 01:12:06 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24603 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24603-submit@debbugs.gnu.org id=B24603.147554347125705 (code B ref 24603); Tue, 04 Oct 2016 01:12:06 +0000 Original-Received: (at 24603) by debbugs.gnu.org; 4 Oct 2016 01:11:11 +0000 Original-Received: from localhost ([127.0.0.1]:43540 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brEGE-0006gO-K6 for submit@debbugs.gnu.org; Mon, 03 Oct 2016 21:11:10 -0400 Original-Received: from mail-wm0-f49.google.com ([74.125.82.49]:36286) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brEG6-0006cg-Kg for 24603@debbugs.gnu.org; Mon, 03 Oct 2016 21:11:05 -0400 Original-Received: by mail-wm0-f49.google.com with SMTP id k125so178183081wma.1 for <24603@debbugs.gnu.org>; Mon, 03 Oct 2016 18:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f4cy8nhghzYQneUFyk3wsYxDU9o9SwsvjM2U2LHHEB8=; b=MZ9oYtOAfRMFLe1ukyX6quUGjxxNca8/ZOBjOnueFNPrfRz/MrkPZ7U2qfNPHW26JE y1qYbPe29tt1gPLHuM3WqNO57pZ+BM94W3FAuIjjntQ16D+cIDCV/G2X1HwZ0apPwq3D HFtQE9faYK0Sx4/uJw9iO8cKb9FZuO/9PDhQzc4gMMi0/TMKwrNrGInkhZmD2B1HhnAM PV1yUCBqdslwjbL7Ul4yDK+hYobkPKl+xmlOC34JiUbMR4K+uGQGvWxmGxhKOgzq72Vl 3B0qiqRCDjVPDhT6pcxX4gnFL9E+AzFLpMV4gSqoIv9aGVRnjqG+WfdImx4oyKKW08Gd 7FvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=f4cy8nhghzYQneUFyk3wsYxDU9o9SwsvjM2U2LHHEB8=; b=b+NznDHRYjtnWrlJzav1Q6nh/iTFw1vK0WbUSbJh2vNtxlGANI7KOTzmD5tEBoFI3C y0pNu5vjAyVgzgBrWmutABHkbvngqWZUaJT3eOQcfWBCpGnf6uq74L8LQk4+in+TJQal RfRG8uu+jpBdTA6t1W18k1jMQJwBAXt+bu6a+NdqYCnYNVpE26gnNAsdE5BsB3sfjgNr wp0V4RcEWlxpqtjL/q4qwZCSoJr2UjTIQmA4mmlB+nbniBf1sRIgRusGs4wWN2tmUGID 999ViQE+CROX1FGh25sFh2CiK5xI/FH7BE+zYbiR7fqaeq7xcC74o+xSJoUkIxFTnW6n /yIQ== X-Gm-Message-State: AA6/9Rmpbwic53qkPab5sHAQNAl8hUV3MdkCaSod3IzgtHflWrFm9jPolKWL62+9kUzA4US6 X-Received: by 10.28.13.66 with SMTP id 63mr11238657wmn.113.1475543456789; Mon, 03 Oct 2016 18:10:56 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([172.16.113.135]) by smtp.gmail.com with ESMTPSA id y4sm1270649wmy.22.2016.10.03.18.10.53 for <24603@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Oct 2016 18:10:54 -0700 (PDT) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id 1ADE11E029D; Tue, 4 Oct 2016 03:10:48 +0200 (CEST) X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1475543441-10493-1-git-send-email-mina86@mina86.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:123995 Archived-At: In Greek, a sigma character has two lower case forms which depend on their position in the word. Implement logic determining it. * src/casefiddle.c (struct casing_context, case_character_impl): Don’t assume inword is true when flag is CASE_UP and false when flag is CASE_DOWN. For final sigma detection we need this information tracked reliably. (CAPITAL_SIGMA, SMALL_SIGMA, SMALL_FINAL_SIGMA): New macros defining Unicode code point of different forms of sigma letter. (do_casify_multibyte_string, do_casify_multibyte_region): Update after changes to case_character. * test/src/casefiddle-tests.el (casefiddle-tests-casing): Add test cases for final sigma. --- etc/NEWS | 4 +++ src/casefiddle.c | 72 +++++++++++++++++++++++++++++++++----------- test/src/casefiddle-tests.el | 15 +++++---- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 3396f9f..4516812 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -247,6 +247,10 @@ of incorrect DŽungla). *** Characters which turn into multiple ones when cased are correctly handled. For example, fi ligature is converted to FI when upper cased. +*** Greek small sigma is correctly handled when at the end of the word. +Strings such as ΌΣΟΣ are now correctly converted to Όσος when +capitalised to follow rules of Greek spelling. + * Changes in Specialized Modes and Packages in Emacs 26.1 diff --git a/src/casefiddle.c b/src/casefiddle.c index 35ff674..ace589c 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c @@ -51,9 +51,7 @@ struct casing_context { When run on a buffer, syntax_prefix_flag_p is taken into account when determined inword flag. */ bool inbuffer; - /* Conceptually, this denotes whether we are inside of a word except - that if flag is CASE_UP it’s always false and if flag is CASE_DOWN - this is always true. */ + /* Whether we are inside of a word. */ bool inword; }; @@ -65,7 +63,7 @@ prepare_casing_context (struct casing_context *ctx, { ctx->flag = flag; ctx->inbuffer = inbuffer; - ctx->inword = flag == CASE_DOWN; + ctx->inword = false; ctx->titlecase_char_table = (int)flag >= (int)CASE_CAPITALIZE ? uniprop_table (intern_c_string ("titlecase")) : Qnil; @@ -95,15 +93,16 @@ case_character_impl (struct casing_str_buf *buf, /* Update inword state */ was_inword = ctx->inword; - if ((int) ctx->flag >= (int) CASE_CAPITALIZE) - ctx->inword = SYNTAX (ch) == Sword && - (!ctx->inbuffer || was_inword || !syntax_prefix_flag_p (ch)); + ctx->inword = SYNTAX (ch) == Sword && + (!ctx->inbuffer || was_inword || !syntax_prefix_flag_p (ch)); /* Normalise flag so its one of CASE_UP, CASE_DOWN or CASE_CAPITALIZE. */ - if (!was_inword) - flag = ctx->flag == CASE_UP ? CASE_UP : CASE_CAPITALIZE; + if (ctx->flag == CASE_CAPITALIZE) + flag = (enum case_action)((int)ctx->flag - was_inword); else if (ctx->flag != CASE_CAPITALIZE_UP) - flag = CASE_DOWN; + flag = ctx->flag; + else if (!was_inword) + flag = CASE_CAPITALIZE; else { cased = ch; @@ -142,7 +141,18 @@ case_character_impl (struct casing_str_buf *buf, buf->len_bytes = CHAR_STRING (cased, buf->data); return cased != ch; } + +/* In Greek, lower case sigma has two forms: one when used in the middle and one + when used at the end of a word. Below is to help handle those cases when + casing. + + The rule does not conflict with any other casing rules so while it is + a conditional one, it is independent on language. */ +#define CAPITAL_SIGMA 0x03A3 +#define SMALL_SIGMA 0x03C3 +#define SMALL_FINAL_SIGMA 0x03C2 + /* Based on CTX, case character CH accordingly. Update CTX as necessary. Return cased character. @@ -156,12 +166,34 @@ case_single_character (struct casing_context *ctx, int ch) } /* Save in BUF result of casing character CH. Return whether casing changed the - character. This is like case_single_character but also handles one-to-many - casing rules. */ -static inline bool -case_character (struct casing_str_buf *buf, struct casing_context *ctx, int ch) + character. + + If not-NULL, NEXT points to the next character in the cased string. If NULL, + it is assumed current character is the last one being cased. This is used to + apply some rules which depend on proceeding state. + + This is like case_single_character but also handles one-to-many casing + rules. */ +static bool +case_character (struct casing_str_buf *buf, struct casing_context *ctx, + int ch, const unsigned char *next) { - return case_character_impl (buf, ctx, ch); + bool changed, was_inword; + + was_inword = ctx->inword; + changed = case_character_impl (buf, ctx, ch); + + /* If we have just down-cased a capital sigma and the next character no longer + has a word syntax (i.e. current character is end of word), use final + sigma. */ + if (was_inword && ch == CAPITAL_SIGMA && changed && + (!next || SYNTAX (STRING_CHAR (next)) != Sword)) + { + buf->len_bytes = CHAR_STRING (SMALL_FINAL_SIGMA, buf->data); + buf->len_chars = 1; + } + + return changed; } static Lisp_Object @@ -223,7 +255,7 @@ do_casify_multibyte_string (struct casing_context *ctx, Lisp_Object obj) if (dst_end - o < sizeof(struct casing_str_buf)) string_overflow (); ch = STRING_CHAR_ADVANCE (src); - case_character ((void *)o, ctx, ch); + case_character ((void *)o, ctx, ch, size > 1 ? src : NULL); n += ((struct casing_str_buf *)o)->len_chars; o += ((struct casing_str_buf *)o)->len_bytes; } @@ -365,13 +397,17 @@ do_casify_multibyte_region (struct casing_context *ctx, ptrdiff_t pos = *startp, pos_byte = CHAR_TO_BYTE (pos), size = *endp - pos; ptrdiff_t opoint = PT, added; struct casing_str_buf buf; - int ch, cased, len; + bool changed; + int ch, len; for (; size; --size) { ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (pos_byte), len); + changed = case_character ( + &buf, ctx, ch, + size > 1 ? BYTE_POS_ADDR (pos_byte + len) : NULL); - if (!case_character (&buf, ctx, ch)) + if (!changed) { pos_byte += len; ++pos; diff --git a/test/src/casefiddle-tests.el b/test/src/casefiddle-tests.el index ae557d7..1bd745e 100644 --- a/test/src/casefiddle-tests.el +++ b/test/src/casefiddle-tests.el @@ -146,13 +146,16 @@ casefiddle-tests--characters ("define" "DEFINE" "define" "Define" "Define") ("fish" "FISH" "fish" "Fish" "Fish") ("Straße" "STRASSE" "straße" "Straße" "Straße") - ;; FIXME: Everything below is broken at the moment. Here’s what - ;; should happen: - ;;("ΌΣΟΣ" "ΌΣΟΣ" "όσος" "Όσος" "Όσος") - ;; And here’s what is actually happening: - ("ΌΣΟΣ" "ΌΣΟΣ" "όσοσ" "Όσοσ" "ΌΣΟΣ") - ("όσος" "ΌΣΟΣ" "όσος" "Όσος" "Όσος")) + ;; The word repeated twice to test behaviour at the end of a word + ;; inside of an input string as well as at the end of the string. + ("ΌΣΟΣ ΌΣΟΣ" "ΌΣΟΣ ΌΣΟΣ" "όσος όσος" "Όσος Όσος" "ΌΣΟΣ ΌΣΟΣ") + ;; What should be done with sole sigma? It is ‘final’ but on the + ;; other hand it does not form a word. Let’s use regular sigma. + ("Σ Σ" "Σ Σ" "σ σ" "Σ Σ" "Σ Σ") + ("όσος" "ΌΣΟΣ" "όσος" "Όσος" "Όσος") + ;; If sigma is already lower case, we don’t want to change it. + ("όσοσ" "ΌΣΟΣ" "όσοσ" "Όσοσ" "Όσοσ")) (nreverse errors)) (let* ((input (car test)) (expected (cdr test)) -- 2.8.0.rc3.226.g39d4020