Ruby
2.1.3p242(2014-09-19revision47630)
Main Page
Modules
Data Structures
Files
File List
Globals
transcode_data.h
Go to the documentation of this file.
1
/**********************************************************************
2
3
transcode_data.h -
4
5
$Author: nobu $
6
created at: Mon 10 Dec 2007 14:01:47 JST 2007
7
8
Copyright (C) 2007 Martin Duerst
9
10
**********************************************************************/
11
12
#include "
ruby/ruby.h
"
13
14
#ifndef RUBY_TRANSCODE_DATA_H
15
#define RUBY_TRANSCODE_DATA_H 1
16
17
RUBY_SYMBOL_EXPORT_BEGIN
18
19
#define WORDINDEX_SHIFT_BITS 2
20
#define WORDINDEX2INFO(widx) ((widx) << WORDINDEX_SHIFT_BITS)
21
#define INFO2WORDINDEX(info) ((info) >> WORDINDEX_SHIFT_BITS)
22
#define BYTE_LOOKUP_BASE(bl) ((bl)[0])
23
#define BYTE_LOOKUP_INFO(bl) ((bl)[1])
24
25
#define PType (unsigned int)
26
27
#define NOMAP (PType 0x01)
/* direct map */
28
#define ONEbt (0x02)
/* one byte payload */
29
#define TWObt (0x03)
/* two bytes payload */
30
#define THREEbt (0x05)
/* three bytes payload */
31
#define FOURbt (0x06)
/* four bytes payload, UTF-8 only, macros start at getBT0 */
32
#define INVALID (PType 0x07)
/* invalid byte sequence */
33
#define UNDEF (PType 0x09)
/* legal but undefined */
34
#define ZERObt (PType 0x0A)
/* zero bytes of payload, i.e. remove */
35
#define FUNii (PType 0x0B)
/* function from info to info */
36
#define FUNsi (PType 0x0D)
/* function from start to info */
37
#define FUNio (PType 0x0E)
/* function from info to output */
38
#define FUNso (PType 0x0F)
/* function from start to output */
39
#define STR1 (PType 0x11)
/* string 4 <= len <= 259 bytes: 1byte length + content */
40
#define GB4bt (PType 0x12)
/* GB18030 four bytes payload */
41
#define FUNsio (PType 0x13)
/* function from start and info to output */
42
43
#define STR1_LENGTH(byte_addr) (unsigned int)(*(byte_addr) + 4)
44
#define STR1_BYTEINDEX(w) ((w) >> 6)
45
#define makeSTR1(bi) (((bi) << 6) | STR1)
46
#define makeSTR1LEN(len) ((len)-4)
47
48
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
49
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
50
#define o3(b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned int)(unsigned char)(b3))<<24)|THREEbt)&0xffffffffU))
51
#define o4(b0,b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|((((unsigned char)(b0))&0x07)<<5)|FOURbt)&0xffffffffU))
52
#define g4(b0,b1,b2,b3) (PType(((((unsigned char)(b0))<<8)|(((unsigned char)(b2))<<16)|((((unsigned char)(b1))&0x0f)<<24)|((((unsigned int)(unsigned char)(b3))&0x0f)<<28)|GB4bt)&0xffffffffU))
53
#define funsio(diff) (PType((((unsigned int)(diff))<<8)|FUNsio))
54
55
#define getBT1(a) ((unsigned char)((a)>> 8))
56
#define getBT2(a) ((unsigned char)((a)>>16))
57
#define getBT3(a) ((unsigned char)((a)>>24))
58
#define getBT0(a) (((unsigned char)((a)>> 5)&0x07)|0xF0)
/* for UTF-8 only!!! */
59
60
#define getGB4bt0(a) ((unsigned char)((a)>> 8))
61
#define getGB4bt1(a) (((unsigned char)((a)>>24)&0x0F)|0x30)
62
#define getGB4bt2(a) ((unsigned char)((a)>>16))
63
#define getGB4bt3(a) (((unsigned char)((a)>>28)&0x0F)|0x30)
64
65
#define o2FUNii(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|FUNii))
66
67
/* do we need these??? maybe not, can be done with simple tables */
68
#define ONETRAIL
/* legal but undefined if one more trailing UTF-8 */
69
#define TWOTRAIL
/* legal but undefined if two more trailing UTF-8 */
70
#define THREETRAIL
/* legal but undefined if three more trailing UTF-8 */
71
72
typedef
enum
{
73
asciicompat_converter
,
/* ASCII-compatible -> ASCII-compatible */
74
asciicompat_decoder
,
/* ASCII-incompatible -> ASCII-compatible */
75
asciicompat_encoder
/* ASCII-compatible -> ASCII-incompatible */
76
/* ASCII-incompatible -> ASCII-incompatible is intentionally omitted. */
77
}
rb_transcoder_asciicompat_type_t
;
78
79
typedef
struct
rb_transcoder
rb_transcoder
;
80
81
/* static structure, one per supported encoding pair */
82
struct
rb_transcoder
{
83
const
char
*
src_encoding
;
84
const
char
*
dst_encoding
;
85
unsigned
int
conv_tree_start
;
86
const
unsigned
char
*
byte_array
;
87
unsigned
int
byte_array_length
;
88
const
unsigned
int
*
word_array
;
89
unsigned
int
word_array_length
;
90
int
word_size
;
91
int
input_unit_length
;
92
int
max_input
;
93
int
max_output
;
94
rb_transcoder_asciicompat_type_t
asciicompat_type
;
95
size_t
state_size
;
96
int (*
state_init_func
)(
void
*);
/* ret==0:success ret!=0:failure(errno) */
97
int (*
state_fini_func
)(
void
*);
/* ret==0:success ret!=0:failure(errno) */
98
VALUE
(*
func_ii
)(
void
*,
VALUE
);
/* info -> info */
99
VALUE
(*
func_si
)(
void
*,
const
unsigned
char
*, size_t);
/* start -> info */
100
ssize_t (*
func_io
)(
void
*,
VALUE
,
const
unsigned
char
*, size_t);
/* info -> output */
101
ssize_t (*
func_so
)(
void
*,
const
unsigned
char
*, size_t,
unsigned
char
*, size_t);
/* start -> output */
102
ssize_t (*
finish_func
)(
void
*,
unsigned
char
*, size_t);
/* -> output */
103
ssize_t (*
resetsize_func
)(
void
*);
/* -> len */
104
ssize_t (*
resetstate_func
)(
void
*,
unsigned
char
*, size_t);
/* -> output */
105
ssize_t (*
func_sio
)(
void
*,
const
unsigned
char
*, size_t,
VALUE
,
unsigned
char
*, size_t);
/* start -> output */
106
};
107
108
void
rb_declare_transcoder
(
const
char
*enc1,
const
char
*enc2,
const
char
*lib);
109
void
rb_register_transcoder
(
const
rb_transcoder
*);
110
111
/*
112
* To get rid of collision of initializer symbols in statically-linked encodings
113
* and transcoders
114
*/
115
#if defined(EXTSTATIC) && EXTSTATIC
116
# define TRANS_INIT(name) void Init_trans_ ## name(void)
117
#else
118
# define TRANS_INIT(name) void Init_ ## name(void)
119
#endif
120
121
RUBY_SYMBOL_EXPORT_END
122
123
#endif
/* RUBY_TRANSCODE_DATA_H */
124
Generated on Mon Sep 22 2014 11:05:39 for Ruby by
1.8.2