ruco-cpp 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7c8882435b1fd99eebef6b07d7e00273934f6f47
4
- data.tar.gz: ed82ad7551bbb55fbc589abaeb074ab2de17cf05
2
+ SHA256:
3
+ metadata.gz: fde0d89b0cea80fd08caa7bf3fc46ee89b24098e53aeb92d64c84a95747cccf1
4
+ data.tar.gz: af7f5b234e5adf5b42271102ec9b132949bc44b0a9a9607bdb39c3b814888f52
5
5
  SHA512:
6
- metadata.gz: e8b1333221d0061e48728e7187c0b4a569d66fe39868e72ed83deab021ebe17f6c2205f133cc713f8b7827e4a6ced041c5a4dbde8339f528e09090569dcac312
7
- data.tar.gz: cc926f9b2347e19c1a309faaa15908067e03bcd2eb38060161341ee02fef8d3dd444ceb492da86e16aabcad703da3dbef6f43b8e775d75db31849f0f4203fd28
6
+ metadata.gz: f28b8c2c8be199bc549a63c096d984e0e7ec51c5ac53ba39fb9b3e2fa5a3a06ace569a913e0bf2233cbfaf44c8a30fe515fa0fa64cd49de5494811bd1dd97eb5
7
+ data.tar.gz: 96e0fe0766a35ec85d0f0f857fe8f65feeb6b0194b2cddd64602c3145757232bfa0dd38f427a927b308e6045d6c294b055d5ed90a711dc8205e83e7324dd8e91
@@ -420,7 +420,7 @@ namespace picojson {
420
420
  MAP(L'\t', L"\\t");
421
421
  #undef MAP
422
422
  default:
423
- if (static_cast<unsigned wchar_t>(*i) < 0x20 || *i == 0x7f) {
423
+ if (static_cast<wchar_t>(*i) < 0x20 || *i == 0x7f) {
424
424
  wchar_t buf[7];
425
425
  SNPRINTF(buf, sizeof(buf), L"\\u%04x", *i & 0xff);
426
426
  copy(buf, buf + 6, oi);
data/lib/ruco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ruco
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco-cpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-22 00:00:00.000000000 Z
11
+ date: 2023-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,58 +28,58 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake-compiler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.9.5
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.9.5
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.3'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.3'
82
+ version: '0'
83
83
  description: Generates an LL(1) parser for a grammar described in a .ruco file
84
84
  email:
85
85
  - davidsiaw@gmail.com
@@ -95,13 +95,6 @@ files:
95
95
  - bin/setup
96
96
  - data/ruco-cpp/Parser.frame
97
97
  - data/ruco-cpp/Scanner.frame
98
- - data/ruco-cpp/picojson/Changes
99
- - data/ruco-cpp/picojson/LICENSE
100
- - data/ruco-cpp/picojson/Makefile
101
- - data/ruco-cpp/picojson/README.mkdn
102
- - data/ruco-cpp/picojson/examples/github-issues.cc
103
- - data/ruco-cpp/picojson/examples/iostream.cc
104
- - data/ruco-cpp/picojson/examples/streaming.cc
105
98
  - data/ruco-cpp/picojson/picojson.h
106
99
  - ext/cocor/Action.cpp
107
100
  - ext/cocor/Action.h
@@ -186,8 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
179
  - !ruby/object:Gem::Version
187
180
  version: '0'
188
181
  requirements: []
189
- rubyforge_project:
190
- rubygems_version: 2.6.14
182
+ rubygems_version: 3.1.4
191
183
  signing_key:
192
184
  specification_version: 4
193
185
  summary: Boilerplate generator for Coco/R
@@ -1,14 +0,0 @@
1
- Revision history for picojson
2
-
3
- 1.1.1 2014-06-25 10:35:00+0900
4
- - tweaks to suppress compiler errors / warning (#38 #39)
5
- - clarify the licenses of the files in exmaple/ (#42)
6
-
7
- 1.1 2014-06-16 12:57:00+0900
8
- - added experimental support for int64 type (#34)
9
- - by default, throw std::runtime_error instead of using assert for runtime errors (#33)
10
- - refine compatibility regarding the use of isinf/isnan (#29, #36)
11
- - remove `.get<int>()` (#35)
12
-
13
- 1.0 2014-06-05 12:54:00+0900
14
- - initial release with a version number
@@ -1,25 +0,0 @@
1
- Copyright 2009-2010 Cybozu Labs, Inc.
2
- Copyright 2011-2014 Kazuho Oku
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice,
9
- this list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
- POSSIBILITY OF SUCH DAMAGE.
@@ -1,8 +0,0 @@
1
- test:
2
- $(MAKE) test-core
3
- $(MAKE) test-core TEST_OPTS=-DPICOJSON_USE_INT64
4
-
5
- test-core:
6
- $(CXX) -o test-core -Wall $(TEST_OPTS) -DTEST_PICOJSON -x c++ - < picojson.h && ./test-core
7
-
8
- .PHONY: test test-core
@@ -1,183 +0,0 @@
1
- # PicoJSON - a C++ JSON parser / serializer
2
-
3
- Copyright &copy; 2009-2010 Cybozu Labs, Inc.
4
- Copyright &copy; 2011-2014 Kazuho Oku
5
-
6
- Licensed under [2-clause BSD license](http://opensource.org/licenses/BSD-2-Clause)
7
-
8
- ## Version
9
-
10
- 1.1.2-dev [![Build Status](https://travis-ci.org/kazuho/picojson.svg?branch=master)](https://travis-ci.org/kazuho/picojson)
11
-
12
- ## Introduction
13
-
14
- PicoJSON is a tiny JSON parser / serializer for C++ with following properties:
15
-
16
- - header-file only
17
- - no external dependencies (only uses standard C++ libraries)
18
- - STL-frendly (arrays are represented by using std::vector, objects are std::map)
19
- - provides both pull interface and streaming (event-based) interface
20
-
21
- ## Reading JSON using the pull interface
22
-
23
- There are two ways to use the pull (DOM-like) interface of picojson. One is to use operator&lt;&lt;, and the other is by specifying a set of iterators specifying the range from where the JSON stream should be read.
24
-
25
- <pre>
26
- picojson::value v;
27
- std::cin &gt;&gt; v;
28
- std::string err = picojson::get_last_error();
29
- if (! err.empty()) {
30
- std::cerr &lt;&lt; err &lt;&lt; std::endl;
31
- }
32
- </pre>
33
-
34
- <pre>
35
- std::istream_iterator input(cin);
36
- picojson::value v;
37
- std::string err;
38
- input = picojson::parse(v, input, std::istream_iterator(), &err);
39
- if (! err.empty()) {
40
- std::cerr &lt;&lt; err &lt;&lt; std::endl;
41
- }
42
- </pre>
43
-
44
- <pre>
45
- const char* json = "{\"a\":1}";
46
- picojson::value v;
47
- std::string err;
48
- picojson::parse(v, json, json + strlen(json), &err);
49
- if (! err.empty()) {
50
- std::cerr &lt;&lt; err &lt;&lt; std::endl;
51
- }
52
- </pre>
53
-
54
- ## Accessing the values
55
-
56
- Values of a JSON object is represented as instances of picojson::value class.
57
-
58
- <pre>
59
- namespace picojson {
60
-
61
- class value {
62
- ...
63
-
64
- public:
65
-
66
- typedef std::vector&lt;value&gt; array;
67
- typedef std::map&lt;std::string, value&gt; object;
68
-
69
- value(); // create a null object
70
- explicit value(bool b); // create a boolean object
71
- explicit value(double n); // create a number object
72
- explicit value(const std::string& s); // create a string object
73
- explicit value(const array& a); // create an array object
74
- explicit value(const object& o); // create an "object"
75
-
76
- bool is&lt;picojson::null&gt;() const; // check if the object is "null"
77
-
78
- bool is&lt;bool&gt;() const; // check if the object is a boolean
79
- const bool& get&lt;bool&gt;() const; // const accessor (usable only if the object is a boolean)
80
- bool& get&lt;bool&gt;(); // non-const accessor (usable only if the object is a boolean)
81
-
82
- bool is&lt;double&gt;() const; // check if the object is a number
83
- const double& get&lt;double&gt;() const; // const accessor (usable only if the object is a number)
84
- double& get&lt;double&gt;(); // non-const accessor (usable only if the object is a number)
85
-
86
- bool is&lt;std::string&gt;() const; // check if the object is a string
87
- const std::string& get&lt;std::string&gt;() const;
88
- // const accessor (usable only if the object is a string)
89
- std::string& get&lt;std::string&gt;(); // non-const accessor (usable only if the object is a string)
90
-
91
- bool is&lt;array&gt;() const; // check if the object is an array
92
- const array& get&lt;array&gt;() const; // const accessor (usable only if the object is an array)
93
- array& get&lt;array&gt;(); // non-const accessor (usable only if the object is an array)
94
-
95
- bool is&lt;object&gt;() const; // check if the object is an "object"
96
- const object& get&lt;object&gt;() const; // const accessor (usable only if the object is an object)
97
- object& get&lt;object&gt;(); // non-const accessor (usable only if the object is an array)
98
-
99
- bool evaluate_as_boolean() const; // evaluates the object as a boolean
100
-
101
- std::string serialize() const; // returns the object in JSON representation
102
- template<typename Iter> void serialize(Iter os) const;
103
- // serializes the object in JSON representation through an output iterator
104
-
105
- std::string to_str() const; // returns the object in string (for casual use)
106
-
107
- };
108
-
109
- }
110
- </pre>
111
-
112
- The code below parses a JSON string and prints the contents of the object.
113
-
114
- <pre>
115
- picojson::value v;
116
-
117
- // parse the input
118
- std::cin &gt;&gt; v;
119
- std::string err = picojson::get_last_error();
120
- if (! err.empty()) {
121
- std::cerr &lt;&lt; err &lt;&lt; std::endl;
122
- exit(1);
123
- }
124
-
125
- // check if the type of the value is "object"
126
- if (! v.is&lt;picojson::object&gt;()) {
127
- std::cerr &lt;&lt; "JSON is not an object" &lt;&lt; std::endl;
128
- exit(2);
129
- }
130
-
131
- // obtain a const reference to the map, and print the contents
132
- const picojson::value::object& obj = v.get&lt;picojson::object&gt;();
133
- for (picojson::value::object::const_iterator i = obj.begin();
134
- i != obj.end();
135
- ++i) {
136
- std::cout &lt;&lt; i-&gt;first &lt;&lt; ': ' &lt;&lt; i-&gt;second.to_str() &lt;&lt; std::endl;
137
- }
138
- </pre>
139
-
140
- Please note that the type check is mandatory; do not forget to check the type of the object by calling is&lt;type&gt;() before accessing the value by calling get&lt;type&gt;().
141
-
142
- ## Reading JSON using the streaming (event-driven) interface
143
-
144
- Please refer to the implementation of picojson::default_parse_context and picojson::null_parse_context. There is also an example (examples/streaming.cc) .
145
-
146
- ## Serializing to JSON
147
-
148
- Instances of the picojson::value class can be serialized in three ways, to ostream, to std::string, or to an output iterator.
149
-
150
- <pre>
151
- picojson::value v;
152
- ...
153
- std::cout &lt;&lt; v;
154
- </pre>
155
-
156
- <pre>
157
- picojson::value v;
158
- ...
159
- std::string json = v.serialize();
160
- </pre>
161
-
162
- <pre>
163
- picojson::value v;
164
- ...
165
- v.serialize(std::ostream_iterator(std::cout));
166
- </pre>
167
-
168
- ## Experimental support for int64_t
169
-
170
- Experimental suport for int64_t becomes available if the code is compiled with preprocessor macro `PICOJSON_USE_INT64`.
171
-
172
- Turning on the feature will cause following changes to picojson:
173
- - new constructor `picojson::value(int64_t)` is defined
174
- - `is<int64_t>()` and `get<int64_t>()` become available
175
- - numerics in JSON within the bounds of int64_t and not using `.` nor `e`/`E` are considered as int64 type
176
- - the values are also avaliable as `double`s as well (i.e. all values which are `.is<int64_t>() == true` are also `.is<double>() == true`)
177
- - int64 values are converted to double once `get<double>()` is called
178
-
179
- Enabling the feature should not cause compatibility problem with code that do not use the feature.
180
-
181
- ## Further reading
182
-
183
- Examples can be found in the <i>examples</i> directory, and on the [Wiki](https://github.com/kazuho/picojson/wiki). Please add your favorite examples to the Wiki.
@@ -1,110 +0,0 @@
1
- /*
2
- * Copyright 2009-2010 Cybozu Labs, Inc.
3
- * Copyright 2011-2014 Kazuho Oku
4
- * All rights reserved.
5
- *
6
- * Redistribution and use in source and binary forms, with or without
7
- * modification, are permitted provided that the following conditions are met:
8
- *
9
- * 1. Redistributions of source code must retain the above copyright notice,
10
- * this list of conditions and the following disclaimer.
11
- *
12
- * 2. Redistributions in binary form must reproduce the above copyright notice,
13
- * this list of conditions and the following disclaimer in the documentation
14
- * and/or other materials provided with the distribution.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
- * POSSIBILITY OF SUCH DAMAGE.
27
- */
28
- #include <curl/curl.h>
29
- #include "../picojson.h"
30
-
31
- typedef struct {
32
- char* data; // response data from server
33
- size_t size; // response size of data
34
- } MEMFILE;
35
-
36
- MEMFILE*
37
- memfopen() {
38
- MEMFILE* mf = (MEMFILE*) malloc(sizeof(MEMFILE));
39
- mf->data = NULL;
40
- mf->size = 0;
41
- return mf;
42
- }
43
-
44
- void
45
- memfclose(MEMFILE* mf) {
46
- if (mf->data) free(mf->data);
47
- free(mf);
48
- }
49
-
50
- size_t
51
- memfwrite(char* ptr, size_t size, size_t nmemb, void* stream) {
52
- MEMFILE* mf = (MEMFILE*) stream;
53
- int block = size * nmemb;
54
- if (!mf->data)
55
- mf->data = (char*) malloc(block);
56
- else
57
- mf->data = (char*) realloc(mf->data, mf->size + block);
58
- if (mf->data) {
59
- memcpy(mf->data + mf->size, ptr, block);
60
- mf->size += block;
61
- }
62
- return block;
63
- }
64
-
65
- char*
66
- memfstrdup(MEMFILE* mf) {
67
- char* buf = (char*)malloc(mf->size + 1);
68
- memcpy(buf, mf->data, mf->size);
69
- buf[mf->size] = 0;
70
- return buf;
71
- }
72
-
73
- using namespace std;
74
- using namespace picojson;
75
-
76
- int
77
- main(int argc, char* argv[]) {
78
- char error[256];
79
-
80
- MEMFILE* mf = memfopen();
81
- CURL* curl = curl_easy_init();
82
- curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repos/kazuho/picojson/issues");
83
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
84
- curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl");
85
- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error);
86
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memfwrite);
87
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, mf);
88
- if (curl_easy_perform(curl) != CURLE_OK) {
89
- cerr << error << endl;
90
- } else {
91
- value v;
92
- string err;
93
- parse(v, mf->data, mf->data + mf->size, &err);
94
- if (err.empty()) {
95
- array arr = v.get<array>();
96
- array::iterator it;
97
- for (it = arr.begin(); it != arr.end(); it++) {
98
- object obj = it->get<object>();
99
- cout << "#" << obj["number"].to_str() << ": " << obj["title"].to_str() << endl;
100
- cout << " " << obj["html_url"].to_str() << endl << endl;
101
- }
102
- } else {
103
- cerr << err << endl;
104
- }
105
- }
106
- curl_easy_cleanup(curl);
107
- memfclose(mf);
108
-
109
- return 0;
110
- }
@@ -1,70 +0,0 @@
1
- /*
2
- * Copyright 2009-2010 Cybozu Labs, Inc.
3
- * Copyright 2011-2014 Kazuho Oku
4
- * All rights reserved.
5
- *
6
- * Redistribution and use in source and binary forms, with or without
7
- * modification, are permitted provided that the following conditions are met:
8
- *
9
- * 1. Redistributions of source code must retain the above copyright notice,
10
- * this list of conditions and the following disclaimer.
11
- *
12
- * 2. Redistributions in binary form must reproduce the above copyright notice,
13
- * this list of conditions and the following disclaimer in the documentation
14
- * and/or other materials provided with the distribution.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
- * POSSIBILITY OF SUCH DAMAGE.
27
- */
28
- #include "../picojson.h"
29
-
30
- int main(void)
31
- {
32
- picojson::value v;
33
-
34
- // read json value from stream
35
- std::cin >> v;
36
- if (std::cin.fail()) {
37
- std::cerr << picojson::get_last_error() << std::endl;
38
- return 1;
39
- }
40
-
41
- // dump json object
42
- std::cout << "---- dump input ----" << std::endl;
43
- std::cout << v << std::endl;
44
-
45
- // accessors
46
- std::cout << "---- analyzing input ----" << std::endl;
47
- if (v.is<picojson::null>()) {
48
- std::cout << "input is null" << std::endl;
49
- } else if (v.is<bool>()) {
50
- std::cout << "input is " << (v.get<bool>() ? "true" : "false") << std::endl;
51
- } else if (v.is<double>()) {
52
- std::cout << "input is " << v.get<double>() << std::endl;
53
- } else if (v.is<std::string>()) {
54
- std::cout << "input is " << v.get<std::string>() << std::endl;
55
- } else if (v.is<picojson::array>()) {
56
- std::cout << "input is an array" << std::endl;
57
- const picojson::array& a = v.get<picojson::array>();
58
- for (picojson::array::const_iterator i = a.begin(); i != a.end(); ++i) {
59
- std::cout << " " << *i << std::endl;
60
- }
61
- } else if (v.is<picojson::object>()) {
62
- std::cout << "input is an object" << std::endl;
63
- const picojson::object& o = v.get<picojson::object>();
64
- for (picojson::object::const_iterator i = o.begin(); i != o.end(); ++i) {
65
- std::cout << i->first << " " << i->second << std::endl;
66
- }
67
- }
68
-
69
- return 0;
70
- }
@@ -1,76 +0,0 @@
1
- /*
2
- * Copyright 2009-2010 Cybozu Labs, Inc.
3
- * Copyright 2011-2014 Kazuho Oku
4
- * All rights reserved.
5
- *
6
- * Redistribution and use in source and binary forms, with or without
7
- * modification, are permitted provided that the following conditions are met:
8
- *
9
- * 1. Redistributions of source code must retain the above copyright notice,
10
- * this list of conditions and the following disclaimer.
11
- *
12
- * 2. Redistributions in binary form must reproduce the above copyright notice,
13
- * this list of conditions and the following disclaimer in the documentation
14
- * and/or other materials provided with the distribution.
15
- *
16
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
- * POSSIBILITY OF SUCH DAMAGE.
27
- */
28
- #include <iostream>
29
- #include <iterator>
30
- #include "../picojson.h"
31
-
32
- // this example reads a array of hashes (each item representing a 2D point),
33
- // and prints the x and y values to stdout
34
-
35
- namespace {
36
-
37
- class root_context : public picojson::deny_parse_context {
38
- public:
39
- bool parse_array_start() {
40
- return true; // only allow array as root
41
- }
42
- template <typename Iter> bool parse_array_item(picojson::input<Iter>& in, size_t) {
43
- picojson::value item;
44
- // parse the array item
45
- picojson::default_parse_context ctx(&item);
46
- if (! picojson::_parse(ctx, in)) {
47
- return false;
48
- }
49
- // assert that the array item is a hash
50
- if (! item.is<picojson::object>()) {
51
- return false;
52
- }
53
- // print x and y
54
- std::cout << item.get("x") << ',' << item.get("y").to_str()
55
- << std::endl;
56
- return true;
57
- }
58
- };
59
-
60
- }
61
-
62
- int main(void)
63
- {
64
- root_context ctx;
65
- std::string err;
66
-
67
- picojson::_parse(ctx, std::istream_iterator<char>(std::cin),
68
- std::istream_iterator<char>(), &err);
69
-
70
- if (! err.empty()) {
71
- std::cerr << err << std::endl;
72
- return 1;
73
- }
74
-
75
- return 0;
76
- }