maint: update copyright
[gnulib.git] / lib / unilbrk / lbrktables.h
1 /* Line breaking auxiliary tables.
2    Copyright (C) 2001-2003, 2006-2014 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2001.
4
5    This program is free software: you can redistribute it and/or modify it
6    under the terms of the GNU Lesser General Public License as published
7    by the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include "unitypes.h"
19
20 /* Line breaking classification.  */
21
22 enum
23 {
24   /* Values >= 25 are resolved at run time. */
25   LBP_BK = 25, /* mandatory break */
26 /*LBP_CR,         carriage return - not used here because it's a DOSism */
27 /*LBP_LF,         line feed - not used here because it's a DOSism */
28   LBP_CM = 26, /* attached characters and combining marks */
29 /*LBP_NL,         next line - not used here because it's equivalent to LBP_BK */
30 /*LBP_SG,         surrogates - not used here because they are not characters */
31   LBP_WJ =  0, /* word joiner */
32   LBP_ZW = 27, /* zero width space */
33   LBP_GL =  1, /* non-breaking (glue) */
34   LBP_SP = 28, /* space */
35   LBP_B2 =  2, /* break opportunity before and after */
36   LBP_BA =  3, /* break opportunity after */
37   LBP_BB =  4, /* break opportunity before */
38   LBP_HY =  5, /* hyphen */
39   LBP_CB = 29, /* contingent break opportunity */
40   LBP_CL =  6, /* closing punctuation */
41   LBP_CP =  7, /* closing parenthesis */
42   LBP_EX =  8, /* exclamation/interrogation */
43   LBP_IN =  9, /* inseparable */
44   LBP_NS = 10, /* non starter */
45   LBP_OP = 11, /* opening punctuation */
46   LBP_QU = 12, /* ambiguous quotation */
47   LBP_IS = 13, /* infix separator (numeric) */
48   LBP_NU = 14, /* numeric */
49   LBP_PO = 15, /* postfix (numeric) */
50   LBP_PR = 16, /* prefix (numeric) */
51   LBP_SY = 17, /* symbols allowing breaks */
52   LBP_AI = 30, /* ambiguous (alphabetic or ideograph) */
53   LBP_AL = 18, /* ordinary alphabetic and symbol characters */
54   LBP_H2 = 19, /* Hangul LV syllable */
55   LBP_H3 = 20, /* Hangul LVT syllable */
56   LBP_ID = 21, /* ideographic */
57   LBP_JL = 22, /* Hangul L Jamo */
58   LBP_JV = 23, /* Hangul V Jamo */
59   LBP_JT = 24, /* Hangul T Jamo */
60   LBP_SA = 31, /* complex context (South East Asian) */
61   LBP_XX = 32  /* unknown */
62 };
63
64 #include "lbrkprop1.h"
65
66 static inline unsigned char
67 unilbrkprop_lookup (ucs4_t uc)
68 {
69   unsigned int index1 = uc >> lbrkprop_header_0;
70   if (index1 < lbrkprop_header_1)
71     {
72       int lookup1 = unilbrkprop.level1[index1];
73       if (lookup1 >= 0)
74         {
75           unsigned int index2 = (uc >> lbrkprop_header_2) & lbrkprop_header_3;
76           int lookup2 = unilbrkprop.level2[lookup1 + index2];
77           if (lookup2 >= 0)
78             {
79               unsigned int index3 = uc & lbrkprop_header_4;
80               return unilbrkprop.level3[lookup2 + index3];
81             }
82         }
83     }
84   return LBP_XX;
85 }
86
87 /* Table indexed by two line breaking classifications.  */
88 #define D 1  /* direct break opportunity, empty in table 7.3 of UTR #14 */
89 #define I 2  /* indirect break opportunity, '%' in table 7.3 of UTR #14 */
90 #define P 3  /* prohibited break,           '^' in table 7.3 of UTR #14 */
91
92 extern const unsigned char unilbrk_table[25][25];
93
94 /* We don't support line breaking of complex-context dependent characters
95    (Thai, Lao, Myanmar, Khmer) yet, because it requires dictionary lookup. */