Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2014 SGI.
0004  * All rights reserved.
0005  */
0006 
0007 #ifndef UTF8NORM_H
0008 #define UTF8NORM_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/export.h>
0012 #include <linux/string.h>
0013 #include <linux/module.h>
0014 #include <linux/unicode.h>
0015 
0016 int utf8version_is_supported(const struct unicode_map *um, unsigned int version);
0017 
0018 /*
0019  * Determine the length of the normalized from of the string,
0020  * excluding any terminating NULL byte.
0021  * Returns 0 if only ignorable code points are present.
0022  * Returns -1 if the input is not valid UTF-8.
0023  */
0024 ssize_t utf8nlen(const struct unicode_map *um, enum utf8_normalization n,
0025         const char *s, size_t len);
0026 
0027 /* Needed in struct utf8cursor below. */
0028 #define UTF8HANGULLEAF  (12)
0029 
0030 /*
0031  * Cursor structure used by the normalizer.
0032  */
0033 struct utf8cursor {
0034     const struct unicode_map *um;
0035     enum utf8_normalization n;
0036     const char  *s;
0037     const char  *p;
0038     const char  *ss;
0039     const char  *sp;
0040     unsigned int    len;
0041     unsigned int    slen;
0042     short int   ccc;
0043     short int   nccc;
0044     unsigned char   hangul[UTF8HANGULLEAF];
0045 };
0046 
0047 /*
0048  * Initialize a utf8cursor to normalize a string.
0049  * Returns 0 on success.
0050  * Returns -1 on failure.
0051  */
0052 int utf8ncursor(struct utf8cursor *u8c, const struct unicode_map *um,
0053         enum utf8_normalization n, const char *s, size_t len);
0054 
0055 /*
0056  * Get the next byte in the normalization.
0057  * Returns a value > 0 && < 256 on success.
0058  * Returns 0 when the end of the normalization is reached.
0059  * Returns -1 if the string being normalized is not valid UTF-8.
0060  */
0061 extern int utf8byte(struct utf8cursor *u8c);
0062 
0063 struct utf8data {
0064     unsigned int maxage;
0065     unsigned int offset;
0066 };
0067 
0068 struct utf8data_table {
0069     const unsigned int *utf8agetab;
0070     int utf8agetab_size;
0071 
0072     const struct utf8data *utf8nfdicfdata;
0073     int utf8nfdicfdata_size;
0074 
0075     const struct utf8data *utf8nfdidata;
0076     int utf8nfdidata_size;
0077 
0078     const unsigned char *utf8data;
0079 };
0080 
0081 extern struct utf8data_table utf8_data_table;
0082 
0083 #endif /* UTF8NORM_H */