2 * Copyright (c) 2018 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 * This code is adapted from the Linux Kernel. We have a
18 * userspace version here such that the hashes will match that
28 static int utf8_casefold(const struct nls_table *table,
29 const unsigned char *str, size_t len,
30 unsigned char *dest, size_t dlen)
32 const struct utf8data *data = utf8nfdicf(table->version);
33 struct utf8cursor cur;
36 if (utf8ncursor(&cur, data, str, len) < 0)
39 for (nlen = 0; nlen < dlen; nlen++) {
40 dest[nlen] = utf8byte(&cur);
53 /* Signal invalid sequence */
57 static int utf8_normalize(const struct nls_table *table,
58 const unsigned char *str, size_t len,
59 unsigned char *dest, size_t dlen)
61 const struct utf8data *data = utf8nfdi(table->version);
62 struct utf8cursor cur;
65 if (utf8ncursor(&cur, data, str, len) < 0)
68 for (nlen = 0; nlen < dlen; nlen++) {
69 dest[nlen] = utf8byte(&cur);
82 /* Signal invalid sequence */
86 const static struct nls_ops utf8_ops = {
87 .casefold = utf8_casefold,
88 .normalize = utf8_normalize,
92 const struct nls_table nls_utf8_12_1 = {
94 .version = UNICODE_AGE(12, 1, 0),