From 8357bf5d72448e43fbe7065ff80a5e9ed160a8b5 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Sun, 25 May 2008 18:23:25 +0000 Subject: [PATCH] Update JSON_VALUE and JSON_OBJECT interface --- json/json_array.e | 25 +++++++++-- json/json_boolean.e | 1 + json/json_null.e | 2 +- json/json_number.e | 1 + json/json_object.e | 4 +- json/json_string.e | 1 + json/json_value.e | 105 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 7 deletions(-) diff --git a/json/json_array.e b/json/json_array.e index e9924815..7ca3c4fc 100644 --- a/json/json_array.e +++ b/json/json_array.e @@ -28,6 +28,25 @@ feature -- Initialization end 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 add(value:JSON_VALUE) is @@ -41,7 +60,7 @@ feature -- Change Element has_new_value:old values.count + 1 = values.count end - +feature -- Report to_json:STRING is --Printable json representation -- [] or [elements] @@ -65,7 +84,7 @@ feature -- Change Element Result.append("]") end - hash_code:INTEGER is + hash_code:INTEGER is -- do from @@ -78,7 +97,7 @@ feature -- Change Element values.forth end Result := Result \\ values.count - + end feature {NONE} --Implementation values:ARRAYED_LIST[JSON_VALUE] diff --git a/json/json_boolean.e b/json/json_boolean.e index 6327246c..ad3ea0bf 100644 --- a/json/json_boolean.e +++ b/json/json_boolean.e @@ -36,4 +36,5 @@ feature -- Access value:BOOLEAN + end diff --git a/json/json_null.e b/json/json_null.e index 58d25c5c..61a820df 100644 --- a/json/json_null.e +++ b/json/json_null.e @@ -22,6 +22,6 @@ feature --Access Result:= null_value.hash_code end -feature -- Implementation +feature {NONE}-- Implementation null_value:STRING is "null" end diff --git a/json/json_number.e b/json/json_number.e index 0ca65ebb..17013e25 100644 --- a/json/json_number.e +++ b/json/json_number.e @@ -52,6 +52,7 @@ feature -- Access Result:=value.is_equal(other.to_json) end + feature -- Implementation value:STRING internal_hash_code:INTEGER diff --git a/json/json_object.e b/json/json_object.e index 474cd0c7..0718ab9e 100644 --- a/json/json_object.e +++ b/json/json_object.e @@ -66,14 +66,12 @@ feature -- Access end get_keys:ARRAY[JSON_STRING] is - -- + -- array containing actually used keys do Result:=object.current_keys end - - feature -- Report to_json:STRING is -- Printable json representation diff --git a/json/json_string.e b/json/json_string.e index 8bc8ec2d..a1e9399f 100644 --- a/json/json_string.e +++ b/json/json_string.e @@ -30,6 +30,7 @@ feature -- Initialization feature -- Access + feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Is JSON_STRING made of same character sequence as `other' diff --git a/json/json_value.e b/json/json_value.e index 8b3d255d..3accba12 100644 --- a/json/json_value.e +++ b/json/json_value.e @@ -29,4 +29,109 @@ feature -- Access deferred 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