Reformatted code to Gobo standard.
This commit is contained in:
@@ -52,8 +52,6 @@ feature -- Change Element
|
||||
add(value:JSON_VALUE) is
|
||||
require
|
||||
not_null:value /= void
|
||||
local
|
||||
l_json_value:JSON_VALUE
|
||||
do
|
||||
values.extend(value)
|
||||
ensure
|
||||
|
||||
@@ -5,36 +5,40 @@ indexing
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
|
||||
JSON_BOOLEAN
|
||||
|
||||
inherit
|
||||
JSON_VALUE
|
||||
|
||||
create
|
||||
|
||||
make_boolean
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make_boolean(a_value:BOOLEAN) is
|
||||
make_boolean (an_item: BOOLEAN) is
|
||||
--
|
||||
do
|
||||
value:=a_value
|
||||
item := an_item
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
item: BOOLEAN
|
||||
|
||||
to_json: STRING is
|
||||
--
|
||||
do
|
||||
Result:=value.out
|
||||
Result := item.out
|
||||
end
|
||||
|
||||
hash_code: INTEGER is
|
||||
--
|
||||
do
|
||||
Result:=value.hash_code
|
||||
Result := item.hash_code
|
||||
end
|
||||
|
||||
|
||||
value:BOOLEAN
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
indexing
|
||||
|
||||
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
||||
author: "Javier Velilla"
|
||||
date: "$Date$"
|
||||
@@ -7,36 +8,38 @@ indexing
|
||||
|
||||
class
|
||||
JSON_NUMBER
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
rename is_equal as is_equal_json_value
|
||||
rename
|
||||
is_equal as is_equal_json_value
|
||||
end
|
||||
create
|
||||
|
||||
make_integer,
|
||||
make_real
|
||||
|
||||
feature -- initialization
|
||||
|
||||
make_integer (argument: INTEGER) is
|
||||
do
|
||||
value:= argument.out
|
||||
item:= argument.out
|
||||
internal_hash_code:=argument.hash_code
|
||||
numeric_type:= "INTEGER"
|
||||
end
|
||||
|
||||
make_real (argument: REAL) is
|
||||
do
|
||||
value:= argument.out
|
||||
item:= argument.out
|
||||
internal_hash_code:=argument.hash_code
|
||||
numeric_type:= "REAL"
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
to_json:STRING is
|
||||
--
|
||||
do
|
||||
Result:=value
|
||||
end
|
||||
|
||||
item: STRING
|
||||
|
||||
hash_code: INTEGER is
|
||||
--
|
||||
@@ -45,16 +48,33 @@ feature -- Access
|
||||
end
|
||||
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_equal (other: like Current): BOOLEAN is
|
||||
-- Is `other' attached to an object of the same type
|
||||
-- as current object and identical to it?
|
||||
do
|
||||
Result:=value.is_equal(other.to_json)
|
||||
Result:=item.is_equal (other.to_json)
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
to_json: STRING is
|
||||
--
|
||||
do
|
||||
Result := item
|
||||
end
|
||||
|
||||
|
||||
feature -- Implementation
|
||||
value:STRING
|
||||
|
||||
internal_hash_code: INTEGER
|
||||
|
||||
numeric_type: STRING -- REAL or INTEGER
|
||||
|
||||
|
||||
invariant
|
||||
|
||||
item_not_void: item /= Void
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
indexing
|
||||
|
||||
description: "[
|
||||
An JSON_OBJECT represent an object in JSON.
|
||||
An object is an unordered set of name/value pairs
|
||||
@@ -18,15 +19,19 @@ indexing
|
||||
|
||||
|
||||
class
|
||||
|
||||
JSON_OBJECT
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
|
||||
create
|
||||
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make is
|
||||
--
|
||||
do
|
||||
@@ -55,6 +60,7 @@ feature -- Change Element
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
has_key (key: JSON_STRING):BOOLEAN is
|
||||
-- has the JSON_OBJECT contains a specific key 'key'.
|
||||
do
|
||||
@@ -81,6 +87,7 @@ feature -- Access
|
||||
|
||||
|
||||
feature -- Report
|
||||
|
||||
to_json: STRING is
|
||||
-- Printable json representation
|
||||
-- {} or {member}
|
||||
@@ -104,8 +111,6 @@ feature -- Report
|
||||
Result.append ("}")
|
||||
end
|
||||
|
||||
|
||||
|
||||
hash_code: INTEGER is
|
||||
-- Hash code value
|
||||
local
|
||||
@@ -125,5 +130,7 @@ feature -- Report
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
object: HASH_TABLE[JSON_VALUE,JSON_STRING]
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
indexing
|
||||
|
||||
description:"[
|
||||
A JSON_STRING represent a string in JSON.
|
||||
A string is a collection of zero or more Unicodes characters, wrapped in double
|
||||
@@ -10,28 +11,41 @@ indexing
|
||||
revision: "$Revision$"
|
||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
|
||||
|
||||
class
|
||||
|
||||
JSON_STRING
|
||||
|
||||
inherit
|
||||
|
||||
JSON_VALUE
|
||||
redefine
|
||||
is_equal
|
||||
end
|
||||
|
||||
create
|
||||
|
||||
make_json
|
||||
|
||||
feature -- Initialization
|
||||
make_json(value:STRING) is
|
||||
--
|
||||
|
||||
make_json (an_item: STRING) is
|
||||
-- Initialize.
|
||||
require
|
||||
item_not_void: an_item /= Void
|
||||
do
|
||||
create buffer.make(256)
|
||||
buffer.append (value)
|
||||
item := an_item
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
item: STRING
|
||||
-- Contents
|
||||
|
||||
|
||||
feature -- Comparison
|
||||
|
||||
is_equal (other: like Current): BOOLEAN is
|
||||
-- Is JSON_STRING made of same character sequence as `other'
|
||||
-- (possibly with a different capacity)?
|
||||
@@ -40,29 +54,33 @@ feature -- Comparison
|
||||
end
|
||||
|
||||
feature -- Change Element
|
||||
append(value:STRING)is
|
||||
|
||||
append (an_item: STRING)is
|
||||
--
|
||||
do
|
||||
buffer.append (value)
|
||||
item.append_string (an_item)
|
||||
end
|
||||
|
||||
|
||||
feature -- Status report
|
||||
|
||||
to_json: STRING is
|
||||
--
|
||||
do
|
||||
create Result.make_empty
|
||||
Result.append ("%"")
|
||||
Result.append (buffer)
|
||||
Result.append (item)
|
||||
Result.append ("%"")
|
||||
end
|
||||
|
||||
hash_code: INTEGER is
|
||||
--
|
||||
do
|
||||
Result:= buffer.hash_code + buffer.count
|
||||
Result := item.hash_code
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
buffer:STRING
|
||||
invariant
|
||||
|
||||
value_not_void: item /= Void
|
||||
|
||||
end
|
||||
|
||||
@@ -1,29 +1,42 @@
|
||||
indexing
|
||||
description: "Objects that ..."
|
||||
|
||||
description: "Parse serialized JSON data"
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
|
||||
JSON_PARSER
|
||||
inherit
|
||||
JSON_READER
|
||||
JSON_TOKENS
|
||||
|
||||
create
|
||||
|
||||
make_parser
|
||||
|
||||
feature {NONE} -- Initialize
|
||||
|
||||
make_parser (a_json: STRING) is
|
||||
-- Initialize.
|
||||
require
|
||||
json_not_empty: a_json /= Void and then not a_json.is_empty
|
||||
do
|
||||
make (a_json)
|
||||
is_parsed := True
|
||||
create current_errors.make_empty
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
is_parsed: BOOLEAN
|
||||
|
||||
current_errors: STRING
|
||||
|
||||
make_parser(a_json:STRING) is
|
||||
--
|
||||
do
|
||||
make(a_json)
|
||||
is_parsed:=true
|
||||
create current_errors.make_empty
|
||||
end
|
||||
|
||||
feature -- Commands
|
||||
|
||||
parse_json: JSON_VALUE is
|
||||
--
|
||||
@@ -53,13 +66,13 @@ feature -- Access
|
||||
elseif is_null then
|
||||
--
|
||||
Result := create {JSON_NULL}
|
||||
next;next;next;
|
||||
next;next;next
|
||||
elseif is_true then
|
||||
Result := create {JSON_BOOLEAN}.make_boolean (true)
|
||||
next;next;next;
|
||||
next;next;next
|
||||
elseif is_false then
|
||||
Result := create {JSON_BOOLEAN}.make_boolean (false)
|
||||
next;next;next;next;
|
||||
next;next;next;next
|
||||
else
|
||||
is_parsed := false
|
||||
current_errors.append ("JSON is not well formed in parse")
|
||||
@@ -249,7 +262,7 @@ feature -- Access
|
||||
if is_a_valid_number (sb) then
|
||||
if sb.is_integer then
|
||||
create Result.make_integer (sb.to_integer)
|
||||
is_integer:=true;
|
||||
is_integer := true
|
||||
elseif sb.is_double and not is_integer then
|
||||
create Result.make_real (sb.to_double)
|
||||
end
|
||||
@@ -259,8 +272,6 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
is_null: BOOLEAN is
|
||||
--
|
||||
local
|
||||
@@ -317,17 +328,16 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE}
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
is_a_valid_number (a_number: STRING): BOOLEAN is
|
||||
-- is 'a_number' a valid number based on this regular expression
|
||||
-- "-?(?: 0|[1-9]\d+)(?: \.\d+)?(?: [eE][+-]?\d+)?\b"?
|
||||
local
|
||||
case_mapping: RX_CASE_MAPPING
|
||||
word_set: RX_CHARACTER_SET
|
||||
regexp: RX_PCRE_REGULAR_EXPRESSION
|
||||
number_regex: STRING
|
||||
l_number:STRING
|
||||
do
|
||||
create regexp.make
|
||||
create word_set.make_empty
|
||||
@@ -347,8 +357,6 @@ feature {NONE}
|
||||
-- is 'a_unicode' a valid unicode based on this regular expression
|
||||
-- "\\u[0-9a-fA-F]{4}"
|
||||
local
|
||||
case_mapping: RX_CASE_MAPPING
|
||||
word_set: RX_CHARACTER_SET
|
||||
regexp: RX_PCRE_REGULAR_EXPRESSION
|
||||
unicode_regex: STRING
|
||||
do
|
||||
@@ -363,19 +371,16 @@ feature {NONE}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
extra_elements: BOOLEAN is
|
||||
--has more elements?
|
||||
local
|
||||
l_string:STRING
|
||||
do
|
||||
|
||||
if has_next then
|
||||
next
|
||||
end
|
||||
from
|
||||
until not actual.is_space or not actual.is_equal ('%R') or
|
||||
until
|
||||
not actual.is_space or not actual.is_equal ('%R') or
|
||||
not actual.is_equal ('%U') or not actual.is_equal ('%T')
|
||||
or not actual.is_equal ('%N') or not has_next
|
||||
loop
|
||||
|
||||
Reference in New Issue
Block a user