-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskt.h
70 lines (53 loc) · 2.33 KB
/
skt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef SKT_H
#define SKT_H
#include <stddef.h>
/* General notes:
* - Strings provided as input to the transliteration functions and to
* skt_sort_key() must be valid UTF-8 and be normalized to NFC or NFKC,
* otherwise they won't be treated correctly.
* - All functions erase the contents of the buffer they are provided as
* argument.
*/
/******************************************************************************
* Metadata.
*****************************************************************************/
#define SKT_NUM_SCHEMES 5
/* All transliteration schemes, lexicographically sorted, NULL-terminated. */
const char *const skt_schemes[SKT_NUM_SCHEMES + 1];
/* Returns a string describing the set of substitutions performed when a given
* transliteration mapping is used.
*/
const char *skt_map_description(const char *input_scheme,
const char *output_scheme);
/******************************************************************************
* Dynamic buffer.
*****************************************************************************/
struct skt_buf {
char *data; /* Buffer contents, nul-terminated. */
size_t size; /* Buffer size, the terminating nul byte not included. */
size_t alloc;
};
/* Initializer. */
#define SKT_BUF_INIT {.data = ""}
/* Destructor. */
void skt_buf_fini(struct skt_buf *buf);
/******************************************************************************
* Main functions.
*****************************************************************************/
/* Creates a sort key for a IAST-encoded string.
* Equivalent to strxfrm(). If the provided string doesn't contain nul bytes,
* the created key won't, too.
*/
void skt_sort_key(struct skt_buf *buf, const char *str, size_t len);
/* A function that transliterates a string.
* Unknown characters are left unchanged. Sequences of characters known the
* transliteration function are replaced with NFC-normalized sequences, which
* are also valid NFKC sequences.
*/
typedef void (*skt_translit)(struct skt_buf *, const char *str, size_t len);
/* Returns a transliteration function for the provided input and output
* schemes. If the requested mapping is not available, 0 is returned.
*/
skt_translit skt_translit_func(const char *input_scheme,
const char *output_scheme);
#endif