Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

newline.c
Go to the documentation of this file.
1 /* autogenerated. */
2 /* src="transcode-tblgen.rb", len=28460, checksum=51276 */
3 /* src="newline.trans", len=3162, checksum=42485 */
4
5 #include "transcode_data.h"
6
7
8
9 static const unsigned char
10 newline_byte_array[516] = {
11 #define universal_newline_offsets 0
12 0, 255,
13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29
30 #define crlf_newline_offsets 258
31 0, 255,
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48
49 };
50 static const unsigned int
51 newline_word_array[11] = {
52 #define universal_newline_infos WORDINDEX2INFO(0)
53 FUNso,
54
55 #define universal_newline WORDINDEX2INFO(1)
56 universal_newline_offsets,
57 universal_newline_infos,
58
59 #define crlf_newline_infos WORDINDEX2INFO(3)
60 NOMAP, o2(0x0d,0x0a),
61
62 #define crlf_newline WORDINDEX2INFO(5)
63 crlf_newline_offsets,
64 crlf_newline_infos,
65
66 #define cr_newline_infos WORDINDEX2INFO(7)
67 NOMAP, o1(0x0d),
68
69 #define cr_newline WORDINDEX2INFO(9)
70 crlf_newline_offsets,
71 cr_newline_infos,
72
73 };
74 #define TRANSCODE_TABLE_INFO newline_byte_array, 516, newline_word_array, 11, ((int)sizeof(unsigned int))
75
76
77 #define STATE (sp[0])
78 #define NORMAL 0
79 #define JUST_AFTER_CR 1
80
81 /* no way to access this information, yet. */
82 #define NEWLINES_MET (sp[1])
83 #define MET_LF 0x01
84 #define MET_CRLF 0x02
85 #define MET_CR 0x04
86
87 static int
88 universal_newline_init(void *statep)
89 {
90 unsigned char *sp = statep;
91 STATE = NORMAL;
92 NEWLINES_MET = 0;
93 return 0;
94 }
95
96 static ssize_t
97 fun_so_universal_newline(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
98 {
99 unsigned char *sp = statep;
100 int len;
101 if (s[0] == '\n') {
102 if (STATE == NORMAL) {
103 NEWLINES_MET |= MET_LF;
104 }
105 else { /* JUST_AFTER_CR */
106 NEWLINES_MET |= MET_CRLF;
107 }
108 o[0] = '\n';
109 len = 1;
110 STATE = NORMAL;
111 }
112 else {
113 len = 0;
114 if (STATE == JUST_AFTER_CR) {
115 o[0] = '\n';
116 len = 1;
117 NEWLINES_MET |= MET_CR;
118 }
119 if (s[0] == '\r') {
120 STATE = JUST_AFTER_CR;
121 }
122 else {
123 o[len++] = s[0];
124 STATE = NORMAL;
125 }
126 }
127
128 return len;
129 }
130
131 static ssize_t
132 universal_newline_finish(void *statep, unsigned char *o, size_t osize)
133 {
134 unsigned char *sp = statep;
135 int len = 0;
136 if (STATE == JUST_AFTER_CR) {
137 o[0] = '\n';
138 len = 1;
139 NEWLINES_MET |= MET_CR;
140 }
141 STATE = NORMAL;
142 return len;
143 }
144
145 static const rb_transcoder
146 rb_universal_newline = {
147 "", "universal_newline", universal_newline,
148 TRANSCODE_TABLE_INFO,
149 1, /* input_unit_length */
150 1, /* max_input */
151 2, /* max_output */
152 asciicompat_converter, /* asciicompat_type */
153 2, universal_newline_init, universal_newline_init, /* state_size, state_init, state_fini */
154 NULL, NULL, NULL, fun_so_universal_newline,
155 universal_newline_finish
156 };
157
158 static const rb_transcoder
159 rb_crlf_newline = {
160 "", "crlf_newline", crlf_newline,
161 TRANSCODE_TABLE_INFO,
162 1, /* input_unit_length */
163 1, /* max_input */
164 2, /* max_output */
165 asciicompat_converter, /* asciicompat_type */
166 0, NULL, NULL, /* state_size, state_init, state_fini */
167 NULL, NULL, NULL, NULL
168 };
169
170 static const rb_transcoder
171 rb_cr_newline = {
172 "", "cr_newline", cr_newline,
173 TRANSCODE_TABLE_INFO,
174 1, /* input_unit_length */
175 1, /* max_input */
176 1, /* max_output */
177 asciicompat_converter, /* asciicompat_type */
178 0, NULL, NULL, /* state_size, state_init, state_fini */
179 NULL, NULL, NULL, NULL
180 };
181
182 void
183 Init_newline(void)
184 {
185 rb_register_transcoder(&rb_universal_newline);
186 rb_register_transcoder(&rb_crlf_newline);
187 rb_register_transcoder(&rb_cr_newline);
188 }
189
190