Avoid "warning: The macro `AC_DECL_SYS_SIGLIST' is obsolete".
[gnulib.git] / lib / unigbrk.in.h
blob5525a575a0de0a11bc0a256aa3ab9a1dbb8055de
1 /* Grapheme cluster breaks in Unicode strings.
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@cs.stanford.edu>, 2010.
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.
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.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef _UNIGBRK_H
19 #define _UNIGBRK_H
21 /* Get bool. */
22 #include <stdbool.h>
24 /* Get size_t. */
25 #include <stddef.h>
27 #include "unitypes.h"
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 /* ========================================================================= */
35 /* Property defined in Unicode Standard Annex #29, section "Grapheme Cluster
36 Boundaries"
37 <https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries> */
39 /* Possible values of the Grapheme_Cluster_Break property.
40 This enumeration may be extended in the future. */
41 enum
43 GBP_OTHER = 0,
44 GBP_CR = 1,
45 GBP_LF = 2,
46 GBP_CONTROL = 3,
47 GBP_EXTEND = 4,
48 GBP_PREPEND = 5,
49 GBP_SPACINGMARK = 6,
50 GBP_L = 7,
51 GBP_V = 8,
52 GBP_T = 9,
53 GBP_LV = 10,
54 GBP_LVT = 11,
55 GBP_RI = 12,
56 GBP_ZWJ = 13,
57 GBP_EB = 14,
58 GBP_EM = 15,
59 GBP_GAZ = 16,
60 GBP_EBG = 17
63 /* Return the Grapheme_Cluster_Break property of a Unicode character. */
64 extern int
65 uc_graphemeclusterbreak_property (ucs4_t uc)
66 _UC_ATTRIBUTE_CONST;
68 /* ========================================================================= */
70 /* Grapheme cluster breaks. */
72 /* Returns true if there is a grapheme cluster boundary between Unicode code
73 points A and B. A "grapheme cluster" is an approximation to a
74 user-perceived character, which sometimes corresponds to multiple code
75 points. For example, an English letter followed by an acute accent can be
76 expressed as two consecutive Unicode code points, but it is perceived by the
77 user as only a single character and therefore constitutes a single grapheme
78 cluster.
80 Implements extended (not legacy) grapheme cluster rules, because UAX #29
81 indicates that they are preferred.
83 Use A == 0 or B == 0 to indicate start of text or end of text,
84 respectively. */
85 extern bool
86 uc_is_grapheme_break (ucs4_t a, ucs4_t b)
87 _UC_ATTRIBUTE_CONST;
89 /* Returns the start of the next grapheme cluster following S, or NULL if the
90 end of the string has been reached. */
91 extern const uint8_t *
92 u8_grapheme_next (const uint8_t *s, const uint8_t *end)
93 _UC_ATTRIBUTE_PURE;
94 extern const uint16_t *
95 u16_grapheme_next (const uint16_t *s, const uint16_t *end)
96 _UC_ATTRIBUTE_PURE;
97 extern const uint32_t *
98 u32_grapheme_next (const uint32_t *s, const uint32_t *end)
99 _UC_ATTRIBUTE_PURE;
101 /* Returns the start of the previous grapheme cluster before S, or NULL if the
102 start of the string has been reached. */
103 extern const uint8_t *
104 u8_grapheme_prev (const uint8_t *s, const uint8_t *start)
105 _UC_ATTRIBUTE_PURE;
106 extern const uint16_t *
107 u16_grapheme_prev (const uint16_t *s, const uint16_t *start)
108 _UC_ATTRIBUTE_PURE;
109 extern const uint32_t *
110 u32_grapheme_prev (const uint32_t *s, const uint32_t *start)
111 _UC_ATTRIBUTE_PURE;
113 /* Determine the grapheme cluster boundaries in S, and store the result at
114 p[0..n-1]. p[i] = 1 means that a new grapheme cluster begins at s[i]. p[i]
115 = 0 means that s[i-1] and s[i] are part of the same grapheme cluster. p[0]
116 will always be 1.
118 extern void
119 u8_grapheme_breaks (const uint8_t *s, size_t n, char *p);
120 extern void
121 u16_grapheme_breaks (const uint16_t *s, size_t n, char *p);
122 extern void
123 u32_grapheme_breaks (const uint32_t *s, size_t n, char *p);
124 extern void
125 ulc_grapheme_breaks (const char *s, size_t n, char *p);
126 extern void
127 uc_grapheme_breaks (const ucs4_t *s, size_t n, char *p);
129 /* ========================================================================= */
131 #ifdef __cplusplus
133 #endif
136 #endif /* _UNIGBRK_H */