benschwarz-smoke 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +47 -0
- data/VERSION.yml +2 -2
- data/lib/core_ext/string.rb +6 -0
- data/lib/smoke/cache.rb +38 -23
- data/lib/smoke/request.rb +4 -8
- data/lib/smoke.rb +7 -2
- data/rdoc/classes/Smoke/Origin.html +340 -0
- data/rdoc/classes/Smoke/Source/Data.html +126 -0
- data/rdoc/classes/Smoke/Source/Feed.html +117 -0
- data/rdoc/classes/Smoke/Source/YQL.html +223 -0
- data/rdoc/classes/Smoke.html +260 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_markdown.html +180 -0
- data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
- data/rdoc/files/lib/smoke/origin_rb.html +49 -0
- data/rdoc/files/lib/smoke/request_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
- data/rdoc/files/lib/smoke_rb.html +65 -0
- data/rdoc/fr_class_index.html +21 -0
- data/rdoc/fr_file_index.html +28 -0
- data/rdoc/fr_method_index.html +4459 -0
- data/rdoc/index.html +15 -0
- data/rdoc/rdoc-style.css +319 -0
- data/spec/smoke/cache_spec.rb +28 -6
- data/vendor/crack/History +15 -0
- data/vendor/crack/LICENSE +20 -0
- data/vendor/crack/README.rdoc +42 -0
- data/vendor/crack/Rakefile +49 -0
- data/vendor/crack/VERSION.yml +4 -0
- data/vendor/crack/crack.gemspec +61 -0
- data/vendor/crack/lib/crack/core_extensions.rb +128 -0
- data/vendor/crack/lib/crack/json.rb +68 -0
- data/vendor/crack/lib/crack/xml.rb +214 -0
- data/vendor/crack/lib/crack.rb +7 -0
- data/vendor/crack/test/crack_test.rb +4 -0
- data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
- data/vendor/crack/test/data/twittersearch-ie.json +1 -0
- data/vendor/crack/test/hash_test.rb +56 -0
- data/vendor/crack/test/json_test.rb +66 -0
- data/vendor/crack/test/string_test.rb +31 -0
- data/vendor/crack/test/test_helper.rb +12 -0
- data/vendor/crack/test/xml_test.rb +489 -0
- data/vendor/dependencies/README.markdown +113 -0
- data/vendor/dependencies/Rakefile +5 -0
- data/vendor/dependencies/bin/dep +83 -0
- data/vendor/dependencies/dependencies.gemspec +15 -0
- data/vendor/dependencies/dependencies.gemspec.erb +27 -0
- data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
- data/vendor/dependencies/lib/dependencies.rb +5 -0
- data/vendor/dependencies/test/dependencies_test.rb +228 -0
- data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
- data/vendor/fakeweb/CHANGELOG +163 -0
- data/vendor/fakeweb/LICENSE.txt +281 -0
- data/vendor/fakeweb/README.rdoc +193 -0
- data/vendor/fakeweb/Rakefile +76 -0
- data/vendor/fakeweb/fakeweb.gemspec +21 -0
- data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
- data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
- data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
- data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
- data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
- data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
- data/vendor/fakeweb/lib/fake_web.rb +172 -0
- data/vendor/fakeweb/lib/fakeweb.rb +2 -0
- data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
- data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
- data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
- data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
- data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
- data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
- data/vendor/fakeweb/test/test_deprecations.rb +54 -0
- data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
- data/vendor/fakeweb/test/test_fake_web.rb +535 -0
- data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
- data/vendor/fakeweb/test/test_helper.rb +74 -0
- data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
- data/vendor/fakeweb/test/test_precedence.rb +51 -0
- data/vendor/fakeweb/test/test_query_string.rb +45 -0
- data/vendor/fakeweb/test/test_regexes.rb +103 -0
- data/vendor/fakeweb/test/test_response_headers.rb +73 -0
- data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
- data/vendor/fakeweb/test/test_utility.rb +70 -0
- data/vendor/json-1.1.3/CHANGES +93 -0
- data/vendor/json-1.1.3/GPL +340 -0
- data/vendor/json-1.1.3/README +78 -0
- data/vendor/json-1.1.3/RUBY +58 -0
- data/vendor/json-1.1.3/Rakefile +309 -0
- data/vendor/json-1.1.3/TODO +1 -0
- data/vendor/json-1.1.3/VERSION +1 -0
- data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
- data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
- data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
- data/vendor/json-1.1.3/data/example.json +1 -0
- data/vendor/json-1.1.3/data/index.html +38 -0
- data/vendor/json-1.1.3/data/prototype.js +4184 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
- data/vendor/json-1.1.3/install.rb +26 -0
- data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
- data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
- data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
- data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
- data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
- data/vendor/json-1.1.3/lib/json/common.rb +354 -0
- data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
- data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
- data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
- data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
- data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
- data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
- data/vendor/json-1.1.3/lib/json/version.rb +9 -0
- data/vendor/json-1.1.3/lib/json.rb +235 -0
- data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
- data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
- data/vendor/json-1.1.3/tests/runner.rb +25 -0
- data/vendor/json-1.1.3/tests/test_json.rb +293 -0
- data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
- data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
- data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
- data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
- data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
- data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
- data/vendor/json-1.1.3/tools/server.rb +62 -0
- data/vendor/moneta/LICENSE +20 -0
- data/vendor/moneta/README +51 -0
- data/vendor/moneta/Rakefile +60 -0
- data/vendor/moneta/TODO +4 -0
- data/vendor/moneta/benchmarks/various.rb +234 -0
- data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
- data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
- data/vendor/moneta/lib/moneta/couch.rb +63 -0
- data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
- data/vendor/moneta/lib/moneta/file.rb +91 -0
- data/vendor/moneta/lib/moneta/lmc.rb +52 -0
- data/vendor/moneta/lib/moneta/memcache.rb +53 -0
- data/vendor/moneta/lib/moneta/memory.rb +11 -0
- data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
- data/vendor/moneta/lib/moneta/redis.rb +49 -0
- data/vendor/moneta/lib/moneta/rufus.rb +41 -0
- data/vendor/moneta/lib/moneta/s3.rb +162 -0
- data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
- data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
- data/vendor/moneta/lib/moneta/xattr.rb +58 -0
- data/vendor/moneta/lib/moneta.rb +76 -0
- data/vendor/moneta/moneta.gemspec +32 -0
- data/vendor/moneta/script/destroy +14 -0
- data/vendor/moneta/script/generate +14 -0
- data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
- data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
- data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
- data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
- data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
- data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
- data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
- data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
- data/vendor/moneta/spec/shared.rb +122 -0
- data/vendor/moneta/spec/spec_helper.rb +7 -0
- data/vendor/rest-client/README.rdoc +151 -0
- data/vendor/rest-client/Rakefile +58 -0
- data/vendor/rest-client/VERSION +1 -0
- data/vendor/rest-client/bin/restclient +87 -0
- data/vendor/rest-client/lib/rest_client.rb +2 -0
- data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
- data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
- data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
- data/vendor/rest-client/lib/restclient/request.rb +238 -0
- data/vendor/rest-client/lib/restclient/resource.rb +146 -0
- data/vendor/rest-client/lib/restclient/response.rb +20 -0
- data/vendor/rest-client/lib/restclient.rb +99 -0
- data/vendor/rest-client/rest-client.gemspec +66 -0
- data/vendor/rest-client/spec/base.rb +4 -0
- data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
- data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
- data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
- data/vendor/rest-client/spec/request_spec.rb +476 -0
- data/vendor/rest-client/spec/resource_spec.rb +75 -0
- data/vendor/rest-client/spec/response_spec.rb +16 -0
- data/vendor/rest-client/spec/restclient_spec.rb +53 -0
- data/vendor/simple-rss/LICENSE +429 -0
- data/vendor/simple-rss/README +43 -0
- data/vendor/simple-rss/Rakefile +212 -0
- data/vendor/simple-rss/install.rb +40 -0
- data/vendor/simple-rss/lib/simple-rss.rb +150 -0
- data/vendor/simple-rss/simple-rss.gemspec +12 -0
- data/vendor/simple-rss/test/base/base_test.rb +51 -0
- data/vendor/simple-rss/test/data/atom.xml +45 -0
- data/vendor/simple-rss/test/data/not-rss.xml +8 -0
- data/vendor/simple-rss/test/data/rss09.rdf +79 -0
- data/vendor/simple-rss/test/data/rss20.xml +818 -0
- data/vendor/simple-rss/test/test_helper.rb +4 -0
- metadata +314 -40
@@ -0,0 +1,182 @@
|
|
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
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
#ifndef _GENERATOR_UNICODE_H_
|
4
|
+
#define _GENERATOR_UNICODE_H_
|
5
|
+
|
6
|
+
typedef enum {
|
7
|
+
conversionOK = 0, /* conversion successful */
|
8
|
+
sourceExhausted, /* partial character in source, but hit end */
|
9
|
+
targetExhausted, /* insuff. room in target for conversion */
|
10
|
+
sourceIllegal /* source sequence is illegal/malformed */
|
11
|
+
} ConversionResult;
|
12
|
+
|
13
|
+
typedef enum {
|
14
|
+
strictConversion = 0,
|
15
|
+
lenientConversion
|
16
|
+
} ConversionFlags;
|
17
|
+
|
18
|
+
typedef unsigned long UTF32; /* at least 32 bits */
|
19
|
+
typedef unsigned short UTF16; /* at least 16 bits */
|
20
|
+
typedef unsigned char UTF8; /* typically 8 bits */
|
21
|
+
|
22
|
+
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
23
|
+
#define UNI_MAX_BMP (UTF32)0x0000FFFF
|
24
|
+
#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
|
25
|
+
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
26
|
+
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
27
|
+
|
28
|
+
#define UNI_SUR_HIGH_START (UTF32)0xD800
|
29
|
+
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
|
30
|
+
#define UNI_SUR_LOW_START (UTF32)0xDC00
|
31
|
+
#define UNI_SUR_LOW_END (UTF32)0xDFFF
|
32
|
+
|
33
|
+
static const int halfShift = 10; /* used for shifting by 10 bits */
|
34
|
+
|
35
|
+
static const UTF32 halfBase = 0x0010000UL;
|
36
|
+
static const UTF32 halfMask = 0x3FFUL;
|
37
|
+
|
38
|
+
void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags);
|
39
|
+
|
40
|
+
#ifndef RARRAY_PTR
|
41
|
+
#define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
|
42
|
+
#endif
|
43
|
+
#ifndef RARRAY_LEN
|
44
|
+
#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
|
45
|
+
#endif
|
46
|
+
#ifndef RSTRING_PTR
|
47
|
+
#define RSTRING_PTR(string) RSTRING(string)->ptr
|
48
|
+
#endif
|
49
|
+
#ifndef RSTRING_LEN
|
50
|
+
#define RSTRING_LEN(string) RSTRING(string)->len
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#endif
|