Added TABLE_ITERABLE interface to JSON_OBJECT

Added JSON_OBJECT.replace (value, key)
This commit is contained in:
Jocelyn Fiat
2012-06-28 16:52:11 +02:00
parent c873d62efa
commit 873f877530

View File

@@ -21,7 +21,9 @@ class
inherit
JSON_VALUE
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
create
make
@@ -41,7 +43,7 @@ feature -- Change Element
require
key_not_present: not has_key (key)
local
l_value: detachable JSON_VALUE
l_value: like value
do
l_value := value
if l_value = Void then
@@ -50,6 +52,19 @@ feature -- Change Element
object.extend (l_value, key)
end
replace (value: detachable JSON_VALUE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: like value
do
l_value := value
if l_value = Void then
create {JSON_NULL} l_value
end
object.force (l_value, key)
end
feature -- Access
has_key (key: JSON_STRING): BOOLEAN
@@ -93,13 +108,28 @@ feature -- Access
t.forth
if not t.after then
Result.append_character (',')
end
end
end
Result.append_character ('}')
end
count: INTEGER
-- Number of field
do
Result := object.count
end
feature -- Access
new_cursor: TABLE_ITERATION_CURSOR [JSON_VALUE, JSON_STRING]
-- Fresh cursor associated with current structure
do
Result := object.new_cursor
end
feature -- Status report
is_empty: BOOLEAN
-- Is empty object?
do