Updated eJSON to use Eiffel 6.8 version.

Basically the changes are:

Replace ? by detachable
indexing by note
removing `is' from features, and in some places replaced by =
In the ecf now we need to include every gobo library, because the gobo.ecf, exclude libraries that are needed.
TODO: the test-suite is not void-safety.
This commit is contained in:
jvelilla
2011-07-07 12:03:25 +00:00
parent 94c5c90eaa
commit f4c472cb9f
26 changed files with 1009 additions and 929 deletions

View File

@@ -1,4 +1,4 @@
indexing
note
description: "A JSON converter"
author: "Paul Cohen"
date: "$Date: $"
@@ -7,35 +7,30 @@ indexing
deferred class JSON_CONVERTER
inherit
inherit
SHARED_EJSON
feature -- Access
value: JSON_VALUE is
-- JSON value
deferred
end
object: ANY is
object: ANY
-- Eiffel object
deferred
end
feature -- Conversion
from_json (j: like value): like object is
-- Convert from JSON value. Returns Void if unable to convert
from_json (j: attached like to_json): detachable like object
-- Convert from JSON value.
-- Returns Void if unable to convert
deferred
end
to_json (o: like object): like value is
to_json (o: like object): detachable JSON_VALUE
-- Convert to JSON value
deferred
end
invariant
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
end -- class JSON_CONVERTER
end

View File

@@ -1,4 +1,4 @@
indexing
note
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
author: "Paul Cohen"
date: "$Date$"
@@ -9,31 +9,30 @@ class JSON_HASH_TABLE_CONVERTER
inherit
JSON_CONVERTER
create
make
feature {NONE} -- Initialization
make is
make
do
create object.make (0)
end
feature -- Access
value: JSON_OBJECT
object: HASH_TABLE [ANY, HASHABLE]
feature -- Conversion
from_json (j: like value): like object is
from_json (j: attached like to_json): like object
local
keys: ARRAY [JSON_STRING]
i: INTEGER
h: HASHABLE
a: ANY
h: detachable HASHABLE
jv: detachable JSON_VALUE
a: detachable ANY
do
keys := j.current_keys
create Result.make (keys.count)
@@ -44,36 +43,46 @@ feature -- Conversion
loop
h ?= json.object (keys [i], void)
check h /= Void end
a := json.object (j.item (keys [i]), Void)
Result.put (a, h)
jv := j.item (keys [i])
if jv /= Void then
a := json.object (jv, Void)
if a /= Void then
Result.put (a, h)
else
check a_attached: a /= Void end
end
else
check j_has_item: False end
end
i := i + 1
end
end
to_json (o: like object): like value is
to_json (o: like object): detachable JSON_OBJECT
local
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
js: JSON_STRING
jv: JSON_VALUE
jv: detachable JSON_VALUE
failed: BOOLEAN
do
create Result.make
from
o.start
c := o.new_cursor
until
o.after
c.after
loop
create js.make_json (o.key_for_iteration.out)
jv := json.value (o.item_for_iteration)
create js.make_json (c.key.out)
jv := json.value (c.item)
if jv /= Void then
Result.put (jv, js)
else
failed := True
end
o.forth
end
c.forth
end
if failed then
Result := Void
end
end
end -- class JSON_HASH_TABLE_CONVERTER
end -- class JSON_HASH_TABLE_CONVERTER

View File

@@ -1,4 +1,4 @@
indexing
note
description: "A JSON converter for LINKED_LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
@@ -9,26 +9,24 @@ class JSON_LINKED_LIST_CONVERTER
inherit
JSON_CONVERTER
create
make
feature {NONE} -- Initialization
make is
make
do
create object.make
end
feature -- Access
value: JSON_ARRAY
object: LINKED_LIST [ANY]
object: LINKED_LIST [detachable ANY]
feature -- Conversion
from_json (j: like value): like object is
from_json (j: like to_json): detachable like object
local
i: INTEGER
do
@@ -42,20 +40,24 @@ feature -- Conversion
i := i + 1
end
end
to_json (o: like object): like value is
to_json (o: like object): JSON_ARRAY
local
c: LINKED_LIST_CURSOR [ANY]
c: ITERATION_CURSOR [detachable ANY]
do
create Result.make_array
from
o.start
c := o.new_cursor
until
o.after
c.after
loop
Result.add (json.value (o.item))
o.forth
if attached json.value (c.item) as v then
Result.add (v)
else
check attached_value: False end
end
c.forth
end
end
end -- class JSON_LINKED_LIST_CONVERTER
end -- class JSON_LINKED_LIST_CONVERTER