From: Michal Nazarewicz <mina86@mina86.com>
To: 24378@debbugs.gnu.org
Subject: bug#24378: [PATCH 6/6] Factor out character category lookup to separate function
Date: Tue, 6 Sep 2016 15:31:34 +0200 [thread overview]
Message-ID: <1473168694-13605-6-git-send-email-mina86@mina86.com> (raw)
In-Reply-To: <1473168694-13605-1-git-send-email-mina86@mina86.com>
* src/character.c (char_unicode_category): New function returning Unicode
general category of specified character.
(alphabeticp, alphanumericp, graphicp, printablep): Use the above.
---
src/character.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/character.c b/src/character.c
index b19e41d..18a8fa3 100644
--- a/src/character.c
+++ b/src/character.c
@@ -960,14 +960,18 @@ character is not ASCII nor 8-bit character, an error is signaled. */)
return make_number (c);
}
+static unicode_category_t
+char_unicode_category (int c)
+{
+ Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c);
+ return INTEGERP (category) ? XINT (category) : UNICODE_CATEGORY_UNKNOWN;
+}
+
/* Return true if C is an alphabetic character. */
bool
alphabeticp (int c)
{
- Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c);
- if (! INTEGERP (category))
- return false;
- EMACS_INT gen_cat = XINT (category);
+ unicode_category_t gen_cat = char_unicode_category (c);
/* See UTS #18. There are additional characters that should be
here, those designated as Other_uppercase, Other_lowercase,
@@ -987,10 +991,7 @@ alphabeticp (int c)
bool
alphanumericp (int c)
{
- Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c);
- if (! INTEGERP (category))
- return false;
- EMACS_INT gen_cat = XINT (category);
+ unicode_category_t gen_cat = char_unicode_category (c);
/* See UTS #18. Same comment as for alphabeticp applies. FIXME. */
return (gen_cat == UNICODE_CATEGORY_Lu
@@ -1009,13 +1010,11 @@ alphanumericp (int c)
bool
graphicp (int c)
{
- Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c);
- if (! INTEGERP (category))
- return false;
- EMACS_INT gen_cat = XINT (category);
+ unicode_category_t gen_cat = char_unicode_category (c);
/* See UTS #18. */
- return (!(gen_cat == UNICODE_CATEGORY_Zs /* space separator */
+ return (!(gen_cat == UNICODE_CATEGORY_UNKNOWN
+ || gen_cat == UNICODE_CATEGORY_Zs /* space separator */
|| gen_cat == UNICODE_CATEGORY_Zl /* line separator */
|| gen_cat == UNICODE_CATEGORY_Zp /* paragraph separator */
|| gen_cat == UNICODE_CATEGORY_Cc /* control */
@@ -1027,13 +1026,11 @@ graphicp (int c)
bool
printablep (int c)
{
- Lisp_Object category = CHAR_TABLE_REF (Vunicode_category_table, c);
- if (! INTEGERP (category))
- return false;
- EMACS_INT gen_cat = XINT (category);
+ unicode_category_t gen_cat = char_unicode_category (c);
/* See UTS #18. */
- return (!(gen_cat == UNICODE_CATEGORY_Cc /* control */
+ return (!(gen_cat == UNICODE_CATEGORY_UNKNOWN
+ || gen_cat == UNICODE_CATEGORY_Cc /* control */
|| gen_cat == UNICODE_CATEGORY_Cs /* surrogate */
|| gen_cat == UNICODE_CATEGORY_Cn)); /* unassigned */
}
--
2.8.0.rc3.226.g39d4020
next prev parent reply other threads:[~2016-09-06 13:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 13:28 bug#24378: [PATCH 0/6] Small fixes and improvements Michal Nazarewicz
2016-09-06 13:31 ` bug#24378: [PATCH 1/6] Don’t use FETCH_MULTIBYTE_CHAR when advancing index Michal Nazarewicz
2016-09-06 13:31 ` bug#24378: [PATCH 2/6] Remove inaccurate comment in regex.c Michal Nazarewicz
2016-09-06 13:31 ` bug#24378: [PATCH 3/6] Replace decimalnump with alphanumericp Michal Nazarewicz
2016-09-06 13:31 ` bug#24378: [PATCH 4/6] Remove dead loop iterations in regex.c Michal Nazarewicz
2016-09-06 13:31 ` bug#24378: [PATCH 5/6] Don’t allocate char-table’s extra slots in regexp-out-charset Michal Nazarewicz
2016-09-06 13:31 ` Michal Nazarewicz [this message]
2016-09-06 14:54 ` bug#24378: [PATCH 6/6] Factor out character category lookup to separate function Eli Zaretskii
2016-09-06 15:11 ` Michal Nazarewicz
2016-09-06 15:21 ` Eli Zaretskii
2016-09-06 15:34 ` Eli Zaretskii
2016-09-06 14:43 ` bug#24378: [PATCH 1/6] Don’t use FETCH_MULTIBYTE_CHAR when advancing index Eli Zaretskii
2016-09-06 15:17 ` Michal Nazarewicz
2016-09-06 15:27 ` Eli Zaretskii
2016-09-06 15:24 ` bug#24378: [PATCH] Remove obsolete comment from FETCH_MULTIBYTE_CHAR documentation Michal Nazarewicz
2016-09-09 16:34 ` bug#24378: [PATCH 0/6] Small fixes and improvements 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473168694-13605-6-git-send-email-mina86@mina86.com \
--to=mina86@mina86.com \
--cc=24378@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.