Linux Audio

Check our new training course

Loading...
v6.13.7
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/*
 3 * Copyright (c) 2014 SGI.
 4 * All rights reserved.
 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>
14#include <linux/unicode.h>
15
16int utf8version_is_supported(const struct unicode_map *um, unsigned int version);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18/*
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 */
24ssize_t utf8nlen(const struct unicode_map *um, enum utf8_normalization n,
25		const char *s, size_t len);
26
27/* Needed in struct utf8cursor below. */
28#define UTF8HANGULLEAF	(12)
29
30/*
31 * Cursor structure used by the normalizer.
32 */
33struct utf8cursor {
34	const struct unicode_map *um;
35	enum utf8_normalization n;
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;
44	unsigned char	hangul[UTF8HANGULLEAF];
45};
46
47/*
48 * Initialize a utf8cursor to normalize a string.
49 * Returns 0 on success.
50 * Returns -1 on failure.
51 */
52int utf8ncursor(struct utf8cursor *u8c, const struct unicode_map *um,
53		enum utf8_normalization n, const char *s, size_t len);
 
 
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 */
61extern int utf8byte(struct utf8cursor *u8c);
62
63struct 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 const struct utf8data_table utf8_data_table;
82
83#endif /* UTF8NORM_H */
v5.14.15
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (c) 2014 SGI.
  4 * All rights reserved.
  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>
 
 14
 15/* Encoding a unicode version number as a single unsigned int. */
 16#define UNICODE_MAJ_SHIFT		(16)
 17#define UNICODE_MIN_SHIFT		(8)
 18
 19#define UNICODE_AGE(MAJ, MIN, REV)			\
 20	(((unsigned int)(MAJ) << UNICODE_MAJ_SHIFT) |	\
 21	 ((unsigned int)(MIN) << UNICODE_MIN_SHIFT) |	\
 22	 ((unsigned int)(REV)))
 23
 24/* Highest unicode version supported by the data tables. */
 25extern int utf8version_is_supported(u8 maj, u8 min, u8 rev);
 26extern int utf8version_latest(void);
 27
 28/*
 29 * Look for the correct const struct utf8data for a unicode version.
 30 * Returns NULL if the version requested is too new.
 31 *
 32 * Two normalization forms are supported: nfdi and nfdicf.
 33 *
 34 * nfdi:
 35 *  - Apply unicode normalization form NFD.
 36 *  - Remove any Default_Ignorable_Code_Point.
 37 *
 38 * nfdicf:
 39 *  - Apply unicode normalization form NFD.
 40 *  - Remove any Default_Ignorable_Code_Point.
 41 *  - Apply a full casefold (C + F).
 42 */
 43extern const struct utf8data *utf8nfdi(unsigned int maxage);
 44extern const struct utf8data *utf8nfdicf(unsigned int maxage);
 45
 46/*
 47 * Determine the maximum age of any unicode character in the string.
 48 * Returns 0 if only unassigned code points are present.
 49 * Returns -1 if the input is not valid UTF-8.
 50 */
 51extern int utf8agemax(const struct utf8data *data, const char *s);
 52extern int utf8nagemax(const struct utf8data *data, const char *s, size_t len);
 53
 54/*
 55 * Determine the minimum age of any unicode character in the string.
 56 * Returns 0 if any unassigned code points are present.
 57 * Returns -1 if the input is not valid UTF-8.
 58 */
 59extern int utf8agemin(const struct utf8data *data, const char *s);
 60extern int utf8nagemin(const struct utf8data *data, const char *s, size_t len);
 61
 62/*
 63 * Determine the length of the normalized from of the string,
 64 * excluding any terminating NULL byte.
 65 * Returns 0 if only ignorable code points are present.
 66 * Returns -1 if the input is not valid UTF-8.
 67 */
 68extern ssize_t utf8len(const struct utf8data *data, const char *s);
 69extern ssize_t utf8nlen(const struct utf8data *data, const char *s, size_t len);
 70
 71/* Needed in struct utf8cursor below. */
 72#define UTF8HANGULLEAF	(12)
 73
 74/*
 75 * Cursor structure used by the normalizer.
 76 */
 77struct utf8cursor {
 78	const struct utf8data	*data;
 
 79	const char	*s;
 80	const char	*p;
 81	const char	*ss;
 82	const char	*sp;
 83	unsigned int	len;
 84	unsigned int	slen;
 85	short int	ccc;
 86	short int	nccc;
 87	unsigned char	hangul[UTF8HANGULLEAF];
 88};
 89
 90/*
 91 * Initialize a utf8cursor to normalize a string.
 92 * Returns 0 on success.
 93 * Returns -1 on failure.
 94 */
 95extern int utf8cursor(struct utf8cursor *u8c, const struct utf8data *data,
 96		      const char *s);
 97extern int utf8ncursor(struct utf8cursor *u8c, const struct utf8data *data,
 98		       const char *s, size_t len);
 99
100/*
101 * Get the next byte in the normalization.
102 * Returns a value > 0 && < 256 on success.
103 * Returns 0 when the end of the normalization is reached.
104 * Returns -1 if the string being normalized is not valid UTF-8.
105 */
106extern int utf8byte(struct utf8cursor *u8c);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
108#endif /* UTF8NORM_H */