Apply pretty print tool.
Apply on each class in test suite and library.
This commit is contained in:
@@ -26,7 +26,9 @@ feature -- Access
|
|||||||
create template_content.make_empty
|
create template_content.make_empty
|
||||||
l_file.read_stream (l_file.count)
|
l_file.read_stream (l_file.count)
|
||||||
l_last_string := l_file.last_string
|
l_last_string := l_file.last_string
|
||||||
check l_last_string /= Void end -- implied by postcondition of `l_file.read_stream'
|
check
|
||||||
|
l_last_string /= Void
|
||||||
|
end -- implied by postcondition of `l_file.read_stream'
|
||||||
template_content.append (l_last_string.string)
|
template_content.append (l_last_string.string)
|
||||||
Result := template_content
|
Result := template_content
|
||||||
l_file.close
|
l_file.close
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
note
|
note
|
||||||
description:
|
description: "JSON Iterator"
|
||||||
|
|
||||||
"JSON Iterator"
|
|
||||||
|
|
||||||
pattern: "Iterator visitor"
|
pattern: "Iterator visitor"
|
||||||
author: "Jocelyn Fiat"
|
author: "Jocelyn Fiat"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
date: "2013/08/01"
|
date: "2013/08/01"
|
||||||
revision: "Revision 0.1"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
@@ -13,6 +10,7 @@ deferred class
|
|||||||
JSON_ITERATOR
|
JSON_ITERATOR
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VISITOR
|
JSON_VISITOR
|
||||||
|
|
||||||
feature -- Visitor Pattern
|
feature -- Visitor Pattern
|
||||||
@@ -52,7 +50,7 @@ feature -- Visitor Pattern
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING)
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
do
|
do
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ class
|
|||||||
JSON_PRETTY_STRING_VISITOR
|
JSON_PRETTY_STRING_VISITOR
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VISITOR
|
JSON_VISITOR
|
||||||
|
|
||||||
create
|
create
|
||||||
make,
|
make, make_custom
|
||||||
make_custom
|
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
@@ -26,7 +26,6 @@ feature -- Initialization
|
|||||||
output := a_output
|
output := a_output
|
||||||
create indentation.make_empty
|
create indentation.make_empty
|
||||||
indentation_step := "%T"
|
indentation_step := "%T"
|
||||||
|
|
||||||
object_count_inlining := a_object_count_inlining
|
object_count_inlining := a_object_count_inlining
|
||||||
array_count_inlining := a_array_count_inlining
|
array_count_inlining := a_array_count_inlining
|
||||||
end
|
end
|
||||||
@@ -34,7 +33,7 @@ feature -- Initialization
|
|||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
output: STRING_32
|
output: STRING_32
|
||||||
-- JSON representation
|
-- JSON representation
|
||||||
|
|
||||||
indentation: like output
|
indentation: like output
|
||||||
|
|
||||||
@@ -60,6 +59,7 @@ feature -- Access
|
|||||||
end
|
end
|
||||||
|
|
||||||
object_count_inlining: INTEGER
|
object_count_inlining: INTEGER
|
||||||
|
|
||||||
array_count_inlining: INTEGER
|
array_count_inlining: INTEGER
|
||||||
|
|
||||||
feature -- Visitor Pattern
|
feature -- Visitor Pattern
|
||||||
@@ -82,10 +82,7 @@ feature -- Visitor Pattern
|
|||||||
until
|
until
|
||||||
l_json_array.off
|
l_json_array.off
|
||||||
loop
|
loop
|
||||||
if
|
if line_number > l_line or l_multiple_lines then
|
||||||
line_number > l_line or
|
|
||||||
l_multiple_lines
|
|
||||||
then
|
|
||||||
new_line
|
new_line
|
||||||
end
|
end
|
||||||
value := l_json_array.item
|
value := l_json_array.item
|
||||||
@@ -96,10 +93,7 @@ feature -- Visitor Pattern
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
exdent
|
exdent
|
||||||
if
|
if line_number > l_line or l_json_array.count >= array_count_inlining then
|
||||||
line_number > l_line or
|
|
||||||
l_json_array.count >= array_count_inlining
|
|
||||||
then
|
|
||||||
new_line
|
new_line
|
||||||
end
|
end
|
||||||
output.append ("]")
|
output.append ("]")
|
||||||
@@ -140,10 +134,7 @@ feature -- Visitor Pattern
|
|||||||
until
|
until
|
||||||
l_pairs.off
|
l_pairs.off
|
||||||
loop
|
loop
|
||||||
if
|
if line_number > l_line or l_multiple_lines then
|
||||||
line_number > l_line or
|
|
||||||
l_multiple_lines
|
|
||||||
then
|
|
||||||
new_line
|
new_line
|
||||||
end
|
end
|
||||||
l_pairs.key_for_iteration.accept (Current)
|
l_pairs.key_for_iteration.accept (Current)
|
||||||
@@ -155,16 +146,13 @@ feature -- Visitor Pattern
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
exdent
|
exdent
|
||||||
if
|
if line_number > l_line or l_pairs.count >= object_count_inlining then
|
||||||
line_number > l_line or
|
|
||||||
l_pairs.count >= object_count_inlining
|
|
||||||
then
|
|
||||||
new_line
|
new_line
|
||||||
end
|
end
|
||||||
output.append ("}")
|
output.append ("}")
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING)
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
do
|
do
|
||||||
output.append ("%"")
|
output.append ("%"")
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
note
|
note
|
||||||
description:
|
description: "JSON Visitor"
|
||||||
|
|
||||||
"JSON Visitor"
|
|
||||||
|
|
||||||
pattern: "Visitor"
|
pattern: "Visitor"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
revision: "Revision 0.1"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
@@ -49,7 +46,7 @@ feature -- Visitor Pattern
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING)
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
require
|
require
|
||||||
a_json_string_not_void: a_json_string /= Void
|
a_json_string_not_void: a_json_string /= Void
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ class
|
|||||||
PRINT_JSON_VISITOR
|
PRINT_JSON_VISITOR
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_VISITOR
|
JSON_VISITOR
|
||||||
|
|
||||||
create make
|
create
|
||||||
|
make
|
||||||
|
|
||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ feature -- Initialization
|
|||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
to_json: STRING
|
to_json: STRING
|
||||||
-- JSON representation
|
-- JSON representation
|
||||||
|
|
||||||
feature -- Visitor Pattern
|
feature -- Visitor Pattern
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ feature -- Visitor Pattern
|
|||||||
value: JSON_VALUE
|
value: JSON_VALUE
|
||||||
l_json_array: ARRAYED_LIST [JSON_VALUE]
|
l_json_array: ARRAYED_LIST [JSON_VALUE]
|
||||||
do
|
do
|
||||||
l_json_array:=a_json_array.array_representation
|
l_json_array := a_json_array.array_representation
|
||||||
to_json.append ("[")
|
to_json.append ("[")
|
||||||
from
|
from
|
||||||
l_json_array.start
|
l_json_array.start
|
||||||
@@ -44,7 +46,7 @@ feature -- Visitor Pattern
|
|||||||
value.accept (Current)
|
value.accept (Current)
|
||||||
l_json_array.forth
|
l_json_array.forth
|
||||||
if not l_json_array.after then
|
if not l_json_array.after then
|
||||||
to_json.append(",")
|
to_json.append (",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
to_json.append ("]")
|
to_json.append ("]")
|
||||||
@@ -71,7 +73,7 @@ feature -- Visitor Pattern
|
|||||||
visit_json_object (a_json_object: JSON_OBJECT)
|
visit_json_object (a_json_object: JSON_OBJECT)
|
||||||
-- Visit `a_json_object'.
|
-- Visit `a_json_object'.
|
||||||
local
|
local
|
||||||
l_pairs: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
l_pairs: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
do
|
do
|
||||||
l_pairs := a_json_object.map_representation
|
l_pairs := a_json_object.map_representation
|
||||||
to_json.append ("{")
|
to_json.append ("{")
|
||||||
@@ -91,7 +93,7 @@ feature -- Visitor Pattern
|
|||||||
to_json.append ("}")
|
to_json.append ("}")
|
||||||
end
|
end
|
||||||
|
|
||||||
visit_json_string (a_json_string: JSON_STRING)
|
visit_json_string (a_json_string: JSON_STRING)
|
||||||
-- Visit `a_json_string'.
|
-- Visit `a_json_string'.
|
||||||
do
|
do
|
||||||
to_json.append ("%"")
|
to_json.append ("%"")
|
||||||
|
|||||||
@@ -5,20 +5,22 @@ note
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
class JSON_ARRAYED_LIST_CONVERTER
|
class
|
||||||
|
JSON_ARRAYED_LIST_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_LIST_CONVERTER
|
|
||||||
|
JSON_LIST_CONVERTER
|
||||||
redefine
|
redefine
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: ARRAYED_LIST [detachable ANY]
|
object: ARRAYED_LIST [detachable ANY]
|
||||||
|
|
||||||
feature {NONE} -- Factory
|
feature {NONE} -- Factory
|
||||||
|
|
||||||
|
|||||||
@@ -5,32 +5,34 @@ note
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
deferred class JSON_CONVERTER
|
deferred class
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
SHARED_EJSON
|
|
||||||
|
SHARED_EJSON
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: ANY
|
object: ANY
|
||||||
-- Eiffel object
|
-- Eiffel object
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: attached like to_json): detachable like object
|
from_json (j: attached like to_json): detachable like object
|
||||||
-- Convert from JSON value.
|
-- Convert from JSON value.
|
||||||
-- Returns Void if unable to convert
|
-- Returns Void if unable to convert
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): detachable JSON_VALUE
|
to_json (o: like object): detachable JSON_VALUE
|
||||||
-- Convert to JSON value
|
-- Convert to JSON value
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
|
has_eiffel_object: object /= Void -- An empty object must be created at creation time!
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,76 +1,82 @@
|
|||||||
note
|
note
|
||||||
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
|
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
|
date: "$Date: 2014-01-30 15:27:41 +0100 (jeu., 30 janv. 2014) $"
|
||||||
revision: "$Revision: 94128 $"
|
revision: "$Revision: 94128 $"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
class JSON_HASH_TABLE_CONVERTER
|
class
|
||||||
|
JSON_HASH_TABLE_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
do
|
do
|
||||||
create object.make (0)
|
create object.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: HASH_TABLE [ANY, HASHABLE]
|
object: HASH_TABLE [ANY, HASHABLE]
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: attached like to_json): like object
|
from_json (j: attached like to_json): like object
|
||||||
do
|
do
|
||||||
create Result.make (j.count)
|
create Result.make (j.count)
|
||||||
across
|
across
|
||||||
j as ic
|
j as ic
|
||||||
loop
|
loop
|
||||||
if attached json.object (ic.item, Void) as l_object then
|
if attached json.object (ic.item, Void) as l_object then
|
||||||
if attached {HASHABLE} json.object (ic.key, Void) as h then
|
if attached {HASHABLE} json.object (ic.key, Void) as h then
|
||||||
Result.put (l_object, h)
|
Result.put (l_object, h)
|
||||||
else
|
else
|
||||||
check key_is_hashable: False end
|
check
|
||||||
|
key_is_hashable: False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
check object_attached: False end
|
check
|
||||||
end
|
object_attached: False
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
to_json (o: like object): detachable JSON_OBJECT
|
to_json (o: like object): detachable JSON_OBJECT
|
||||||
local
|
local
|
||||||
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
|
c: HASH_TABLE_ITERATION_CURSOR [ANY, HASHABLE]
|
||||||
js: JSON_STRING
|
js: JSON_STRING
|
||||||
failed: BOOLEAN
|
failed: BOOLEAN
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
from
|
from
|
||||||
c := o.new_cursor
|
c := o.new_cursor
|
||||||
until
|
until
|
||||||
c.after
|
c.after
|
||||||
loop
|
loop
|
||||||
if attached {JSON_STRING} json.value (c.key) as l_key then
|
if attached {JSON_STRING} json.value (c.key) as l_key then
|
||||||
js := l_key
|
js := l_key
|
||||||
else
|
else
|
||||||
create js.make_json (c.key.out)
|
create js.make_json (c.key.out)
|
||||||
end
|
end
|
||||||
if attached json.value (c.item) as jv then
|
if attached json.value (c.item) as jv then
|
||||||
Result.put (jv, js)
|
Result.put (jv, js)
|
||||||
else
|
else
|
||||||
failed := True
|
failed := True
|
||||||
end
|
end
|
||||||
c.forth
|
c.forth
|
||||||
end
|
end
|
||||||
if failed then
|
if failed then
|
||||||
Result := Void
|
Result := Void
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class JSON_HASH_TABLE_CONVERTER
|
end -- class JSON_HASH_TABLE_CONVERTER
|
||||||
|
|||||||
@@ -5,20 +5,22 @@ note
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
class JSON_LINKED_LIST_CONVERTER
|
class
|
||||||
|
JSON_LINKED_LIST_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_LIST_CONVERTER
|
|
||||||
|
JSON_LIST_CONVERTER
|
||||||
redefine
|
redefine
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: LINKED_LIST [detachable ANY]
|
object: LINKED_LIST [detachable ANY]
|
||||||
|
|
||||||
feature {NONE} -- Factory
|
feature {NONE} -- Factory
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
note
|
note
|
||||||
description: "A JSON converter for LIST [ANY]"
|
description: "A JSON converter for LIST [ANY]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
deferred class JSON_LIST_CONVERTER
|
deferred class
|
||||||
|
JSON_LIST_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
do
|
do
|
||||||
object := new_object (0)
|
object := new_object (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: LIST [detachable ANY]
|
object: LIST [detachable ANY]
|
||||||
|
|
||||||
feature {NONE} -- Factory
|
feature {NONE} -- Factory
|
||||||
|
|
||||||
@@ -31,44 +33,44 @@ feature {NONE} -- Factory
|
|||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: attached like to_json): detachable like object
|
from_json (j: attached like to_json): detachable like object
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
Result := new_object (j.count)
|
Result := new_object (j.count)
|
||||||
from
|
from
|
||||||
i := 1
|
i := 1
|
||||||
until
|
until
|
||||||
i > j.count
|
i > j.count
|
||||||
loop
|
loop
|
||||||
Result.extend (json.object (j [i], Void))
|
Result.extend (json.object (j [i], Void))
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): detachable JSON_ARRAY
|
to_json (o: like object): detachable JSON_ARRAY
|
||||||
local
|
local
|
||||||
c: ITERATION_CURSOR [detachable ANY]
|
c: ITERATION_CURSOR [detachable ANY]
|
||||||
jv: detachable JSON_VALUE
|
jv: detachable JSON_VALUE
|
||||||
failed: BOOLEAN
|
failed: BOOLEAN
|
||||||
do
|
do
|
||||||
create Result.make_array
|
create Result.make_array
|
||||||
from
|
from
|
||||||
c := o.new_cursor
|
c := o.new_cursor
|
||||||
until
|
until
|
||||||
c.after
|
c.after
|
||||||
loop
|
loop
|
||||||
jv := json.value (c.item)
|
jv := json.value (c.item)
|
||||||
if jv /= Void then
|
if jv /= Void then
|
||||||
Result.add (jv)
|
Result.add (jv)
|
||||||
else
|
else
|
||||||
failed := True
|
failed := True
|
||||||
end
|
end
|
||||||
c.forth
|
c.forth
|
||||||
end
|
end
|
||||||
if failed then
|
if failed then
|
||||||
Result := Void
|
Result := Void
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class JSON_ARRAYED_LIST_CONVERTER
|
end -- class JSON_ARRAYED_LIST_CONVERTER
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ note
|
|||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
class EJSON
|
class
|
||||||
|
EJSON
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
EXCEPTIONS
|
EXCEPTIONS
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -19,9 +21,9 @@ feature -- Access
|
|||||||
i: INTEGER
|
i: INTEGER
|
||||||
ja: JSON_ARRAY
|
ja: JSON_ARRAY
|
||||||
do
|
do
|
||||||
-- Try to convert from basic Eiffel types. Note that we check with
|
-- Try to convert from basic Eiffel types. Note that we check with
|
||||||
-- `conforms_to' since the client may have subclassed the base class
|
-- `conforms_to' since the client may have subclassed the base class
|
||||||
-- that these basic types are derived from.
|
-- that these basic types are derived from.
|
||||||
if an_object = Void then
|
if an_object = Void then
|
||||||
create {JSON_NULL} Result
|
create {JSON_NULL} Result
|
||||||
elseif attached {BOOLEAN} an_object as b then
|
elseif attached {BOOLEAN} an_object as b then
|
||||||
@@ -56,7 +58,9 @@ feature -- Access
|
|||||||
if attached value (a @ i) as v then
|
if attached value (a @ i) as v then
|
||||||
ja.add (v)
|
ja.add (v)
|
||||||
else
|
else
|
||||||
check value_attached: False end
|
check
|
||||||
|
value_attached: False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
@@ -65,15 +69,13 @@ feature -- Access
|
|||||||
create {JSON_STRING} Result.make_json (c8.out)
|
create {JSON_STRING} Result.make_json (c8.out)
|
||||||
elseif attached {CHARACTER_32} an_object as c32 then
|
elseif attached {CHARACTER_32} an_object as c32 then
|
||||||
create {JSON_STRING} Result.make_json (c32.out)
|
create {JSON_STRING} Result.make_json (c32.out)
|
||||||
|
|
||||||
elseif attached {STRING_8} an_object as s8 then
|
elseif attached {STRING_8} an_object as s8 then
|
||||||
create {JSON_STRING} Result.make_json (s8)
|
create {JSON_STRING} Result.make_json (s8)
|
||||||
elseif attached {STRING_32} an_object as s32 then
|
elseif attached {STRING_32} an_object as s32 then
|
||||||
create {JSON_STRING} Result.make_json_from_string_32 (s32)
|
create {JSON_STRING} Result.make_json_from_string_32 (s32)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Result = Void then
|
if Result = Void then
|
||||||
-- Now check the converters
|
-- Now check the converters
|
||||||
if an_object /= Void and then attached converter_for (an_object) as jc then
|
if an_object /= Void and then attached converter_for (an_object) as jc then
|
||||||
Result := jc.to_json (an_object)
|
Result := jc.to_json (an_object)
|
||||||
else
|
else
|
||||||
@@ -84,7 +86,7 @@ feature -- Access
|
|||||||
|
|
||||||
object (a_value: detachable JSON_VALUE; base_class: detachable STRING): detachable ANY
|
object (a_value: detachable JSON_VALUE; base_class: detachable STRING): detachable ANY
|
||||||
-- Eiffel object from JSON value. If `base_class' /= Void an eiffel
|
-- Eiffel object from JSON value. If `base_class' /= Void an eiffel
|
||||||
-- object based on `base_class' will be returned. Raises an "eJSON
|
-- object based on `base_class' will be returned. Raises an "eJSON
|
||||||
-- exception" if unable to convert value.
|
-- exception" if unable to convert value.
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
|
|||||||
@@ -1,75 +1,75 @@
|
|||||||
note
|
note
|
||||||
description: "[
|
description: "[
|
||||||
JSON_ARRAY represent an array in JSON.
|
JSON_ARRAY represent an array in JSON.
|
||||||
An array in JSON is an ordered set of names.
|
An array in JSON is an ordered set of names.
|
||||||
Examples
|
Examples
|
||||||
array
|
array
|
||||||
[]
|
[]
|
||||||
[elements]
|
[elements]
|
||||||
]"
|
]"
|
||||||
|
author: "Javier Velilla"
|
||||||
author: "Javier Velilla"
|
date: "2008/08/24"
|
||||||
date: "2008/08/24"
|
revision: "Revision 0.1"
|
||||||
revision: "Revision 0.1"
|
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_ARRAY
|
JSON_ARRAY
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
|
JSON_VALUE
|
||||||
|
|
||||||
ITERABLE [JSON_VALUE]
|
ITERABLE [JSON_VALUE]
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
DEBUG_OUTPUT
|
||||||
|
|
||||||
create
|
create
|
||||||
make_array
|
make_array
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_array
|
make_array
|
||||||
-- Initialize JSON Array
|
-- Initialize JSON Array
|
||||||
do
|
do
|
||||||
create values.make (10)
|
create values.make (10)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
i_th alias "[]" (i: INTEGER): JSON_VALUE
|
i_th alias "[]" (i: INTEGER): JSON_VALUE
|
||||||
-- Item at `i'-th position
|
-- Item at `i'-th position
|
||||||
require
|
require
|
||||||
is_valid_index: valid_index (i)
|
is_valid_index: valid_index (i)
|
||||||
do
|
do
|
||||||
Result := values.i_th (i)
|
Result := values.i_th (i)
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING
|
representation: STRING
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
Result := "["
|
Result := "["
|
||||||
from
|
from
|
||||||
i := 1
|
i := 1
|
||||||
until
|
until
|
||||||
i > count
|
i > count
|
||||||
loop
|
loop
|
||||||
Result.append (i_th (i).representation)
|
Result.append (i_th (i).representation)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
if i <= count then
|
if i <= count then
|
||||||
Result.append_character (',')
|
Result.append_character (',')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Result.append_character (']')
|
Result.append_character (']')
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_array' procedure on `a_visitor'.)
|
-- (Call `visit_json_array' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_array (Current)
|
a_visitor.visit_json_array (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
@@ -81,98 +81,96 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Mesurement
|
feature -- Mesurement
|
||||||
|
|
||||||
count: INTEGER
|
count: INTEGER
|
||||||
-- Number of items.
|
-- Number of items.
|
||||||
do
|
do
|
||||||
Result := values.count
|
Result := values.count
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
valid_index (i: INTEGER): BOOLEAN
|
valid_index (i: INTEGER): BOOLEAN
|
||||||
-- Is `i' a valid index?
|
-- Is `i' a valid index?
|
||||||
do
|
do
|
||||||
Result := (1 <= i) and (i <= count)
|
Result := (1 <= i) and (i <= count)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
put_front (v: JSON_VALUE)
|
put_front (v: JSON_VALUE)
|
||||||
require
|
require
|
||||||
v_not_void: v /= Void
|
v_not_void: v /= Void
|
||||||
do
|
do
|
||||||
values.put_front (v)
|
values.put_front (v)
|
||||||
ensure
|
ensure
|
||||||
has_new_value: old values.count + 1 = values.count and
|
has_new_value: old values.count + 1 = values.count and values.first = v
|
||||||
values.first = v
|
end
|
||||||
end
|
|
||||||
|
|
||||||
add, extend (v: JSON_VALUE)
|
add, extend (v: JSON_VALUE)
|
||||||
require
|
require
|
||||||
v_not_void: v /= Void
|
v_not_void: v /= Void
|
||||||
do
|
do
|
||||||
values.extend (v)
|
values.extend (v)
|
||||||
ensure
|
ensure
|
||||||
has_new_value: old values.count + 1 = values.count and
|
has_new_value: old values.count + 1 = values.count and values.has (v)
|
||||||
values.has (v)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
prune_all (v: JSON_VALUE)
|
prune_all (v: JSON_VALUE)
|
||||||
-- Remove all occurrences of `v'.
|
-- Remove all occurrences of `v'.
|
||||||
require
|
require
|
||||||
v_not_void: v /= Void
|
v_not_void: v /= Void
|
||||||
do
|
do
|
||||||
values.prune_all (v)
|
values.prune_all (v)
|
||||||
ensure
|
ensure
|
||||||
not_has_new_value: not values.has (v)
|
not_has_new_value: not values.has (v)
|
||||||
end
|
end
|
||||||
|
|
||||||
wipe_out
|
wipe_out
|
||||||
-- Remove all items.
|
-- Remove all items.
|
||||||
do
|
do
|
||||||
values.wipe_out
|
values.wipe_out
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
from
|
from
|
||||||
values.start
|
values.start
|
||||||
Result := values.item.hash_code
|
Result := values.item.hash_code
|
||||||
until
|
until
|
||||||
values.off
|
values.off
|
||||||
loop
|
loop
|
||||||
Result:= ((Result \\ 8388593) |<< 8) + values.item.hash_code
|
Result := ((Result \\ 8388593) |<< 8) + values.item.hash_code
|
||||||
values.forth
|
values.forth
|
||||||
end
|
end
|
||||||
Result := Result \\ values.count
|
Result := Result \\ values.count
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
array_representation: ARRAYED_LIST [JSON_VALUE]
|
array_representation: ARRAYED_LIST [JSON_VALUE]
|
||||||
-- Representation as a sequences of values
|
-- Representation as a sequences of values
|
||||||
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object
|
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object
|
||||||
do
|
do
|
||||||
Result := values
|
Result := values
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := count.out + " item(s)"
|
Result := count.out + " item(s)"
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
values: ARRAYED_LIST [JSON_VALUE]
|
values: ARRAYED_LIST [JSON_VALUE]
|
||||||
-- Value container
|
-- Value container
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
value_not_void: values /= Void
|
value_not_void: values /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,61 +1,62 @@
|
|||||||
note
|
note
|
||||||
description: "JSON Truth values"
|
description: "JSON Truth values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
revision: "Revision 0.1"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_BOOLEAN
|
JSON_BOOLEAN
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
|
JSON_VALUE
|
||||||
|
|
||||||
create
|
create
|
||||||
make_boolean
|
make_boolean
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_boolean (an_item: BOOLEAN)
|
make_boolean (an_item: BOOLEAN)
|
||||||
--Initialize.
|
--Initialize.
|
||||||
do
|
do
|
||||||
item := an_item
|
item := an_item
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
item: BOOLEAN
|
item: BOOLEAN
|
||||||
-- Content
|
-- Content
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
representation: STRING
|
||||||
|
do
|
||||||
|
if item then
|
||||||
|
Result := "true"
|
||||||
|
else
|
||||||
|
Result := "false"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
representation: STRING
|
|
||||||
do
|
|
||||||
if item then
|
|
||||||
Result := "true"
|
|
||||||
else
|
|
||||||
Result := "false"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
|
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_boolean (Current)
|
a_visitor.visit_json_boolean (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := item.out
|
Result := item.out
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,47 +1,48 @@
|
|||||||
note
|
note
|
||||||
description: "JSON Null Values"
|
description: "JSON Null Values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
revision: "Revision 0.1"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_NULL
|
JSON_NULL
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
|
JSON_VALUE
|
||||||
|
|
||||||
feature --Access
|
feature --Access
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := null_value.hash_code
|
Result := null_value.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
representation: STRING
|
||||||
|
do
|
||||||
|
Result := "null"
|
||||||
|
end
|
||||||
|
|
||||||
representation: STRING
|
|
||||||
do
|
|
||||||
Result := "null"
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_element_a' procedure on `a_visitor'.)
|
-- (Call `visit_element_a' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_null (Current)
|
a_visitor.visit_json_null (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := null_value
|
Result := null_value
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE}-- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
null_value: STRING = "null"
|
null_value: STRING = "null"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,99 +1,99 @@
|
|||||||
note
|
note
|
||||||
|
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
||||||
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
author: "Javier Velilla"
|
||||||
author: "Javier Velilla"
|
date: "2008/08/24"
|
||||||
date: "2008/08/24"
|
revision: "Revision 0.1"
|
||||||
revision: "Revision 0.1"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_NUMBER
|
JSON_NUMBER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
redefine
|
JSON_VALUE
|
||||||
is_equal
|
redefine
|
||||||
end
|
is_equal
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_integer,
|
make_integer, make_natural, make_real
|
||||||
make_natural,
|
|
||||||
make_real
|
|
||||||
|
|
||||||
feature {NONE} -- initialization
|
feature {NONE} -- initialization
|
||||||
|
|
||||||
make_integer (an_argument: INTEGER_64)
|
make_integer (an_argument: INTEGER_64)
|
||||||
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
numeric_type := INTEGER_TYPE
|
numeric_type := INTEGER_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
make_natural (an_argument: NATURAL_64)
|
make_natural (an_argument: NATURAL_64)
|
||||||
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
numeric_type := NATURAL_TYPE
|
numeric_type := NATURAL_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
make_real (an_argument: DOUBLE)
|
make_real (an_argument: DOUBLE)
|
||||||
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
|
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
|
||||||
do
|
do
|
||||||
item := an_argument.out
|
item := an_argument.out
|
||||||
numeric_type := DOUBLE_TYPE
|
numeric_type := DOUBLE_TYPE
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
item: STRING
|
item: STRING
|
||||||
-- Content
|
-- Content
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
--Hash code value
|
--Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
representation: STRING
|
||||||
|
do
|
||||||
|
Result := item
|
||||||
|
end
|
||||||
|
|
||||||
representation: STRING
|
|
||||||
do
|
|
||||||
Result := item
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_number' procedure on `a_visitor'.)
|
-- (Call `visit_json_number' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_number (Current)
|
a_visitor.visit_json_number (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN
|
is_equal (other: like Current): BOOLEAN
|
||||||
-- Is `other' attached to an object of the same type
|
-- Is `other' attached to an object of the same type
|
||||||
-- as current object and identical to it?
|
-- as current object and identical to it?
|
||||||
do
|
do
|
||||||
Result := item.is_equal (other.item)
|
Result := item.is_equal (other.item)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := item
|
Result := item
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
INTEGER_TYPE: INTEGER = 1
|
INTEGER_TYPE: INTEGER = 1
|
||||||
DOUBLE_TYPE: INTEGER = 2
|
|
||||||
NATURAL_TYPE: INTEGER = 3
|
|
||||||
|
|
||||||
numeric_type: INTEGER
|
DOUBLE_TYPE: INTEGER = 2
|
||||||
|
|
||||||
|
NATURAL_TYPE: INTEGER = 3
|
||||||
|
|
||||||
|
numeric_type: INTEGER
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
item_not_void: item /= Void
|
item_not_void: item /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,182 +1,180 @@
|
|||||||
note
|
note
|
||||||
|
description: "[
|
||||||
description: "[
|
An JSON_OBJECT represent an object in JSON.
|
||||||
An JSON_OBJECT represent an object in JSON.
|
An object is an unordered set of name/value pairs
|
||||||
An object is an unordered set of name/value pairs
|
|
||||||
|
Examples:
|
||||||
Examples:
|
|
||||||
|
object
|
||||||
object
|
{}
|
||||||
{}
|
{"key": "value"}
|
||||||
{"key": "value"}
|
]"
|
||||||
|
author: "Javier Velilla"
|
||||||
]"
|
date: "2008/08/24"
|
||||||
author: "Javier Velilla"
|
revision: "Revision 0.1"
|
||||||
date: "2008/08/24"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
revision: "Revision 0.1"
|
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_OBJECT
|
JSON_OBJECT
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
|
|
||||||
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
|
JSON_VALUE
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
|
||||||
|
|
||||||
|
DEBUG_OUTPUT
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
-- Initialize
|
-- Initialize
|
||||||
do
|
do
|
||||||
create object.make (10)
|
create object.make (10)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
put (value: detachable JSON_VALUE; key: JSON_STRING)
|
put (value: detachable JSON_VALUE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: like value
|
l_value: like value
|
||||||
do
|
do
|
||||||
l_value := value
|
l_value := value
|
||||||
if l_value = Void then
|
if l_value = Void then
|
||||||
create {JSON_NULL} l_value
|
create {JSON_NULL} l_value
|
||||||
end
|
end
|
||||||
object.extend (l_value, key)
|
object.extend (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: JSON_STRING
|
l_value: JSON_STRING
|
||||||
do
|
do
|
||||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||||
put (l_value, key)
|
put (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
put_integer (value: INTEGER_64; key: JSON_STRING)
|
||||||
|
-- Assuming there is no item of key `key',
|
||||||
|
-- insert `value' with `key'.
|
||||||
|
require
|
||||||
|
key_not_present: not has_key (key)
|
||||||
|
local
|
||||||
|
l_value: JSON_NUMBER
|
||||||
|
do
|
||||||
|
create l_value.make_integer (value)
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
put_integer (value: INTEGER_64; key: JSON_STRING)
|
put_natural (value: NATURAL_64; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_integer (value)
|
create l_value.make_natural (value)
|
||||||
put (l_value, key)
|
put (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_natural (value: NATURAL_64; key: JSON_STRING)
|
put_real (value: DOUBLE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_natural (value)
|
create l_value.make_real (value)
|
||||||
put (l_value, key)
|
put (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_real (value: DOUBLE; key: JSON_STRING)
|
put_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_BOOLEAN
|
||||||
do
|
do
|
||||||
create l_value.make_real (value)
|
create l_value.make_boolean (value)
|
||||||
put (l_value, key)
|
put (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_boolean (value: BOOLEAN; key: JSON_STRING)
|
replace (value: detachable JSON_VALUE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
local
|
||||||
key_not_present: not has_key (key)
|
l_value: like value
|
||||||
local
|
do
|
||||||
l_value: JSON_BOOLEAN
|
l_value := value
|
||||||
do
|
if l_value = Void then
|
||||||
create l_value.make_boolean (value)
|
create {JSON_NULL} l_value
|
||||||
put (l_value, key)
|
end
|
||||||
end
|
object.force (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
replace (value: detachable JSON_VALUE; key: JSON_STRING)
|
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: like value
|
l_value: JSON_STRING
|
||||||
do
|
do
|
||||||
l_value := value
|
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||||
if l_value = Void then
|
replace (l_value, key)
|
||||||
create {JSON_NULL} l_value
|
end
|
||||||
end
|
|
||||||
object.force (l_value, key)
|
|
||||||
end
|
|
||||||
|
|
||||||
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_STRING
|
l_value: JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
create l_value.make_integer (value)
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
|
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_integer (value)
|
create l_value.make_natural (value)
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
|
replace_with_real (value: DOUBLE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_natural (value)
|
create l_value.make_real (value)
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_real (value: DOUBLE; key: JSON_STRING)
|
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: JSON_BOOLEAN
|
||||||
do
|
do
|
||||||
create l_value.make_real (value)
|
create l_value.make_boolean (value)
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
|
|
||||||
-- Assuming there is no item of key `key',
|
|
||||||
-- insert `value' with `key'.
|
|
||||||
local
|
|
||||||
l_value: JSON_BOOLEAN
|
|
||||||
do
|
|
||||||
create l_value.make_boolean (value)
|
|
||||||
replace (l_value, key)
|
|
||||||
end
|
|
||||||
|
|
||||||
remove (key: JSON_STRING)
|
remove (key: JSON_STRING)
|
||||||
-- Remove item indexed by `key' if any.
|
-- Remove item indexed by `key' if any.
|
||||||
@@ -185,59 +183,59 @@ feature -- Change Element
|
|||||||
end
|
end
|
||||||
|
|
||||||
wipe_out
|
wipe_out
|
||||||
-- Reset all items to default values; reset status.
|
-- Reset all items to default values; reset status.
|
||||||
do
|
do
|
||||||
object.wipe_out
|
object.wipe_out
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
has_key (key: JSON_STRING): BOOLEAN
|
has_key (key: JSON_STRING): BOOLEAN
|
||||||
-- has the JSON_OBJECT contains a specific key 'key'.
|
-- has the JSON_OBJECT contains a specific key 'key'.
|
||||||
do
|
do
|
||||||
Result := object.has (key)
|
Result := object.has (key)
|
||||||
end
|
end
|
||||||
|
|
||||||
has_item (value: JSON_VALUE): BOOLEAN
|
has_item (value: JSON_VALUE): BOOLEAN
|
||||||
-- has the JSON_OBJECT contain a specfic item 'value'
|
-- has the JSON_OBJECT contain a specfic item 'value'
|
||||||
do
|
do
|
||||||
Result := object.has_item (value)
|
Result := object.has_item (value)
|
||||||
end
|
end
|
||||||
|
|
||||||
item (key: JSON_STRING): detachable JSON_VALUE
|
item (key: JSON_STRING): detachable JSON_VALUE
|
||||||
-- the json_value associated with a key.
|
-- the json_value associated with a key.
|
||||||
do
|
do
|
||||||
Result := object.item (key)
|
Result := object.item (key)
|
||||||
end
|
end
|
||||||
|
|
||||||
current_keys: ARRAY [JSON_STRING]
|
current_keys: ARRAY [JSON_STRING]
|
||||||
-- array containing actually used keys
|
-- array containing actually used keys
|
||||||
do
|
do
|
||||||
Result := object.current_keys
|
Result := object.current_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING
|
representation: STRING
|
||||||
local
|
local
|
||||||
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
do
|
do
|
||||||
create Result.make (2)
|
create Result.make (2)
|
||||||
Result.append_character ('{')
|
Result.append_character ('{')
|
||||||
from
|
from
|
||||||
t := map_representation
|
t := map_representation
|
||||||
t.start
|
t.start
|
||||||
until
|
until
|
||||||
t.after
|
t.after
|
||||||
loop
|
loop
|
||||||
Result.append (t.key_for_iteration.representation)
|
Result.append (t.key_for_iteration.representation)
|
||||||
Result.append_character (':')
|
Result.append_character (':')
|
||||||
Result.append (t.item_for_iteration.representation)
|
Result.append (t.item_for_iteration.representation)
|
||||||
t.forth
|
t.forth
|
||||||
if not t.after then
|
if not t.after then
|
||||||
Result.append_character (',')
|
Result.append_character (',')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Result.append_character ('}')
|
Result.append_character ('}')
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Mesurement
|
feature -- Mesurement
|
||||||
|
|
||||||
@@ -265,53 +263,53 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_object' procedure on `a_visitor'.)
|
-- (Call `visit_json_object' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_object (Current)
|
a_visitor.visit_json_object (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
map_representation: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
--A representation that maps keys to values
|
--A representation that maps keys to values
|
||||||
do
|
do
|
||||||
Result := object
|
Result := object
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
from
|
from
|
||||||
object.start
|
object.start
|
||||||
Result := object.out.hash_code
|
Result := object.out.hash_code
|
||||||
until
|
until
|
||||||
object.off
|
object.off
|
||||||
loop
|
loop
|
||||||
Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code
|
Result := ((Result \\ 8388593) |<< 8) + object.item_for_iteration.hash_code
|
||||||
object.forth
|
object.forth
|
||||||
end
|
end
|
||||||
-- Ensure it is a positive value.
|
-- Ensure it is a positive value.
|
||||||
Result := Result.hash_code
|
Result := Result.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := count.out + " item(s)"
|
Result := count.out + " item(s)"
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
object: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
object: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||||
-- Value container
|
-- Value container
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
object_not_void: object /= Void
|
object_not_void: object /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,30 +1,26 @@
|
|||||||
note
|
note
|
||||||
|
description: "[
|
||||||
description: "[
|
A JSON_STRING represent a string in JSON.
|
||||||
A JSON_STRING represent a string in JSON.
|
A string is a collection of zero or more Unicodes characters, wrapped in double
|
||||||
A string is a collection of zero or more Unicodes characters, wrapped in double
|
quotes, using blackslash espaces.
|
||||||
quotes, using blackslash espaces.
|
]"
|
||||||
]"
|
author: "Javier Velilla"
|
||||||
|
date: "2008/08/24"
|
||||||
author: "Javier Velilla"
|
revision: "Revision 0.1"
|
||||||
date: "2008/08/24"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
revision: "Revision 0.1"
|
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
|
||||||
|
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_STRING
|
JSON_STRING
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_VALUE
|
|
||||||
redefine
|
JSON_VALUE
|
||||||
is_equal
|
redefine
|
||||||
end
|
is_equal
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_json,
|
make_json, make_json_from_string_32, make_with_escaped_json
|
||||||
make_json_from_string_32,
|
|
||||||
make_with_escaped_json
|
|
||||||
|
|
||||||
convert
|
convert
|
||||||
make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}),
|
make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}),
|
||||||
@@ -32,34 +28,34 @@ convert
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_json (s: READABLE_STRING_8)
|
make_json (s: READABLE_STRING_8)
|
||||||
-- Initialize.
|
-- Initialize.
|
||||||
require
|
require
|
||||||
item_not_void: s /= Void
|
item_not_void: s /= Void
|
||||||
do
|
do
|
||||||
make_with_escaped_json (escaped_json_string (s))
|
make_with_escaped_json (escaped_json_string (s))
|
||||||
end
|
end
|
||||||
|
|
||||||
make_json_from_string_32 (s: READABLE_STRING_32)
|
make_json_from_string_32 (s: READABLE_STRING_32)
|
||||||
-- Initialize from STRING_32 `s'.
|
-- Initialize from STRING_32 `s'.
|
||||||
require
|
require
|
||||||
item_not_void: s /= Void
|
item_not_void: s /= Void
|
||||||
do
|
do
|
||||||
make_with_escaped_json (escaped_json_string_32 (s))
|
make_with_escaped_json (escaped_json_string_32 (s))
|
||||||
end
|
end
|
||||||
|
|
||||||
make_with_escaped_json (s: READABLE_STRING_8)
|
make_with_escaped_json (s: READABLE_STRING_8)
|
||||||
-- Initialize with an_item already escaped
|
-- Initialize with an_item already escaped
|
||||||
require
|
require
|
||||||
item_not_void: s /= Void
|
item_not_void: s /= Void
|
||||||
do
|
do
|
||||||
item := s
|
item := s
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
item: STRING
|
item: STRING
|
||||||
-- Contents with escaped entities if any
|
-- Contents with escaped entities if any
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
@@ -86,14 +82,14 @@ feature -- Conversion
|
|||||||
unescape_to_string_32 (Result)
|
unescape_to_string_32 (Result)
|
||||||
end
|
end
|
||||||
|
|
||||||
representation: STRING
|
representation: STRING
|
||||||
-- String representation of `item' with escaped entities if any
|
-- String representation of `item' with escaped entities if any
|
||||||
do
|
do
|
||||||
create Result.make (item.count + 2)
|
create Result.make (item.count + 2)
|
||||||
Result.append_character ('%"')
|
Result.append_character ('%"')
|
||||||
Result.append (item)
|
Result.append (item)
|
||||||
Result.append_character ('%"')
|
Result.append_character ('%"')
|
||||||
end
|
end
|
||||||
|
|
||||||
unescape_to_string_8 (a_output: STRING_8)
|
unescape_to_string_8 (a_output: STRING_8)
|
||||||
-- Unescape string `item' into `a_output'.
|
-- Unescape string `item' into `a_output'.
|
||||||
@@ -105,11 +101,15 @@ feature -- Conversion
|
|||||||
do
|
do
|
||||||
s := item
|
s := item
|
||||||
n := s.count
|
n := s.count
|
||||||
from i := 1 until i > n loop
|
from
|
||||||
c := s[i]
|
i := 1
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
|
c := s [i]
|
||||||
if c = '\' then
|
if c = '\' then
|
||||||
if i < n then
|
if i < n then
|
||||||
inspect s[i+1]
|
inspect s [i + 1]
|
||||||
when '\' then
|
when '\' then
|
||||||
a_output.append_character ('\')
|
a_output.append_character ('\')
|
||||||
i := i + 2
|
i := i + 2
|
||||||
@@ -132,7 +132,7 @@ feature -- Conversion
|
|||||||
a_output.append_character ('%T')
|
a_output.append_character ('%T')
|
||||||
i := i + 2
|
i := i + 2
|
||||||
when 'u' then
|
when 'u' then
|
||||||
--| Leave Unicode \uXXXX unescaped
|
--| Leave Unicode \uXXXX unescaped
|
||||||
a_output.append_character ('\')
|
a_output.append_character ('\')
|
||||||
i := i + 1
|
i := i + 1
|
||||||
else
|
else
|
||||||
@@ -153,7 +153,7 @@ feature -- Conversion
|
|||||||
unescape_to_string_32 (a_output: STRING_32)
|
unescape_to_string_32 (a_output: STRING_32)
|
||||||
-- Unescape string `item' into `a_output' string 32.
|
-- Unescape string `item' into `a_output' string 32.
|
||||||
--| some encoders uses UTF-8 , and not the recommended pure json encoding
|
--| some encoders uses UTF-8 , and not the recommended pure json encoding
|
||||||
--| thus, let's support the UTF-8 encoding during decoding.
|
--| thus, let's support the UTF-8 encoding during decoding.
|
||||||
local
|
local
|
||||||
s: READABLE_STRING_8
|
s: READABLE_STRING_8
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
@@ -163,11 +163,15 @@ feature -- Conversion
|
|||||||
do
|
do
|
||||||
s := item
|
s := item
|
||||||
n := s.count
|
n := s.count
|
||||||
from i := 1 until i > n loop
|
from
|
||||||
|
i := 1
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
ch := s.item (i)
|
ch := s.item (i)
|
||||||
if ch = '\' then
|
if ch = '\' then
|
||||||
if i < n then
|
if i < n then
|
||||||
inspect s[i+1]
|
inspect s [i + 1]
|
||||||
when '\' then
|
when '\' then
|
||||||
a_output.append_character ('\')
|
a_output.append_character ('\')
|
||||||
i := i + 2
|
i := i + 2
|
||||||
@@ -207,37 +211,27 @@ feature -- Conversion
|
|||||||
c := ch.natural_32_code
|
c := ch.natural_32_code
|
||||||
if c <= 0x7F then
|
if c <= 0x7F then
|
||||||
-- 0xxxxxxx
|
-- 0xxxxxxx
|
||||||
check ch = c.to_character_32 end
|
check
|
||||||
|
ch = c.to_character_32
|
||||||
|
end
|
||||||
a_output.append_character (ch)
|
a_output.append_character (ch)
|
||||||
elseif c <= 0xDF then
|
elseif c <= 0xDF then
|
||||||
-- 110xxxxx 10xxxxxx
|
-- 110xxxxx 10xxxxxx
|
||||||
i := i + 1
|
i := i + 1
|
||||||
if i <= n then
|
if i <= n then
|
||||||
a_output.append_code (
|
a_output.append_code (((c & 0x1F) |<< 6) | (s.code (i) & 0x3F))
|
||||||
((c & 0x1F) |<< 6) |
|
|
||||||
(s.code (i) & 0x3F)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
elseif c <= 0xEF then
|
elseif c <= 0xEF then
|
||||||
-- 1110xxxx 10xxxxxx 10xxxxxx
|
-- 1110xxxx 10xxxxxx 10xxxxxx
|
||||||
i := i + 2
|
i := i + 2
|
||||||
if i <= n then
|
if i <= n then
|
||||||
a_output.append_code (
|
a_output.append_code (((c & 0xF) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F))
|
||||||
((c & 0xF) |<< 12) |
|
|
||||||
((s.code (i - 1) & 0x3F) |<< 6) |
|
|
||||||
(s.code (i) & 0x3F)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
elseif c <= 0xF7 then
|
elseif c <= 0xF7 then
|
||||||
-- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
-- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||||
i := i + 3
|
i := i + 3
|
||||||
if i <= n then
|
if i <= n then
|
||||||
a_output.append_code (
|
a_output.append_code (((c & 0x7) |<< 18) | ((s.code (i - 2) & 0x3F) |<< 12) | ((s.code (i - 1) & 0x3F) |<< 6) | (s.code (i) & 0x3F))
|
||||||
((c & 0x7) |<< 18) |
|
|
||||||
((s.code (i - 2) & 0x3F) |<< 12) |
|
|
||||||
((s.code (i - 1) & 0x3F) |<< 6) |
|
|
||||||
(s.code (i) & 0x3F)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
@@ -247,52 +241,52 @@ feature -- Conversion
|
|||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_json_string' procedure on `a_visitor'.)
|
-- (Call `visit_json_string' procedure on `a_visitor'.)
|
||||||
do
|
do
|
||||||
a_visitor.visit_json_string (Current)
|
a_visitor.visit_json_string (Current)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
|
|
||||||
is_equal (other: like Current): BOOLEAN
|
is_equal (other: like Current): BOOLEAN
|
||||||
-- Is JSON_STRING made of same character sequence as `other'
|
-- Is JSON_STRING made of same character sequence as `other'
|
||||||
-- (possibly with a different capacity)?
|
-- (possibly with a different capacity)?
|
||||||
do
|
do
|
||||||
Result := item.same_string (other.item)
|
Result := item.same_string (other.item)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
append (a_string: STRING)
|
append (a_string: STRING)
|
||||||
-- Add a_string
|
-- Add a_string
|
||||||
require
|
require
|
||||||
a_string_not_void: a_string /= Void
|
a_string_not_void: a_string /= Void
|
||||||
do
|
do
|
||||||
item.append_string (a_string)
|
item.append_string (a_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
hash_code: INTEGER
|
hash_code: INTEGER
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
debug_output: STRING
|
debug_output: STRING
|
||||||
-- String that should be displayed in debugger to represent `Current'.
|
-- String that should be displayed in debugger to represent `Current'.
|
||||||
do
|
do
|
||||||
Result := item
|
Result := item
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
|
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
|
||||||
-- Is `s' an hexadecimal value?
|
-- Is `s' an hexadecimal value?
|
||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
@@ -302,7 +296,7 @@ feature {NONE} -- Implementation
|
|||||||
until
|
until
|
||||||
i > s.count or not Result
|
i > s.count or not Result
|
||||||
loop
|
loop
|
||||||
Result := s[i].is_hexa_digit
|
Result := s [i].is_hexa_digit
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -317,13 +311,11 @@ feature {NONE} -- Implementation
|
|||||||
char: CHARACTER
|
char: CHARACTER
|
||||||
do
|
do
|
||||||
nb := s.count
|
nb := s.count
|
||||||
|
|
||||||
if nb >= 2 and then s.item (2) = 'x' then
|
if nb >= 2 and then s.item (2) = 'x' then
|
||||||
i := 3
|
i := 3
|
||||||
else
|
else
|
||||||
i := 1
|
i := 1
|
||||||
end
|
end
|
||||||
|
|
||||||
from
|
from
|
||||||
until
|
until
|
||||||
i > nb
|
i > nb
|
||||||
@@ -339,26 +331,37 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
escaped_json_string (s: READABLE_STRING_8): STRING_8
|
escaped_json_string (s: READABLE_STRING_8): STRING_8
|
||||||
-- JSON string with '"' and '\' characters escaped
|
-- JSON string with '"' and '\' characters escaped
|
||||||
require
|
require
|
||||||
s_not_void: s /= Void
|
s_not_void: s /= Void
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
c: CHARACTER_8
|
c: CHARACTER_8
|
||||||
do
|
do
|
||||||
n := s.count
|
n := s.count
|
||||||
create Result.make (n + n // 10)
|
create Result.make (n + n // 10)
|
||||||
from i := 1 until i > n loop
|
from
|
||||||
|
i := 1
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
c := s.item (i)
|
c := s.item (i)
|
||||||
inspect c
|
inspect c
|
||||||
when '%"' then Result.append_string ("\%"")
|
when '%"' then
|
||||||
when '\' then Result.append_string ("\\")
|
Result.append_string ("\%"")
|
||||||
when '%B' then Result.append_string ("\b")
|
when '\' then
|
||||||
when '%F' then Result.append_string ("\f")
|
Result.append_string ("\\")
|
||||||
when '%N' then Result.append_string ("\n")
|
when '%B' then
|
||||||
when '%R' then Result.append_string ("\r")
|
Result.append_string ("\b")
|
||||||
when '%T' then Result.append_string ("\t")
|
when '%F' then
|
||||||
|
Result.append_string ("\f")
|
||||||
|
when '%N' then
|
||||||
|
Result.append_string ("\n")
|
||||||
|
when '%R' then
|
||||||
|
Result.append_string ("\r")
|
||||||
|
when '%T' then
|
||||||
|
Result.append_string ("\t")
|
||||||
else
|
else
|
||||||
Result.extend (c)
|
Result.extend (c)
|
||||||
end
|
end
|
||||||
@@ -366,10 +369,10 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
escaped_json_string_32 (s: READABLE_STRING_32): STRING_8
|
escaped_json_string_32 (s: READABLE_STRING_32): STRING_8
|
||||||
-- JSON string with '"' and '\' characters and Unicode escaped
|
-- JSON string with '"' and '\' characters and Unicode escaped
|
||||||
require
|
require
|
||||||
s_not_void: s /= Void
|
s_not_void: s /= Void
|
||||||
local
|
local
|
||||||
i, j, n: INTEGER
|
i, j, n: INTEGER
|
||||||
uc: CHARACTER_32
|
uc: CHARACTER_32
|
||||||
@@ -378,25 +381,36 @@ feature {NONE} -- Implementation
|
|||||||
do
|
do
|
||||||
n := s.count
|
n := s.count
|
||||||
create Result.make (n + n // 10)
|
create Result.make (n + n // 10)
|
||||||
from i := 1 until i > n loop
|
from
|
||||||
|
i := 1
|
||||||
|
until
|
||||||
|
i > n
|
||||||
|
loop
|
||||||
uc := s.item (i)
|
uc := s.item (i)
|
||||||
if uc.is_character_8 then
|
if uc.is_character_8 then
|
||||||
c := uc.to_character_8
|
c := uc.to_character_8
|
||||||
inspect c
|
inspect c
|
||||||
when '%"' then Result.append_string ("\%"")
|
when '%"' then
|
||||||
when '\' then Result.append_string ("\\")
|
Result.append_string ("\%"")
|
||||||
when '%B' then Result.append_string ("\b")
|
when '\' then
|
||||||
when '%F' then Result.append_string ("\f")
|
Result.append_string ("\\")
|
||||||
when '%N' then Result.append_string ("\n")
|
when '%B' then
|
||||||
when '%R' then Result.append_string ("\r")
|
Result.append_string ("\b")
|
||||||
when '%T' then Result.append_string ("\t")
|
when '%F' then
|
||||||
|
Result.append_string ("\f")
|
||||||
|
when '%N' then
|
||||||
|
Result.append_string ("\n")
|
||||||
|
when '%R' then
|
||||||
|
Result.append_string ("\r")
|
||||||
|
when '%T' then
|
||||||
|
Result.append_string ("\t")
|
||||||
else
|
else
|
||||||
Result.extend (c)
|
Result.extend (c)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result.append ("\u")
|
Result.append ("\u")
|
||||||
h := uc.code.to_hex_string
|
h := uc.code.to_hex_string
|
||||||
-- Remove first 0 and keep 4 hexa digit
|
-- Remove first 0 and keep 4 hexa digit
|
||||||
from
|
from
|
||||||
j := 1
|
j := 1
|
||||||
until
|
until
|
||||||
@@ -405,14 +419,15 @@ feature {NONE} -- Implementation
|
|||||||
j := j + 1
|
j := j + 1
|
||||||
end
|
end
|
||||||
h := h.substring (j, h.count)
|
h := h.substring (j, h.count)
|
||||||
|
|
||||||
from
|
from
|
||||||
until
|
until
|
||||||
h.count >= 4
|
h.count >= 4
|
||||||
loop
|
loop
|
||||||
h.prepend_integer (0)
|
h.prepend_integer (0)
|
||||||
end
|
end
|
||||||
check h.count = 4 end
|
check
|
||||||
|
h.count = 4
|
||||||
|
end
|
||||||
Result.append (h)
|
Result.append (h)
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
@@ -420,6 +435,6 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
item_not_void: item /= Void
|
item_not_void: item /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
note
|
note
|
||||||
description:"[
|
description: "[
|
||||||
JSON_VALUE represent a value in JSON.
|
JSON_VALUE represent a value in JSON.
|
||||||
A value can be
|
A value can be
|
||||||
* a string in double quotes
|
* a string in double quotes
|
||||||
* a number
|
* a number
|
||||||
* boolean value(true, false )
|
* boolean value(true, false )
|
||||||
* null
|
* null
|
||||||
* an object
|
* an object
|
||||||
* an array
|
* an array
|
||||||
]"
|
]"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "2008/05/19"
|
date: "2008/05/19"
|
||||||
revision: "Revision 0.1"
|
revision: "Revision 0.1"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license: "MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
|
|
||||||
|
|
||||||
deferred class
|
deferred class
|
||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
HASHABLE
|
|
||||||
|
|
||||||
DEBUG_OUTPUT
|
HASHABLE
|
||||||
|
|
||||||
|
DEBUG_OUTPUT
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
representation: STRING
|
representation: STRING
|
||||||
-- UTF-8 encoded Unicode string representation of Current
|
-- UTF-8 encoded Unicode string representation of Current
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Visitor pattern
|
feature -- Visitor pattern
|
||||||
|
|
||||||
accept (a_visitor: JSON_VISITOR)
|
accept (a_visitor: JSON_VISITOR)
|
||||||
-- Accept `a_visitor'.
|
-- Accept `a_visitor'.
|
||||||
-- (Call `visit_*' procedure on `a_visitor'.)
|
-- (Call `visit_*' procedure on `a_visitor'.)
|
||||||
require
|
require
|
||||||
a_visitor_not_void: a_visitor /= Void
|
a_visitor_not_void: a_visitor /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
note
|
note
|
||||||
|
|
||||||
description: "Parse serialized JSON data"
|
description: "Parse serialized JSON data"
|
||||||
author: "jvelilla"
|
author: "jvelilla"
|
||||||
date: "2008/08/24"
|
date: "2008/08/24"
|
||||||
@@ -9,7 +8,9 @@ class
|
|||||||
JSON_PARSER
|
JSON_PARSER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
JSON_READER
|
JSON_READER
|
||||||
|
|
||||||
JSON_TOKENS
|
JSON_TOKENS
|
||||||
|
|
||||||
create
|
create
|
||||||
@@ -62,18 +63,18 @@ feature -- Element change
|
|||||||
feature -- Commands
|
feature -- Commands
|
||||||
|
|
||||||
parse_json: detachable JSON_VALUE
|
parse_json: detachable JSON_VALUE
|
||||||
-- Parse JSON data `representation'
|
-- Parse JSON data `representation'
|
||||||
-- start ::= object | array
|
-- start ::= object | array
|
||||||
do
|
do
|
||||||
if is_valid_start_symbol then
|
if is_valid_start_symbol then
|
||||||
Result := parse
|
Result := parse
|
||||||
if extra_elements then
|
if extra_elements then
|
||||||
is_parsed := False
|
is_parsed := False
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
is_parsed := False
|
is_parsed := False
|
||||||
report_error ("Syntax error unexpected token, expecting `{' or `['")
|
report_error ("Syntax error unexpected token, expecting `{' or `['")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parse: detachable JSON_VALUE
|
parse: detachable JSON_VALUE
|
||||||
@@ -92,7 +93,7 @@ feature -- Commands
|
|||||||
when j_ARRAY_OPEN then
|
when j_ARRAY_OPEN then
|
||||||
Result := parse_array
|
Result := parse_array
|
||||||
else
|
else
|
||||||
if c.is_digit or c = j_MINUS then
|
if c.is_digit or c = j_MINUS then
|
||||||
Result := parse_number
|
Result := parse_number
|
||||||
elseif is_null then
|
elseif is_null then
|
||||||
Result := create {JSON_NULL}
|
Result := create {JSON_NULL}
|
||||||
@@ -131,15 +132,19 @@ feature -- Commands
|
|||||||
l_value: detachable JSON_VALUE
|
l_value: detachable JSON_VALUE
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
-- check if is an empty object {}
|
-- check if is an empty object {}
|
||||||
next
|
next
|
||||||
skip_white_spaces
|
skip_white_spaces
|
||||||
if actual = j_OBJECT_CLOSE then
|
if actual = j_OBJECT_CLOSE then
|
||||||
--is an empty object
|
--is an empty object
|
||||||
else
|
else
|
||||||
-- a complex object {"key" : "value"}
|
-- a complex object {"key" : "value"}
|
||||||
previous
|
previous
|
||||||
from has_more := True until not has_more loop
|
from
|
||||||
|
has_more := True
|
||||||
|
until
|
||||||
|
not has_more
|
||||||
|
loop
|
||||||
next
|
next
|
||||||
skip_white_spaces
|
skip_white_spaces
|
||||||
l_json_string := parse_string
|
l_json_string := parse_string
|
||||||
@@ -153,7 +158,6 @@ feature -- Commands
|
|||||||
report_error ("%N Input string is a not well formed JSON, expected: : found: " + actual.out)
|
report_error ("%N Input string is a not well formed JSON, expected: : found: " + actual.out)
|
||||||
has_more := False
|
has_more := False
|
||||||
end
|
end
|
||||||
|
|
||||||
l_value := parse
|
l_value := parse
|
||||||
if is_parsed and then (l_value /= Void and l_json_string /= Void) then
|
if is_parsed and then (l_value /= Void and l_json_string /= Void) then
|
||||||
Result.put (l_value, l_json_string)
|
Result.put (l_value, l_json_string)
|
||||||
@@ -168,7 +172,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
has_more := False
|
has_more := False
|
||||||
-- explain the error
|
-- explain the error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -241,11 +245,11 @@ feature -- Commands
|
|||||||
c: like actual
|
c: like actual
|
||||||
do
|
do
|
||||||
create Result.make_array
|
create Result.make_array
|
||||||
--check if is an empty array []
|
--check if is an empty array []
|
||||||
next
|
next
|
||||||
skip_white_spaces
|
skip_white_spaces
|
||||||
if actual = j_array_close then
|
if actual = j_array_close then
|
||||||
--is an empty array
|
--is an empty array
|
||||||
else
|
else
|
||||||
previous
|
previous
|
||||||
from
|
from
|
||||||
@@ -263,7 +267,7 @@ feature -- Commands
|
|||||||
c := actual
|
c := actual
|
||||||
if c = j_ARRAY_CLOSE then
|
if c = j_ARRAY_CLOSE then
|
||||||
flag := False
|
flag := False
|
||||||
elseif c /= ',' then
|
elseif c /= ',' then
|
||||||
flag := False
|
flag := False
|
||||||
is_parsed := False
|
is_parsed := False
|
||||||
report_error ("Array is not well formed JSON, found [" + c.out + " ]")
|
report_error ("Array is not well formed JSON, found [" + c.out + " ]")
|
||||||
@@ -286,7 +290,6 @@ feature -- Commands
|
|||||||
do
|
do
|
||||||
create sb.make_empty
|
create sb.make_empty
|
||||||
sb.append_character (actual)
|
sb.append_character (actual)
|
||||||
|
|
||||||
from
|
from
|
||||||
flag := True
|
flag := True
|
||||||
until
|
until
|
||||||
@@ -294,16 +297,13 @@ feature -- Commands
|
|||||||
loop
|
loop
|
||||||
next
|
next
|
||||||
c := actual
|
c := actual
|
||||||
if not has_next or is_close_token (c)
|
if not has_next or is_close_token (c) or c = ',' or c = '%N' or c = '%R' then
|
||||||
or c = ',' or c = '%N' or c = '%R'
|
|
||||||
then
|
|
||||||
flag := False
|
flag := False
|
||||||
previous
|
previous
|
||||||
else
|
else
|
||||||
sb.append_character (c)
|
sb.append_character (c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_valid_number (sb) then
|
if is_valid_number (sb) then
|
||||||
if sb.is_integer then
|
if sb.is_integer then
|
||||||
create Result.make_integer (sb.to_integer)
|
create Result.make_integer (sb.to_integer)
|
||||||
@@ -313,7 +313,7 @@ feature -- Commands
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
is_parsed := False
|
is_parsed := False
|
||||||
report_error ("Expected a number, found: [ " + sb + " ]")
|
report_error ("Expected a number, found: [ " + sb + " ]")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ feature -- Commands
|
|||||||
l_string: STRING
|
l_string: STRING
|
||||||
do
|
do
|
||||||
l_null := null_id
|
l_null := null_id
|
||||||
l_string := json_substring (index,index + l_null.count - 1)
|
l_string := json_substring (index, index + l_null.count - 1)
|
||||||
if l_string.is_equal (l_null) then
|
if l_string.is_equal (l_null) then
|
||||||
Result := True
|
Result := True
|
||||||
end
|
end
|
||||||
@@ -350,7 +350,7 @@ feature -- Commands
|
|||||||
l_string: STRING
|
l_string: STRING
|
||||||
do
|
do
|
||||||
l_true := true_id
|
l_true := true_id
|
||||||
l_string := json_substring (index,index + l_true.count - 1)
|
l_string := json_substring (index, index + l_true.count - 1)
|
||||||
if l_string.is_equal (l_true) then
|
if l_string.is_equal (l_true) then
|
||||||
Result := True
|
Result := True
|
||||||
end
|
end
|
||||||
@@ -376,12 +376,12 @@ feature -- Commands
|
|||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
is_valid_number (a_number: STRING): BOOLEAN
|
is_valid_number (a_number: STRING): BOOLEAN
|
||||||
-- is 'a_number' a valid number based on this regular expression
|
-- is 'a_number' a valid number based on this regular expression
|
||||||
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
|
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
|
||||||
local
|
local
|
||||||
s: detachable STRING
|
s: detachable STRING
|
||||||
c: CHARACTER
|
c: CHARACTER
|
||||||
i,n: INTEGER
|
i, n: INTEGER
|
||||||
do
|
do
|
||||||
create s.make_empty
|
create s.make_empty
|
||||||
n := a_number.count
|
n := a_number.count
|
||||||
@@ -390,34 +390,52 @@ feature {NONE} -- Implementation
|
|||||||
else
|
else
|
||||||
Result := True
|
Result := True
|
||||||
i := 1
|
i := 1
|
||||||
--| "-?"
|
--| "-?"
|
||||||
c := a_number[i]
|
c := a_number [i]
|
||||||
if c = '-' then
|
if c = '-' then
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
--| "0|[1-9]\d*
|
--| "0|[1-9]\d*
|
||||||
if c.is_digit then
|
if c.is_digit then
|
||||||
if c = '0' then
|
if c = '0' then
|
||||||
--| "0"
|
--| "0"
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
else
|
else
|
||||||
--| "[1-9]"
|
--| "[1-9]"
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
--| "\d*"
|
i := i + 1;
|
||||||
from until i > n or not c.is_digit loop
|
c := a_number [i]
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
--| "\d*"
|
||||||
|
from
|
||||||
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Result then
|
if Result then
|
||||||
--| "(\.\d+)?"
|
--| "(\.\d+)?"
|
||||||
if c = '.' then
|
if c = '.' then
|
||||||
--| "\.\d+" = "\.\d\d*"
|
--| "\.\d+" = "\.\d\d*"
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
if c.is_digit then
|
if c.is_digit then
|
||||||
from until i > n or not c.is_digit loop
|
from
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result := False --| expecting digit
|
Result := False --| expecting digit
|
||||||
@@ -426,23 +444,37 @@ feature {NONE} -- Implementation
|
|||||||
end
|
end
|
||||||
if Result then --| "(?:[eE][+-]?\d+)?\b"
|
if Result then --| "(?:[eE][+-]?\d+)?\b"
|
||||||
if c = 'e' or c = 'E' then
|
if c = 'e' or c = 'E' then
|
||||||
--| "[eE][+-]?\d+"
|
--| "[eE][+-]?\d+"
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
if c = '+' or c = '-' then
|
if c = '+' or c = '-' then
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
if c.is_digit then
|
if c.is_digit then
|
||||||
from until i > n or not c.is_digit loop
|
from
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result := False --| expecting digit
|
Result := False --| expecting digit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Result then --| "\b"
|
if Result then --| "\b"
|
||||||
from until i > n or not c.is_space loop
|
from
|
||||||
s.extend (c); i := i + 1; c := a_number[i]
|
until
|
||||||
|
i > n or not c.is_space
|
||||||
|
loop
|
||||||
|
s.extend (c);
|
||||||
|
i := i + 1;
|
||||||
|
c := a_number [i]
|
||||||
end
|
end
|
||||||
Result := i > n and then s.same_string (a_number)
|
Result := i > n and then s.same_string (a_number)
|
||||||
end
|
end
|
||||||
@@ -454,19 +486,15 @@ feature {NONE} -- Implementation
|
|||||||
local
|
local
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
if
|
if a_unicode.count = 6 and then a_unicode [1] = '\' and then a_unicode [2] = 'u' then
|
||||||
a_unicode.count = 6 and then
|
|
||||||
a_unicode[1] = '\' and then
|
|
||||||
a_unicode[2] = 'u'
|
|
||||||
then
|
|
||||||
from
|
from
|
||||||
Result := True
|
Result := True
|
||||||
i := 3
|
i := 3
|
||||||
until
|
until
|
||||||
i > 6 or Result = False
|
i > 6 or Result = False
|
||||||
loop
|
loop
|
||||||
inspect a_unicode[i]
|
inspect a_unicode [i]
|
||||||
when '0'..'9', 'a'..'f', 'A'..'F' then
|
when '0'..'9', 'a'..'f', 'A'..'F' then
|
||||||
else
|
else
|
||||||
Result := False
|
Result := False
|
||||||
end
|
end
|
||||||
@@ -493,11 +521,11 @@ feature {NONE} -- Implementation
|
|||||||
Result := has_next
|
Result := has_next
|
||||||
end
|
end
|
||||||
|
|
||||||
is_valid_start_symbol : BOOLEAN
|
is_valid_start_symbol: BOOLEAN
|
||||||
-- expecting `{' or `[' as start symbol
|
-- expecting `{' or `[' as start symbol
|
||||||
do
|
do
|
||||||
if attached representation as s and then s.count > 0 then
|
if attached representation as s and then s.count > 0 then
|
||||||
Result := s[1] = '{' or s[1] = '['
|
Result := s [1] = '{' or s [1] = '['
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -509,5 +537,4 @@ feature {NONE} -- Constants
|
|||||||
|
|
||||||
null_id: STRING = "null"
|
null_id: STRING = "null"
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,22 +12,22 @@ create
|
|||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_json: STRING)
|
make (a_json: STRING)
|
||||||
-- Initialize Reader
|
-- Initialize Reader
|
||||||
do
|
do
|
||||||
set_representation (a_json)
|
set_representation (a_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Commands
|
feature -- Commands
|
||||||
|
|
||||||
set_representation (a_json: STRING)
|
set_representation (a_json: STRING)
|
||||||
-- Set `representation'.
|
-- Set `representation'.
|
||||||
do
|
do
|
||||||
a_json.left_adjust
|
a_json.left_adjust
|
||||||
a_json.right_adjust
|
a_json.right_adjust
|
||||||
representation := a_json
|
representation := a_json
|
||||||
index := 1
|
index := 1
|
||||||
end
|
end
|
||||||
|
|
||||||
read: CHARACTER
|
read: CHARACTER
|
||||||
-- Read character
|
-- Read character
|
||||||
@@ -65,7 +65,7 @@ feature -- Commands
|
|||||||
from
|
from
|
||||||
c := actual
|
c := actual
|
||||||
until
|
until
|
||||||
(c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T' ) or not has_next
|
(c /= ' ' and c /= '%N' and c /= '%R' and c /= '%U' and c /= '%T') or not has_next
|
||||||
loop
|
loop
|
||||||
next
|
next
|
||||||
c := actual
|
c := actual
|
||||||
|
|||||||
@@ -10,36 +10,40 @@ class
|
|||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
j_OBJECT_OPEN: CHARACTER = '{'
|
j_OBJECT_OPEN: CHARACTER = '{'
|
||||||
|
|
||||||
j_ARRAY_OPEN: CHARACTER = '['
|
j_ARRAY_OPEN: CHARACTER = '['
|
||||||
|
|
||||||
j_OBJECT_CLOSE: CHARACTER = '}'
|
j_OBJECT_CLOSE: CHARACTER = '}'
|
||||||
|
|
||||||
j_ARRAY_CLOSE: CHARACTER = ']'
|
j_ARRAY_CLOSE: CHARACTER = ']'
|
||||||
|
|
||||||
j_STRING: CHARACTER = '"'
|
j_STRING: CHARACTER = '"'
|
||||||
|
|
||||||
j_PLUS: CHARACTER = '+'
|
j_PLUS: CHARACTER = '+'
|
||||||
|
|
||||||
j_MINUS: CHARACTER = '-'
|
j_MINUS: CHARACTER = '-'
|
||||||
|
|
||||||
j_DOT: CHARACTER = '.'
|
j_DOT: CHARACTER = '.'
|
||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
is_open_token (c: CHARACTER): BOOLEAN
|
is_open_token (c: CHARACTER): BOOLEAN
|
||||||
-- Characters which open a type
|
-- Characters which open a type
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
when j_OBJECT_OPEN, j_ARRAY_OPEN, j_STRING, j_PLUS, j_MINUS, j_DOT then
|
when j_OBJECT_OPEN, j_ARRAY_OPEN, j_STRING, j_PLUS, j_MINUS, j_DOT then
|
||||||
Result := True
|
Result := True
|
||||||
else
|
else
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_close_token (c: CHARACTER): BOOLEAN
|
is_close_token (c: CHARACTER): BOOLEAN
|
||||||
-- Characters which close a type
|
-- Characters which close a type
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
when j_OBJECT_CLOSE, j_ARRAY_CLOSE, j_STRING then
|
when j_OBJECT_CLOSE, j_ARRAY_CLOSE, j_STRING then
|
||||||
Result := True
|
Result := True
|
||||||
else
|
else
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -51,26 +55,24 @@ feature -- Status report
|
|||||||
-- %R carriage Return
|
-- %R carriage Return
|
||||||
-- %T horizontal Tab
|
-- %T horizontal Tab
|
||||||
-- %B Backspace
|
-- %B Backspace
|
||||||
-- / Solidus
|
-- / Solidus
|
||||||
-- " Quotation
|
-- " Quotation
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
when '%F', '%H', '%N', '%R', '%T', '%B', '/', '"' then
|
when '%F', '%H', '%N', '%R', '%T', '%B', '/', '"' then
|
||||||
Result := True
|
Result := True
|
||||||
else
|
else
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
is_special_control (c: CHARACTER): BOOLEAN
|
is_special_control (c: CHARACTER): BOOLEAN
|
||||||
--Control Characters
|
--Control Characters
|
||||||
-- \b\f\n\r\t
|
-- \b\f\n\r\t
|
||||||
do
|
do
|
||||||
inspect c
|
inspect c
|
||||||
when 'b', 'f', 'n', 'r', 't' then
|
when 'b', 'f', 'n', 'r', 't' then
|
||||||
Result := True
|
Result := True
|
||||||
else
|
else
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,36 @@
|
|||||||
note
|
note
|
||||||
description: "[
|
description: "[
|
||||||
Shared factory class for creating JSON objects. Maps JSON
|
Shared factory class for creating JSON objects. Maps JSON
|
||||||
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
|
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
|
||||||
LINKED_LISTs. Use non-conforming inheritance from this
|
LINKED_LISTs. Use non-conforming inheritance from this
|
||||||
class to ensure that your classes share the same
|
class to ensure that your classes share the same
|
||||||
JSON_FACTORY instance.
|
JSON_FACTORY instance.
|
||||||
]"
|
]"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision: 89185 $"
|
revision: "$Revision: 89185 $"
|
||||||
file: "$HeadURL: $"
|
file: "$HeadURL: $"
|
||||||
|
|
||||||
class SHARED_EJSON
|
class
|
||||||
|
SHARED_EJSON
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
json: EJSON
|
json: EJSON
|
||||||
-- A shared EJSON instance with default converters for
|
-- A shared EJSON instance with default converters for
|
||||||
--LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE]
|
--LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE]
|
||||||
local
|
local
|
||||||
jalc: JSON_ARRAYED_LIST_CONVERTER
|
jalc: JSON_ARRAYED_LIST_CONVERTER
|
||||||
jllc: JSON_LINKED_LIST_CONVERTER
|
jllc: JSON_LINKED_LIST_CONVERTER
|
||||||
jhtc: JSON_HASH_TABLE_CONVERTER
|
jhtc: JSON_HASH_TABLE_CONVERTER
|
||||||
once
|
once
|
||||||
create Result
|
create Result
|
||||||
|
create jalc.make
|
||||||
|
Result.add_converter (jalc)
|
||||||
|
create jllc.make
|
||||||
|
Result.add_converter (jllc)
|
||||||
|
create jhtc.make
|
||||||
|
Result.add_converter (jhtc)
|
||||||
|
end
|
||||||
|
|
||||||
create jalc.make
|
|
||||||
Result.add_converter (jalc)
|
|
||||||
|
|
||||||
create jllc.make
|
|
||||||
Result.add_converter (jllc)
|
|
||||||
|
|
||||||
create jhtc.make
|
|
||||||
Result.add_converter (jhtc)
|
|
||||||
end
|
|
||||||
|
|
||||||
end -- class SHARED_EJSON
|
end -- class SHARED_EJSON
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
note
|
note
|
||||||
description : "test_suite application root class"
|
description: "test_suite application root class"
|
||||||
date : "$Date$"
|
date: "$Date$"
|
||||||
revision : "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
APPLICATION
|
APPLICATION
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
ARGUMENTS
|
ARGUMENTS
|
||||||
|
|
||||||
create
|
create
|
||||||
@@ -17,7 +18,7 @@ feature {NONE} -- Initialization
|
|||||||
make
|
make
|
||||||
-- Run application.
|
-- Run application.
|
||||||
do
|
do
|
||||||
--| Add your code here
|
--| Add your code here
|
||||||
print ("Hello Eiffel World!%N")
|
print ("Hello Eiffel World!%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,32 @@
|
|||||||
|
|
||||||
class
|
class
|
||||||
AUTHOR
|
AUTHOR
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_name: STRING_32)
|
make (a_name: STRING_32)
|
||||||
-- Create an author with `a_name' as `name'.
|
-- Create an author with `a_name' as `name'.
|
||||||
do
|
do
|
||||||
set_name (a_name)
|
set_name (a_name)
|
||||||
ensure
|
ensure
|
||||||
name_set: name = a_name
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: STRING_32
|
name: STRING_32
|
||||||
-- Author name
|
-- Author name
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
set_name (a_name: STRING_32)
|
set_name (a_name: STRING_32)
|
||||||
-- Set `name' with `a_name'.
|
-- Set `name' with `a_name'.
|
||||||
do
|
do
|
||||||
name := a_name
|
name := a_name
|
||||||
ensure
|
ensure
|
||||||
name_set: name = a_name
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class AUTHOR
|
end -- class AUTHOR
|
||||||
|
|||||||
@@ -1,60 +1,59 @@
|
|||||||
|
|
||||||
class
|
class
|
||||||
BOOK
|
BOOK
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32)
|
make (a_title: STRING_32; a_author: AUTHOR; a_isbn: STRING_32)
|
||||||
-- Create a book with `a_title' as `title',
|
-- Create a book with `a_title' as `title',
|
||||||
-- `a_author' as `author', and `a_isbn' as `isbn',
|
-- `a_author' as `author', and `a_isbn' as `isbn'.
|
||||||
do
|
do
|
||||||
set_title (a_title)
|
set_title (a_title)
|
||||||
set_author (a_author)
|
set_author (a_author)
|
||||||
set_isbn (a_isbn)
|
set_isbn (a_isbn)
|
||||||
ensure
|
ensure
|
||||||
title_set: title = a_title
|
title_set: title = a_title
|
||||||
author_set: author = a_author
|
author_set: author = a_author
|
||||||
isbn_set: isbn = a_isbn
|
isbn_set: isbn = a_isbn
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
title: STRING_32
|
title: STRING_32
|
||||||
-- Main title.
|
-- Main title.
|
||||||
|
|
||||||
isbn: STRING_32
|
isbn: STRING_32
|
||||||
-- ISBN.
|
-- ISBN.
|
||||||
|
|
||||||
author: AUTHOR
|
author: AUTHOR
|
||||||
-- Author.
|
-- Author.
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
set_title (a_title: STRING_32)
|
set_title (a_title: STRING_32)
|
||||||
-- Set `title' with `a_title'.
|
-- Set `title' with `a_title'.
|
||||||
do
|
do
|
||||||
title := a_title
|
title := a_title
|
||||||
ensure
|
ensure
|
||||||
title_set: title = a_title
|
title_set: title = a_title
|
||||||
end
|
end
|
||||||
|
|
||||||
set_author (a_author: AUTHOR)
|
set_author (a_author: AUTHOR)
|
||||||
-- Set `author' with `a_author'.
|
-- Set `author' with `a_author'.
|
||||||
do
|
do
|
||||||
author := a_author
|
author := a_author
|
||||||
ensure
|
ensure
|
||||||
author_set: author = a_author
|
author_set: author = a_author
|
||||||
end
|
end
|
||||||
|
|
||||||
set_isbn (a_isbn: STRING_32)
|
set_isbn (a_isbn: STRING_32)
|
||||||
-- Set `isbn' with `a_isbn'.
|
-- Set `isbn' with `a_isbn'.
|
||||||
do
|
do
|
||||||
isbn := a_isbn
|
isbn := a_isbn
|
||||||
ensure
|
ensure
|
||||||
isbn_set: isbn = a_isbn
|
isbn_set: isbn = a_isbn
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class BOOK
|
end -- class BOOK
|
||||||
|
|||||||
@@ -2,77 +2,81 @@ class
|
|||||||
BOOK_COLLECTION
|
BOOK_COLLECTION
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_name: STRING_32)
|
make (a_name: STRING_32)
|
||||||
-- Create a collection of book with `a_name' as `name'
|
-- Create a book collection with `a_name' as `name'.
|
||||||
do
|
do
|
||||||
set_name (a_name)
|
set_name (a_name)
|
||||||
create book_index.make (10)
|
create book_index.make (10)
|
||||||
ensure
|
ensure
|
||||||
name_set: name = a_name
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: STRING_32
|
name: STRING_32
|
||||||
-- Name.
|
-- Name.
|
||||||
|
|
||||||
books: LIST [BOOK]
|
books: LIST [BOOK]
|
||||||
-- collection of book.
|
-- collection of book.
|
||||||
do
|
do
|
||||||
create {LINKED_LIST [BOOK]} Result.make
|
create {LINKED_LIST [BOOK]} Result.make
|
||||||
across book_index as it loop
|
across
|
||||||
|
book_index as it
|
||||||
|
loop
|
||||||
Result.append (it.item)
|
Result.append (it.item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
books_by_author (a_author: STRING_32): LIST [BOOK]
|
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||||
-- Books wrote by `a_author' in this collection.
|
-- Books wrote by `a_author' in this collection.
|
||||||
do
|
do
|
||||||
if attached book_index [a_author] as l_result then
|
if attached book_index [a_author] as l_result then
|
||||||
Result := l_result
|
Result := l_result
|
||||||
else
|
else
|
||||||
create {LINKED_LIST [BOOK]} Result.make
|
create {LINKED_LIST [BOOK]} Result.make
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
set_name (a_name: STRING_32)
|
set_name (a_name: STRING_32)
|
||||||
-- Set `name' with `a_name'.
|
-- Set `name' with `a_name'.
|
||||||
do
|
do
|
||||||
name := a_name
|
name := a_name
|
||||||
ensure
|
ensure
|
||||||
name_set: name = a_name
|
name_set: name = a_name
|
||||||
end
|
end
|
||||||
|
|
||||||
add_book (a_book: BOOK)
|
add_book (a_book: BOOK)
|
||||||
-- Extend collection with `a_book'.
|
-- Extend collection with `a_book'.
|
||||||
local
|
local
|
||||||
l: detachable LIST [BOOK]
|
l: detachable LIST [BOOK]
|
||||||
do
|
do
|
||||||
l := book_index.at (a_book.author.name )
|
l := book_index.at (a_book.author.name)
|
||||||
if l = Void then
|
if l = Void then
|
||||||
create {LINKED_LIST [BOOK]} l.make
|
create {LINKED_LIST [BOOK]} l.make
|
||||||
book_index.put (l, a_book.author.name)
|
book_index.put (l, a_book.author.name)
|
||||||
end
|
end
|
||||||
l.force (a_book)
|
l.force (a_book)
|
||||||
end
|
end
|
||||||
|
|
||||||
add_books (book_list: like books)
|
add_books (book_list: like books)
|
||||||
-- Append collection with `book_list'.
|
-- Append collection with `book_list'.
|
||||||
do
|
do
|
||||||
across book_list as it loop
|
across
|
||||||
|
book_list as it
|
||||||
|
loop
|
||||||
add_book (it.item)
|
add_book (it.item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
||||||
-- Association of author name and its books.
|
-- Association of author name and its books.
|
||||||
|
|
||||||
end -- class BOOK_COLLECTION
|
end -- class BOOK_COLLECTION
|
||||||
|
|||||||
@@ -1,53 +1,54 @@
|
|||||||
note
|
note
|
||||||
description: "A JSON converter for AUTHOR"
|
description: "A JSON converter for AUTHOR"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_AUTHOR_CONVERTER
|
JSON_AUTHOR_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
local
|
local
|
||||||
ucs: STRING_32
|
ucs: STRING_32
|
||||||
do
|
do
|
||||||
create ucs.make_from_string ("")
|
create ucs.make_from_string ("")
|
||||||
create object.make (ucs)
|
create object.make (ucs)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: AUTHOR
|
object: AUTHOR
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
do
|
do
|
||||||
if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then
|
if attached {STRING_32} json.object (j.item (name_key), Void) as l_name then
|
||||||
create Result.make (l_name)
|
create Result.make (l_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (json.value (o.name), name_key)
|
Result.put (json.value (o.name), name_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
name_key: JSON_STRING
|
name_key: JSON_STRING
|
||||||
-- Author's name label.
|
-- Author's name label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("name")
|
create Result.make_json ("name")
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class JSON_AUTHOR_CONVERTER
|
end -- class JSON_AUTHOR_CONVERTER
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
note
|
note
|
||||||
description: "A JSON converter for BOOK_COLLECTION"
|
description: "A JSON converter for BOOK_COLLECTION"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_BOOK_COLLECTION_CONVERTER
|
JSON_BOOK_COLLECTION_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
local
|
local
|
||||||
ucs: STRING_32
|
ucs: STRING_32
|
||||||
do
|
do
|
||||||
create ucs.make_from_string ("")
|
create ucs.make_from_string ("")
|
||||||
create object.make (ucs)
|
create object.make (ucs)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: BOOK_COLLECTION
|
object: BOOK_COLLECTION
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
local
|
local
|
||||||
l_books: LINKED_LIST [BOOK]
|
l_books: LINKED_LIST [BOOK]
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
attached {STRING_32} json.object (j.item (name_key), Void) as l_name and
|
attached {STRING_32} json.object (j.item (name_key), Void) as l_name and
|
||||||
attached {JSON_ARRAY} j.item (books_key) as l_json_array
|
attached {JSON_ARRAY} j.item (books_key) as l_json_array
|
||||||
then
|
then
|
||||||
create Result.make (l_name)
|
create Result.make (l_name)
|
||||||
create l_books.make
|
create l_books.make
|
||||||
|
|
||||||
across
|
across
|
||||||
l_json_array as it
|
l_json_array as it
|
||||||
until
|
until
|
||||||
@@ -52,32 +52,31 @@ feature -- Conversion
|
|||||||
-- Failed
|
-- Failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Result /= Void then
|
if Result /= Void then
|
||||||
Result.add_books (l_books)
|
Result.add_books (l_books)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (json.value (o.name), name_key)
|
Result.put (json.value (o.name), name_key)
|
||||||
Result.put (json.value (o.books), books_key)
|
Result.put (json.value (o.books), books_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
name_key: JSON_STRING
|
name_key: JSON_STRING
|
||||||
-- Collection's name label.
|
-- Collection's name label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("name")
|
create Result.make_json ("name")
|
||||||
end
|
end
|
||||||
|
|
||||||
books_key: JSON_STRING
|
books_key: JSON_STRING
|
||||||
-- Book list label.
|
-- Book list label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("books")
|
create Result.make_json ("books")
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class JSON_BOOK_COLLECTION_CONVERTER
|
end -- class JSON_BOOK_COLLECTION_CONVERTER
|
||||||
|
|||||||
@@ -1,73 +1,74 @@
|
|||||||
note
|
note
|
||||||
description: "A JSON converter for BOOK"
|
description: "A JSON converter for BOOK"
|
||||||
author: "Paul Cohen"
|
author: "Paul Cohen"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_BOOK_CONVERTER
|
JSON_BOOK_CONVERTER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
JSON_CONVERTER
|
|
||||||
|
JSON_CONVERTER
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make
|
make
|
||||||
local
|
local
|
||||||
ucs: STRING_32
|
ucs: STRING_32
|
||||||
a: AUTHOR
|
a: AUTHOR
|
||||||
do
|
do
|
||||||
create ucs.make_from_string ("")
|
create ucs.make_from_string ("")
|
||||||
create a.make (ucs)
|
create a.make (ucs)
|
||||||
create object.make (ucs, a, ucs)
|
create object.make (ucs, a, ucs)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
object: BOOK
|
object: BOOK
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
from_json (j: like to_json): detachable like object
|
from_json (j: like to_json): detachable like object
|
||||||
do
|
do
|
||||||
if
|
if
|
||||||
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
|
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
|
||||||
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
|
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
|
||||||
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
|
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
|
||||||
then
|
then
|
||||||
create Result.make (l_title, l_author, l_isbn)
|
create Result.make (l_title, l_author, l_isbn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_json (o: like object): JSON_OBJECT
|
to_json (o: like object): JSON_OBJECT
|
||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put (json.value (o.title), title_key)
|
Result.put (json.value (o.title), title_key)
|
||||||
Result.put (json.value (o.isbn), isbn_key)
|
Result.put (json.value (o.isbn), isbn_key)
|
||||||
Result.put (json.value (o.author), author_key)
|
Result.put (json.value (o.author), author_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
title_key: JSON_STRING
|
title_key: JSON_STRING
|
||||||
-- Book's title label.
|
-- Book's title label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("title")
|
create Result.make_json ("title")
|
||||||
end
|
end
|
||||||
|
|
||||||
isbn_key: JSON_STRING
|
isbn_key: JSON_STRING
|
||||||
-- Book ISBN label.
|
-- Book ISBN label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("isbn")
|
create Result.make_json ("isbn")
|
||||||
end
|
end
|
||||||
|
|
||||||
author_key: JSON_STRING
|
author_key: JSON_STRING
|
||||||
-- Author label.
|
-- Author label.
|
||||||
once
|
once
|
||||||
create Result.make_json ("author")
|
create Result.make_json ("author")
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class JSON_BOOK_CONVERTER
|
end -- class JSON_BOOK_CONVERTER
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
note
|
note
|
||||||
description: "Linked list and hash table converters test."
|
description: "Linked list and hash table converters test."
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
TEST_DS
|
TEST_DS
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
SHARED_EJSON
|
|
||||||
|
SHARED_EJSON
|
||||||
undefine
|
undefine
|
||||||
default_create
|
default_create
|
||||||
end
|
end
|
||||||
@@ -17,60 +17,56 @@ inherit
|
|||||||
|
|
||||||
feature -- Test
|
feature -- Test
|
||||||
|
|
||||||
test_linked_list_converter
|
test_linked_list_converter
|
||||||
-- Convert a linked list to a json value and
|
-- Convert a linked list to a json value and
|
||||||
-- convert this one to a linked list.
|
-- convert this one to a linked list.
|
||||||
local
|
local
|
||||||
l: LINKED_LIST [STRING]
|
l: LINKED_LIST [STRING]
|
||||||
s: STRING
|
s: STRING
|
||||||
do
|
do
|
||||||
create l.make
|
create l.make
|
||||||
l.force ("foo")
|
l.force ("foo")
|
||||||
l.force ("bar")
|
l.force ("bar")
|
||||||
|
if attached json.value (l) as l_value then
|
||||||
|
s := l_value.representation
|
||||||
|
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
|
||||||
|
else
|
||||||
|
assert ("LINKED_LIST converted to a JSON value", False)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if attached json.value (l) as l_value then
|
test_hash_table_converter
|
||||||
s := l_value.representation
|
|
||||||
assert ("JSON array converted to LINKED_LIST", attached {LINKED_LIST [detachable ANY]} json.object (l_value, "LINKED_LIST"))
|
|
||||||
else
|
|
||||||
assert ("LINKED_LIST converted to a JSON value", False)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test_hash_table_converter
|
|
||||||
-- Convert a hash table to a json value and
|
-- Convert a hash table to a json value and
|
||||||
-- convert this one to a hash table.
|
-- convert this one to a hash table.
|
||||||
local
|
local
|
||||||
t: HASH_TABLE [STRING, STRING]
|
t: HASH_TABLE [STRING, STRING]
|
||||||
s: STRING
|
s: STRING
|
||||||
l_ucs_key: detachable STRING_32
|
l_ucs_key: detachable STRING_32
|
||||||
do
|
do
|
||||||
create t.make (2)
|
create t.make (2)
|
||||||
t.put ("foo", "1")
|
t.put ("foo", "1")
|
||||||
t.put ("bar", "2")
|
t.put ("bar", "2")
|
||||||
|
if attached json.value (t) as l_value then
|
||||||
if attached json.value (t) as l_value then
|
s := l_value.representation
|
||||||
s := l_value.representation
|
if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then
|
||||||
if attached {HASH_TABLE [ANY, HASHABLE]} json.object (l_value, "HASH_TABLE") as t2 then
|
create l_ucs_key.make_from_string ("1")
|
||||||
|
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
||||||
create l_ucs_key.make_from_string ("1")
|
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
|
||||||
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
else
|
||||||
assert ("ucs_value.string.is_equal (%"foo%")", l_ucs_value.string.is_equal ("foo"))
|
assert ("ucs_value /= Void", False)
|
||||||
else
|
end
|
||||||
assert ("ucs_value /= Void", False)
|
create l_ucs_key.make_from_string ("2")
|
||||||
end
|
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
||||||
|
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
|
||||||
create l_ucs_key.make_from_string ("2")
|
else
|
||||||
if attached {STRING_32} t2 [l_ucs_key] as l_ucs_value then
|
assert ("ucs_value /= Void", False)
|
||||||
assert ("ucs_value.string.is_equal (%"bar%")", l_ucs_value.string.is_equal ("bar"))
|
end
|
||||||
else
|
else
|
||||||
assert ("ucs_value /= Void", False)
|
assert ("JSON object converted to HASH_TABLE", False);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
assert ("JSON object converted to HASH_TABLE", False);
|
assert ("HASH_TABLE converted to a JSON value", False)
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
assert ("HASH_TABLE converted to a JSON value", False)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end -- class TEST_DS
|
end -- class TEST_DS
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,14 @@
|
|||||||
|
|
||||||
note
|
note
|
||||||
description: "Parsing and converter of book collection test."
|
description: "Parsing and converter of book collection test."
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
TEST_JSON_CUSTOM_CLASSES
|
TEST_JSON_CUSTOM_CLASSES
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
SHARED_EJSON
|
|
||||||
|
SHARED_EJSON
|
||||||
undefine
|
undefine
|
||||||
default_create
|
default_create
|
||||||
end
|
end
|
||||||
@@ -17,25 +17,24 @@ inherit
|
|||||||
|
|
||||||
feature -- Test
|
feature -- Test
|
||||||
|
|
||||||
test_custom_classes
|
test_custom_classes
|
||||||
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
|
-- Parse JSON representation to JSON_OBJECT and test book collection converter.
|
||||||
local
|
local
|
||||||
jbc: JSON_BOOK_CONVERTER
|
jbc: JSON_BOOK_CONVERTER
|
||||||
jbcc: JSON_BOOK_COLLECTION_CONVERTER
|
jbcc: JSON_BOOK_COLLECTION_CONVERTER
|
||||||
jac: JSON_AUTHOR_CONVERTER
|
jac: JSON_AUTHOR_CONVERTER
|
||||||
parser: JSON_PARSER
|
parser: JSON_PARSER
|
||||||
jrep: STRING
|
jrep: STRING
|
||||||
do
|
do
|
||||||
create jbc.make
|
create jbc.make
|
||||||
json.add_converter (jbc)
|
json.add_converter (jbc)
|
||||||
create jbcc.make
|
create jbcc.make
|
||||||
json.add_converter (jbcc)
|
json.add_converter (jbcc)
|
||||||
create jac.make
|
create jac.make
|
||||||
json.add_converter (jac)
|
json.add_converter (jac)
|
||||||
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
|
jrep := "{%"name%":%"Test collection%",%"books%":[{%"title%":%"eJSON: The Definitive Guide%",%"isbn%":%"123123-413243%",%"author%":{%"name%":%"Foo Bar%"}}]}"
|
||||||
create parser.make_parser (jrep)
|
create parser.make_parser (jrep)
|
||||||
|
if attached {JSON_OBJECT} parser.parse as l_json_object then
|
||||||
if attached {JSON_OBJECT} parser.parse as l_json_object then
|
|
||||||
if attached {BOOK_COLLECTION} json.object (l_json_object, "BOOK_COLLECTION") as l_collection then
|
if attached {BOOK_COLLECTION} json.object (l_json_object, "BOOK_COLLECTION") as l_collection then
|
||||||
if attached {JSON_OBJECT} json.value (l_collection) as l_json_object_2 then
|
if attached {JSON_OBJECT} json.value (l_collection) as l_json_object_2 then
|
||||||
assert ("JSON representation is correct", l_json_object_2.representation.same_string (jrep))
|
assert ("JSON representation is correct", l_json_object_2.representation.same_string (jrep))
|
||||||
@@ -47,7 +46,7 @@ feature -- Test
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
assert ("JSON object representation to JSON_OBJECT", False)
|
assert ("JSON object representation to JSON_OBJECT", False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end -- class TEST_JSON_CUSTOM_CLASS
|
end -- class TEST_JSON_CUSTOM_CLASS
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class
|
|||||||
TEST_JSON_SUITE
|
TEST_JSON_SUITE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
||||||
EQA_TEST_SET
|
EQA_TEST_SET
|
||||||
redefine
|
redefine
|
||||||
on_prepare
|
on_prepare
|
||||||
@@ -27,38 +28,38 @@ feature {NONE} -- Events
|
|||||||
feature -- Tests Pass
|
feature -- Tests Pass
|
||||||
|
|
||||||
test_json_pass1
|
test_json_pass1
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("pass1.json") as json_file then
|
if attached json_file_from ("pass1.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("pass1.json",parse_json.is_parsed = True)
|
assert ("pass1.json", parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_pass2
|
test_json_pass2
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("pass2.json") as json_file then
|
if attached json_file_from ("pass2.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("pass2.json",parse_json.is_parsed = True)
|
assert ("pass2.json", parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_pass3
|
test_json_pass3
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("pass3.json") as json_file then
|
if attached json_file_from ("pass3.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("pass3.json",parse_json.is_parsed = True)
|
assert ("pass3.json", parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,14 +70,10 @@ feature -- Tests Pass
|
|||||||
s: READABLE_STRING_32
|
s: READABLE_STRING_32
|
||||||
do
|
do
|
||||||
s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }"
|
s := {STRING_32} "{ %"nihaoma%": %"你好吗\t?%" }"
|
||||||
|
|
||||||
parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s))
|
parse_json := new_json_parser (utf.string_32_to_utf_8_string_8 (s))
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("utf8.pass1.json", parse_json.is_parsed = True)
|
assert ("utf8.pass1.json", parse_json.is_parsed = True)
|
||||||
if
|
if attached {JSON_OBJECT} json_value as jo and then attached {JSON_STRING} jo.item ("nihaoma") as js then
|
||||||
attached {JSON_OBJECT} json_value as jo and then
|
|
||||||
attached {JSON_STRING} jo.item ("nihaoma") as js
|
|
||||||
then
|
|
||||||
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?"))
|
assert ("utf8.nihaoma", js.unescaped_string_32.same_string ({STRING_32} "你好吗%T?"))
|
||||||
else
|
else
|
||||||
assert ("utf8.nihaoma", False)
|
assert ("utf8.nihaoma", False)
|
||||||
@@ -84,408 +81,400 @@ feature -- Tests Pass
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Tests Failures
|
feature -- Tests Failures
|
||||||
test_json_fail1
|
|
||||||
--
|
test_json_fail1
|
||||||
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail1.json") as json_file then
|
if attached json_file_from ("fail1.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail1.json",parse_json.is_parsed = False)
|
assert ("fail1.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail2
|
test_json_fail2
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail2.json") as json_file then
|
if attached json_file_from ("fail2.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail2.json",parse_json.is_parsed = False)
|
assert ("fail2.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail3
|
test_json_fail3
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail3.json") as json_file then
|
if attached json_file_from ("fail3.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail3.json",parse_json.is_parsed = False)
|
assert ("fail3.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail4
|
test_json_fail4
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail4.json") as json_file then
|
if attached json_file_from ("fail4.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail4.json",parse_json.is_parsed = False)
|
assert ("fail4.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail5
|
test_json_fail5
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail5.json") as json_file then
|
if attached json_file_from ("fail5.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail5.json",parse_json.is_parsed = False)
|
assert ("fail5.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail6
|
test_json_fail6
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail6.json") as json_file then
|
if attached json_file_from ("fail6.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail6.json",parse_json.is_parsed = False )
|
assert ("fail6.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail7
|
test_json_fail7
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail7.json") as json_file then
|
if attached json_file_from ("fail7.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail7.json",parse_json.is_parsed = False)
|
assert ("fail7.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail8
|
test_json_fail8
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail8.json") as json_file then
|
if attached json_file_from ("fail8.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail8.json",parse_json.is_parsed = False )
|
assert ("fail8.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail9
|
test_json_fail9
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail9.json") as json_file then
|
if attached json_file_from ("fail9.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail9.json",parse_json.is_parsed = False)
|
assert ("fail9.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test_json_fail10
|
test_json_fail10
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail10.json") as json_file then
|
if attached json_file_from ("fail10.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail10.json",parse_json.is_parsed = False)
|
assert ("fail10.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail11
|
test_json_fail11
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail11.json") as json_file then
|
if attached json_file_from ("fail11.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail11.json",parse_json.is_parsed = False)
|
assert ("fail11.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail12
|
test_json_fail12
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail12.json") as json_file then
|
if attached json_file_from ("fail12.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail12.json",parse_json.is_parsed = False)
|
assert ("fail12.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail13
|
test_json_fail13
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail13.json") as json_file then
|
if attached json_file_from ("fail13.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail13.json",parse_json.is_parsed = False)
|
assert ("fail13.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail14
|
test_json_fail14
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail14.json") as json_file then
|
if attached json_file_from ("fail14.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail14.json",parse_json.is_parsed = False)
|
assert ("fail14.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail15
|
test_json_fail15
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail15.json") as json_file then
|
if attached json_file_from ("fail15.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail15.json",parse_json.is_parsed = False)
|
assert ("fail15.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail16
|
test_json_fail16
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail16.json") as json_file then
|
if attached json_file_from ("fail16.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail16.json",parse_json.is_parsed = False)
|
assert ("fail16.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail17
|
test_json_fail17
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail17.json") as json_file then
|
if attached json_file_from ("fail17.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail17.json",parse_json.is_parsed = False)
|
assert ("fail17.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail18
|
test_json_fail18
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail18.json") as json_file then
|
if attached json_file_from ("fail18.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail18.json",parse_json.is_parsed = True)
|
assert ("fail18.json", parse_json.is_parsed = True)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail19
|
test_json_fail19
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail19.json") as json_file then
|
if attached json_file_from ("fail19.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail19.json",parse_json.is_parsed = False)
|
assert ("fail19.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail20
|
test_json_fail20
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail20.json") as json_file then
|
if attached json_file_from ("fail20.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail20.json",parse_json.is_parsed = False)
|
assert ("fail20.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail21
|
test_json_fail21
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail21.json") as json_file then
|
if attached json_file_from ("fail21.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail21.json",parse_json.is_parsed = False)
|
assert ("fail21.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail22
|
||||||
test_json_fail22
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail22.json") as json_file then
|
if attached json_file_from ("fail22.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail22.json",parse_json.is_parsed = False)
|
assert ("fail22.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail23
|
test_json_fail23
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail23.json") as json_file then
|
if attached json_file_from ("fail23.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail23.json",parse_json.is_parsed = False)
|
assert ("fail23.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail24
|
test_json_fail24
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail24.json") as json_file then
|
if attached json_file_from ("fail24.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail24.json",parse_json.is_parsed = False)
|
assert ("fail24.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail25
|
test_json_fail25
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail25.json") as json_file then
|
if attached json_file_from ("fail25.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail25.json",parse_json.is_parsed = False)
|
assert ("fail25.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail26
|
||||||
test_json_fail26
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail26.json") as json_file then
|
if attached json_file_from ("fail26.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail26.json",parse_json.is_parsed = False)
|
assert ("fail26.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail27
|
||||||
test_json_fail27
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail27.json") as json_file then
|
if attached json_file_from ("fail27.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail27.json",parse_json.is_parsed = False)
|
assert ("fail27.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail28
|
||||||
test_json_fail28
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail28.json") as json_file then
|
if attached json_file_from ("fail28.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail28.json",parse_json.is_parsed = False)
|
assert ("fail28.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail29
|
||||||
test_json_fail29
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail29.json") as json_file then
|
if attached json_file_from ("fail29.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail29.json",parse_json.is_parsed = False )
|
assert ("fail29.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_json_fail30
|
||||||
test_json_fail30
|
--
|
||||||
--
|
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail30.json") as json_file then
|
if attached json_file_from ("fail30.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail30.json",parse_json.is_parsed = False)
|
assert ("fail30.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail31
|
test_json_fail31
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail31.json") as json_file then
|
if attached json_file_from ("fail31.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail31.json",parse_json.is_parsed = False)
|
assert ("fail31.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail32
|
test_json_fail32
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail32.json") as json_file then
|
if attached json_file_from ("fail32.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail32.json",parse_json.is_parsed = False)
|
assert ("fail32.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test_json_fail33
|
test_json_fail33
|
||||||
--
|
--
|
||||||
local
|
local
|
||||||
parse_json: like new_json_parser
|
parse_json: like new_json_parser
|
||||||
do
|
do
|
||||||
if attached json_file_from ("fail33.json") as json_file then
|
if attached json_file_from ("fail33.json") as json_file then
|
||||||
parse_json := new_json_parser (json_file)
|
parse_json := new_json_parser (json_file)
|
||||||
json_value := parse_json.parse_json
|
json_value := parse_json.parse_json
|
||||||
assert ("fail33.json",parse_json.is_parsed = False)
|
assert ("fail33.json", parse_json.is_parsed = False)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -495,23 +484,22 @@ feature -- JSON_FROM_FILE
|
|||||||
|
|
||||||
json_value: detachable JSON_VALUE
|
json_value: detachable JSON_VALUE
|
||||||
|
|
||||||
json_file_from (fn: STRING): detachable STRING
|
json_file_from (fn: STRING): detachable STRING
|
||||||
local
|
local
|
||||||
f: RAW_FILE
|
f: RAW_FILE
|
||||||
l_path: STRING
|
l_path: STRING
|
||||||
test_dir: STRING
|
test_dir: STRING
|
||||||
i: INTEGER
|
i: INTEGER
|
||||||
do
|
do
|
||||||
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
test_dir := (create {EXECUTION_ENVIRONMENT}).current_working_directory
|
||||||
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
test_dir.append_character ((create {OPERATING_ENVIRONMENT}).directory_separator)
|
||||||
|
|
||||||
l_path := test_dir + fn
|
l_path := test_dir + fn
|
||||||
create f.make_with_name (l_path)
|
create f.make_with_name (l_path)
|
||||||
if f.exists then
|
if f.exists then
|
||||||
-- Found json file
|
-- Found json file
|
||||||
else
|
else
|
||||||
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
|
-- before EiffelStudio 7.3 , the current dir of autotest execution was not the parent dir of ecf but something like
|
||||||
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
|
-- ..json\test\autotest\test_suite\EIFGENs\test_suite\Testing\execution\TEST_JSON_SUITE.test_json_fail1\..\..\..\..\..\fail1.json
|
||||||
from
|
from
|
||||||
i := 5
|
i := 5
|
||||||
until
|
until
|
||||||
@@ -536,9 +524,7 @@ feature -- JSON_FROM_FILE
|
|||||||
create Result.make_parser (a_string)
|
create Result.make_parser (a_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
file_reader /= Void
|
file_reader /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user