Skip to content

Commit 9c6b6b9

Browse files
committed
Merge pull request #11 from jocelyn/improved_sept_2014
Fixed various issue with parsing string (such as \t and related), Implemented escaping of slash '/' only in case of '</' to avoid potential issue with javascript and </script> Many feature renaming to match Eiffel style and naming convention, kept previous feature as obsolete. Restructured the library to make easy extraction of "converter" classes if needed in the future. Marked converters classes as obsolete. Updated part of the code to use new feature names. Updated license and copyright. Updated classes with bottom indexing notes related to copyright and license.
2 parents de28294 + 0647a74 commit 9c6b6b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1216
-785
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
*.ecf text
88
*.bat text
99
*.json text
10+
*.txt text

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*.swp
2-
EIFGENs
2+
EIFGENs/

History.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
History file for EJSON
1+
History file for EJSON
22
======================
33

44
team: ""
@@ -23,4 +23,4 @@ implementation.
2323

2424
*Added converters and factory classes
2525

26-
*Added new top level directories; library, test, build and example
26+
*Added new top level directories; library, test, build and example

License.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
Copyright (c) 2010 Javier Velilla and others, http://ejson.origo.ethz.ch
1+
Copyright (c) 2010-2014 Javier Velilla and others,
2+
https://github.com/eiffelhub/json .
23

34

45
Permission is hereby granted, free of charge, to any person obtaining a copy
56
of this software and associated documentation files (the "Software"), to deal
67
in the Software without restriction, including without limitation the rights
78
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89
copies of the Software, and to permit persons to whom the Software is
9-
furnished to do so, subject to the following conditions:
10+
furnished to do so, subject to the following conditions:
1011

1112
The above copyright notice and this permission notice shall be included in
12-
all copies or substantial portions of the Software.
13+
all copies or substantial portions of the Software.
1314

1415
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1516
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1617
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1718
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1819
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1920
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20-
THE SOFTWARE.
21+
THE SOFTWARE.

library/kernel/converters/json_arrayed_list_converter.e renamed to library/converter/json_arrayed_list_converter.e

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
class
99
JSON_ARRAYED_LIST_CONVERTER
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
JSON_LIST_CONVERTER
@@ -29,4 +32,7 @@ feature {NONE} -- Factory
2932
create Result.make (nb)
3033
end
3134

35+
note
36+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
37+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
3238
end -- class JSON_ARRAYED_LIST_CONVERTER

library/kernel/converters/json_converter.e renamed to library/converter/json_converter.e

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
deferred class
99
JSON_CONVERTER
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
SHARED_EJSON
@@ -35,4 +38,7 @@ feature -- Conversion
3538
invariant
3639
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
3740

41+
note
42+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
43+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
3844
end

library/kernel/converters/json_hash_table_converter.e renamed to library/converter/json_hash_table_converter.e

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
class
99
JSON_HASH_TABLE_CONVERTER
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
JSON_CONVERTER
@@ -52,31 +55,34 @@ feature -- Conversion
5255

5356
to_json (o: like object): detachable JSON_OBJECT
5457
local
55-
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
5658
js: JSON_STRING
5759
failed: BOOLEAN
5860
do
5961
create Result.make
60-
from
61-
c := o.new_cursor
62-
until
63-
c.after
62+
across
63+
o as c
6464
loop
6565
if attached {JSON_STRING} json.value (c.key) as l_key then
6666
js := l_key
6767
else
68-
create js.make_json (c.key.out)
68+
if attached {READABLE_STRING_GENERAL} c.key as s_key then
69+
create js.make_from_string_general (s_key)
70+
else
71+
create js.make_from_string (c.key.out)
72+
end
6973
end
7074
if attached json.value (c.item) as jv then
7175
Result.put (jv, js)
7276
else
7377
failed := True
7478
end
75-
c.forth
7679
end
7780
if failed then
7881
Result := Void
7982
end
8083
end
8184

85+
note
86+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
87+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
8288
end -- class JSON_HASH_TABLE_CONVERTER

library/kernel/converters/json_linked_list_converter.e renamed to library/converter/json_linked_list_converter.e

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
class
99
JSON_LINKED_LIST_CONVERTER
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
JSON_LIST_CONVERTER
@@ -29,4 +32,7 @@ feature {NONE} -- Factory
2932
create Result.make
3033
end
3134

35+
note
36+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
37+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
3238
end -- class JSON_LINKED_LIST_CONVERTER

library/kernel/converters/json_list_converter.e renamed to library/converter/json_list_converter.e

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
deferred class
99
JSON_LIST_CONVERTER
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
JSON_CONVERTER
@@ -51,17 +54,15 @@ feature -- Conversion
5154
to_json (o: like object): detachable JSON_ARRAY
5255
local
5356
c: ITERATION_CURSOR [detachable ANY]
54-
jv: detachable JSON_VALUE
5557
failed: BOOLEAN
5658
do
57-
create Result.make_array
59+
create Result.make (o.count)
5860
from
5961
c := o.new_cursor
6062
until
6163
c.after
6264
loop
63-
jv := json.value (c.item)
64-
if jv /= Void then
65+
if attached json.value (c.item) as jv then
6566
Result.add (jv)
6667
else
6768
failed := True
@@ -73,4 +74,7 @@ feature -- Conversion
7374
end
7475
end
7576

77+
note
78+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
79+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
7680
end -- class JSON_ARRAYED_LIST_CONVERTER

library/kernel/ejson.e renamed to library/converter/support/ejson.e

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ note
88
class
99
EJSON
1010

11+
obsolete
12+
"This JSON converter design has issues [Sept/2014]."
13+
1114
inherit
1215

1316
EXCEPTIONS
@@ -27,7 +30,7 @@ feature -- Access
2730
if an_object = Void then
2831
create {JSON_NULL} Result
2932
elseif attached {BOOLEAN} an_object as b then
30-
create {JSON_BOOLEAN} Result.make_boolean (b)
33+
create {JSON_BOOLEAN} Result.make (b)
3134
elseif attached {INTEGER_8} an_object as i8 then
3235
create {JSON_NUMBER} Result.make_integer (i8)
3336
elseif attached {INTEGER_16} an_object as i16 then
@@ -49,7 +52,7 @@ feature -- Access
4952
elseif attached {REAL_64} an_object as r64 then
5053
create {JSON_NUMBER} Result.make_real (r64)
5154
elseif attached {ARRAY [detachable ANY]} an_object as a then
52-
create ja.make_array
55+
create ja.make (a.count)
5356
from
5457
i := a.lower
5558
until
@@ -66,13 +69,13 @@ feature -- Access
6669
end
6770
Result := ja
6871
elseif attached {CHARACTER_8} an_object as c8 then
69-
create {JSON_STRING} Result.make_json (c8.out)
72+
create {JSON_STRING} Result.make_from_string (c8.out)
7073
elseif attached {CHARACTER_32} an_object as c32 then
71-
create {JSON_STRING} Result.make_json (c32.out)
74+
create {JSON_STRING} Result.make_from_string_32 (create {STRING_32}.make_filled (c32, 1))
7275
elseif attached {STRING_8} an_object as s8 then
73-
create {JSON_STRING} Result.make_json (s8)
76+
create {JSON_STRING} Result.make_from_string (s8)
7477
elseif attached {STRING_32} an_object as s32 then
75-
create {JSON_STRING} Result.make_json_from_string_32 (s32)
78+
create {JSON_STRING} Result.make_from_string_32 (s32)
7679
end
7780
if Result = Void then
7881
-- Now check the converters
@@ -162,12 +165,10 @@ feature -- Access
162165
-- "eJSON exception" if unable to convert value.
163166
require
164167
json_not_void: json /= Void
165-
local
166-
jv: detachable JSON_VALUE
167168
do
168169
json_parser.set_representation (json)
169-
jv := json_parser.parse
170-
if jv /= Void then
170+
json_parser.parse_content
171+
if json_parser.is_valid and then attached json_parser.parsed_json_value as jv then
171172
Result := object (jv, base_class)
172173
end
173174
end
@@ -192,8 +193,8 @@ feature -- Access
192193
js_key, js_value: JSON_STRING
193194
do
194195
create Result.make
195-
create js_key.make_json ("$ref")
196-
create js_value.make_json (s)
196+
create js_key.make_from_string ("$ref")
197+
create js_value.make_from_string (s)
197198
Result.put (js_value, js_key)
198199
end
199200

@@ -207,7 +208,7 @@ feature -- Access
207208
local
208209
c: ITERATION_CURSOR [STRING]
209210
do
210-
create Result.make_array
211+
create Result.make (l.count)
211212
from
212213
c := l.new_cursor
213214
until
@@ -264,7 +265,10 @@ feature {NONE} -- Implementation (JSON parser)
264265

265266
json_parser: JSON_PARSER
266267
once
267-
create Result.make_parser ("")
268+
create Result.make_with_string ("{}")
268269
end
269270

271+
note
272+
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
273+
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
270274
end -- class EJSON

0 commit comments

Comments
 (0)