...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package yaml
24
25 const (
26
27 input_raw_buffer_size = 512
28
29
30
31 input_buffer_size = input_raw_buffer_size * 3
32
33
34 output_buffer_size = 128
35
36
37
38 output_raw_buffer_size = (output_buffer_size*2 + 2)
39
40
41 initial_stack_size = 16
42 initial_queue_size = 16
43 initial_string_size = 16
44 )
45
46
47
48 func is_alpha(b []byte, i int) bool {
49 return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-'
50 }
51
52
53 func is_digit(b []byte, i int) bool {
54 return b[i] >= '0' && b[i] <= '9'
55 }
56
57
58 func as_digit(b []byte, i int) int {
59 return int(b[i]) - '0'
60 }
61
62
63 func is_hex(b []byte, i int) bool {
64 return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f'
65 }
66
67
68 func as_hex(b []byte, i int) int {
69 bi := b[i]
70 if bi >= 'A' && bi <= 'F' {
71 return int(bi) - 'A' + 10
72 }
73 if bi >= 'a' && bi <= 'f' {
74 return int(bi) - 'a' + 10
75 }
76 return int(bi) - '0'
77 }
78
79
80 func is_ascii(b []byte, i int) bool {
81 return b[i] <= 0x7F
82 }
83
84
85 func is_printable(b []byte, i int) bool {
86 return ((b[i] == 0x0A) ||
87 (b[i] >= 0x20 && b[i] <= 0x7E) ||
88 (b[i] == 0xC2 && b[i+1] >= 0xA0) ||
89 (b[i] > 0xC2 && b[i] < 0xED) ||
90 (b[i] == 0xED && b[i+1] < 0xA0) ||
91 (b[i] == 0xEE) ||
92 (b[i] == 0xEF &&
93 !(b[i+1] == 0xBB && b[i+2] == 0xBF) &&
94 !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))))
95 }
96
97
98 func is_z(b []byte, i int) bool {
99 return b[i] == 0x00
100 }
101
102
103 func is_bom(b []byte, i int) bool {
104 return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF
105 }
106
107
108 func is_space(b []byte, i int) bool {
109 return b[i] == ' '
110 }
111
112
113 func is_tab(b []byte, i int) bool {
114 return b[i] == '\t'
115 }
116
117
118 func is_blank(b []byte, i int) bool {
119
120 return b[i] == ' ' || b[i] == '\t'
121 }
122
123
124 func is_break(b []byte, i int) bool {
125 return (b[i] == '\r' ||
126 b[i] == '\n' ||
127 b[i] == 0xC2 && b[i+1] == 0x85 ||
128 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 ||
129 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9)
130 }
131
132 func is_crlf(b []byte, i int) bool {
133 return b[i] == '\r' && b[i+1] == '\n'
134 }
135
136
137 func is_breakz(b []byte, i int) bool {
138
139 return (
140
141 b[i] == '\r' ||
142 b[i] == '\n' ||
143 b[i] == 0xC2 && b[i+1] == 0x85 ||
144 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 ||
145 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 ||
146
147 b[i] == 0)
148 }
149
150
151 func is_spacez(b []byte, i int) bool {
152
153 return (
154
155 b[i] == ' ' ||
156
157 b[i] == '\r' ||
158 b[i] == '\n' ||
159 b[i] == 0xC2 && b[i+1] == 0x85 ||
160 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 ||
161 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 ||
162 b[i] == 0)
163 }
164
165
166 func is_blankz(b []byte, i int) bool {
167
168 return (
169
170 b[i] == ' ' || b[i] == '\t' ||
171
172 b[i] == '\r' ||
173 b[i] == '\n' ||
174 b[i] == 0xC2 && b[i+1] == 0x85 ||
175 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 ||
176 b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 ||
177 b[i] == 0)
178 }
179
180
181 func width(b byte) int {
182
183
184 if b&0x80 == 0x00 {
185 return 1
186 }
187 if b&0xE0 == 0xC0 {
188 return 2
189 }
190 if b&0xF0 == 0xE0 {
191 return 3
192 }
193 if b&0xF8 == 0xF0 {
194 return 4
195 }
196 return 0
197
198 }
199
View as plain text