Fixed bug where a JSON string had to end with CRLF. But that's optional.
Reformatted code to Gobo standard.
This commit is contained in:
@@ -1,97 +1,116 @@
|
|||||||
indexing
|
indexing
|
||||||
|
|
||||||
description: "Objects that ..."
|
description: "Objects that ..."
|
||||||
author: ""
|
author: ""
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
JSON_READER
|
JSON_READER
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make
|
make
|
||||||
feature -- Access
|
|
||||||
make(a_json:STRING) is
|
feature -- Initialization
|
||||||
|
|
||||||
|
make (a_json: STRING) is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
representation:=a_json
|
representation := a_json
|
||||||
index:=1
|
index := 1
|
||||||
end
|
end
|
||||||
|
|
||||||
read:CHARACTER is
|
|
||||||
|
feature -- Commands
|
||||||
|
|
||||||
|
read: CHARACTER is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
if not representation.is_empty then
|
if not representation.is_empty then
|
||||||
Result:= representation.item (index)
|
Result := representation.item (index)
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
has_next: BOOLEAN is
|
||||||
actual:CHARACTER is
|
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
Result:=representation.item (index)
|
if index <= representation.count then
|
||||||
|
Result := True
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
has_next:BOOLEAN is
|
has_previous: BOOLEAN is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
if index <= representation.count then
|
if index >=1 then
|
||||||
Result:=True
|
Result := True
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
has_previous:BOOLEAN is
|
|
||||||
--
|
|
||||||
do
|
|
||||||
if index >=1 then
|
|
||||||
Result:=True
|
|
||||||
end
|
|
||||||
end
|
|
||||||
next is
|
next is
|
||||||
--
|
--
|
||||||
require
|
require
|
||||||
has_more_elements: has_next
|
has_more_elements: has_next
|
||||||
do
|
do
|
||||||
index:=index + 1
|
index := index + 1
|
||||||
ensure
|
ensure
|
||||||
incremented: old index + 1 = index
|
incremented: old index + 1 = index
|
||||||
end
|
end
|
||||||
|
|
||||||
previous is
|
previous is
|
||||||
--
|
--
|
||||||
require
|
require
|
||||||
not_is_first: has_previous
|
not_is_first: has_previous
|
||||||
do
|
do
|
||||||
index:=index - 1
|
index := index - 1
|
||||||
ensure
|
ensure
|
||||||
incremented: old index - 1 = index
|
incremented: old index - 1 = index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
skip_withe_spaces is
|
skip_withe_spaces is
|
||||||
-- Remove withe spaces
|
-- Remove withe spaces
|
||||||
do
|
do
|
||||||
from
|
from
|
||||||
until not actual.is_space or not has_next
|
until not actual.is_space or not has_next
|
||||||
loop
|
loop
|
||||||
next
|
next
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
json_substring (start_index, end_index: INTEGER_32):STRING is
|
json_substring (start_index, end_index: INTEGER_32): STRING is
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
Result:=representation.substring (start_index, end_index)
|
Result := representation.substring (start_index, end_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
representation: STRING
|
||||||
|
-- Serialized representation of the original JSON string
|
||||||
|
|
||||||
|
|
||||||
feature -- Implementation
|
feature {NONE} -- Implementation
|
||||||
representation:STRING
|
|
||||||
--linear representation of the original json string
|
actual: CHARACTER is
|
||||||
index:INTEGER
|
-- Current character or '%U' if none
|
||||||
--actual index
|
do
|
||||||
|
if index > representation.count then
|
||||||
|
Result := '%U'
|
||||||
|
else
|
||||||
|
Result := representation.item (index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
index: INTEGER
|
||||||
|
-- Actual index
|
||||||
|
|
||||||
|
|
||||||
|
invariant
|
||||||
|
|
||||||
|
representation_not_void: representation /= Void
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user