Updated skip_white_spaces, now check %U and %T codes

This commit is contained in:
jvelilla
2010-03-16 00:08:37 +00:00
parent 5d63c63a39
commit e638eeaae4

View File

@@ -1,118 +1,118 @@
indexing indexing
description: "Objects that ..." description: "Objects that ..."
author: "jvelilla" author: "jvelilla"
date: "2008/08/24" date: "2008/08/24"
revision: "0.1" revision: "0.1"
class class
JSON_READER JSON_READER
create create
make make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_json: STRING) is make (a_json: STRING) is
-- 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) is set_representation (a_json: STRING) is
-- 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 is read: CHARACTER is
-- Read character -- Read character
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
next is next is
-- Move to next index -- Move to next index
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
-- Move to previous index -- Move to previous index
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_white_spaces is skip_white_spaces is
-- Remove white spaces -- Remove white spaces
local local
c: like actual c: like actual
do do
from from
c := actual c := actual
until until
(c /= ' ' and c /= '%N' and c /= '%R') 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
end end
end end
json_substring (start_index, end_index: INTEGER_32): STRING is json_substring (start_index, end_index: INTEGER_32): STRING is
-- JSON representation between `start_index' and `end_index' -- JSON representation between `start_index' and `end_index'
do do
Result := representation.substring (start_index, end_index) Result := representation.substring (start_index, end_index)
end end
feature -- Status report feature -- Status report
has_next: BOOLEAN is has_next: BOOLEAN is
-- Has a next character? -- Has a next character?
do do
Result := index <= representation.count Result := index <= representation.count
end end
has_previous: BOOLEAN is has_previous: BOOLEAN is
-- Has a previous character? -- Has a previous character?
do do
Result := index >= 1 Result := index >= 1
end end
feature -- Access feature -- Access
representation: STRING representation: STRING
-- Serialized representation of the original JSON string -- Serialized representation of the original JSON string
feature {NONE} -- Implementation feature {NONE} -- Implementation
actual: CHARACTER is actual: CHARACTER is
-- Current character or '%U' if none -- Current character or '%U' if none
do do
if index > representation.count then if index > representation.count then
Result := '%U' Result := '%U'
else else
Result := representation.item (index) Result := representation.item (index)
end end
end end
index: INTEGER index: INTEGER
-- Actual index -- Actual index
invariant invariant
representation_not_void: representation /= Void representation_not_void: representation /= Void
end end