eJson initial import
This commit is contained in:
87
json/json_array.e
Normal file
87
json/json_array.e
Normal file
@@ -0,0 +1,87 @@
|
||||
indexing
|
||||
description: "[
|
||||
JSON_ARRAY represent an array in JSON.
|
||||
An array in JSON is an ordered set of names.
|
||||
Examples
|
||||
array
|
||||
[]
|
||||
[elements]
|
||||
]"
|
||||
|
||||
author: "Javier Velilla"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
JSON_ARRAY
|
||||
inherit
|
||||
JSON_VALUE
|
||||
|
||||
create
|
||||
make_array
|
||||
|
||||
feature -- Initialization
|
||||
make_array is
|
||||
--
|
||||
do
|
||||
create values.make (10)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
feature -- Change Element
|
||||
add(value:JSON_VALUE) is
|
||||
require
|
||||
not_null:value /= void
|
||||
local
|
||||
l_json_value:JSON_VALUE
|
||||
do
|
||||
values.extend(value)
|
||||
ensure
|
||||
has_new_value:old values.count + 1 = values.count
|
||||
end
|
||||
|
||||
|
||||
to_json:STRING is
|
||||
--Printable json representation
|
||||
-- [] or [elements]
|
||||
local
|
||||
value:JSON_VALUE
|
||||
do
|
||||
create Result.make_empty
|
||||
Result.append("[")
|
||||
from
|
||||
values.start
|
||||
until
|
||||
values.off
|
||||
loop
|
||||
value:=values.item
|
||||
Result.append(value.to_json)
|
||||
values.forth
|
||||
if not values.after then
|
||||
Result.append(",")
|
||||
end
|
||||
end
|
||||
Result.append("]")
|
||||
end
|
||||
|
||||
hash_code:INTEGER is
|
||||
--
|
||||
do
|
||||
from
|
||||
values.start
|
||||
Result:=values.item.hash_code
|
||||
until
|
||||
values.off
|
||||
loop
|
||||
Result:= ((Result \\ 8388593) |<< 8) + values.item.hash_code
|
||||
values.forth
|
||||
end
|
||||
Result := Result \\ values.count
|
||||
|
||||
end
|
||||
feature {NONE} --Implementation
|
||||
values:ARRAYED_LIST[JSON_VALUE]
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user