Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:56:01

0001 /*
0002  * Copyright (c) 2014-2021 Steven G. Johnson, Jiahao Chen, Peter Colberg, Tony Kelman, Scott P. Jones, and other contributors.
0003  * Copyright (c) 2009 Public Software Group e. V., Berlin, Germany
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0021  * DEALINGS IN THE SOFTWARE.
0022  */
0023 
0024 
0025 /**
0026  * @mainpage
0027  *
0028  * utf8proc is a free/open-source (MIT/expat licensed) C library
0029  * providing Unicode normalization, case-folding, and other operations
0030  * for strings in the UTF-8 encoding, supporting up-to-date Unicode versions.
0031  * See the utf8proc home page (http://julialang.org/utf8proc/)
0032  * for downloads and other information, or the source code on github
0033  * (https://github.com/JuliaLang/utf8proc).
0034  *
0035  * For the utf8proc API documentation, see: @ref utf8proc.h
0036  *
0037  * The features of utf8proc include:
0038  *
0039  * - Transformation of strings (utf8proc_map()) to:
0040  *    - decompose (@ref UTF8PROC_DECOMPOSE) or compose (@ref UTF8PROC_COMPOSE) Unicode combining characters (http://en.wikipedia.org/wiki/Combining_character)
0041  *    - canonicalize Unicode compatibility characters (@ref UTF8PROC_COMPAT)
0042  *    - strip "ignorable" (@ref UTF8PROC_IGNORE) characters, control characters (@ref UTF8PROC_STRIPCC), or combining characters such as accents (@ref UTF8PROC_STRIPMARK)
0043  *    - case-folding (@ref UTF8PROC_CASEFOLD)
0044  * - Unicode normalization: utf8proc_NFD(), utf8proc_NFC(), utf8proc_NFKD(), utf8proc_NFKC()
0045  * - Detecting grapheme boundaries (utf8proc_grapheme_break() and @ref UTF8PROC_CHARBOUND)
0046  * - Character-width computation: utf8proc_charwidth()
0047  * - Classification of characters by Unicode category: utf8proc_category() and utf8proc_category_string()
0048  * - Encode (utf8proc_encode_char()) and decode (utf8proc_iterate()) Unicode codepoints to/from UTF-8.
0049  */
0050 
0051 /** @file */
0052 
0053 #ifndef UTF8PROC_H
0054 #define UTF8PROC_H
0055 
0056 /** @name API version
0057  *
0058  * The utf8proc API version MAJOR.MINOR.PATCH, following
0059  * semantic-versioning rules (http://semver.org) based on API
0060  * compatibility.
0061  *
0062  * This is also returned at runtime by utf8proc_version(); however, the
0063  * runtime version may append a string like "-dev" to the version number
0064  * for prerelease versions.
0065  *
0066  * @note The shared-library version number in the Makefile
0067  *       (and CMakeLists.txt, and MANIFEST) may be different,
0068  *       being based on ABI compatibility rather than API compatibility.
0069  */
0070 /** @{ */
0071 /** The MAJOR version number (increased when backwards API compatibility is broken). */
0072 #define UTF8PROC_VERSION_MAJOR 2
0073 /** The MINOR version number (increased when new functionality is added in a backwards-compatible manner). */
0074 #define UTF8PROC_VERSION_MINOR 10
0075 /** The PATCH version (increased for fixes that do not change the API). */
0076 #define UTF8PROC_VERSION_PATCH 0
0077 /** @} */
0078 
0079 #include <stdlib.h>
0080 
0081 #if defined(_MSC_VER) && _MSC_VER < 1800
0082 // MSVC prior to 2013 lacked stdbool.h and stdint.h
0083 typedef signed char utf8proc_int8_t;
0084 typedef unsigned char utf8proc_uint8_t;
0085 typedef short utf8proc_int16_t;
0086 typedef unsigned short utf8proc_uint16_t;
0087 typedef int utf8proc_int32_t;
0088 typedef unsigned int utf8proc_uint32_t;
0089 #  ifdef _WIN64
0090 typedef __int64 utf8proc_ssize_t;
0091 typedef unsigned __int64 utf8proc_size_t;
0092 #  else
0093 typedef int utf8proc_ssize_t;
0094 typedef unsigned int utf8proc_size_t;
0095 #  endif
0096 #  ifndef __cplusplus
0097 // emulate C99 bool
0098 typedef unsigned char utf8proc_bool;
0099 #    ifndef __bool_true_false_are_defined
0100 #      define false 0
0101 #      define true 1
0102 #      define __bool_true_false_are_defined 1
0103 #    endif
0104 #  else
0105 typedef bool utf8proc_bool;
0106 #  endif
0107 #else
0108 #  include <stddef.h>
0109 #  include <stdbool.h>
0110 #  include <stdint.h>
0111 typedef int8_t utf8proc_int8_t;
0112 typedef uint8_t utf8proc_uint8_t;
0113 typedef int16_t utf8proc_int16_t;
0114 typedef uint16_t utf8proc_uint16_t;
0115 typedef int32_t utf8proc_int32_t;
0116 typedef uint32_t utf8proc_uint32_t;
0117 typedef size_t utf8proc_size_t;
0118 typedef ptrdiff_t utf8proc_ssize_t;
0119 typedef bool utf8proc_bool;
0120 #endif
0121 #include <limits.h>
0122 
0123 #ifdef UTF8PROC_STATIC
0124 #  define UTF8PROC_DLLEXPORT
0125 #else
0126 #  ifdef _WIN32
0127 #    ifdef UTF8PROC_EXPORTS
0128 #      define UTF8PROC_DLLEXPORT __declspec(dllexport)
0129 #    else
0130 #      define UTF8PROC_DLLEXPORT __declspec(dllimport)
0131 #    endif
0132 #  elif __GNUC__ >= 4
0133 #    define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default")))
0134 #  else
0135 #    define UTF8PROC_DLLEXPORT
0136 #  endif
0137 #endif
0138 
0139 #ifdef __cplusplus
0140 extern "C" {
0141 #endif
0142 
0143 /**
0144  * Option flags used by several functions in the library.
0145  */
0146 typedef enum {
0147   /** The given UTF-8 input is NULL terminated. */
0148   UTF8PROC_NULLTERM  = (1<<0),
0149   /** Unicode Versioning Stability has to be respected. */
0150   UTF8PROC_STABLE    = (1<<1),
0151   /** Compatibility decomposition (i.e. formatting information is lost). */
0152   UTF8PROC_COMPAT    = (1<<2),
0153   /** Return a result with decomposed characters. */
0154   UTF8PROC_COMPOSE   = (1<<3),
0155   /** Return a result with decomposed characters. */
0156   UTF8PROC_DECOMPOSE = (1<<4),
0157   /** Strip "default ignorable characters" such as SOFT-HYPHEN or ZERO-WIDTH-SPACE. */
0158   UTF8PROC_IGNORE    = (1<<5),
0159   /** Return an error, if the input contains unassigned codepoints. */
0160   UTF8PROC_REJECTNA  = (1<<6),
0161   /**
0162    * Indicating that NLF-sequences (LF, CRLF, CR, NEL) are representing a
0163    * line break, and should be converted to the codepoint for line
0164    * separation (LS).
0165    */
0166   UTF8PROC_NLF2LS    = (1<<7),
0167   /**
0168    * Indicating that NLF-sequences are representing a paragraph break, and
0169    * should be converted to the codepoint for paragraph separation
0170    * (PS).
0171    */
0172   UTF8PROC_NLF2PS    = (1<<8),
0173   /** Indicating that the meaning of NLF-sequences is unknown. */
0174   UTF8PROC_NLF2LF    = (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS),
0175   /** Strips and/or convers control characters.
0176    *
0177    * NLF-sequences are transformed into space, except if one of the
0178    * NLF2LS/PS/LF options is given. HorizontalTab (HT) and FormFeed (FF)
0179    * are treated as a NLF-sequence in this case.  All other control
0180    * characters are simply removed.
0181    */
0182   UTF8PROC_STRIPCC   = (1<<9),
0183   /**
0184    * Performs unicode case folding, to be able to do a case-insensitive
0185    * string comparison.
0186    */
0187   UTF8PROC_CASEFOLD  = (1<<10),
0188   /**
0189    * Inserts 0xFF bytes at the beginning of each sequence which is
0190    * representing a single grapheme cluster (see UAX#29).
0191    */
0192   UTF8PROC_CHARBOUND = (1<<11),
0193   /** Lumps certain characters together.
0194    *
0195    * E.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-". See lump.md for details.
0196    *
0197    * If NLF2LF is set, this includes a transformation of paragraph and
0198    * line separators to ASCII line-feed (LF).
0199    */
0200   UTF8PROC_LUMP      = (1<<12),
0201   /** Strips all character markings.
0202    *
0203    * This includes non-spacing, spacing and enclosing (i.e. accents).
0204    * @note This option works only with @ref UTF8PROC_COMPOSE or
0205    *       @ref UTF8PROC_DECOMPOSE
0206    */
0207   UTF8PROC_STRIPMARK = (1<<13),
0208   /**
0209    * Strip unassigned codepoints.
0210    */
0211   UTF8PROC_STRIPNA    = (1<<14),
0212 } utf8proc_option_t;
0213 
0214 /** @name Error codes
0215  * Error codes being returned by almost all functions.
0216  */
0217 /** @{ */
0218 /** Memory could not be allocated. */
0219 #define UTF8PROC_ERROR_NOMEM -1
0220 /** The given string is too long to be processed. */
0221 #define UTF8PROC_ERROR_OVERFLOW -2
0222 /** The given string is not a legal UTF-8 string. */
0223 #define UTF8PROC_ERROR_INVALIDUTF8 -3
0224 /** The @ref UTF8PROC_REJECTNA flag was set and an unassigned codepoint was found. */
0225 #define UTF8PROC_ERROR_NOTASSIGNED -4
0226 /** Invalid options have been used. */
0227 #define UTF8PROC_ERROR_INVALIDOPTS -5
0228 /** @} */
0229 
0230 /* @name Types */
0231 
0232 /** Holds the value of a property. */
0233 typedef utf8proc_int16_t utf8proc_propval_t;
0234 
0235 /** Struct containing information about a codepoint. */
0236 typedef struct utf8proc_property_struct {
0237   /**
0238    * Unicode category.
0239    * @see utf8proc_category_t.
0240    */
0241   utf8proc_propval_t category;
0242   utf8proc_propval_t combining_class;
0243   /**
0244    * Bidirectional class.
0245    * @see utf8proc_bidi_class_t.
0246    */
0247   utf8proc_propval_t bidi_class;
0248   /**
0249    * @anchor Decomposition type.
0250    * @see utf8proc_decomp_type_t.
0251    */
0252   utf8proc_propval_t decomp_type;
0253   utf8proc_uint16_t decomp_seqindex;
0254   utf8proc_uint16_t casefold_seqindex;
0255   utf8proc_uint16_t uppercase_seqindex;
0256   utf8proc_uint16_t lowercase_seqindex;
0257   utf8proc_uint16_t titlecase_seqindex;
0258   /**
0259    * Character combining table.
0260    *
0261    * The character combining table is formally indexed by two
0262    * characters, the first and second character that might form a
0263    * combining pair. The table entry then contains the combined
0264    * character. Most character pairs cannot be combined. There are
0265    * about 1,000 characters that can be the first character in a
0266    * combining pair, and for most, there are only a handful for
0267    * possible second characters.
0268    *
0269    * The combining table is stored as sparse matrix in the CSR
0270    * (compressed sparse row) format. That is, it is stored as two
0271    * arrays, `utf8proc_uint32_t utf8proc_combinations_second[]` and
0272    * `utf8proc_uint32_t utf8proc_combinations_combined[]`. These
0273    * contain the second combining characters and the combined
0274    * character of every combining pair.
0275    *
0276    * - `comb_index`: Index into the combining table if this character
0277    *   is the first character in a combining pair, else 0x3ff
0278    *
0279    * - `comb_length`: Number of table entries for this first character
0280    *
0281    * - `comb_is_second`: As optimization we also record whether this
0282    *   character is the second combining character in any pair. If
0283    *   not, we can skip the table lookup.
0284    *
0285    * A table lookup starts from a given character pair. It first
0286    * checks whether the first character is stored in the table
0287    * (checking whether the index is 0x3ff) and whether the second
0288    * index is stored in the table (looking at `comb_is_second`). If
0289    * so, the `comb_length` table entries will be checked sequentially
0290    * for a match.
0291    */
0292   utf8proc_uint16_t comb_index:10;
0293   utf8proc_uint16_t comb_length:5;
0294   utf8proc_uint16_t comb_issecond:1;
0295   unsigned bidi_mirrored:1;
0296   unsigned comp_exclusion:1;
0297   /**
0298    * Can this codepoint be ignored?
0299    *
0300    * Used by utf8proc_decompose_char() when @ref UTF8PROC_IGNORE is
0301    * passed as an option.
0302    */
0303   unsigned ignorable:1;
0304   unsigned control_boundary:1;
0305   /** The width of the codepoint. */
0306   unsigned charwidth:2;
0307   /** East Asian width class A */
0308   unsigned ambiguous_width:1;
0309   unsigned pad:1;
0310   /**
0311    * Boundclass.
0312    * @see utf8proc_boundclass_t.
0313    */
0314   unsigned boundclass:6;
0315   unsigned indic_conjunct_break:2;
0316 } utf8proc_property_t;
0317 
0318 /** Unicode categories. */
0319 typedef enum {
0320   UTF8PROC_CATEGORY_CN  = 0, /**< Other, not assigned */
0321   UTF8PROC_CATEGORY_LU  = 1, /**< Letter, uppercase */
0322   UTF8PROC_CATEGORY_LL  = 2, /**< Letter, lowercase */
0323   UTF8PROC_CATEGORY_LT  = 3, /**< Letter, titlecase */
0324   UTF8PROC_CATEGORY_LM  = 4, /**< Letter, modifier */
0325   UTF8PROC_CATEGORY_LO  = 5, /**< Letter, other */
0326   UTF8PROC_CATEGORY_MN  = 6, /**< Mark, nonspacing */
0327   UTF8PROC_CATEGORY_MC  = 7, /**< Mark, spacing combining */
0328   UTF8PROC_CATEGORY_ME  = 8, /**< Mark, enclosing */
0329   UTF8PROC_CATEGORY_ND  = 9, /**< Number, decimal digit */
0330   UTF8PROC_CATEGORY_NL = 10, /**< Number, letter */
0331   UTF8PROC_CATEGORY_NO = 11, /**< Number, other */
0332   UTF8PROC_CATEGORY_PC = 12, /**< Punctuation, connector */
0333   UTF8PROC_CATEGORY_PD = 13, /**< Punctuation, dash */
0334   UTF8PROC_CATEGORY_PS = 14, /**< Punctuation, open */
0335   UTF8PROC_CATEGORY_PE = 15, /**< Punctuation, close */
0336   UTF8PROC_CATEGORY_PI = 16, /**< Punctuation, initial quote */
0337   UTF8PROC_CATEGORY_PF = 17, /**< Punctuation, final quote */
0338   UTF8PROC_CATEGORY_PO = 18, /**< Punctuation, other */
0339   UTF8PROC_CATEGORY_SM = 19, /**< Symbol, math */
0340   UTF8PROC_CATEGORY_SC = 20, /**< Symbol, currency */
0341   UTF8PROC_CATEGORY_SK = 21, /**< Symbol, modifier */
0342   UTF8PROC_CATEGORY_SO = 22, /**< Symbol, other */
0343   UTF8PROC_CATEGORY_ZS = 23, /**< Separator, space */
0344   UTF8PROC_CATEGORY_ZL = 24, /**< Separator, line */
0345   UTF8PROC_CATEGORY_ZP = 25, /**< Separator, paragraph */
0346   UTF8PROC_CATEGORY_CC = 26, /**< Other, control */
0347   UTF8PROC_CATEGORY_CF = 27, /**< Other, format */
0348   UTF8PROC_CATEGORY_CS = 28, /**< Other, surrogate */
0349   UTF8PROC_CATEGORY_CO = 29, /**< Other, private use */
0350 } utf8proc_category_t;
0351 
0352 /** Bidirectional character classes. */
0353 typedef enum {
0354   UTF8PROC_BIDI_CLASS_L     = 1, /**< Left-to-Right */
0355   UTF8PROC_BIDI_CLASS_LRE   = 2, /**< Left-to-Right Embedding */
0356   UTF8PROC_BIDI_CLASS_LRO   = 3, /**< Left-to-Right Override */
0357   UTF8PROC_BIDI_CLASS_R     = 4, /**< Right-to-Left */
0358   UTF8PROC_BIDI_CLASS_AL    = 5, /**< Right-to-Left Arabic */
0359   UTF8PROC_BIDI_CLASS_RLE   = 6, /**< Right-to-Left Embedding */
0360   UTF8PROC_BIDI_CLASS_RLO   = 7, /**< Right-to-Left Override */
0361   UTF8PROC_BIDI_CLASS_PDF   = 8, /**< Pop Directional Format */
0362   UTF8PROC_BIDI_CLASS_EN    = 9, /**< European Number */
0363   UTF8PROC_BIDI_CLASS_ES   = 10, /**< European Separator */
0364   UTF8PROC_BIDI_CLASS_ET   = 11, /**< European Number Terminator */
0365   UTF8PROC_BIDI_CLASS_AN   = 12, /**< Arabic Number */
0366   UTF8PROC_BIDI_CLASS_CS   = 13, /**< Common Number Separator */
0367   UTF8PROC_BIDI_CLASS_NSM  = 14, /**< Nonspacing Mark */
0368   UTF8PROC_BIDI_CLASS_BN   = 15, /**< Boundary Neutral */
0369   UTF8PROC_BIDI_CLASS_B    = 16, /**< Paragraph Separator */
0370   UTF8PROC_BIDI_CLASS_S    = 17, /**< Segment Separator */
0371   UTF8PROC_BIDI_CLASS_WS   = 18, /**< Whitespace */
0372   UTF8PROC_BIDI_CLASS_ON   = 19, /**< Other Neutrals */
0373   UTF8PROC_BIDI_CLASS_LRI  = 20, /**< Left-to-Right Isolate */
0374   UTF8PROC_BIDI_CLASS_RLI  = 21, /**< Right-to-Left Isolate */
0375   UTF8PROC_BIDI_CLASS_FSI  = 22, /**< First Strong Isolate */
0376   UTF8PROC_BIDI_CLASS_PDI  = 23, /**< Pop Directional Isolate */
0377 } utf8proc_bidi_class_t;
0378 
0379 /** Decomposition type. */
0380 typedef enum {
0381   UTF8PROC_DECOMP_TYPE_FONT      = 1, /**< Font */
0382   UTF8PROC_DECOMP_TYPE_NOBREAK   = 2, /**< Nobreak */
0383   UTF8PROC_DECOMP_TYPE_INITIAL   = 3, /**< Initial */
0384   UTF8PROC_DECOMP_TYPE_MEDIAL    = 4, /**< Medial */
0385   UTF8PROC_DECOMP_TYPE_FINAL     = 5, /**< Final */
0386   UTF8PROC_DECOMP_TYPE_ISOLATED  = 6, /**< Isolated */
0387   UTF8PROC_DECOMP_TYPE_CIRCLE    = 7, /**< Circle */
0388   UTF8PROC_DECOMP_TYPE_SUPER     = 8, /**< Super */
0389   UTF8PROC_DECOMP_TYPE_SUB       = 9, /**< Sub */
0390   UTF8PROC_DECOMP_TYPE_VERTICAL = 10, /**< Vertical */
0391   UTF8PROC_DECOMP_TYPE_WIDE     = 11, /**< Wide */
0392   UTF8PROC_DECOMP_TYPE_NARROW   = 12, /**< Narrow */
0393   UTF8PROC_DECOMP_TYPE_SMALL    = 13, /**< Small */
0394   UTF8PROC_DECOMP_TYPE_SQUARE   = 14, /**< Square */
0395   UTF8PROC_DECOMP_TYPE_FRACTION = 15, /**< Fraction */
0396   UTF8PROC_DECOMP_TYPE_COMPAT   = 16, /**< Compat */
0397 } utf8proc_decomp_type_t;
0398 
0399 /** Boundclass property. (TR29) */
0400 typedef enum {
0401   UTF8PROC_BOUNDCLASS_START              =  0, /**< Start */
0402   UTF8PROC_BOUNDCLASS_OTHER              =  1, /**< Other */
0403   UTF8PROC_BOUNDCLASS_CR                 =  2, /**< Cr */
0404   UTF8PROC_BOUNDCLASS_LF                 =  3, /**< Lf */
0405   UTF8PROC_BOUNDCLASS_CONTROL            =  4, /**< Control */
0406   UTF8PROC_BOUNDCLASS_EXTEND             =  5, /**< Extend */
0407   UTF8PROC_BOUNDCLASS_L                  =  6, /**< L */
0408   UTF8PROC_BOUNDCLASS_V                  =  7, /**< V */
0409   UTF8PROC_BOUNDCLASS_T                  =  8, /**< T */
0410   UTF8PROC_BOUNDCLASS_LV                 =  9, /**< Lv */
0411   UTF8PROC_BOUNDCLASS_LVT                = 10, /**< Lvt */
0412   UTF8PROC_BOUNDCLASS_REGIONAL_INDICATOR = 11, /**< Regional indicator */
0413   UTF8PROC_BOUNDCLASS_SPACINGMARK        = 12, /**< Spacingmark */
0414   UTF8PROC_BOUNDCLASS_PREPEND            = 13, /**< Prepend */
0415   UTF8PROC_BOUNDCLASS_ZWJ                = 14, /**< Zero Width Joiner */
0416 
0417   /* the following are no longer used in Unicode 11, but we keep
0418      the constants here for backward compatibility */
0419   UTF8PROC_BOUNDCLASS_E_BASE             = 15, /**< Emoji Base */
0420   UTF8PROC_BOUNDCLASS_E_MODIFIER         = 16, /**< Emoji Modifier */
0421   UTF8PROC_BOUNDCLASS_GLUE_AFTER_ZWJ     = 17, /**< Glue_After_ZWJ */
0422   UTF8PROC_BOUNDCLASS_E_BASE_GAZ         = 18, /**< E_BASE + GLUE_AFTER_ZJW */
0423 
0424   /* the Extended_Pictographic property is used in the Unicode 11
0425      grapheme-boundary rules, so we store it in the boundclass field */
0426   UTF8PROC_BOUNDCLASS_EXTENDED_PICTOGRAPHIC = 19,
0427   UTF8PROC_BOUNDCLASS_E_ZWG = 20, /* UTF8PROC_BOUNDCLASS_EXTENDED_PICTOGRAPHIC + ZWJ */
0428 } utf8proc_boundclass_t;
0429 
0430 /** Indic_Conjunct_Break property. (TR44) */
0431 typedef enum {
0432   UTF8PROC_INDIC_CONJUNCT_BREAK_NONE = 0,
0433   UTF8PROC_INDIC_CONJUNCT_BREAK_LINKER = 1,
0434   UTF8PROC_INDIC_CONJUNCT_BREAK_CONSONANT = 2,
0435   UTF8PROC_INDIC_CONJUNCT_BREAK_EXTEND = 3,
0436 } utf8proc_indic_conjunct_break_t;
0437 
0438 /**
0439  * Function pointer type passed to utf8proc_map_custom() and
0440  * utf8proc_decompose_custom(), which is used to specify a user-defined
0441  * mapping of codepoints to be applied in conjunction with other mappings.
0442  */
0443 typedef utf8proc_int32_t (*utf8proc_custom_func)(utf8proc_int32_t codepoint, void *data);
0444 
0445 /**
0446  * Array containing the byte lengths of a UTF-8 encoded codepoint based
0447  * on the first byte.
0448  */
0449 UTF8PROC_DLLEXPORT extern const utf8proc_int8_t utf8proc_utf8class[256];
0450 
0451 /**
0452  * Returns the utf8proc API version as a string MAJOR.MINOR.PATCH
0453  * (http://semver.org format), possibly with a "-dev" suffix for
0454  * development versions.
0455  */
0456 UTF8PROC_DLLEXPORT const char *utf8proc_version(void);
0457 
0458 /**
0459  * Returns the utf8proc supported Unicode version as a string MAJOR.MINOR.PATCH.
0460  */
0461 UTF8PROC_DLLEXPORT const char *utf8proc_unicode_version(void);
0462 
0463 /**
0464  * Returns an informative error string for the given utf8proc error code
0465  * (e.g. the error codes returned by utf8proc_map()).
0466  */
0467 UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(utf8proc_ssize_t errcode);
0468 
0469 /**
0470  * Reads a single codepoint from the UTF-8 sequence being pointed to by `str`.
0471  * The maximum number of bytes read is `strlen`, unless `strlen` is
0472  * negative (in which case up to 4 bytes are read).
0473  *
0474  * If a valid codepoint could be read, it is stored in the variable
0475  * pointed to by `codepoint_ref`, otherwise that variable will be set to -1.
0476  * In case of success, the number of bytes read is returned; otherwise, a
0477  * negative error code is returned.
0478  */
0479 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_int32_t *codepoint_ref);
0480 
0481 /**
0482  * Check if a codepoint is valid (regardless of whether it has been
0483  * assigned a value by the current Unicode standard).
0484  *
0485  * @return 1 if the given `codepoint` is valid and otherwise return 0.
0486  */
0487 UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_codepoint_valid(utf8proc_int32_t codepoint);
0488 
0489 /**
0490  * Encodes the codepoint as an UTF-8 string in the byte array pointed
0491  * to by `dst`. This array must be at least 4 bytes long.
0492  *
0493  * In case of success the number of bytes written is returned, and
0494  * otherwise 0 is returned.
0495  *
0496  * This function does not check whether `codepoint` is valid Unicode.
0497  */
0498 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_encode_char(utf8proc_int32_t codepoint, utf8proc_uint8_t *dst);
0499 
0500 /**
0501  * Look up the properties for a given codepoint.
0502  *
0503  * @param codepoint The Unicode codepoint.
0504  *
0505  * @returns
0506  * A pointer to a (constant) struct containing information about
0507  * the codepoint.
0508  * @par
0509  * If the codepoint is unassigned or invalid, a pointer to a special struct is
0510  * returned in which `category` is 0 (@ref UTF8PROC_CATEGORY_CN).
0511  */
0512 UTF8PROC_DLLEXPORT const utf8proc_property_t *utf8proc_get_property(utf8proc_int32_t codepoint);
0513 
0514 /** Decompose a codepoint into an array of codepoints.
0515  *
0516  * @param codepoint the codepoint.
0517  * @param dst the destination buffer.
0518  * @param bufsize the size of the destination buffer.
0519  * @param options one or more of the following flags:
0520  * - @ref UTF8PROC_REJECTNA  - return an error `codepoint` is unassigned
0521  * - @ref UTF8PROC_IGNORE    - strip "default ignorable" codepoints
0522  * - @ref UTF8PROC_CASEFOLD  - apply Unicode casefolding
0523  * - @ref UTF8PROC_COMPAT    - replace certain codepoints with their
0524  *                             compatibility decomposition
0525  * - @ref UTF8PROC_CHARBOUND - insert 0xFF bytes before each grapheme cluster
0526  * - @ref UTF8PROC_LUMP      - lump certain different codepoints together
0527  * - @ref UTF8PROC_STRIPMARK - remove all character marks
0528  * - @ref UTF8PROC_STRIPNA   - remove unassigned codepoints
0529  * @param last_boundclass
0530  * Pointer to an integer variable containing
0531  * the previous codepoint's (boundclass + indic_conjunct_break << 1) if the @ref UTF8PROC_CHARBOUND
0532  * option is used.  If the string is being processed in order, this can be initialized to 0 for
0533  * the beginning of the string, and is thereafter updated automatically.  Otherwise, this parameter is ignored.
0534  *
0535  * @return
0536  * In case of success, the number of codepoints written is returned; in case
0537  * of an error, a negative error code is returned (utf8proc_errmsg()).
0538  * @par
0539  * If the number of written codepoints would be bigger than `bufsize`, the
0540  * required buffer size is returned, while the buffer will be overwritten with
0541  * undefined data.
0542  */
0543 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(
0544   utf8proc_int32_t codepoint, utf8proc_int32_t *dst, utf8proc_ssize_t bufsize,
0545   utf8proc_option_t options, int *last_boundclass
0546 );
0547 
0548 /**
0549  * The same as utf8proc_decompose_char(), but acts on a whole UTF-8
0550  * string and orders the decomposed sequences correctly.
0551  *
0552  * If the @ref UTF8PROC_NULLTERM flag in `options` is set, processing
0553  * will be stopped, when a NULL byte is encountered, otherwise `strlen`
0554  * bytes are processed.  The result (in the form of 32-bit unicode
0555  * codepoints) is written into the buffer being pointed to by
0556  * `buffer` (which must contain at least `bufsize` entries).  In case of
0557  * success, the number of codepoints written is returned; in case of an
0558  * error, a negative error code is returned (utf8proc_errmsg()).
0559  * See utf8proc_decompose_custom() to supply additional transformations.
0560  *
0561  * If the number of written codepoints would be bigger than `bufsize`, the
0562  * required buffer size is returned, while the buffer will be overwritten with
0563  * undefined data.
0564  */
0565 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose(
0566   const utf8proc_uint8_t *str, utf8proc_ssize_t strlen,
0567   utf8proc_int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options
0568 );
0569 
0570 /**
0571  * The same as utf8proc_decompose(), but also takes a `custom_func` mapping function
0572  * that is called on each codepoint in `str` before any other transformations
0573  * (along with a `custom_data` pointer that is passed through to `custom_func`).
0574  * The `custom_func` argument is ignored if it is `NULL`.  See also utf8proc_map_custom().
0575  */
0576 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_custom(
0577   const utf8proc_uint8_t *str, utf8proc_ssize_t strlen,
0578   utf8proc_int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options,
0579   utf8proc_custom_func custom_func, void *custom_data
0580 );
0581 
0582 /**
0583  * Normalizes the sequence of `length` codepoints pointed to by `buffer`
0584  * in-place (i.e., the result is also stored in `buffer`).
0585  *
0586  * @param buffer the (native-endian UTF-32) unicode codepoints to re-encode.
0587  * @param length the length (in codepoints) of the buffer.
0588  * @param options a bitwise or (`|`) of one or more of the following flags:
0589  * - @ref UTF8PROC_NLF2LS  - convert LF, CRLF, CR and NEL into LS
0590  * - @ref UTF8PROC_NLF2PS  - convert LF, CRLF, CR and NEL into PS
0591  * - @ref UTF8PROC_NLF2LF  - convert LF, CRLF, CR and NEL into LF
0592  * - @ref UTF8PROC_STRIPCC - strip or convert all non-affected control characters
0593  * - @ref UTF8PROC_COMPOSE - try to combine decomposed codepoints into composite
0594  *                           codepoints
0595  * - @ref UTF8PROC_STABLE  - prohibit combining characters that would violate
0596  *                           the unicode versioning stability
0597  *
0598  * @return
0599  * In case of success, the length (in codepoints) of the normalized UTF-32 string is
0600  * returned; otherwise, a negative error code is returned (utf8proc_errmsg()).
0601  *
0602  * @warning The entries of the array pointed to by `str` have to be in the
0603  *          range `0x0000` to `0x10FFFF`. Otherwise, the program might crash!
0604  */
0605 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
0606 
0607 /**
0608  * Reencodes the sequence of `length` codepoints pointed to by `buffer`
0609  * UTF-8 data in-place (i.e., the result is also stored in `buffer`).
0610  * Can optionally normalize the UTF-32 sequence prior to UTF-8 conversion.
0611  *
0612  * @param buffer the (native-endian UTF-32) unicode codepoints to re-encode.
0613  * @param length the length (in codepoints) of the buffer.
0614  * @param options a bitwise or (`|`) of one or more of the following flags:
0615  * - @ref UTF8PROC_NLF2LS  - convert LF, CRLF, CR and NEL into LS
0616  * - @ref UTF8PROC_NLF2PS  - convert LF, CRLF, CR and NEL into PS
0617  * - @ref UTF8PROC_NLF2LF  - convert LF, CRLF, CR and NEL into LF
0618  * - @ref UTF8PROC_STRIPCC - strip or convert all non-affected control characters
0619  * - @ref UTF8PROC_COMPOSE - try to combine decomposed codepoints into composite
0620  *                           codepoints
0621  * - @ref UTF8PROC_STABLE  - prohibit combining characters that would violate
0622  *                           the unicode versioning stability
0623  * - @ref UTF8PROC_CHARBOUND - insert 0xFF bytes before each grapheme cluster
0624  *
0625  * @return
0626  * In case of success, the length (in bytes) of the resulting nul-terminated
0627  * UTF-8 string is returned; otherwise, a negative error code is returned
0628  * (utf8proc_errmsg()).
0629  *
0630  * @warning The amount of free space pointed to by `buffer` must
0631  *          exceed the amount of the input data by one byte, and the
0632  *          entries of the array pointed to by `str` have to be in the
0633  *          range `0x0000` to `0x10FFFF`. Otherwise, the program might crash!
0634  */
0635 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_reencode(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options);
0636 
0637 /**
0638  * Given a pair of consecutive codepoints, return whether a grapheme break is
0639  * permitted between them (as defined by the extended grapheme clusters in UAX#29).
0640  *
0641  * @param codepoint1 The first codepoint.
0642  * @param codepoint2 The second codepoint, occurring consecutively after `codepoint1`.
0643  * @param state Beginning with Version 29 (Unicode 9.0.0), this algorithm requires
0644  *              state to break graphemes. This state can be passed in as a pointer
0645  *              in the `state` argument and should initially be set to 0. If the
0646  *              state is not passed in (i.e. a null pointer is passed), UAX#29 rules
0647  *              GB10/12/13 which require this state will not be applied, essentially
0648  *              matching the rules in Unicode 8.0.0.
0649  *
0650  * @warning If the state parameter is used, `utf8proc_grapheme_break_stateful` must
0651  *          be called IN ORDER on ALL potential breaks in a string.  However, it
0652  *          is safe to reset the state to zero after a grapheme break.
0653  */
0654 UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_grapheme_break_stateful(
0655     utf8proc_int32_t codepoint1, utf8proc_int32_t codepoint2, utf8proc_int32_t *state);
0656 
0657 /**
0658  * Same as utf8proc_grapheme_break_stateful(), except without support for the
0659  * Unicode 9 additions to the algorithm. Supported for legacy reasons.
0660  */
0661 UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_grapheme_break(
0662     utf8proc_int32_t codepoint1, utf8proc_int32_t codepoint2);
0663 
0664 
0665 /**
0666  * Given a codepoint `c`, return the codepoint of the corresponding
0667  * lower-case character, if any; otherwise (if there is no lower-case
0668  * variant, or if `c` is not a valid codepoint) return `c`.
0669  */
0670 UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_tolower(utf8proc_int32_t c);
0671 
0672 /**
0673  * Given a codepoint `c`, return the codepoint of the corresponding
0674  * upper-case character, if any; otherwise (if there is no upper-case
0675  * variant, or if `c` is not a valid codepoint) return `c`.
0676  */
0677 UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_toupper(utf8proc_int32_t c);
0678 
0679 /**
0680  * Given a codepoint `c`, return the codepoint of the corresponding
0681  * title-case character, if any; otherwise (if there is no title-case
0682  * variant, or if `c` is not a valid codepoint) return `c`.
0683  */
0684 UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_totitle(utf8proc_int32_t c);
0685 
0686 /**
0687  * Given a codepoint `c`, return `1` if the codepoint corresponds to a lower-case character
0688  * and `0` otherwise.
0689  */
0690 UTF8PROC_DLLEXPORT int utf8proc_islower(utf8proc_int32_t c);
0691 
0692 /**
0693  * Given a codepoint `c`, return `1` if the codepoint corresponds to an upper-case character
0694  * and `0` otherwise.
0695  */
0696 UTF8PROC_DLLEXPORT int utf8proc_isupper(utf8proc_int32_t c);
0697 
0698 /**
0699  * Given a codepoint, return a character width analogous to `wcwidth(codepoint)`,
0700  * except that a width of 0 is returned for non-printable codepoints
0701  * instead of -1 as in `wcwidth`.
0702  *
0703  * @note
0704  * If you want to check for particular types of non-printable characters,
0705  * (analogous to `isprint` or `iscntrl`), use utf8proc_category(). */
0706 UTF8PROC_DLLEXPORT int utf8proc_charwidth(utf8proc_int32_t codepoint);
0707 
0708 /**
0709  * Given a codepoint, return whether it has East Asian width class A (Ambiguous)
0710  *
0711  * Codepoints with this property are considered to have charwidth 1 (if they are printable)
0712  * but some East Asian fonts render them as double width.
0713  */
0714 UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_charwidth_ambiguous(utf8proc_int32_t codepoint);
0715 
0716 /**
0717  * Return the Unicode category for the codepoint (one of the
0718  * @ref utf8proc_category_t constants.)
0719  */
0720 UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t codepoint);
0721 
0722 /**
0723  * Return the two-letter (nul-terminated) Unicode category string for
0724  * the codepoint (e.g. `"Lu"` or `"Co"`).
0725  */
0726 UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t codepoint);
0727 
0728 /**
0729  * Maps the given UTF-8 string pointed to by `str` to a new UTF-8
0730  * string, allocated dynamically by `malloc` and returned via `dstptr`.
0731  *
0732  * If the @ref UTF8PROC_NULLTERM flag in the `options` field is set,
0733  * the length is determined by a NULL terminator, otherwise the
0734  * parameter `strlen` is evaluated to determine the string length, but
0735  * in any case the result will be NULL terminated (though it might
0736  * contain NULL characters with the string if `str` contained NULL
0737  * characters). Other flags in the `options` field are passed to the
0738  * functions defined above, and regarded as described.  See also
0739  * utf8proc_map_custom() to supply a custom codepoint transformation.
0740  *
0741  * In case of success the length of the new string is returned,
0742  * otherwise a negative error code is returned.
0743  *
0744  * @note The memory of the new UTF-8 string will have been allocated
0745  * with `malloc`, and should therefore be deallocated with `free`.
0746  */
0747 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map(
0748   const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_uint8_t **dstptr, utf8proc_option_t options
0749 );
0750 
0751 /**
0752  * Like utf8proc_map(), but also takes a `custom_func` mapping function
0753  * that is called on each codepoint in `str` before any other transformations
0754  * (along with a `custom_data` pointer that is passed through to `custom_func`).
0755  * The `custom_func` argument is ignored if it is `NULL`.
0756  */
0757 UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map_custom(
0758   const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_uint8_t **dstptr, utf8proc_option_t options,
0759   utf8proc_custom_func custom_func, void *custom_data
0760 );
0761 
0762 /** @name Unicode normalization
0763  *
0764  * Returns a pointer to newly allocated memory of a NFD, NFC, NFKD, NFKC or
0765  * NFKC_Casefold normalized version of the null-terminated string `str`.  These
0766  * are shortcuts to calling utf8proc_map() with @ref UTF8PROC_NULLTERM
0767  * combined with @ref UTF8PROC_STABLE and flags indicating the normalization.
0768  */
0769 /** @{ */
0770 /** NFD normalization (@ref UTF8PROC_DECOMPOSE). */
0771 UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str);
0772 /** NFC normalization (@ref UTF8PROC_COMPOSE). */
0773 UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str);
0774 /** NFKD normalization (@ref UTF8PROC_DECOMPOSE and @ref UTF8PROC_COMPAT). */
0775 UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str);
0776 /** NFKC normalization (@ref UTF8PROC_COMPOSE and @ref UTF8PROC_COMPAT). */
0777 UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str);
0778 /**
0779  * NFKC_Casefold normalization (@ref UTF8PROC_COMPOSE and @ref UTF8PROC_COMPAT
0780  * and @ref UTF8PROC_CASEFOLD and @ref UTF8PROC_IGNORE).
0781  **/
0782 UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC_Casefold(const utf8proc_uint8_t *str);
0783 /** @} */
0784 
0785 #ifdef __cplusplus
0786 }
0787 #endif
0788 
0789 #endif