scout 5.1.2 → 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/lib/scout.rb +1 -1
- data/lib/scout/server.rb +4 -1
- data/vendor/json_pure/CHANGES +43 -0
- data/vendor/json_pure/{RUBY → COPYING} +1 -1
- data/vendor/json_pure/GPL +7 -7
- data/vendor/json_pure/README +319 -39
- data/vendor/json_pure/Rakefile +69 -47
- data/vendor/json_pure/VERSION +1 -1
- data/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
- data/vendor/json_pure/benchmarks/generator_benchmark.rb +64 -5
- data/vendor/json_pure/benchmarks/ohai.json +1216 -0
- data/vendor/json_pure/benchmarks/ohai.ruby +1 -0
- data/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
- data/vendor/json_pure/benchmarks/parser_benchmark.rb +67 -5
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +9 -4
- data/vendor/json_pure/ext/json/ext/generator/generator.c +831 -409
- data/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +8 -4
- data/vendor/json_pure/ext/json/ext/parser/parser.c +292 -186
- data/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +218 -112
- data/vendor/json_pure/lib/json/add/core.rb +20 -7
- data/vendor/json_pure/lib/json/add/rails.rb +2 -2
- data/vendor/json_pure/lib/json/common.rb +85 -42
- data/vendor/json_pure/lib/json/pure.rb +3 -3
- data/vendor/json_pure/lib/json/pure/generator.rb +112 -90
- data/vendor/json_pure/lib/json/pure/parser.rb +42 -4
- data/vendor/json_pure/lib/json/version.rb +1 -1
- data/vendor/json_pure/tests/test_json.rb +46 -18
- data/vendor/json_pure/tests/test_json_addition.rb +4 -6
- data/vendor/json_pure/tests/test_json_encoding.rb +68 -0
- data/vendor/json_pure/tests/test_json_generate.rb +30 -14
- data/vendor/json_pure/tests/test_json_rails.rb +5 -7
- data/vendor/json_pure/tests/test_json_unicode.rb +20 -6
- metadata +26 -15
- data/vendor/json_pure/doc-templates/main.txt +0 -283
- data/vendor/json_pure/ext/json/ext/generator/unicode.c +0 -182
- data/vendor/json_pure/ext/json/ext/generator/unicode.h +0 -53
- data/vendor/json_pure/ext/json/ext/parser/unicode.c +0 -154
- data/vendor/json_pure/ext/json/ext/parser/unicode.h +0 -58
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 5
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
version: 5.1.3
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Highgroove Studios
|
@@ -9,19 +14,21 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-30 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: elif
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
25
32
|
description: |
|
26
33
|
Scout makes monitoring and reporting on your web applications as flexible and simple as possible.
|
27
34
|
|
@@ -83,24 +90,26 @@ files:
|
|
83
90
|
- vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat
|
84
91
|
- vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat
|
85
92
|
- vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log
|
93
|
+
- vendor/json_pure/benchmarks/generator2_benchmark.rb
|
86
94
|
- vendor/json_pure/benchmarks/generator_benchmark.rb
|
95
|
+
- vendor/json_pure/benchmarks/ohai.json
|
96
|
+
- vendor/json_pure/benchmarks/ohai.ruby
|
97
|
+
- vendor/json_pure/benchmarks/parser2_benchmark.rb
|
87
98
|
- vendor/json_pure/benchmarks/parser_benchmark.rb
|
88
99
|
- vendor/json_pure/bin/edit_json.rb
|
89
100
|
- vendor/json_pure/bin/prettify_json.rb
|
90
101
|
- vendor/json_pure/CHANGES
|
102
|
+
- vendor/json_pure/COPYING
|
91
103
|
- vendor/json_pure/data/example.json
|
92
104
|
- vendor/json_pure/data/index.html
|
93
105
|
- vendor/json_pure/data/prototype.js
|
94
|
-
- vendor/json_pure/doc-templates/main.txt
|
95
106
|
- vendor/json_pure/ext/json/ext/generator/extconf.rb
|
96
107
|
- vendor/json_pure/ext/json/ext/generator/generator.c
|
97
|
-
- vendor/json_pure/ext/json/ext/generator/
|
98
|
-
- vendor/json_pure/ext/json/ext/generator/unicode.h
|
108
|
+
- vendor/json_pure/ext/json/ext/generator/generator.h
|
99
109
|
- vendor/json_pure/ext/json/ext/parser/extconf.rb
|
100
110
|
- vendor/json_pure/ext/json/ext/parser/parser.c
|
111
|
+
- vendor/json_pure/ext/json/ext/parser/parser.h
|
101
112
|
- vendor/json_pure/ext/json/ext/parser/parser.rl
|
102
|
-
- vendor/json_pure/ext/json/ext/parser/unicode.c
|
103
|
-
- vendor/json_pure/ext/json/ext/parser/unicode.h
|
104
113
|
- vendor/json_pure/GPL
|
105
114
|
- vendor/json_pure/install.rb
|
106
115
|
- vendor/json_pure/lib/json/add/core.rb
|
@@ -124,7 +133,6 @@ files:
|
|
124
133
|
- vendor/json_pure/lib/json.rb
|
125
134
|
- vendor/json_pure/Rakefile
|
126
135
|
- vendor/json_pure/README
|
127
|
-
- vendor/json_pure/RUBY
|
128
136
|
- vendor/json_pure/tests/fixtures/fail1.json
|
129
137
|
- vendor/json_pure/tests/fixtures/fail10.json
|
130
138
|
- vendor/json_pure/tests/fixtures/fail11.json
|
@@ -158,6 +166,7 @@ files:
|
|
158
166
|
- vendor/json_pure/tests/fixtures/pass3.json
|
159
167
|
- vendor/json_pure/tests/test_json.rb
|
160
168
|
- vendor/json_pure/tests/test_json_addition.rb
|
169
|
+
- vendor/json_pure/tests/test_json_encoding.rb
|
161
170
|
- vendor/json_pure/tests/test_json_fixtures.rb
|
162
171
|
- vendor/json_pure/tests/test_json_generate.rb
|
163
172
|
- vendor/json_pure/tests/test_json_rails.rb
|
@@ -190,18 +199,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
199
|
requirements:
|
191
200
|
- - ">="
|
192
201
|
- !ruby/object:Gem::Version
|
202
|
+
segments:
|
203
|
+
- 0
|
193
204
|
version: "0"
|
194
|
-
version:
|
195
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
206
|
requirements:
|
197
207
|
- - ">="
|
198
208
|
- !ruby/object:Gem::Version
|
209
|
+
segments:
|
210
|
+
- 0
|
199
211
|
version: "0"
|
200
|
-
version:
|
201
212
|
requirements: []
|
202
213
|
|
203
214
|
rubyforge_project: scout
|
204
|
-
rubygems_version: 1.3.
|
215
|
+
rubygems_version: 1.3.6
|
205
216
|
signing_key:
|
206
217
|
specification_version: 3
|
207
218
|
summary: Scout makes monitoring and reporting on your web applications as flexible and simple as possible.
|
@@ -1,283 +0,0 @@
|
|
1
|
-
# = json - JSON for Ruby
|
2
|
-
#
|
3
|
-
# == Description
|
4
|
-
#
|
5
|
-
# This is a implementation of the JSON specification according to RFC 4627
|
6
|
-
# (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
|
7
|
-
# will be two variants available:
|
8
|
-
#
|
9
|
-
# * A pure ruby variant, that relies on the iconv and the stringscan
|
10
|
-
# extensions, which are both part of the ruby standard library.
|
11
|
-
# * The quite a bit faster C extension variant, which is in parts implemented
|
12
|
-
# in C and comes with its own unicode conversion functions and a parser
|
13
|
-
# generated by the ragel state machine compiler
|
14
|
-
# (http://www.cs.queensu.ca/~thurston/ragel).
|
15
|
-
#
|
16
|
-
# Both variants of the JSON generator escape all non-ASCII an control
|
17
|
-
# characters with \uXXXX escape sequences, and support UTF-16 surrogate pairs
|
18
|
-
# in order to be able to generate the whole range of unicode code points. This
|
19
|
-
# means that generated JSON text is encoded as UTF-8 (because ASCII is a subset
|
20
|
-
# of UTF-8) and at the same time avoids decoding problems for receiving
|
21
|
-
# endpoints, that don't expect UTF-8 encoded texts. On the negative side this
|
22
|
-
# may lead to a bit longer strings than necessarry.
|
23
|
-
#
|
24
|
-
# All strings, that are to be encoded as JSON strings, should be UTF-8 byte
|
25
|
-
# sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
|
26
|
-
# encoded, please use the to_json_raw_object method of String (which produces
|
27
|
-
# an object, that contains a byte array) and decode the result on the receiving
|
28
|
-
# endpoint.
|
29
|
-
#
|
30
|
-
# == Author
|
31
|
-
#
|
32
|
-
# Florian Frank <mailto:flori@ping.de>
|
33
|
-
#
|
34
|
-
# == License
|
35
|
-
#
|
36
|
-
# This software is distributed under the same license as Ruby itself, see
|
37
|
-
# http://www.ruby-lang.org/en/LICENSE.txt.
|
38
|
-
#
|
39
|
-
# == Download
|
40
|
-
#
|
41
|
-
# The latest version of this library can be downloaded at
|
42
|
-
#
|
43
|
-
# * http://rubyforge.org/frs?group_id=953
|
44
|
-
#
|
45
|
-
# Online Documentation should be located at
|
46
|
-
#
|
47
|
-
# * http://json.rubyforge.org
|
48
|
-
#
|
49
|
-
# == Usage
|
50
|
-
#
|
51
|
-
# To use JSON you can
|
52
|
-
# require 'json'
|
53
|
-
# to load the installed variant (either the extension 'json' or the pure
|
54
|
-
# variant 'json_pure'). If you have installed the extension variant, you can
|
55
|
-
# pick either the extension variant or the pure variant by typing
|
56
|
-
# require 'json/ext'
|
57
|
-
# or
|
58
|
-
# require 'json/pure'
|
59
|
-
#
|
60
|
-
# You can choose to load a set of common additions to ruby core's objects if
|
61
|
-
# you
|
62
|
-
# require 'json/add/core'
|
63
|
-
#
|
64
|
-
# After requiring this you can, e. g., serialise/deserialise Ruby ranges:
|
65
|
-
#
|
66
|
-
# JSON JSON(1..10) # => 1..10
|
67
|
-
#
|
68
|
-
# To find out how to add JSON support to other or your own classes, read the
|
69
|
-
# Examples section below.
|
70
|
-
#
|
71
|
-
# To get the best compatibility to rails' JSON implementation, you can
|
72
|
-
# require 'json/add/rails'
|
73
|
-
#
|
74
|
-
# Both of the additions attempt to require 'json' (like above) first, if it has
|
75
|
-
# not been required yet.
|
76
|
-
#
|
77
|
-
# == Speed Comparisons
|
78
|
-
#
|
79
|
-
# I have created some benchmark results (see the benchmarks/data-p4-3Ghz
|
80
|
-
# subdir of the package) for the JSON-parser to estimate the speed up in the C
|
81
|
-
# extension:
|
82
|
-
#
|
83
|
-
# Comparing times (call_time_mean):
|
84
|
-
# 1 ParserBenchmarkExt#parser 900 repeats:
|
85
|
-
# 553.922304770 ( real) -> 21.500x
|
86
|
-
# 0.001805307
|
87
|
-
# 2 ParserBenchmarkYAML#parser 1000 repeats:
|
88
|
-
# 224.513358139 ( real) -> 8.714x
|
89
|
-
# 0.004454078
|
90
|
-
# 3 ParserBenchmarkPure#parser 1000 repeats:
|
91
|
-
# 26.755020642 ( real) -> 1.038x
|
92
|
-
# 0.037376163
|
93
|
-
# 4 ParserBenchmarkRails#parser 1000 repeats:
|
94
|
-
# 25.763381731 ( real) -> 1.000x
|
95
|
-
# 0.038814780
|
96
|
-
# calls/sec ( time) -> speed covers
|
97
|
-
# secs/call
|
98
|
-
#
|
99
|
-
# In the table above 1 is JSON::Ext::Parser, 2 is YAML.load with YAML
|
100
|
-
# compatbile JSON document, 3 is is JSON::Pure::Parser, and 4 is
|
101
|
-
# ActiveSupport::JSON.decode. The ActiveSupport JSON-decoder converts the
|
102
|
-
# input first to YAML and then uses the YAML-parser, the conversion seems to
|
103
|
-
# slow it down so much that it is only as fast as the JSON::Pure::Parser!
|
104
|
-
#
|
105
|
-
# If you look at the benchmark data you can see that this is mostly caused by
|
106
|
-
# the frequent high outliers - the median of the Rails-parser runs is still
|
107
|
-
# overall smaller than the median of the JSON::Pure::Parser runs:
|
108
|
-
#
|
109
|
-
# Comparing times (call_time_median):
|
110
|
-
# 1 ParserBenchmarkExt#parser 900 repeats:
|
111
|
-
# 800.592479481 ( real) -> 26.936x
|
112
|
-
# 0.001249075
|
113
|
-
# 2 ParserBenchmarkYAML#parser 1000 repeats:
|
114
|
-
# 271.002390644 ( real) -> 9.118x
|
115
|
-
# 0.003690004
|
116
|
-
# 3 ParserBenchmarkRails#parser 1000 repeats:
|
117
|
-
# 30.227910865 ( real) -> 1.017x
|
118
|
-
# 0.033082008
|
119
|
-
# 4 ParserBenchmarkPure#parser 1000 repeats:
|
120
|
-
# 29.722384421 ( real) -> 1.000x
|
121
|
-
# 0.033644676
|
122
|
-
# calls/sec ( time) -> speed covers
|
123
|
-
# secs/call
|
124
|
-
#
|
125
|
-
# I have benchmarked the JSON-Generator as well. This generated a few more
|
126
|
-
# values, because there are different modes that also influence the achieved
|
127
|
-
# speed:
|
128
|
-
#
|
129
|
-
# Comparing times (call_time_mean):
|
130
|
-
# 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
131
|
-
# 547.354332608 ( real) -> 15.090x
|
132
|
-
# 0.001826970
|
133
|
-
# 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
134
|
-
# 443.968212317 ( real) -> 12.240x
|
135
|
-
# 0.002252414
|
136
|
-
# 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
137
|
-
# 375.104545883 ( real) -> 10.341x
|
138
|
-
# 0.002665923
|
139
|
-
# 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
140
|
-
# 49.978706968 ( real) -> 1.378x
|
141
|
-
# 0.020008521
|
142
|
-
# 5 GeneratorBenchmarkRails#generator 1000 repeats:
|
143
|
-
# 38.531868759 ( real) -> 1.062x
|
144
|
-
# 0.025952543
|
145
|
-
# 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
146
|
-
# 36.927649925 ( real) -> 1.018x 7 (>=3859)
|
147
|
-
# 0.027079979
|
148
|
-
# 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
149
|
-
# 36.272134441 ( real) -> 1.000x 6 (>=3859)
|
150
|
-
# 0.027569373
|
151
|
-
# calls/sec ( time) -> speed covers
|
152
|
-
# secs/call
|
153
|
-
#
|
154
|
-
# In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
|
155
|
-
# JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
|
156
|
-
# bit faster than the generator_safe and generator_pretty methods of the pure
|
157
|
-
# variant but slower than the others.
|
158
|
-
#
|
159
|
-
# To achieve the fastest JSON text output, you can use the fast_generate
|
160
|
-
# method. Beware, that this will disable the checking for circular Ruby data
|
161
|
-
# structures, which may cause JSON to go into an infinite loop.
|
162
|
-
#
|
163
|
-
# Here are the median comparisons for completeness' sake:
|
164
|
-
#
|
165
|
-
# Comparing times (call_time_median):
|
166
|
-
# 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
|
167
|
-
# 708.258020939 ( real) -> 16.547x
|
168
|
-
# 0.001411915
|
169
|
-
# 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
|
170
|
-
# 569.105020353 ( real) -> 13.296x
|
171
|
-
# 0.001757145
|
172
|
-
# 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
|
173
|
-
# 482.825371244 ( real) -> 11.280x
|
174
|
-
# 0.002071142
|
175
|
-
# 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
|
176
|
-
# 62.717626652 ( real) -> 1.465x
|
177
|
-
# 0.015944481
|
178
|
-
# 5 GeneratorBenchmarkRails#generator 1000 repeats:
|
179
|
-
# 43.965681162 ( real) -> 1.027x
|
180
|
-
# 0.022745013
|
181
|
-
# 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
|
182
|
-
# 43.929073409 ( real) -> 1.026x 7 (>=3859)
|
183
|
-
# 0.022763968
|
184
|
-
# 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
|
185
|
-
# 42.802514491 ( real) -> 1.000x 6 (>=3859)
|
186
|
-
# 0.023363113
|
187
|
-
# calls/sec ( time) -> speed covers
|
188
|
-
# secs/call
|
189
|
-
#
|
190
|
-
# == Examples
|
191
|
-
#
|
192
|
-
# To create a JSON text from a ruby data structure, you can call JSON.generate
|
193
|
-
# like that:
|
194
|
-
#
|
195
|
-
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
196
|
-
# # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
|
197
|
-
#
|
198
|
-
# To create a valid JSON text you have to make sure, that the output is
|
199
|
-
# embedded in either a JSON array [] or a JSON object {}. The easiest way to do
|
200
|
-
# this, is by putting your values in a Ruby Array or Hash instance.
|
201
|
-
#
|
202
|
-
# To get back a ruby data structure from a JSON text, you have to call
|
203
|
-
# JSON.parse on it:
|
204
|
-
#
|
205
|
-
# JSON.parse json
|
206
|
-
# # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
|
207
|
-
#
|
208
|
-
# Note, that the range from the original data structure is a simple
|
209
|
-
# string now. The reason for this is, that JSON doesn't support ranges
|
210
|
-
# or arbitrary classes. In this case the json library falls back to call
|
211
|
-
# Object#to_json, which is the same as #to_s.to_json.
|
212
|
-
#
|
213
|
-
# It's possible to add JSON support serialization to arbitrary classes by
|
214
|
-
# simply implementing a more specialized version of the #to_json method, that
|
215
|
-
# should return a JSON object (a hash converted to JSON with #to_json) like
|
216
|
-
# this (don't forget the *a for all the arguments):
|
217
|
-
#
|
218
|
-
# class Range
|
219
|
-
# def to_json(*a)
|
220
|
-
# {
|
221
|
-
# 'json_class' => self.class.name, # = 'Range'
|
222
|
-
# 'data' => [ first, last, exclude_end? ]
|
223
|
-
# }.to_json(*a)
|
224
|
-
# end
|
225
|
-
# end
|
226
|
-
#
|
227
|
-
# The hash key 'json_class' is the class, that will be asked to deserialise the
|
228
|
-
# JSON representation later. In this case it's 'Range', but any namespace of
|
229
|
-
# the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
|
230
|
-
# used to store the necessary data to configure the object to be deserialised.
|
231
|
-
#
|
232
|
-
# If a the key 'json_class' is found in a JSON object, the JSON parser checks
|
233
|
-
# if the given class responds to the json_create class method. If so, it is
|
234
|
-
# called with the JSON object converted to a Ruby hash. So a range can
|
235
|
-
# be deserialised by implementing Range.json_create like this:
|
236
|
-
#
|
237
|
-
# class Range
|
238
|
-
# def self.json_create(o)
|
239
|
-
# new(*o['data'])
|
240
|
-
# end
|
241
|
-
# end
|
242
|
-
#
|
243
|
-
# Now it possible to serialise/deserialise ranges as well:
|
244
|
-
#
|
245
|
-
# json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
246
|
-
# # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
|
247
|
-
# JSON.parse json
|
248
|
-
# # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
|
249
|
-
#
|
250
|
-
# JSON.generate always creates the shortest possible string representation of a
|
251
|
-
# ruby data structure in one line. This good for data storage or network
|
252
|
-
# protocols, but not so good for humans to read. Fortunately there's also
|
253
|
-
# JSON.pretty_generate (or JSON.pretty_generate) that creates a more
|
254
|
-
# readable output:
|
255
|
-
#
|
256
|
-
# puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
|
257
|
-
# [
|
258
|
-
# 1,
|
259
|
-
# 2,
|
260
|
-
# {
|
261
|
-
# "a": 3.141
|
262
|
-
# },
|
263
|
-
# false,
|
264
|
-
# true,
|
265
|
-
# null,
|
266
|
-
# {
|
267
|
-
# "json_class": "Range",
|
268
|
-
# "data": [
|
269
|
-
# 4,
|
270
|
-
# 10,
|
271
|
-
# false
|
272
|
-
# ]
|
273
|
-
# }
|
274
|
-
# ]
|
275
|
-
#
|
276
|
-
# There are also the methods Kernel#j for generate, and Kernel#jj for
|
277
|
-
# pretty_generate output to the console, that work analogous to Core Ruby's p
|
278
|
-
# and the pp library's pp methods.
|
279
|
-
#
|
280
|
-
# The script tools/server.rb contains a small example if you want to test, how
|
281
|
-
# receiving a JSON object from a webrick server in your browser with the
|
282
|
-
# javasript prototype library (http://www.prototypejs.org) works.
|
283
|
-
#
|
@@ -1,182 +0,0 @@
|
|
1
|
-
#include "unicode.h"
|
2
|
-
|
3
|
-
#define unicode_escape(buffer, character) \
|
4
|
-
snprintf(buf, 7, "\\u%04x", (unsigned int) (character)); \
|
5
|
-
rb_str_buf_cat(buffer, buf, 6);
|
6
|
-
|
7
|
-
/*
|
8
|
-
* Copyright 2001-2004 Unicode, Inc.
|
9
|
-
*
|
10
|
-
* Disclaimer
|
11
|
-
*
|
12
|
-
* This source code is provided as is by Unicode, Inc. No claims are
|
13
|
-
* made as to fitness for any particular purpose. No warranties of any
|
14
|
-
* kind are expressed or implied. The recipient agrees to determine
|
15
|
-
* applicability of information provided. If this file has been
|
16
|
-
* purchased on magnetic or optical media from Unicode, Inc., the
|
17
|
-
* sole remedy for any claim will be exchange of defective media
|
18
|
-
* within 90 days of receipt.
|
19
|
-
*
|
20
|
-
* Limitations on Rights to Redistribute This Code
|
21
|
-
*
|
22
|
-
* Unicode, Inc. hereby grants the right to freely use the information
|
23
|
-
* supplied in this file in the creation of products supporting the
|
24
|
-
* Unicode Standard, and to make copies of this file in any form
|
25
|
-
* for internal or external distribution as long as this notice
|
26
|
-
* remains attached.
|
27
|
-
*/
|
28
|
-
|
29
|
-
/*
|
30
|
-
* Index into the table below with the first byte of a UTF-8 sequence to
|
31
|
-
* get the number of trailing bytes that are supposed to follow it.
|
32
|
-
* Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
|
33
|
-
* left as-is for anyone who may want to do such conversion, which was
|
34
|
-
* allowed in earlier algorithms.
|
35
|
-
*/
|
36
|
-
static const char trailingBytesForUTF8[256] = {
|
37
|
-
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 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, 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, 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, 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, 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, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
43
|
-
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
44
|
-
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
|
45
|
-
};
|
46
|
-
|
47
|
-
/*
|
48
|
-
* Magic values subtracted from a buffer value during UTF8 conversion.
|
49
|
-
* This table contains as many values as there might be trailing bytes
|
50
|
-
* in a UTF-8 sequence.
|
51
|
-
*/
|
52
|
-
static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
53
|
-
0x03C82080UL, 0xFA082080UL, 0x82082080UL };
|
54
|
-
|
55
|
-
/*
|
56
|
-
* Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
|
57
|
-
* into the first byte, depending on how many bytes follow. There are
|
58
|
-
* as many entries in this table as there are UTF-8 sequence types.
|
59
|
-
* (I.e., one byte sequence, two byte... etc.). Remember that sequencs
|
60
|
-
* for *legal* UTF-8 will be 4 or fewer bytes total.
|
61
|
-
*/
|
62
|
-
static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
63
|
-
|
64
|
-
/*
|
65
|
-
* Utility routine to tell whether a sequence of bytes is legal UTF-8.
|
66
|
-
* This must be called with the length pre-determined by the first byte.
|
67
|
-
* If not calling this from ConvertUTF8to*, then the length can be set by:
|
68
|
-
* length = trailingBytesForUTF8[*source]+1;
|
69
|
-
* and the sequence is illegal right away if there aren't that many bytes
|
70
|
-
* available.
|
71
|
-
* If presented with a length > 4, this returns 0. The Unicode
|
72
|
-
* definition of UTF-8 goes up to 4-byte sequences.
|
73
|
-
*/
|
74
|
-
|
75
|
-
inline static unsigned char isLegalUTF8(const UTF8 *source, int length)
|
76
|
-
{
|
77
|
-
UTF8 a;
|
78
|
-
const UTF8 *srcptr = source+length;
|
79
|
-
switch (length) {
|
80
|
-
default: return 0;
|
81
|
-
/* Everything else falls through when "1"... */
|
82
|
-
case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
|
83
|
-
case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return 0;
|
84
|
-
case 2: if ((a = (*--srcptr)) > 0xBF) return 0;
|
85
|
-
|
86
|
-
switch (*source) {
|
87
|
-
/* no fall-through in this inner switch */
|
88
|
-
case 0xE0: if (a < 0xA0) return 0; break;
|
89
|
-
case 0xED: if (a > 0x9F) return 0; break;
|
90
|
-
case 0xF0: if (a < 0x90) return 0; break;
|
91
|
-
case 0xF4: if (a > 0x8F) return 0; break;
|
92
|
-
default: if (a < 0x80) return 0;
|
93
|
-
}
|
94
|
-
|
95
|
-
case 1: if (*source >= 0x80 && *source < 0xC2) return 0;
|
96
|
-
}
|
97
|
-
if (*source > 0xF4) return 0;
|
98
|
-
return 1;
|
99
|
-
}
|
100
|
-
|
101
|
-
void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags)
|
102
|
-
{
|
103
|
-
char buf[7];
|
104
|
-
const UTF8* source = (UTF8 *) RSTRING_PTR(string);
|
105
|
-
const UTF8* sourceEnd = source + RSTRING_LEN(string);
|
106
|
-
|
107
|
-
while (source < sourceEnd) {
|
108
|
-
UTF32 ch = 0;
|
109
|
-
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
|
110
|
-
if (source + extraBytesToRead >= sourceEnd) {
|
111
|
-
rb_raise(rb_path2class("JSON::GeneratorError"),
|
112
|
-
"partial character in source, but hit end");
|
113
|
-
}
|
114
|
-
if (!isLegalUTF8(source, extraBytesToRead+1)) {
|
115
|
-
rb_raise(rb_path2class("JSON::GeneratorError"),
|
116
|
-
"source sequence is illegal/malformed");
|
117
|
-
}
|
118
|
-
/*
|
119
|
-
* The cases all fall through. See "Note A" below.
|
120
|
-
*/
|
121
|
-
switch (extraBytesToRead) {
|
122
|
-
case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
|
123
|
-
case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
|
124
|
-
case 3: ch += *source++; ch <<= 6;
|
125
|
-
case 2: ch += *source++; ch <<= 6;
|
126
|
-
case 1: ch += *source++; ch <<= 6;
|
127
|
-
case 0: ch += *source++;
|
128
|
-
}
|
129
|
-
ch -= offsetsFromUTF8[extraBytesToRead];
|
130
|
-
|
131
|
-
if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
|
132
|
-
/* UTF-16 surrogate values are illegal in UTF-32 */
|
133
|
-
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
|
134
|
-
if (flags == strictConversion) {
|
135
|
-
source -= (extraBytesToRead+1); /* return to the illegal value itself */
|
136
|
-
rb_raise(rb_path2class("JSON::GeneratorError"),
|
137
|
-
"source sequence is illegal/malformed");
|
138
|
-
} else {
|
139
|
-
unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
|
140
|
-
}
|
141
|
-
} else {
|
142
|
-
/* normal case */
|
143
|
-
if (ch == '"') {
|
144
|
-
rb_str_buf_cat2(buffer, "\\\"");
|
145
|
-
} else if (ch == '\\') {
|
146
|
-
rb_str_buf_cat2(buffer, "\\\\");
|
147
|
-
} else if (ch == '/') {
|
148
|
-
rb_str_buf_cat2(buffer, "\\/");
|
149
|
-
} else if (ch >= 0x20 && ch <= 0x7f) {
|
150
|
-
rb_str_buf_cat(buffer, (char *) source - 1, 1);
|
151
|
-
} else if (ch == '\n') {
|
152
|
-
rb_str_buf_cat2(buffer, "\\n");
|
153
|
-
} else if (ch == '\r') {
|
154
|
-
rb_str_buf_cat2(buffer, "\\r");
|
155
|
-
} else if (ch == '\t') {
|
156
|
-
rb_str_buf_cat2(buffer, "\\t");
|
157
|
-
} else if (ch == '\f') {
|
158
|
-
rb_str_buf_cat2(buffer, "\\f");
|
159
|
-
} else if (ch == '\b') {
|
160
|
-
rb_str_buf_cat2(buffer, "\\b");
|
161
|
-
} else if (ch < 0x20) {
|
162
|
-
unicode_escape(buffer, (UTF16) ch);
|
163
|
-
} else {
|
164
|
-
unicode_escape(buffer, (UTF16) ch);
|
165
|
-
}
|
166
|
-
}
|
167
|
-
} else if (ch > UNI_MAX_UTF16) {
|
168
|
-
if (flags == strictConversion) {
|
169
|
-
source -= (extraBytesToRead+1); /* return to the start */
|
170
|
-
rb_raise(rb_path2class("JSON::GeneratorError"),
|
171
|
-
"source sequence is illegal/malformed");
|
172
|
-
} else {
|
173
|
-
unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
|
174
|
-
}
|
175
|
-
} else {
|
176
|
-
/* target is a character in range 0xFFFF - 0x10FFFF. */
|
177
|
-
ch -= halfBase;
|
178
|
-
unicode_escape(buffer, (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START));
|
179
|
-
unicode_escape(buffer, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START));
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|