-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathutflib.h
More file actions
68 lines (53 loc) · 1.62 KB
/
utflib.h
File metadata and controls
68 lines (53 loc) · 1.62 KB
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
/*
utflib.h - small unicode conversion library
Copyright (C) 2024 Alibek Omarov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef UTFLIB_H
#define UTFLIB_H
#include STDINT_H
#include <stddef.h>
typedef struct utfstate_s utfstate_t;
extern const uint32_t table_cp1251[64];
// feed utf8 characters one by one
// if it returns 0, feed more
// utfstate_t must be zero initialized
uint32_t Q_DecodeUTF8( utfstate_t *s, uint32_t ch );
uint32_t Q_DecodeUTF16( utfstate_t *s, uint32_t ch );
size_t Q_EncodeUTF8( char dst[4], uint32_t ch );
size_t Q_UTF8Length( const char *s );
// srcsize in byte pairs
size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize );
// function to convert Unicode codepoints into CP1251 or CP1252
uint32_t Q_UnicodeToCP1251( uint32_t uc );
uint32_t Q_UnicodeToCP1252( uint32_t uc );
typedef struct utfstate_s
{
#ifdef __cplusplus
utfstate_s() : uc( 0 ), len( 0 ), k( 0 ) { }
uint32_t Decode( uint8_t ch )
{
return Q_DecodeUTF8( this, ch );
}
uint32_t Decode( uint16_t ch )
{
return Q_DecodeUTF16( this, ch );
}
void Reset()
{
uc = 0;
len = k = 0;
}
#endif // __cplusplus
uint32_t uc;
uint8_t len;
uint8_t k;
} utfstate_t;
#endif // UTFLIB_H