1 /*----------------------------------------------------
2 Desc : functions and macros for processing UTF-8
3 Author : Scott McKellar
6 Copyright 2008 Scott McKellar
10 ---------- -----------------------------------------
11 2008/11/20 Initial creation
12 ---------------------------------------------------*/
17 extern unsigned char osrf_utf8_mask_[]; // Lookup table of bitmasks
19 // Meanings of the various bit switches:
21 #define UTF8_CONTROL 0x01
22 #define UTF8_PRINT 0x02
23 #define UTF8_CONTINUE 0x04
24 #define UTF8_2_BYTE 0x08
25 #define UTF8_3_BYTE 0x10
26 #define UTF8_4_BYTE 0x20
27 #define UTF8_SYNC 0x40
28 #define UTF8_VALID 0x80
32 #define is_utf8_control( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_CONTROL )
33 #define is_utf8_print( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_PRINT )
34 #define is_utf8_continue( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_CONTINUE )
35 #define is_utf8_2_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_2_BYTE )
36 #define is_utf8_3_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_3_BYTE )
37 #define is_utf8_4_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_4_BYTE )
38 #define is_utf8_sync( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_SYNC )
39 #define is_utf8( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_VALID )
41 // Equivalent functions, for when you need a function pointer
43 int is__utf8__control( int c );
44 int is__utf8__print( int c );
45 int is__utf8__continue( int c );
46 int is__utf8__2_byte( int c );
47 int is__utf8__3_byte( int c );
48 int is__utf8__4_byte( int c );
49 int is__utf8__sync( int c );
50 int is__utf8( int c );
52 // Translate a string, escaping as needed, and append the
53 // result to a growing_buffer
55 int buffer_append_utf8( growing_buffer* buf, const char* string );