Thomas Gleixner | 9f80685 | 2019-05-29 07:18:08 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 SGI. |
| 4 | * All rights reserved. |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef UTF8NORM_H |
| 8 | #define UTF8NORM_H |
| 9 | |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/export.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/module.h> |
Christoph Hellwig | 49bd03c | 2021-09-15 09:00:00 +0200 | [diff] [blame] | 14 | #include <linux/unicode.h> |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 15 | |
Christoph Hellwig | 2b3d047 | 2021-09-15 09:00:05 +0200 | [diff] [blame] | 16 | int utf8version_is_supported(const struct unicode_map *um, unsigned int version); |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 17 | |
| 18 | /* |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 19 | * Determine the length of the normalized from of the string, |
| 20 | * excluding any terminating NULL byte. |
| 21 | * Returns 0 if only ignorable code points are present. |
| 22 | * Returns -1 if the input is not valid UTF-8. |
| 23 | */ |
Christoph Hellwig | 6ca99ce | 2021-09-15 09:00:04 +0200 | [diff] [blame] | 24 | ssize_t utf8nlen(const struct unicode_map *um, enum utf8_normalization n, |
| 25 | const char *s, size_t len); |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 26 | |
Olaf Weber | a8384c6 | 2019-04-25 13:49:18 -0400 | [diff] [blame] | 27 | /* Needed in struct utf8cursor below. */ |
| 28 | #define UTF8HANGULLEAF (12) |
| 29 | |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 30 | /* |
| 31 | * Cursor structure used by the normalizer. |
| 32 | */ |
| 33 | struct utf8cursor { |
Christoph Hellwig | 6ca99ce | 2021-09-15 09:00:04 +0200 | [diff] [blame] | 34 | const struct unicode_map *um; |
| 35 | enum utf8_normalization n; |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 36 | const char *s; |
| 37 | const char *p; |
| 38 | const char *ss; |
| 39 | const char *sp; |
| 40 | unsigned int len; |
| 41 | unsigned int slen; |
| 42 | short int ccc; |
| 43 | short int nccc; |
Olaf Weber | a8384c6 | 2019-04-25 13:49:18 -0400 | [diff] [blame] | 44 | unsigned char hangul[UTF8HANGULLEAF]; |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * Initialize a utf8cursor to normalize a string. |
| 49 | * Returns 0 on success. |
| 50 | * Returns -1 on failure. |
| 51 | */ |
Christoph Hellwig | 6ca99ce | 2021-09-15 09:00:04 +0200 | [diff] [blame] | 52 | int utf8ncursor(struct utf8cursor *u8c, const struct unicode_map *um, |
| 53 | enum utf8_normalization n, const char *s, size_t len); |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Get the next byte in the normalization. |
| 57 | * Returns a value > 0 && < 256 on success. |
| 58 | * Returns 0 when the end of the normalization is reached. |
| 59 | * Returns -1 if the string being normalized is not valid UTF-8. |
| 60 | */ |
| 61 | extern int utf8byte(struct utf8cursor *u8c); |
| 62 | |
Christoph Hellwig | 2b3d047 | 2021-09-15 09:00:05 +0200 | [diff] [blame] | 63 | struct utf8data { |
| 64 | unsigned int maxage; |
| 65 | unsigned int offset; |
| 66 | }; |
| 67 | |
| 68 | struct utf8data_table { |
| 69 | const unsigned int *utf8agetab; |
| 70 | int utf8agetab_size; |
| 71 | |
| 72 | const struct utf8data *utf8nfdicfdata; |
| 73 | int utf8nfdicfdata_size; |
| 74 | |
| 75 | const struct utf8data *utf8nfdidata; |
| 76 | int utf8nfdidata_size; |
| 77 | |
| 78 | const unsigned char *utf8data; |
| 79 | }; |
| 80 | |
| 81 | extern struct utf8data_table utf8_data_table; |
| 82 | |
Olaf Weber | 44594c2 | 2019-04-25 13:45:46 -0400 | [diff] [blame] | 83 | #endif /* UTF8NORM_H */ |