1#ifndef TREE_SITTER_UNICODE_H_
2#define TREE_SITTER_UNICODE_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <limits.h>
9#include <stdint.h>
10
11#define U_EXPORT
12#define U_EXPORT2
13#include "unicode/utf8.h"
14#include "unicode/utf16.h"
15
16static const int32_t TS_DECODE_ERROR = U_SENTINEL;
17
18// These functions read one unicode code point from the given string,
19// returning the number of bytes consumed.
20typedef uint32_t (*UnicodeDecodeFunction)(
21 const uint8_t *string,
22 uint32_t length,
23 int32_t *code_point
24);
25
26static inline uint32_t ts_decode_utf8(
27 const uint8_t *string,
28 uint32_t length,
29 int32_t *code_point
30) {
31 uint32_t i = 0;
32 U8_NEXT(string, i, length, *code_point);
33 return i;
34}
35
36static inline uint32_t ts_decode_utf16(
37 const uint8_t *string,
38 uint32_t length,
39 int32_t *code_point
40) {
41 uint32_t i = 0;
42 U16_NEXT(((uint16_t *)string), i, length, *code_point);
43 return i * 2;
44}
45
46#ifdef __cplusplus
47}
48#endif
49
50#endif // TREE_SITTER_UNICODE_H_