taps2 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.rdoc → README.md} +29 -22
- data/bin/{schema → schema2} +17 -8
- data/bin/{schema.cmd → schema2.cmd} +0 -0
- data/bin/{taps → taps2} +1 -1
- data/lib/taps/chunksize.rb +16 -12
- data/lib/taps/cli.rb +33 -38
- data/lib/taps/config.rb +2 -2
- data/lib/taps/data_stream.rb +256 -262
- data/lib/taps/errors.rb +1 -1
- data/lib/taps/log.rb +1 -1
- data/lib/taps/monkey.rb +10 -9
- data/lib/taps/multipart.rb +1 -2
- data/lib/taps/operation.rb +81 -86
- data/lib/taps/progress_bar.rb +42 -45
- data/lib/taps/schema.rb +2 -2
- data/lib/taps/server.rb +37 -38
- data/lib/taps/utils.rb +31 -34
- data/lib/taps/version.rb +13 -13
- data/lib/vendor/okjson.rb +115 -161
- data/spec/base.rb +2 -2
- data/spec/chunksize_spec.rb +6 -6
- data/spec/cli_spec.rb +6 -6
- data/spec/data_stream_spec.rb +4 -4
- data/spec/operation_spec.rb +17 -18
- data/spec/server_spec.rb +7 -7
- data/spec/utils_spec.rb +20 -20
- metadata +38 -39
- data/VERSION.yml +0 -5
data/lib/taps/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
1
|
module Taps
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
module Version
|
3
|
+
MAJOR = 0
|
4
|
+
MINOR = 6
|
5
|
+
PATCH = 0
|
6
|
+
BUILD = 0
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def self.current
|
9
|
+
version = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
10
|
+
version += ".#{BUILD}" if BUILD > 0
|
11
|
+
version
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
def self.compatible_version
|
15
|
+
"#{MAJOR}.#{MINOR}"
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
|
-
|
data/lib/vendor/okjson.rb
CHANGED
@@ -41,21 +41,16 @@ module OkJson
|
|
41
41
|
def decode(s)
|
42
42
|
ts = lex(s)
|
43
43
|
v, ts = textparse(ts)
|
44
|
-
|
45
|
-
raise OkJson::ParserError, 'trailing garbage'
|
46
|
-
end
|
44
|
+
raise OkJson::ParserError, 'trailing garbage' unless ts.empty?
|
47
45
|
v
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
48
|
# Parses a "json text" in the sense of RFC 4627.
|
52
49
|
# Returns the parsed value and any trailing tokens.
|
53
50
|
# Note: this is almost the same as valparse,
|
54
51
|
# except that it does not accept atomic values.
|
55
52
|
def textparse(ts)
|
56
|
-
if ts.length < 0
|
57
|
-
raise OkJson::ParserError, 'empty'
|
58
|
-
end
|
53
|
+
raise OkJson::ParserError, 'empty' if ts.length < 0
|
59
54
|
|
60
55
|
typ, _, val = ts[0]
|
61
56
|
case typ
|
@@ -65,41 +60,33 @@ module OkJson
|
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
68
|
-
|
69
63
|
# Parses a "value" in the sense of RFC 4627.
|
70
64
|
# Returns the parsed value and any trailing tokens.
|
71
65
|
def valparse(ts)
|
72
|
-
if ts.length < 0
|
73
|
-
raise OkJson::ParserError, 'empty'
|
74
|
-
end
|
66
|
+
raise OkJson::ParserError, 'empty' if ts.length < 0
|
75
67
|
|
76
68
|
typ, _, val = ts[0]
|
77
69
|
case typ
|
78
70
|
when '{' then objparse(ts)
|
79
71
|
when '[' then arrparse(ts)
|
80
|
-
when :val
|
72
|
+
when :val, :str then [val, ts[1..-1]]
|
81
73
|
else
|
82
74
|
raise OkJson::ParserError, "unexpected #{val.inspect}"
|
83
75
|
end
|
84
76
|
end
|
85
77
|
|
86
|
-
|
87
78
|
# Parses an "object" in the sense of RFC 4627.
|
88
79
|
# Returns the parsed value and any trailing tokens.
|
89
80
|
def objparse(ts)
|
90
81
|
ts = eat('{', ts)
|
91
82
|
obj = {}
|
92
83
|
|
93
|
-
if ts[0][0] == '}'
|
94
|
-
return obj, ts[1..-1]
|
95
|
-
end
|
84
|
+
return obj, ts[1..-1] if ts[0][0] == '}'
|
96
85
|
|
97
86
|
k, v, ts = pairparse(ts)
|
98
87
|
obj[k] = v
|
99
88
|
|
100
|
-
if ts[0][0] == '}'
|
101
|
-
return obj, ts[1..-1]
|
102
|
-
end
|
89
|
+
return obj, ts[1..-1] if ts[0][0] == '}'
|
103
90
|
|
104
91
|
loop do
|
105
92
|
ts = eat(',', ts)
|
@@ -107,42 +94,33 @@ module OkJson
|
|
107
94
|
k, v, ts = pairparse(ts)
|
108
95
|
obj[k] = v
|
109
96
|
|
110
|
-
if ts[0][0] == '}'
|
111
|
-
return obj, ts[1..-1]
|
112
|
-
end
|
97
|
+
return obj, ts[1..-1] if ts[0][0] == '}'
|
113
98
|
end
|
114
99
|
end
|
115
100
|
|
116
|
-
|
117
101
|
# Parses a "member" in the sense of RFC 4627.
|
118
102
|
# Returns the parsed value and any trailing tokens.
|
119
103
|
def pairparse(ts)
|
120
|
-
(typ, _, k)
|
121
|
-
|
122
|
-
|
123
|
-
end
|
104
|
+
(typ, _, k) = ts[0]
|
105
|
+
ts = ts[1..-1]
|
106
|
+
raise OkJson::ParserError, "unexpected #{k.inspect}" if typ != :str
|
124
107
|
ts = eat(':', ts)
|
125
108
|
v, ts = valparse(ts)
|
126
109
|
[k, v, ts]
|
127
110
|
end
|
128
111
|
|
129
|
-
|
130
112
|
# Parses an "array" in the sense of RFC 4627.
|
131
113
|
# Returns the parsed value and any trailing tokens.
|
132
114
|
def arrparse(ts)
|
133
115
|
ts = eat('[', ts)
|
134
116
|
arr = []
|
135
117
|
|
136
|
-
if ts[0][0] == ']'
|
137
|
-
return arr, ts[1..-1]
|
138
|
-
end
|
118
|
+
return arr, ts[1..-1] if ts[0][0] == ']'
|
139
119
|
|
140
120
|
v, ts = valparse(ts)
|
141
121
|
arr << v
|
142
122
|
|
143
|
-
if ts[0][0] == ']'
|
144
|
-
return arr, ts[1..-1]
|
145
|
-
end
|
123
|
+
return arr, ts[1..-1] if ts[0][0] == ']'
|
146
124
|
|
147
125
|
loop do
|
148
126
|
ts = eat(',', ts)
|
@@ -150,13 +128,10 @@ module OkJson
|
|
150
128
|
v, ts = valparse(ts)
|
151
129
|
arr << v
|
152
130
|
|
153
|
-
if ts[0][0] == ']'
|
154
|
-
return arr, ts[1..-1]
|
155
|
-
end
|
131
|
+
return arr, ts[1..-1] if ts[0][0] == ']'
|
156
132
|
end
|
157
133
|
end
|
158
134
|
|
159
|
-
|
160
135
|
def eat(typ, ts)
|
161
136
|
if ts[0][0] != typ
|
162
137
|
raise OkJson::ParserError, "expected #{typ} (got #{ts[0].inspect})"
|
@@ -164,25 +139,21 @@ module OkJson
|
|
164
139
|
ts[1..-1]
|
165
140
|
end
|
166
141
|
|
167
|
-
|
168
142
|
# Sans s and returns a list of json tokens,
|
169
143
|
# excluding white space (as defined in RFC 4627).
|
170
144
|
def lex(s)
|
171
145
|
ts = []
|
172
|
-
|
146
|
+
until s.empty?
|
173
147
|
typ, lexeme, val = tok(s)
|
174
|
-
if typ
|
175
|
-
raise OkJson::ParserError, "invalid character at #{s[0,10].inspect}"
|
176
|
-
end
|
177
|
-
if typ != :space
|
178
|
-
ts << [typ, lexeme, val]
|
148
|
+
if typ.nil?
|
149
|
+
raise OkJson::ParserError, "invalid character at #{s[0, 10].inspect}"
|
179
150
|
end
|
151
|
+
ts << [typ, lexeme, val] if typ != :space
|
180
152
|
s = s[lexeme.length..-1]
|
181
153
|
end
|
182
154
|
ts
|
183
155
|
end
|
184
156
|
|
185
|
-
|
186
157
|
# Scans the first token in s and
|
187
158
|
# returns a 3-element list, or nil
|
188
159
|
# if no such token exists.
|
@@ -198,35 +169,41 @@ module OkJson
|
|
198
169
|
# it is the lexeme.
|
199
170
|
def tok(s)
|
200
171
|
case s[0]
|
201
|
-
when
|
202
|
-
when
|
203
|
-
when
|
204
|
-
when
|
205
|
-
when
|
206
|
-
when
|
207
|
-
when
|
208
|
-
when
|
209
|
-
when
|
210
|
-
when
|
211
|
-
when Spc then [:space, s[0,1], s[0,1]]
|
212
|
-
when
|
213
|
-
when
|
214
|
-
when
|
215
|
-
else
|
172
|
+
when '{' then ['{', s[0, 1], s[0, 1]]
|
173
|
+
when '}' then ['}', s[0, 1], s[0, 1]]
|
174
|
+
when ':' then [':', s[0, 1], s[0, 1]]
|
175
|
+
when ',' then [',', s[0, 1], s[0, 1]]
|
176
|
+
when '[' then ['[', s[0, 1], s[0, 1]]
|
177
|
+
when ']' then [']', s[0, 1], s[0, 1]]
|
178
|
+
when 'n' then nulltok(s)
|
179
|
+
when 't' then truetok(s)
|
180
|
+
when 'f' then falsetok(s)
|
181
|
+
when '"' then strtok(s)
|
182
|
+
when Spc then [:space, s[0, 1], s[0, 1]]
|
183
|
+
when "\t" then [:space, s[0, 1], s[0, 1]]
|
184
|
+
when "\n" then [:space, s[0, 1], s[0, 1]]
|
185
|
+
when "\r" then [:space, s[0, 1], s[0, 1]]
|
186
|
+
else numtok(s)
|
216
187
|
end
|
217
188
|
end
|
218
189
|
|
190
|
+
def nulltok(s)
|
191
|
+
s[0, 4] == 'null' && [:val, 'null', nil]
|
192
|
+
end
|
219
193
|
|
220
|
-
def
|
221
|
-
|
222
|
-
|
194
|
+
def truetok(s)
|
195
|
+
s[0, 4] == 'true' && [:val, 'true', true]
|
196
|
+
end
|
223
197
|
|
198
|
+
def falsetok(s)
|
199
|
+
s[0, 5] == 'false' && [:val, 'false', false]
|
200
|
+
end
|
224
201
|
|
225
202
|
def numtok(s)
|
226
203
|
m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
|
227
204
|
if m && m.begin(0) == 0
|
228
205
|
if m[3] && !m[2]
|
229
|
-
[:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
|
206
|
+
[:val, m[0], Integer(m[1]) * (10**Integer(m[3][1..-1]))]
|
230
207
|
elsif m[2]
|
231
208
|
[:val, m[0], Float(m[0])]
|
232
209
|
else
|
@@ -235,61 +212,57 @@ module OkJson
|
|
235
212
|
end
|
236
213
|
end
|
237
214
|
|
238
|
-
|
239
215
|
def strtok(s)
|
240
216
|
m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s)
|
241
|
-
|
242
|
-
raise OkJson::ParserError, "invalid string literal at #{abbrev(s)}"
|
243
|
-
end
|
217
|
+
raise OkJson::ParserError, "invalid string literal at #{abbrev(s)}" unless m
|
244
218
|
[:str, m[0], unquote(m[0])]
|
245
219
|
end
|
246
220
|
|
247
|
-
|
248
221
|
def abbrev(s)
|
249
|
-
t = s[0,10]
|
222
|
+
t = s[0, 10]
|
250
223
|
p = t['`']
|
251
|
-
t = t[0,p] if p
|
252
|
-
t
|
224
|
+
t = t[0, p] if p
|
225
|
+
t += '...' if t.length < s.length
|
253
226
|
'`' + t + '`'
|
254
227
|
end
|
255
228
|
|
256
|
-
|
257
229
|
# Converts a quoted json string literal q into a UTF-8-encoded string.
|
258
230
|
# The rules are different than for Ruby, so we cannot use eval.
|
259
231
|
# Unquote will raise OkJson::ParserError, an error if q contains control characters.
|
260
232
|
def unquote(q)
|
261
233
|
q = q[1...-1]
|
262
234
|
a = q.dup # allocate a big enough string
|
263
|
-
r
|
235
|
+
r = 0
|
236
|
+
w = 0
|
264
237
|
while r < q.length
|
265
238
|
c = q[r]
|
266
239
|
case true
|
267
|
-
when c ==
|
240
|
+
when c == '\\'
|
268
241
|
r += 1
|
269
242
|
if r >= q.length
|
270
243
|
raise OkJson::ParserError, "string literal ends with a \"\\\": \"#{q}\""
|
271
244
|
end
|
272
245
|
|
273
246
|
case q[r]
|
274
|
-
when
|
247
|
+
when '"', '\\', '/', "'"
|
275
248
|
a[w] = q[r]
|
276
249
|
r += 1
|
277
250
|
w += 1
|
278
|
-
when
|
251
|
+
when 'b', 'f', 'n', 'r', 't'
|
279
252
|
a[w] = Unesc[q[r]]
|
280
253
|
r += 1
|
281
254
|
w += 1
|
282
|
-
when
|
255
|
+
when 'u'
|
283
256
|
r += 1
|
284
257
|
uchar = begin
|
285
|
-
hexdec4(q[r,4])
|
258
|
+
hexdec4(q[r, 4])
|
286
259
|
rescue RuntimeError => e
|
287
|
-
raise OkJson::ParserError, "invalid escape sequence \\u#{q[r,4]}: #{e}"
|
260
|
+
raise OkJson::ParserError, "invalid escape sequence \\u#{q[r, 4]}: #{e}"
|
288
261
|
end
|
289
262
|
r += 4
|
290
263
|
if surrogate? uchar
|
291
|
-
if q.length >= r+6
|
292
|
-
uchar1 = hexdec4(q[r+2,4])
|
264
|
+
if q.length >= r + 6
|
265
|
+
uchar1 = hexdec4(q[r + 2, 4])
|
293
266
|
uchar = subst(uchar, uchar1)
|
294
267
|
if uchar != Ucharerr
|
295
268
|
# A valid pair; consume.
|
@@ -301,7 +274,7 @@ module OkJson
|
|
301
274
|
else
|
302
275
|
raise OkJson::ParserError, "invalid escape char #{q[r]} in \"#{q}\""
|
303
276
|
end
|
304
|
-
when c ==
|
277
|
+
when c == '"', c < Spc
|
305
278
|
raise OkJson::ParserError, "invalid character in string literal \"#{q}\""
|
306
279
|
else
|
307
280
|
# Copy anything else byte-for-byte.
|
@@ -312,51 +285,41 @@ module OkJson
|
|
312
285
|
w += 1
|
313
286
|
end
|
314
287
|
end
|
315
|
-
a[0,w]
|
288
|
+
a[0, w]
|
316
289
|
end
|
317
290
|
|
318
|
-
|
319
291
|
def hexdec4(s)
|
320
|
-
if s.length != 4
|
321
|
-
|
322
|
-
end
|
323
|
-
(nibble(s[0])<<12) | (nibble(s[1])<<8) | (nibble(s[2])<<4) | nibble(s[3])
|
292
|
+
raise OkJson::ParserError, 'short' if s.length != 4
|
293
|
+
(nibble(s[0]) << 12) | (nibble(s[1]) << 8) | (nibble(s[2]) << 4) | nibble(s[3])
|
324
294
|
end
|
325
295
|
|
326
|
-
|
327
296
|
def subst(u1, u2)
|
328
297
|
if Usurr1 <= u1 && u1 < Usurr2 && Usurr2 <= u2 && u2 < Usurr3
|
329
|
-
return ((u1-Usurr1)<<10) | (u2-Usurr2) + Usurrself
|
298
|
+
return ((u1 - Usurr1) << 10) | (u2 - Usurr2) + Usurrself
|
330
299
|
end
|
331
|
-
|
300
|
+
Ucharerr
|
332
301
|
end
|
333
302
|
|
334
|
-
|
335
303
|
def unsubst(u)
|
336
|
-
if u < Usurrself || u > Umax || surrogate?(u)
|
337
|
-
return Ucharerr, Ucharerr
|
338
|
-
end
|
304
|
+
return Ucharerr, Ucharerr if u < Usurrself || u > Umax || surrogate?(u)
|
339
305
|
u -= Usurrself
|
340
|
-
[Usurr1 + ((u>>10)&0x3ff), Usurr2 + (u&0x3ff)]
|
306
|
+
[Usurr1 + ((u >> 10) & 0x3ff), Usurr2 + (u & 0x3ff)]
|
341
307
|
end
|
342
308
|
|
343
|
-
|
344
309
|
def surrogate?(u)
|
345
310
|
Usurr1 <= u && u < Usurr3
|
346
311
|
end
|
347
312
|
|
348
|
-
|
349
313
|
def nibble(c)
|
350
314
|
case true
|
351
|
-
when
|
352
|
-
when
|
353
|
-
when
|
315
|
+
when c >= '0' && c <= '9' then c.ord - '0'.ord
|
316
|
+
when c >= 'a' && c <= 'z' then c.ord - 'a'.ord + 10
|
317
|
+
when c >= 'A' && c <= 'Z' then c.ord - 'A'.ord + 10
|
354
318
|
else
|
355
319
|
raise OkJson::ParserError, "invalid hex code #{c}"
|
356
320
|
end
|
357
321
|
end
|
358
322
|
|
359
|
-
|
360
323
|
# Encodes x into a json text. It may contain only
|
361
324
|
# Array, Hash, String, Numeric, true, false, nil.
|
362
325
|
# (Note, this list excludes Symbol.)
|
@@ -371,41 +334,38 @@ module OkJson
|
|
371
334
|
when String then strenc(x)
|
372
335
|
when Numeric then numenc(x)
|
373
336
|
when Symbol then strenc(x.to_s)
|
374
|
-
when true then
|
375
|
-
when false then
|
376
|
-
when nil then
|
377
|
-
else
|
337
|
+
when true then 'true'
|
338
|
+
when false then 'false'
|
339
|
+
when nil then 'null'
|
340
|
+
else 'null'
|
378
341
|
end
|
379
342
|
end
|
380
343
|
|
381
|
-
|
382
344
|
def objenc(x)
|
383
|
-
'{' + x.map{|k,v| encode(k) + ':' + encode(v)}.join(',') + '}'
|
345
|
+
'{' + x.map { |k, v| encode(k) + ':' + encode(v) }.join(',') + '}'
|
384
346
|
end
|
385
347
|
|
386
|
-
|
387
348
|
def arrenc(a)
|
388
|
-
'[' + a.map{|x| encode(x)}.join(',') + ']'
|
349
|
+
'[' + a.map { |x| encode(x) }.join(',') + ']'
|
389
350
|
end
|
390
351
|
|
391
|
-
|
392
352
|
def strenc(s)
|
393
353
|
t = StringIO.new
|
394
|
-
t.putc(
|
354
|
+
t.putc('"')
|
395
355
|
r = 0
|
396
356
|
while r < s.length
|
397
357
|
case s[r]
|
398
|
-
when
|
399
|
-
when
|
400
|
-
when
|
401
|
-
when
|
402
|
-
when
|
403
|
-
when
|
404
|
-
when
|
358
|
+
when '"' then t.print('\\"')
|
359
|
+
when '\\' then t.print('\\\\')
|
360
|
+
when "\b" then t.print('\\b')
|
361
|
+
when "\f" then t.print('\\f')
|
362
|
+
when "\n" then t.print('\\n')
|
363
|
+
when "\r" then t.print('\\r')
|
364
|
+
when "\t" then t.print('\\t')
|
405
365
|
else
|
406
366
|
c = s[r]
|
407
367
|
case true
|
408
|
-
when Spc <= c && c <=
|
368
|
+
when Spc <= c && c <= '~'
|
409
369
|
t.putc(c)
|
410
370
|
when true
|
411
371
|
u, size = uchardec(s, r)
|
@@ -420,33 +380,30 @@ module OkJson
|
|
420
380
|
t.print('\\u')
|
421
381
|
hexenc4(t, u2)
|
422
382
|
end
|
423
|
-
else
|
424
|
-
# invalid byte; skip it
|
425
383
|
end
|
426
384
|
end
|
427
385
|
r += 1
|
428
386
|
end
|
429
|
-
t.putc(
|
387
|
+
t.putc('"')
|
430
388
|
t.string
|
431
389
|
end
|
432
390
|
|
433
|
-
|
434
391
|
def hexenc4(t, u)
|
435
|
-
t.putc(Hex[(u>>12)&0xf])
|
436
|
-
t.putc(Hex[(u>>8)&0xf])
|
437
|
-
t.putc(Hex[(u>>4)&0xf])
|
438
|
-
t.putc(Hex[u&0xf])
|
392
|
+
t.putc(Hex[(u >> 12) & 0xf])
|
393
|
+
t.putc(Hex[(u >> 8) & 0xf])
|
394
|
+
t.putc(Hex[(u >> 4) & 0xf])
|
395
|
+
t.putc(Hex[u & 0xf])
|
439
396
|
end
|
440
397
|
|
441
|
-
|
442
398
|
def numenc(x)
|
443
|
-
|
444
|
-
return 'null'
|
445
|
-
|
446
|
-
|
399
|
+
begin
|
400
|
+
return 'null' if x.nan? || x.infinite?
|
401
|
+
rescue
|
402
|
+
nil
|
403
|
+
end
|
404
|
+
x.to_s
|
447
405
|
end
|
448
406
|
|
449
|
-
|
450
407
|
# Decodes unicode character u from UTF-8
|
451
408
|
# bytes in string s at position i.
|
452
409
|
# Returns u and the number of bytes read.
|
@@ -457,53 +414,50 @@ module OkJson
|
|
457
414
|
c0 = s[i].ord
|
458
415
|
|
459
416
|
# 1-byte, 7-bit sequence?
|
460
|
-
if c0 < Utagx
|
461
|
-
return [c0, 1]
|
462
|
-
end
|
417
|
+
return [c0, 1] if c0 < Utagx
|
463
418
|
|
464
419
|
# unexpected continuation byte?
|
465
420
|
return [Ucharerr, 1] if c0 < Utag2
|
466
421
|
|
467
422
|
# need continuation byte
|
468
423
|
return [Ucharerr, 1] if n < 2
|
469
|
-
c1 = s[i+1].ord
|
424
|
+
c1 = s[i + 1].ord
|
470
425
|
return [Ucharerr, 1] if c1 < Utagx || Utag2 <= c1
|
471
426
|
|
472
427
|
# 2-byte, 11-bit sequence?
|
473
428
|
if c0 < Utag3
|
474
|
-
u = (c0&Umask2)<<6 | (c1&Umaskx)
|
429
|
+
u = (c0 & Umask2) << 6 | (c1 & Umaskx)
|
475
430
|
return [Ucharerr, 1] if u <= Uchar1max
|
476
431
|
return [u, 2]
|
477
432
|
end
|
478
433
|
|
479
434
|
# need second continuation byte
|
480
435
|
return [Ucharerr, 1] if n < 3
|
481
|
-
c2 = s[i+2].ord
|
436
|
+
c2 = s[i + 2].ord
|
482
437
|
return [Ucharerr, 1] if c2 < Utagx || Utag2 <= c2
|
483
438
|
|
484
439
|
# 3-byte, 16-bit sequence?
|
485
440
|
if c0 < Utag4
|
486
|
-
u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
|
441
|
+
u = (c0 & Umask3) << 12 | (c1 & Umaskx) << 6 | (c2 & Umaskx)
|
487
442
|
return [Ucharerr, 1] if u <= Uchar2max
|
488
443
|
return [u, 3]
|
489
444
|
end
|
490
445
|
|
491
446
|
# need third continuation byte
|
492
447
|
return [Ucharerr, 1] if n < 4
|
493
|
-
c3 = s[i+3].ord
|
448
|
+
c3 = s[i + 3].ord
|
494
449
|
return [Ucharerr, 1] if c3 < Utagx || Utag2 <= c3
|
495
450
|
|
496
451
|
# 4-byte, 21-bit sequence?
|
497
452
|
if c0 < Utag5
|
498
|
-
u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
|
453
|
+
u = (c0 & Umask4) << 18 | (c1 & Umaskx) << 12 | (c2 & Umaskx) << 6 | (c3 & Umaskx)
|
499
454
|
return [Ucharerr, 1] if u <= Uchar3max
|
500
455
|
return [u, 4]
|
501
456
|
end
|
502
457
|
|
503
|
-
|
458
|
+
[Ucharerr, 1]
|
504
459
|
end
|
505
460
|
|
506
|
-
|
507
461
|
# Encodes unicode character u as UTF-8
|
508
462
|
# bytes in string a at position i.
|
509
463
|
# Returns the number of bytes written.
|
@@ -513,19 +467,19 @@ module OkJson
|
|
513
467
|
a[i] = (u & 0xff).chr
|
514
468
|
1
|
515
469
|
when u <= Uchar2max
|
516
|
-
a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
|
517
|
-
a[i+1] = (Utagx | (u&Umaskx)).chr
|
470
|
+
a[i + 0] = (Utag2 | ((u >> 6) & 0xff)).chr
|
471
|
+
a[i + 1] = (Utagx | (u & Umaskx)).chr
|
518
472
|
2
|
519
473
|
when u <= Uchar3max
|
520
|
-
a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
|
521
|
-
a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
|
522
|
-
a[i+2] = (Utagx | (u&Umaskx)).chr
|
474
|
+
a[i + 0] = (Utag3 | ((u >> 12) & 0xff)).chr
|
475
|
+
a[i + 1] = (Utagx | ((u >> 6) & Umaskx)).chr
|
476
|
+
a[i + 2] = (Utagx | (u & Umaskx)).chr
|
523
477
|
3
|
524
478
|
else
|
525
|
-
a[i+0] = (Utag4 | ((u>>18)&0xff)).chr
|
526
|
-
a[i+1] = (Utagx | ((u>>12)&Umaskx)).chr
|
527
|
-
a[i+2] = (Utagx | ((u>>6)&Umaskx)).chr
|
528
|
-
a[i+3] = (Utagx | (u&Umaskx)).chr
|
479
|
+
a[i + 0] = (Utag4 | ((u >> 18) & 0xff)).chr
|
480
|
+
a[i + 1] = (Utagx | ((u >> 12) & Umaskx)).chr
|
481
|
+
a[i + 2] = (Utagx | ((u >> 6) & Umaskx)).chr
|
482
|
+
a[i + 3] = (Utagx | (u & Umaskx)).chr
|
529
483
|
4
|
530
484
|
end
|
531
485
|
end
|
@@ -539,9 +493,9 @@ module OkJson
|
|
539
493
|
Umask2 = 0x1f # 0001 1111
|
540
494
|
Umask3 = 0x0f # 0000 1111
|
541
495
|
Umask4 = 0x07 # 0000 0111
|
542
|
-
Uchar1max = (1<<7) - 1
|
543
|
-
Uchar2max = (1<<11) - 1
|
544
|
-
Uchar3max = (1<<16) - 1
|
496
|
+
Uchar1max = (1 << 7) - 1
|
497
|
+
Uchar2max = (1 << 11) - 1
|
498
|
+
Uchar3max = (1 << 16) - 1
|
545
499
|
Ucharerr = 0xFFFD # unicode "replacement char"
|
546
500
|
Usurrself = 0x10000
|
547
501
|
Usurr1 = 0xd800
|
@@ -550,6 +504,6 @@ module OkJson
|
|
550
504
|
Umax = 0x10ffff
|
551
505
|
|
552
506
|
Spc = ' '[0]
|
553
|
-
Unesc = {
|
554
|
-
Hex = '0123456789abcdef'
|
507
|
+
Unesc = { 'b' => "\b", 'f' => "\f", 'n' => "\n", 'r' => "\r", 't' => "\t" }.freeze
|
508
|
+
Hex = '0123456789abcdef'.freeze
|
555
509
|
end
|