]> git.notmuchmail.org Git - notmuch/blob - util/unicode-util.c
Merge branch 'release'
[notmuch] / util / unicode-util.c
1 #include "unicode-util.h"
2
3 /* Based on Xapian::Unicode::is_wordchar, to avoid forcing clients to
4  * link directly to libxapian.
5  */
6
7 static bool
8 unicode_is_wordchar (notmuch_unichar ch)
9 {
10     switch (g_unichar_type (ch)) {
11     case G_UNICODE_UPPERCASE_LETTER:
12     case G_UNICODE_LOWERCASE_LETTER:
13     case G_UNICODE_TITLECASE_LETTER:
14     case G_UNICODE_MODIFIER_LETTER:
15     case G_UNICODE_OTHER_LETTER:
16     case G_UNICODE_NON_SPACING_MARK:
17     case G_UNICODE_ENCLOSING_MARK:
18     case G_UNICODE_SPACING_MARK:
19     case G_UNICODE_DECIMAL_NUMBER:
20     case G_UNICODE_LETTER_NUMBER:
21     case G_UNICODE_OTHER_NUMBER:
22     case G_UNICODE_CONNECT_PUNCTUATION:
23         return true;
24     default:
25         return false;
26     }
27 }
28
29 bool
30 unicode_word_utf8 (const char *utf8_str)
31 {
32     gunichar *decoded = g_utf8_to_ucs4_fast (utf8_str, -1, NULL);
33     const gunichar *p = decoded;
34     bool ret;
35
36     while (*p && unicode_is_wordchar (*p))
37         p++;
38
39     ret =  (*p == '\0');
40
41     g_free (decoded);
42     return ret;
43 }