]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_utf8.h
1. Add doxygen markup for documentation.
[OpenSRF.git] / include / opensrf / osrf_utf8.h
1 /*----------------------------------------------------
2  Desc    : functions and macros for processing UTF-8
3  Author  : Scott McKellar
4  Notes   : 
5
6  Copyright 2008 Scott McKellar
7  All Rights reserved
8  
9  Date       Change
10  ---------- -----------------------------------------
11  2008/11/20 Initial creation
12  ---------------------------------------------------*/
13
14 #ifndef OSRF_UTF8_H
15 #define OSRF_UTF8_H
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 extern unsigned char osrf_utf8_mask_[];  // Lookup table of bitmasks
22
23 // Meanings of the various bit switches:
24
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
33
34 // macros:
35
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 )
44
45 // Equivalent functions, for when you need a function pointer
46
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 );
55
56 // Translate a string, escaping as needed, and append the
57 // result to a growing_buffer
58
59 int buffer_append_utf8( growing_buffer* buf, const char* string );
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 #endif