Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:43:17

0001 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
0002 /* Grapheme cluster breaks in Unicode strings.
0003    Copyright (C) 2010-2026 Free Software Foundation, Inc.
0004    Written by Ben Pfaff <blp@cs.stanford.edu>, 2010.
0005 
0006    This file is free software.
0007    It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
0008    You can redistribute it and/or modify it under either
0009      - the terms of the GNU Lesser General Public License as published
0010        by the Free Software Foundation, either version 3, or (at your
0011        option) any later version, or
0012      - the terms of the GNU General Public License as published by the
0013        Free Software Foundation; either version 2, or (at your option)
0014        any later version, or
0015      - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
0016 
0017    This file is distributed in the hope that it will be useful,
0018    but WITHOUT ANY WARRANTY; without even the implied warranty of
0019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0020    Lesser General Public License and the GNU General Public License
0021    for more details.
0022 
0023    You should have received a copy of the GNU Lesser General Public
0024    License and of the GNU General Public License along with this
0025    program.  If not, see <https://www.gnu.org/licenses/>.  */
0026 
0027 #ifndef _UNIGBRK_H
0028 #define _UNIGBRK_H
0029 
0030 /* Get bool.  */
0031 #include <stdbool.h>
0032 
0033 /* Get size_t. */
0034 #include <stddef.h>
0035 
0036 #include "unitypes.h"
0037 
0038 #ifdef __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /* ========================================================================= */
0043 
0044 /* Property defined in Unicode Standard Annex #29, section "Grapheme Cluster
0045    Boundaries"
0046    <https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries> */
0047 
0048 /* Possible values of the Grapheme_Cluster_Break property.
0049    This enumeration may be extended in the future.  */
0050 enum
0051 {
0052   GBP_OTHER        = 0,
0053   GBP_CR           = 1,
0054   GBP_LF           = 2,
0055   GBP_CONTROL      = 3,
0056   GBP_EXTEND       = 4,
0057   GBP_PREPEND      = 5,
0058   GBP_SPACINGMARK  = 6,
0059   GBP_L            = 7,
0060   GBP_V            = 8,
0061   GBP_T            = 9,
0062   GBP_LV           = 10,
0063   GBP_LVT          = 11,
0064   GBP_RI           = 12,
0065   GBP_ZWJ          = 13,
0066   GBP_EB           = 14, /* obsolete */
0067   GBP_EM           = 15, /* obsolete */
0068   GBP_GAZ          = 16, /* obsolete */
0069   GBP_EBG          = 17  /* obsolete */
0070 };
0071 
0072 /* Return the Grapheme_Cluster_Break property of a Unicode character. */
0073 extern int
0074        uc_graphemeclusterbreak_property (ucs4_t uc)
0075        _UC_ATTRIBUTE_CONST;
0076 
0077 /* ========================================================================= */
0078 
0079 /* Grapheme cluster breaks.  */
0080 
0081 /* Returns true if there is a grapheme cluster boundary between Unicode code
0082    points A and B.  A "grapheme cluster" is an approximation to a
0083    user-perceived character, which sometimes corresponds to multiple code
0084    points.  For example, an English letter followed by an acute accent can be
0085    expressed as two consecutive Unicode code points, but it is perceived by the
0086    user as only a single character and therefore constitutes a single grapheme
0087    cluster.
0088 
0089    Implements extended (not legacy) grapheme cluster rules, because UAX #29
0090    indicates that they are preferred.
0091 
0092    Note: This function does not work right with syllables in Indic scripts or
0093    emojis, because it does not look at the characters before A and after B.
0094 
0095    Use A == 0 or B == 0 to indicate start of text or end of text,
0096    respectively. */
0097 extern bool
0098        uc_is_grapheme_break (ucs4_t a, ucs4_t b)
0099        _UC_ATTRIBUTE_CONST;
0100 
0101 /* Returns the start of the next grapheme cluster following S, or NULL if the
0102    end of the string has been reached.
0103    Note: These functions do not work right with syllables in Indic scripts or
0104    emojis, because they do not consider the characters before S. */
0105 extern const uint8_t *
0106        u8_grapheme_next (const uint8_t *s, const uint8_t *end)
0107        _UC_ATTRIBUTE_PURE;
0108 extern const uint16_t *
0109        u16_grapheme_next (const uint16_t *s, const uint16_t *end)
0110        _UC_ATTRIBUTE_PURE;
0111 extern const uint32_t *
0112        u32_grapheme_next (const uint32_t *s, const uint32_t *end)
0113        _UC_ATTRIBUTE_PURE;
0114 #ifndef _LIBUNISTRING_NO_CONST_GENERICS
0115 # ifdef __cplusplus
0116 }
0117 # endif
0118 /* Don't silently convert a 'const uintN_t *' to a 'uintN_t *'.  Programmers
0119    want compiler warnings for 'const' related mistakes.  */
0120 # ifdef __cplusplus
0121 template <typename T>
0122   T * u8_grapheme_next_template (T* s, const uint8_t *end);
0123 template <>
0124   inline uint8_t * u8_grapheme_next_template (uint8_t *s, const uint8_t *end)
0125   { return const_cast<uint8_t *>(u8_grapheme_next (s, end)); }
0126 template <>
0127   inline const uint8_t * u8_grapheme_next_template (const uint8_t *s, const uint8_t *end)
0128   { return u8_grapheme_next (s, end); }
0129 #  undef u8_grapheme_next
0130 #  define u8_grapheme_next u8_grapheme_next_template
0131 # elif !defined u8_grapheme_next
0132 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0133        || defined __ICC  || defined __TINYC__ \
0134        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0135 #   define u8_grapheme_next(s,end) \
0136       _Generic ((s), \
0137                 uint8_t *: (uint8_t *) u8_grapheme_next ((s), (end)), \
0138                 default  :             u8_grapheme_next ((s), (end)))
0139 #  endif
0140 # endif
0141 # ifdef __cplusplus
0142 template <typename T>
0143   T * u16_grapheme_next_template (T* s, const uint16_t *end);
0144 template <>
0145   inline uint16_t * u16_grapheme_next_template (uint16_t *s, const uint16_t *end)
0146   { return const_cast<uint16_t *>(u16_grapheme_next (s, end)); }
0147 template <>
0148   inline const uint16_t * u16_grapheme_next_template (const uint16_t *s, const uint16_t *end)
0149   { return u16_grapheme_next (s, end); }
0150 #  undef u16_grapheme_next
0151 #  define u16_grapheme_next u16_grapheme_next_template
0152 # elif !defined u16_grapheme_next
0153 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0154        || defined __ICC  || defined __TINYC__ \
0155        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0156 #   define u16_grapheme_next(s,end) \
0157       _Generic ((s), \
0158                 uint16_t *: (uint16_t *) u16_grapheme_next ((s), (end)), \
0159                 default   :              u16_grapheme_next ((s), (end)))
0160 #  endif
0161 # endif
0162 # ifdef __cplusplus
0163 template <typename T>
0164   T * u32_grapheme_next_template (T* s, const uint32_t *end);
0165 template <>
0166   inline uint32_t * u32_grapheme_next_template (uint32_t *s, const uint32_t *end)
0167   { return const_cast<uint32_t *>(u32_grapheme_next (s, end)); }
0168 template <>
0169   inline const uint32_t * u32_grapheme_next_template (const uint32_t *s, const uint32_t *end)
0170   { return u32_grapheme_next (s, end); }
0171 #  undef u32_grapheme_next
0172 #  define u32_grapheme_next u32_grapheme_next_template
0173 # elif !defined u32_grapheme_next
0174 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0175        || defined __ICC  || defined __TINYC__ \
0176        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0177 #   define u32_grapheme_next(s,end) \
0178       _Generic ((s), \
0179                 uint32_t *: (uint32_t *) u32_grapheme_next ((s), (end)), \
0180                 default   :              u32_grapheme_next ((s), (end)))
0181 #  endif
0182 # endif
0183 # ifdef __cplusplus
0184 extern "C" {
0185 # endif
0186 #endif
0187 
0188 /* Returns the start of the previous grapheme cluster before S, or NULL if the
0189    start of the string has been reached.
0190    Note: These functions do not work right with syllables in Indic scripts or
0191    emojis, because they do not consider the characters at or after S. */
0192 extern const uint8_t *
0193        u8_grapheme_prev (const uint8_t *s, const uint8_t *start)
0194        _UC_ATTRIBUTE_PURE;
0195 extern const uint16_t *
0196        u16_grapheme_prev (const uint16_t *s, const uint16_t *start)
0197        _UC_ATTRIBUTE_PURE;
0198 extern const uint32_t *
0199        u32_grapheme_prev (const uint32_t *s, const uint32_t *start)
0200        _UC_ATTRIBUTE_PURE;
0201 #ifndef _LIBUNISTRING_NO_CONST_GENERICS
0202 # ifdef __cplusplus
0203 }
0204 # endif
0205 /* Don't silently convert a 'const uintN_t *' to a 'uintN_t *'.  Programmers
0206    want compiler warnings for 'const' related mistakes.  */
0207 # ifdef __cplusplus
0208 template <typename T>
0209   T * u8_grapheme_prev_template (T* s, const uint8_t *start);
0210 template <>
0211   inline uint8_t * u8_grapheme_prev_template (uint8_t *s, const uint8_t *start)
0212   { return const_cast<uint8_t *>(u8_grapheme_prev (s, start)); }
0213 template <>
0214   inline const uint8_t * u8_grapheme_prev_template (const uint8_t *s, const uint8_t *start)
0215   { return u8_grapheme_prev (s, start); }
0216 #  undef u8_grapheme_prev
0217 #  define u8_grapheme_prev u8_grapheme_prev_template
0218 # elif !defined u8_grapheme_prev
0219 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0220        || defined __ICC  || defined __TINYC__ \
0221        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0222 #   define u8_grapheme_prev(s,start) \
0223       _Generic ((s), \
0224                 uint8_t *: (uint8_t *) u8_grapheme_prev ((s), (start)), \
0225                 default  :             u8_grapheme_prev ((s), (start)))
0226 #  endif
0227 # endif
0228 # ifdef __cplusplus
0229 template <typename T>
0230   T * u16_grapheme_prev_template (T* s, const uint16_t *start);
0231 template <>
0232   inline uint16_t * u16_grapheme_prev_template (uint16_t *s, const uint16_t *start)
0233   { return const_cast<uint16_t *>(u16_grapheme_prev (s, start)); }
0234 template <>
0235   inline const uint16_t * u16_grapheme_prev_template (const uint16_t *s, const uint16_t *start)
0236   { return u16_grapheme_prev (s, start); }
0237 #  undef u16_grapheme_prev
0238 #  define u16_grapheme_prev u16_grapheme_prev_template
0239 # elif !defined u16_grapheme_prev
0240 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0241        || defined __ICC  || defined __TINYC__ \
0242        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0243 #   define u16_grapheme_prev(s,start) \
0244       _Generic ((s), \
0245                 uint16_t *: (uint16_t *) u16_grapheme_prev ((s), (start)), \
0246                 default   :              u16_grapheme_prev ((s), (start)))
0247 #  endif
0248 # endif
0249 # ifdef __cplusplus
0250 template <typename T>
0251   T * u32_grapheme_prev_template (T* s, const uint32_t *start);
0252 template <>
0253   inline uint32_t * u32_grapheme_prev_template (uint32_t *s, const uint32_t *start)
0254   { return const_cast<uint32_t *>(u32_grapheme_prev (s, start)); }
0255 template <>
0256   inline const uint32_t * u32_grapheme_prev_template (const uint32_t *s, const uint32_t *start)
0257   { return u32_grapheme_prev (s, start); }
0258 #  undef u32_grapheme_prev
0259 #  define u32_grapheme_prev u32_grapheme_prev_template
0260 # elif !defined u32_grapheme_prev
0261 #  if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
0262        || defined __ICC  || defined __TINYC__ \
0263        || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
0264 #   define u32_grapheme_prev(s,start) \
0265       _Generic ((s), \
0266                 uint32_t *: (uint32_t *) u32_grapheme_prev ((s), (start)), \
0267                 default   :              u32_grapheme_prev ((s), (start)))
0268 #  endif
0269 # endif
0270 # ifdef __cplusplus
0271 extern "C" {
0272 # endif
0273 #endif
0274 
0275 /* Determine the grapheme cluster boundaries in S, and store the result at
0276    p[0..n-1].  p[i] = 1 means that a new grapheme cluster begins at s[i].  p[i]
0277    = 0 means that s[i-1] and s[i] are part of the same grapheme cluster.  p[0]
0278    will always be 1.
0279  */
0280 extern void
0281        u8_grapheme_breaks (const uint8_t *s, size_t n, char *p);
0282 extern void
0283        u16_grapheme_breaks (const uint16_t *s, size_t n, char *p);
0284 extern void
0285        u32_grapheme_breaks (const uint32_t *s, size_t n, char *p);
0286 extern void
0287        ulc_grapheme_breaks (const char *s, size_t n, char *p);
0288 extern void
0289        uc_grapheme_breaks (const ucs4_t *s, size_t n, char *p);
0290 
0291 /* ========================================================================= */
0292 
0293 #ifdef __cplusplus
0294 }
0295 #endif
0296 
0297 
0298 #endif /* _UNIGBRK_H */