]> icculus.org git repositories - divverent/darkplaces.git/blob - utf8lib.h
improve sprintf a bit to match with documentation
[divverent/darkplaces.git] / utf8lib.h
1 /*
2  * UTF-8 utility functions for DarkPlaces
3  */
4 #ifndef UTF8LIB_H__
5 #define UTF8LIB_H__
6
7 #include "qtypes.h"
8
9 // types for unicode strings
10 // let them be 32 bit for now
11 // normally, whcar_t is 16 or 32 bit, 16 on linux I think, 32 on haiku and maybe windows
12 #ifdef _MSC_VER
13 #include <stdint.h>
14 typedef __int32 U_int32;
15 #else
16 #include <stdint.h>
17 #include <sys/types.h>
18 typedef int32_t U_int32;
19 #endif
20
21 // Uchar, a wide character
22 typedef U_int32 Uchar;
23
24 // Initialize UTF8, this registers cvars which allows for UTF8 to be disabled
25 // completely.
26 // When UTF8 is disabled, every u8_ function will work exactly as you'd expect
27 // a non-utf8 version to work: u8_strlen() will wrap to strlen()
28 // u8_byteofs() and u8_charidx() will simply return whatever is passed as index parameter
29 // u8_getchar() will will just return the next byte, u8_fromchar will write one byte, ...
30 extern cvar_t    utf8_enable;
31 void   u8_Init(void);
32
33 size_t u8_strlen(const char*);
34 size_t u8_strnlen(const char*, size_t);
35 int    u8_byteofs(const char*, size_t, size_t*);
36 int    u8_charidx(const char*, size_t, size_t*);
37 size_t u8_bytelen(const char*, size_t);
38 size_t u8_prevbyte(const char*, size_t);
39 Uchar  u8_getchar(const char*, const char**);
40 Uchar  u8_getnchar(const char*, const char**, size_t);
41 int    u8_fromchar(Uchar, char*, size_t);
42 size_t u8_wcstombs(char*, const Uchar*, size_t);
43 size_t u8_COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid);
44
45 // returns a static buffer, use this for inlining
46 char  *u8_encodech(Uchar ch, size_t*);
47
48 #endif // UTF8LIB_H__