Ported r75 (all JSON value classes) from POC_CONVERTERS_FACTORY branch to trunk
This commit is contained in:
@@ -41,6 +41,25 @@ feature -- Access
|
||||
Result := values.i_th (i)
|
||||
end
|
||||
|
||||
representation: STRING is
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
Result := "["
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i > count
|
||||
loop
|
||||
Result.append (i_th (i).representation)
|
||||
i := i + 1
|
||||
if i <= count then
|
||||
Result.append_character (',')
|
||||
end
|
||||
end
|
||||
Result.append_character (']')
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
|
||||
@@ -32,6 +32,15 @@ feature -- Access
|
||||
Result := item.hash_code
|
||||
end
|
||||
|
||||
representation: STRING is
|
||||
do
|
||||
if item then
|
||||
Result := "true"
|
||||
else
|
||||
Result := "false"
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
|
||||
@@ -18,6 +18,11 @@ feature --Access
|
||||
Result := null_value.hash_code
|
||||
end
|
||||
|
||||
representation: STRING is
|
||||
do
|
||||
Result := "null"
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
|
||||
@@ -17,19 +17,27 @@ inherit
|
||||
|
||||
create
|
||||
make_integer,
|
||||
make_natural,
|
||||
make_real
|
||||
|
||||
feature {NONE} -- initialization
|
||||
|
||||
make_integer (an_argument: INTEGER) is
|
||||
-- Initialize an instance of JSON_NUMBER as INTEGER
|
||||
make_integer (an_argument: INTEGER_64) is
|
||||
-- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
|
||||
do
|
||||
item := an_argument.out
|
||||
numeric_type := INTEGER_TYPE
|
||||
end
|
||||
|
||||
make_natural (an_argument: NATURAL_64) is
|
||||
-- Initialize an instance of JSON_NUMBER from the unsigned integer value of `an_argument'.
|
||||
do
|
||||
item := an_argument.out
|
||||
numeric_type := NATURAL_TYPE
|
||||
end
|
||||
|
||||
make_real (an_argument: DOUBLE) is
|
||||
-- Initialize an instance of JSON_NUMBER as DOUBLE
|
||||
-- Initialize an instance of JSON_NUMBER from the floating point value of `an_argument'.
|
||||
do
|
||||
item := an_argument.out
|
||||
numeric_type := DOUBLE_TYPE
|
||||
@@ -46,6 +54,11 @@ feature -- Access
|
||||
Result := item.hash_code
|
||||
end
|
||||
|
||||
representation: STRING is
|
||||
do
|
||||
Result := item
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
@@ -76,6 +89,7 @@ feature -- Implementation
|
||||
|
||||
INTEGER_TYPE: INTEGER is 1
|
||||
DOUBLE_TYPE: INTEGER is 2
|
||||
NATURAL_TYPE: INTEGER is 3
|
||||
|
||||
numeric_type: INTEGER
|
||||
|
||||
|
||||
@@ -76,6 +76,28 @@ feature -- Access
|
||||
Result := object.current_keys
|
||||
end
|
||||
|
||||
representation: STRING is
|
||||
local
|
||||
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
do
|
||||
Result := "{"
|
||||
from
|
||||
t := map_representation
|
||||
t.start
|
||||
until
|
||||
t.after
|
||||
loop
|
||||
Result.append (t.key_for_iteration.representation)
|
||||
Result.append (":")
|
||||
Result.append (t.item_for_iteration.representation)
|
||||
t.forth
|
||||
if not t.after then
|
||||
Result.append_character (',')
|
||||
end
|
||||
end
|
||||
Result.append_character ('}')
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
|
||||
@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
|
||||
require
|
||||
item_not_void: an_item /= Void
|
||||
do
|
||||
item := an_item
|
||||
item := escaped_json_string (an_item)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -39,6 +39,13 @@ feature -- Access
|
||||
item: STRING
|
||||
-- Contents
|
||||
|
||||
representation: STRING is
|
||||
do
|
||||
Result := "%""
|
||||
Result.append (item)
|
||||
Result.append_character ('%"')
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
@@ -83,6 +90,18 @@ feature -- Status report
|
||||
Result := item
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
escaped_json_string (s: STRING): STRING is
|
||||
-- JSON string with '"' and '\' characters escaped
|
||||
require
|
||||
s_not_void: s /= Void
|
||||
do
|
||||
Result := s.twin
|
||||
Result.replace_substring_all ("\", "\\")
|
||||
Result.replace_substring_all ("%"", "\%"")
|
||||
end
|
||||
|
||||
invariant
|
||||
value_not_void: item /= Void
|
||||
|
||||
|
||||
@@ -23,6 +23,13 @@ inherit
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
feature -- Access
|
||||
|
||||
representation: STRING is
|
||||
-- UTF-8 encoded Unicode string representation of Current
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Visitor pattern
|
||||
|
||||
accept (a_visitor: JSON_VISITOR) is
|
||||
|
||||
Reference in New Issue
Block a user