blob: bd00d587747a7c09b9aa85ce0f97647d28649ee6 [file] [log] [blame]
Thomas Gleixner9f806852019-05-29 07:18:08 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Olaf Weber44594c22019-04-25 13:45:46 -04002/*
3 * Copyright (c) 2014 SGI.
4 * All rights reserved.
Olaf Weber44594c22019-04-25 13:45:46 -04005 */
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 Hellwig49bd03c2021-09-15 09:00:00 +020014#include <linux/unicode.h>
Olaf Weber44594c22019-04-25 13:45:46 -040015
Christoph Hellwig2b3d0472021-09-15 09:00:05 +020016int utf8version_is_supported(const struct unicode_map *um, unsigned int version);
Olaf Weber44594c22019-04-25 13:45:46 -040017
18/*
Olaf Weber44594c22019-04-25 13:45:46 -040019 * 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 Hellwig6ca99ce2021-09-15 09:00:04 +020024ssize_t utf8nlen(const struct unicode_map *um, enum utf8_normalization n,
25 const char *s, size_t len);
Olaf Weber44594c22019-04-25 13:45:46 -040026
Olaf Webera8384c62019-04-25 13:49:18 -040027/* Needed in struct utf8cursor below. */
28#define UTF8HANGULLEAF (12)
29
Olaf Weber44594c22019-04-25 13:45:46 -040030/*
31 * Cursor structure used by the normalizer.
32 */
33struct utf8cursor {
Christoph Hellwig6ca99ce2021-09-15 09:00:04 +020034 const struct unicode_map *um;
35 enum utf8_normalization n;
Olaf Weber44594c22019-04-25 13:45:46 -040036 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 Webera8384c62019-04-25 13:49:18 -040044 unsigned char hangul[UTF8HANGULLEAF];
Olaf Weber44594c22019-04-25 13:45:46 -040045};
46
47/*
48 * Initialize a utf8cursor to normalize a string.
49 * Returns 0 on success.
50 * Returns -1 on failure.
51 */
Christoph Hellwig6ca99ce2021-09-15 09:00:04 +020052int utf8ncursor(struct utf8cursor *u8c, const struct unicode_map *um,
53 enum utf8_normalization n, const char *s, size_t len);
Olaf Weber44594c22019-04-25 13:45:46 -040054
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 */
61extern int utf8byte(struct utf8cursor *u8c);
62
Christoph Hellwig2b3d0472021-09-15 09:00:05 +020063struct utf8data {
64 unsigned int maxage;
65 unsigned int offset;
66};
67
68struct 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
81extern struct utf8data_table utf8_data_table;
82
Olaf Weber44594c22019-04-25 13:45:46 -040083#endif /* UTF8NORM_H */