4
// The size of the input raw buffer.
5
input_raw_buffer_size = 512
7
// The size of the input buffer.
8
// It should be possible to decode the whole raw buffer.
9
input_buffer_size = input_raw_buffer_size * 3
11
// The size of the output buffer.
12
output_buffer_size = 128
14
// The size of the output raw buffer.
15
// It should be possible to encode the whole output buffer.
16
output_raw_buffer_size = (output_buffer_size*2 + 2)
18
// The size of other stacks and queues.
19
initial_stack_size = 16
20
initial_queue_size = 16
21
initial_string_size = 16
24
// Check if the character at the specified position is an alphabetical
25
// character, a digit, '_', or '-'.
26
func is_alpha(b []byte, i int) bool {
27
return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-'
30
// Check if the character at the specified position is a digit.
31
func is_digit(b []byte, i int) bool {
32
return b[i] >= '0' && b[i] <= '9'
35
// Get the value of a digit.
36
func as_digit(b []byte, i int) int {
37
return int(b[i]) - '0'
40
// Check if the character at the specified position is a hex-digit.
41
func is_hex(b []byte, i int) bool {
42
return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f'
45
// Get the value of a hex-digit.
46
func as_hex(b []byte, i int) int {
48
if bi >= 'A' && bi <= 'F' {
49
return int(bi) - 'A' + 10
51
if bi >= 'a' && bi <= 'f' {
52
return int(bi) - 'a' + 10
57
// Check if the character is ASCII.
58
func is_ascii(b []byte, i int) bool {
62
// Check if the character at the start of the buffer can be printed unescaped.
63
func is_printable(b []byte, i int) bool {
64
return ((b[i] == 0x0A) || // . == #x0A
65
(b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E
66
(b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF
67
(b[i] > 0xC2 && b[i] < 0xED) ||
68
(b[i] == 0xED && b[i+1] < 0xA0) ||
70
(b[i] == 0xEF && // #xE000 <= . <= #xFFFD
71
!(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF
72
!(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF))))
75
// Check if the character at the specified position is NUL.
76
func is_z(b []byte, i int) bool {
80
// Check if the beginning of the buffer is a BOM.
81
func is_bom(b []byte, i int) bool {
82
return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF
85
// Check if the character at the specified position is space.
86
func is_space(b []byte, i int) bool {
90
// Check if the character at the specified position is tab.
91
func is_tab(b []byte, i int) bool {
95
// Check if the character at the specified position is blank (space or tab).
96
func is_blank(b []byte, i int) bool {
97
//return is_space(b, i) || is_tab(b, i)
98
return b[i] == ' ' || b[i] == '\t'
101
// Check if the character at the specified position is a line break.
102
func is_break(b []byte, i int) bool {
103
return (b[i] == '\r' || // CR (#xD)
104
b[i] == '\n' || // LF (#xA)
105
b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
106
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
107
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029)
110
func is_crlf(b []byte, i int) bool {
111
return b[i] == '\r' && b[i+1] == '\n'
114
// Check if the character is a line break or NUL.
115
func is_breakz(b []byte, i int) bool {
116
//return is_break(b, i) || is_z(b, i)
117
return ( // is_break:
118
b[i] == '\r' || // CR (#xD)
119
b[i] == '\n' || // LF (#xA)
120
b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
121
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
122
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
127
// Check if the character is a line break, space, or NUL.
128
func is_spacez(b []byte, i int) bool {
129
//return is_space(b, i) || is_breakz(b, i)
130
return ( // is_space:
133
b[i] == '\r' || // CR (#xD)
134
b[i] == '\n' || // LF (#xA)
135
b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
136
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
137
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
141
// Check if the character is a line break, space, tab, or NUL.
142
func is_blankz(b []byte, i int) bool {
143
//return is_blank(b, i) || is_breakz(b, i)
144
return ( // is_blank:
145
b[i] == ' ' || b[i] == '\t' ||
147
b[i] == '\r' || // CR (#xD)
148
b[i] == '\n' || // LF (#xA)
149
b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85)
150
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028)
151
b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029)
155
// Determine the width of the character.
156
func width(b byte) int {
157
// Don't replace these by a switch without first
158
// confirming that it is being inlined.