| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef LIBUNICODE_H |
| 25 |
#define LIBUNICODE_H |
| 26 |
|
| 27 |
#include <inttypes.h> |
| 28 |
|
| 29 |
#define LRE_BOOL int |
| 30 |
|
| 31 |
|
| 32 |
#define CONFIG_ALL_UNICODE |
| 33 |
|
| 34 |
#define LRE_CC_RES_LEN_MAX 3 |
| 35 |
|
| 36 |
typedef enum { |
| 37 |
UNICODE_NFC, |
| 38 |
UNICODE_NFD, |
| 39 |
UNICODE_NFKC, |
| 40 |
UNICODE_NFKD, |
| 41 |
} UnicodeNormalizationEnum; |
| 42 |
|
| 43 |
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type); |
| 44 |
int lre_canonicalize(uint32_t c, BOOL is_unicode); |
| 45 |
LRE_BOOL lre_is_cased(uint32_t c); |
| 46 |
LRE_BOOL lre_is_case_ignorable(uint32_t c); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
typedef struct { |
| 51 |
int len; |
| 52 |
int size; |
| 53 |
uint32_t *points; |
| 54 |
void *mem_opaque; |
| 55 |
void *(*realloc_func)(void *opaque, void *ptr, size_t size); |
| 56 |
} CharRange; |
| 57 |
|
| 58 |
typedef enum { |
| 59 |
CR_OP_UNION, |
| 60 |
CR_OP_INTER, |
| 61 |
CR_OP_XOR, |
| 62 |
} CharRangeOpEnum; |
| 63 |
|
| 64 |
void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); |
| 65 |
void cr_free(CharRange *cr); |
| 66 |
int cr_realloc(CharRange *cr, int size); |
| 67 |
int cr_copy(CharRange *cr, const CharRange *cr1); |
| 68 |
|
| 69 |
static inline int cr_add_point(CharRange *cr, uint32_t v) |
| 70 |
{ |
| 71 |
if (cr->len >= cr->size) { |
| 72 |
if (cr_realloc(cr, cr->len + 1)) |
| 73 |
return -1; |
| 74 |
} |
| 75 |
cr->points[cr->len++] = v; |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2) |
| 80 |
{ |
| 81 |
if ((cr->len + 2) > cr->size) { |
| 82 |
if (cr_realloc(cr, cr->len + 2)) |
| 83 |
return -1; |
| 84 |
} |
| 85 |
cr->points[cr->len++] = c1; |
| 86 |
cr->points[cr->len++] = c2; |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len); |
| 91 |
|
| 92 |
static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2) |
| 93 |
{ |
| 94 |
uint32_t b_pt[2]; |
| 95 |
b_pt[0] = c1; |
| 96 |
b_pt[1] = c2 + 1; |
| 97 |
return cr_union1(cr, b_pt, 2); |
| 98 |
} |
| 99 |
|
| 100 |
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len, |
| 101 |
const uint32_t *b_pt, int b_len, int op); |
| 102 |
|
| 103 |
int cr_invert(CharRange *cr); |
| 104 |
|
| 105 |
int cr_regexp_canonicalize(CharRange *cr, BOOL is_unicode); |
| 106 |
|
| 107 |
#ifdef CONFIG_ALL_UNICODE |
| 108 |
|
| 109 |
LRE_BOOL lre_is_id_start(uint32_t c); |
| 110 |
LRE_BOOL lre_is_id_continue(uint32_t c); |
| 111 |
|
| 112 |
int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len, |
| 113 |
UnicodeNormalizationEnum n_type, |
| 114 |
void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
int unicode_script(CharRange *cr, |
| 119 |
const char *script_name, LRE_BOOL is_ext); |
| 120 |
int unicode_general_category(CharRange *cr, const char *gc_name); |
| 121 |
int unicode_prop(CharRange *cr, const char *prop_name); |
| 122 |
|
| 123 |
#endif |
| 124 |
|
| 125 |
#undef LRE_BOOL |
| 126 |
|
| 127 |
#endif |