Ported r75 (all JSON value classes) from POC_CONVERTERS_FACTORY branch to trunk

This commit is contained in:
paul.cohen
2010-03-08 22:45:41 +00:00
parent 2710cae1da
commit a0e570226c
7 changed files with 500 additions and 405 deletions

View File

@@ -41,6 +41,25 @@ feature -- Access
Result := values.i_th (i) Result := values.i_th (i)
end 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 feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is

View File

@@ -32,6 +32,15 @@ feature -- Access
Result := item.hash_code Result := item.hash_code
end end
representation: STRING is
do
if item then
Result := "true"
else
Result := "false"
end
end
feature -- Visitor pattern feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is

View File

@@ -18,6 +18,11 @@ feature --Access
Result := null_value.hash_code Result := null_value.hash_code
end end
representation: STRING is
do
Result := "null"
end
feature -- Visitor pattern feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is

View File

@@ -17,19 +17,27 @@ inherit
create create
make_integer, make_integer,
make_natural,
make_real make_real
feature {NONE} -- initialization feature {NONE} -- initialization
make_integer (an_argument: INTEGER) is make_integer (an_argument: INTEGER_64) is
-- Initialize an instance of JSON_NUMBER as INTEGER -- Initialize an instance of JSON_NUMBER from the integer value of `an_argument'.
do do
item := an_argument.out item := an_argument.out
numeric_type := INTEGER_TYPE numeric_type := INTEGER_TYPE
end 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 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 do
item := an_argument.out item := an_argument.out
numeric_type := DOUBLE_TYPE numeric_type := DOUBLE_TYPE
@@ -46,6 +54,11 @@ feature -- Access
Result := item.hash_code Result := item.hash_code
end end
representation: STRING is
do
Result := item
end
feature -- Visitor pattern feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is
@@ -76,6 +89,7 @@ feature -- Implementation
INTEGER_TYPE: INTEGER is 1 INTEGER_TYPE: INTEGER is 1
DOUBLE_TYPE: INTEGER is 2 DOUBLE_TYPE: INTEGER is 2
NATURAL_TYPE: INTEGER is 3
numeric_type: INTEGER numeric_type: INTEGER

View File

@@ -76,6 +76,28 @@ feature -- Access
Result := object.current_keys Result := object.current_keys
end 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 feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is

View File

@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
require require
item_not_void: an_item /= Void item_not_void: an_item /= Void
do do
item := an_item item := escaped_json_string (an_item)
end end
feature -- Access feature -- Access
@@ -39,6 +39,13 @@ feature -- Access
item: STRING item: STRING
-- Contents -- Contents
representation: STRING is
do
Result := "%""
Result.append (item)
Result.append_character ('%"')
end
feature -- Visitor pattern feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is
@@ -83,6 +90,18 @@ feature -- Status report
Result := item Result := item
end 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 invariant
value_not_void: item /= Void value_not_void: item /= Void

View File

@@ -23,6 +23,13 @@ inherit
DEBUG_OUTPUT DEBUG_OUTPUT
feature -- Access
representation: STRING is
-- UTF-8 encoded Unicode string representation of Current
deferred
end
feature -- Visitor pattern feature -- Visitor pattern
accept (a_visitor: JSON_VISITOR) is accept (a_visitor: JSON_VISITOR) is