blob: da7264328630109276d4132208d1a2f4fc91b396 [file] [log] [blame]
Alexander Gutkin439f3d12014-02-28 11:33:45 +00001/*
2 * The authors of this software are Rob Pike and Ken Thompson.
3 * Copyright (c) 2002 by Lucent Technologies.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose without fee is hereby granted, provided that this entire notice
6 * is included in all copies of any software which is or includes a copy
7 * or modification of this software and in all copies of the supporting
8 * documentation for such software.
9 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
Alexander Gutkin96039b72014-03-04 17:22:31 +000010 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
11 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
Alexander Gutkin439f3d12014-02-28 11:33:45 +000012 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
13 */
Alexander Gutkin439f3d12014-02-28 11:33:45 +000014#include "utf.h"
Alexander Gutkin96039b72014-03-04 17:22:31 +000015#include "utfdef.h"
Alexander Gutkin439f3d12014-02-28 11:33:45 +000016
Alexander Gutkin439f3d12014-02-28 11:33:45 +000017static
Alexander Gutkin96039b72014-03-04 17:22:31 +000018Rune*
19rbsearch(Rune c, Rune *t, int n, int ne)
Alexander Gutkin439f3d12014-02-28 11:33:45 +000020{
21 Rune *p;
22 int m;
23
24 while(n > 1) {
Alexander Gutkin96039b72014-03-04 17:22:31 +000025 m = n >> 1;
Alexander Gutkin439f3d12014-02-28 11:33:45 +000026 p = t + m*ne;
27 if(c >= p[0]) {
28 t = p;
29 n = n-m;
30 } else
31 n = m;
32 }
33 if(n && c >= t[0])
34 return t;
35 return 0;
36}
37
Alexander Gutkin96039b72014-03-04 17:22:31 +000038/*
39 * The "ideographic" property is hard to extract from UnicodeData.txt,
40 * so it is hard coded here.
41 *
42 * It is defined in the Unicode PropList.txt file, for example
43 * PropList-3.0.0.txt. Unlike the UnicodeData.txt file, the format of
44 * PropList changes between versions. This property appears relatively static;
45 * it is the same in version 4.0.1, except that version defines some >16 bit
46 * chars as ideographic as well: 20000..2a6d6, and 2f800..2Fa1d.
47 */
48static Rune __isideographicr[] = {
49 0x3006, 0x3007, /* 3006 not in Unicode 2, in 2.1 */
50 0x3021, 0x3029,
51 0x3038, 0x303a, /* not in Unicode 2 or 2.1 */
52 0x3400, 0x4db5, /* not in Unicode 2 or 2.1 */
53 0x4e00, 0x9fbb, /* 0x9FA6..0x9FBB added for 4.1.0? */
54 0xf900, 0xfa2d,
55 0x20000, 0x2A6D6,
56 0x2F800, 0x2FA1D,
57};
Alexander Gutkin439f3d12014-02-28 11:33:45 +000058
59int
Alexander Gutkin96039b72014-03-04 17:22:31 +000060isideographicrune(Rune c)
Alexander Gutkin439f3d12014-02-28 11:33:45 +000061{
62 Rune *p;
63
Alexander Gutkin96039b72014-03-04 17:22:31 +000064 p = rbsearch(c, __isideographicr, nelem(__isideographicr)/2, 2);
Alexander Gutkin439f3d12014-02-28 11:33:45 +000065 if(p && c >= p[0] && c <= p[1])
66 return 1;
Alexander Gutkin439f3d12014-02-28 11:33:45 +000067 return 0;
68}
69
Alexander Gutkin9d00b262014-03-10 16:09:01 +000070#include "runetypebody.h"