From fa35ab07a07355ef27a9f570e0a0278e08c349a0 Mon Sep 17 00:00:00 2001 From: berend Date: Tue, 5 Aug 2008 03:26:08 +0000 Subject: [PATCH] Fixed bug where a JSON string had to end with CRLF. But that's optional. Reformatted code to Gobo standard. --- json/scanner/json_reader.e | 135 +++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 58 deletions(-) diff --git a/json/scanner/json_reader.e b/json/scanner/json_reader.e index 291c4cfb..6d50c934 100644 --- a/json/scanner/json_reader.e +++ b/json/scanner/json_reader.e @@ -1,97 +1,116 @@ indexing + description: "Objects that ..." author: "" date: "$Date$" revision: "$Revision$" class + JSON_READER create + make -feature -- Access - make(a_json:STRING) is + +feature -- Initialization + + make (a_json: STRING) is -- - do - representation:=a_json - index:=1 - end + do + representation := a_json + index := 1 + end - read:CHARACTER is + +feature -- Commands + + read: CHARACTER is -- - do - if not representation.is_empty then - Result:= representation.item (index) - end - + do + if not representation.is_empty then + Result := representation.item (index) end + end - - actual:CHARACTER is + has_next: BOOLEAN is -- - do - Result:=representation.item (index) + do + if index <= representation.count then + Result := True end + end - has_next:BOOLEAN is + has_previous: BOOLEAN is -- - do - if index <= representation.count then - Result:=True - end + do + if index >=1 then + Result := True end + end - has_previous:BOOLEAN is - -- - do - if index >=1 then - Result:=True - end - end next is -- - require - has_more_elements: has_next - do - index:=index + 1 - ensure - incremented: old index + 1 = index - end + require + has_more_elements: has_next + do + index := index + 1 + ensure + incremented: old index + 1 = index + end previous is -- - require - not_is_first: has_previous - do - index:=index - 1 - ensure - incremented: old index - 1 = index - end + require + not_is_first: has_previous + do + index := index - 1 + ensure + incremented: old index - 1 = index + end skip_withe_spaces is -- Remove withe spaces - do - from - until not actual.is_space or not has_next - loop - next - end + do + from + until not actual.is_space or not has_next + loop + next end + end - json_substring (start_index, end_index: INTEGER_32):STRING is - -- - do - Result:=representation.substring (start_index, end_index) - end + json_substring (start_index, end_index: INTEGER_32): STRING is + -- + do + Result := representation.substring (start_index, end_index) + end +feature -- Access + + representation: STRING + -- Serialized representation of the original JSON string -feature -- Implementation - representation:STRING - --linear representation of the original json string - index:INTEGER - --actual index +feature {NONE} -- Implementation + + actual: CHARACTER is + -- Current character or '%U' if none + 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