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 ---------------------------------------------------*/
21 extern unsigned char osrf_utf8_mask_[]; // Lookup table of bitmasks
23 // Meanings of the various bit switches:
25 #define UTF8_CONTROL 0x01
26 #define UTF8_PRINT 0x02
27 #define UTF8_CONTINUE 0x04
28 #define UTF8_2_BYTE 0x08
29 #define UTF8_3_BYTE 0x10
30 #define UTF8_4_BYTE 0x20
31 #define UTF8_SYNC 0x40
32 #define UTF8_VALID 0x80
36 #define is_utf8_control( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_CONTROL )
37 #define is_utf8_print( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_PRINT )
38 #define is_utf8_continue( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_CONTINUE )
39 #define is_utf8_2_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_2_BYTE )
40 #define is_utf8_3_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_3_BYTE )
41 #define is_utf8_4_byte( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_4_BYTE )
42 #define is_utf8_sync( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_SYNC )
43 #define is_utf8( x ) ( osrf_utf8_mask_[ (x) & 0xFF ] & UTF8_VALID )
45 // Equivalent functions, for when you need a function pointer
47 int is__utf8__control( int c );
48 int is__utf8__print( int c );
49 int is__utf8__continue( int c );
50 int is__utf8__2_byte( int c );
51 int is__utf8__3_byte( int c );
52 int is__utf8__4_byte( int c );
53 int is__utf8__sync( int c );
54 int is__utf8( int c );
56 // Translate a string, escaping as needed, and append the
57 // result to a growing_buffer
59 int buffer_append_utf8( growing_buffer* buf, const char* string );