2019-05-29 14:18:08 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2019-04-25 17:45:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 SGI.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTF8NORM_H
|
|
|
|
#define UTF8NORM_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/module.h>
|
2021-09-15 07:00:00 +00:00
|
|
|
#include <linux/unicode.h>
|
2019-04-25 17:45:46 +00:00
|
|
|
|
2021-09-15 07:00:05 +00:00
|
|
|
int utf8version_is_supported(const struct unicode_map *um, unsigned int version);
|
2019-04-25 17:45:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the length of the normalized from of the string,
|
|
|
|
* excluding any terminating NULL byte.
|
|
|
|
* Returns 0 if only ignorable code points are present.
|
|
|
|
* Returns -1 if the input is not valid UTF-8.
|
|
|
|
*/
|
2021-09-15 07:00:04 +00:00
|
|
|
ssize_t utf8nlen(const struct unicode_map *um, enum utf8_normalization n,
|
|
|
|
const char *s, size_t len);
|
2019-04-25 17:45:46 +00:00
|
|
|
|
2019-04-25 17:49:18 +00:00
|
|
|
/* Needed in struct utf8cursor below. */
|
|
|
|
#define UTF8HANGULLEAF (12)
|
|
|
|
|
2019-04-25 17:45:46 +00:00
|
|
|
/*
|
|
|
|
* Cursor structure used by the normalizer.
|
|
|
|
*/
|
|
|
|
struct utf8cursor {
|
2021-09-15 07:00:04 +00:00
|
|
|
const struct unicode_map *um;
|
|
|
|
enum utf8_normalization n;
|
2019-04-25 17:45:46 +00:00
|
|
|
const char *s;
|
|
|
|
const char *p;
|
|
|
|
const char *ss;
|
|
|
|
const char *sp;
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int slen;
|
|
|
|
short int ccc;
|
|
|
|
short int nccc;
|
2019-04-25 17:49:18 +00:00
|
|
|
unsigned char hangul[UTF8HANGULLEAF];
|
2019-04-25 17:45:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a utf8cursor to normalize a string.
|
|
|
|
* Returns 0 on success.
|
|
|
|
* Returns -1 on failure.
|
|
|
|
*/
|
2021-09-15 07:00:04 +00:00
|
|
|
int utf8ncursor(struct utf8cursor *u8c, const struct unicode_map *um,
|
|
|
|
enum utf8_normalization n, const char *s, size_t len);
|
2019-04-25 17:45:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the next byte in the normalization.
|
|
|
|
* Returns a value > 0 && < 256 on success.
|
|
|
|
* Returns 0 when the end of the normalization is reached.
|
|
|
|
* Returns -1 if the string being normalized is not valid UTF-8.
|
|
|
|
*/
|
|
|
|
extern int utf8byte(struct utf8cursor *u8c);
|
|
|
|
|
2021-09-15 07:00:05 +00:00
|
|
|
struct utf8data {
|
|
|
|
unsigned int maxage;
|
|
|
|
unsigned int offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct utf8data_table {
|
|
|
|
const unsigned int *utf8agetab;
|
|
|
|
int utf8agetab_size;
|
|
|
|
|
|
|
|
const struct utf8data *utf8nfdicfdata;
|
|
|
|
int utf8nfdicfdata_size;
|
|
|
|
|
|
|
|
const struct utf8data *utf8nfdidata;
|
|
|
|
int utf8nfdidata_size;
|
|
|
|
|
|
|
|
const unsigned char *utf8data;
|
|
|
|
};
|
|
|
|
|
2024-08-09 15:38:53 +00:00
|
|
|
extern const struct utf8data_table utf8_data_table;
|
2021-09-15 07:00:05 +00:00
|
|
|
|
2019-04-25 17:45:46 +00:00
|
|
|
#endif /* UTF8NORM_H */
|