Update JSON_VALUE and JSON_OBJECT interface
This commit is contained in:
@@ -28,6 +28,25 @@ feature -- Initialization
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
i_th alias "[]", infix "@" (i: INTEGER):JSON_VALUE is
|
||||||
|
-- Item at `i'-th position
|
||||||
|
do
|
||||||
|
Result := values.i_th (i)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Mesurement
|
||||||
|
count:INTEGER is
|
||||||
|
--
|
||||||
|
do
|
||||||
|
Result:=values.count
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Status report
|
||||||
|
valid_index (i: INTEGER): BOOLEAN is
|
||||||
|
-- Is `i' a valid index?
|
||||||
|
do
|
||||||
|
Result := (1 <= i) and (i <= count)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
add(value:JSON_VALUE) is
|
add(value:JSON_VALUE) is
|
||||||
@@ -41,7 +60,7 @@ feature -- Change Element
|
|||||||
has_new_value:old values.count + 1 = values.count
|
has_new_value:old values.count + 1 = values.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Report
|
||||||
to_json:STRING is
|
to_json:STRING is
|
||||||
--Printable json representation
|
--Printable json representation
|
||||||
-- [] or [elements]
|
-- [] or [elements]
|
||||||
|
|||||||
@@ -36,4 +36,5 @@ feature -- Access
|
|||||||
|
|
||||||
value:BOOLEAN
|
value:BOOLEAN
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ feature --Access
|
|||||||
Result:= null_value.hash_code
|
Result:= null_value.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Implementation
|
feature {NONE}-- Implementation
|
||||||
null_value:STRING is "null"
|
null_value:STRING is "null"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ feature -- Access
|
|||||||
Result:=value.is_equal(other.to_json)
|
Result:=value.is_equal(other.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
value:STRING
|
value:STRING
|
||||||
internal_hash_code:INTEGER
|
internal_hash_code:INTEGER
|
||||||
|
|||||||
@@ -66,14 +66,12 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
|
|
||||||
get_keys:ARRAY[JSON_STRING] is
|
get_keys:ARRAY[JSON_STRING] is
|
||||||
--
|
-- array containing actually used keys
|
||||||
do
|
do
|
||||||
Result:=object.current_keys
|
Result:=object.current_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
to_json:STRING is
|
to_json:STRING is
|
||||||
-- Printable json representation
|
-- Printable json representation
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ feature -- Initialization
|
|||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
is_equal (other: like Current): BOOLEAN is
|
is_equal (other: like Current): BOOLEAN is
|
||||||
-- Is JSON_STRING made of same character sequence as `other'
|
-- Is JSON_STRING made of same character sequence as `other'
|
||||||
|
|||||||
@@ -29,4 +29,109 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Status Report
|
||||||
|
|
||||||
|
is_json_array:BOOLEAN is
|
||||||
|
-- Does `Current' represent a JSON_ARRAY?
|
||||||
|
do
|
||||||
|
if generating_type.is_equal ("JSON_ARRAY") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
is_json_string:BOOLEAN is
|
||||||
|
-- Does `Current' represent a JSON_STRING?
|
||||||
|
do
|
||||||
|
if generating_type.is_equal ("JSON_STRING") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
is_json_object:BOOLEAN is
|
||||||
|
-- Does `Current' represent a JSON_OBJECT?
|
||||||
|
do
|
||||||
|
|
||||||
|
if generating_type.is_equal ("JSON_OBJECT") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
is_json_number:BOOLEAN is
|
||||||
|
-- Does 'Current' represent a JSON_NUMBER?
|
||||||
|
do
|
||||||
|
if generating_type.is_equal ("JSON_NUMBER") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
is_json_boolean:BOOLEAN is
|
||||||
|
-- Does 'Current' represent a JSON_BOOLEAN?
|
||||||
|
do
|
||||||
|
if generating_type.is_equal ("JSON_BOOLEAN") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
is_json_null:BOOLEAN is
|
||||||
|
-- Does 'Current' represent a JSON_NULL?
|
||||||
|
do
|
||||||
|
if generating_type.is_equal ("JSON_NULL") then
|
||||||
|
Result := true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Conversion
|
||||||
|
|
||||||
|
to_json_array:JSON_ARRAY is
|
||||||
|
-- Convert `Current' as a JSON_ARRAY.
|
||||||
|
require
|
||||||
|
is_a_json_array:is_json_array
|
||||||
|
do
|
||||||
|
Result ?= Current
|
||||||
|
end
|
||||||
|
|
||||||
|
to_json_string:JSON_STRING is
|
||||||
|
-- Convert `Current' as a JSON_STRING.
|
||||||
|
require
|
||||||
|
is_a_json_string: is_json_string
|
||||||
|
do
|
||||||
|
Result ?= Current
|
||||||
|
end
|
||||||
|
|
||||||
|
to_json_object:JSON_OBJECT is
|
||||||
|
-- Convert 'Current' as a JSON_OBJECT
|
||||||
|
require
|
||||||
|
is_a_json_object: is_json_object
|
||||||
|
do
|
||||||
|
Result?=Current
|
||||||
|
end
|
||||||
|
|
||||||
|
to_json_number:JSON_NUMBER is
|
||||||
|
-- Convert 'Current' as a JSON_NUMBER
|
||||||
|
require
|
||||||
|
is_a_json_number:is_json_number
|
||||||
|
do
|
||||||
|
Result ?= Current
|
||||||
|
end
|
||||||
|
|
||||||
|
to_json_boolean:JSON_BOOLEAN is
|
||||||
|
-- Convert 'Current' as a JSON_BOOLEAN
|
||||||
|
require
|
||||||
|
is_a_json_boolean:is_json_boolean
|
||||||
|
do
|
||||||
|
Result ?= Current
|
||||||
|
end
|
||||||
|
|
||||||
|
to_json_null:JSON_NULL is
|
||||||
|
-- Convert 'Current' as a JSON_NULL
|
||||||
|
require
|
||||||
|
is_a_json_null:is_json_null
|
||||||
|
do
|
||||||
|
Result ?= Current
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user