Converted ecf file to complete void-safe.
Improved JSON_PRETTY_STRING_VISITOR to support STRING_8 or STRING_32 output. Added examples. Added doc in the folder "doc". Updated Readme and other files. Added package.iron file.
This commit is contained in:
@@ -10,7 +10,8 @@ inherit
|
||||
JSON_VISITOR
|
||||
|
||||
create
|
||||
make, make_custom
|
||||
make,
|
||||
make_custom
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
@@ -32,14 +33,52 @@ feature -- Initialization
|
||||
|
||||
feature -- Access
|
||||
|
||||
output: STRING_32
|
||||
output: STRING_GENERAL
|
||||
-- JSON representation
|
||||
|
||||
indentation: like output
|
||||
feature -- Settings
|
||||
|
||||
indentation_step: like indentation
|
||||
indentation_step: STRING
|
||||
-- Text used for indentation.
|
||||
--| by default a tabulation "%T"
|
||||
|
||||
line_number: INTEGER
|
||||
object_count_inlining: INTEGER
|
||||
-- Inline where object item count is under `object_count_inlining'.
|
||||
--| ex 3:
|
||||
--| { "a", "b", "c" }
|
||||
--| ex 2:
|
||||
--| {
|
||||
--| "a",
|
||||
--| "b",
|
||||
--| "c"
|
||||
--| }
|
||||
|
||||
array_count_inlining: INTEGER
|
||||
-- Inline where array item count is under `object_count_inlining'.
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_indentation_step (a_step: STRING)
|
||||
-- Set `indentation_step' to `a_step'.
|
||||
do
|
||||
indentation_step := a_step
|
||||
end
|
||||
|
||||
set_object_count_inlining (a_nb: INTEGER)
|
||||
-- Set `object_count_inlining' to `a_nb'.
|
||||
do
|
||||
object_count_inlining := a_nb
|
||||
end
|
||||
|
||||
set_array_count_inlining (a_nb: INTEGER)
|
||||
-- Set `array_count_inlining' to `a_nb'.
|
||||
do
|
||||
array_count_inlining := a_nb
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
indentation: STRING
|
||||
|
||||
indent
|
||||
do
|
||||
@@ -58,9 +97,7 @@ feature -- Access
|
||||
line_number := line_number + 1
|
||||
end
|
||||
|
||||
object_count_inlining: INTEGER
|
||||
|
||||
array_count_inlining: INTEGER
|
||||
line_number: INTEGER
|
||||
|
||||
feature -- Visitor Pattern
|
||||
|
||||
@@ -71,10 +108,14 @@ feature -- Visitor Pattern
|
||||
l_json_array: ARRAYED_LIST [JSON_VALUE]
|
||||
l_line: like line_number
|
||||
l_multiple_lines: BOOLEAN
|
||||
l_output: like output
|
||||
do
|
||||
l_output := output
|
||||
l_json_array := a_json_array.array_representation
|
||||
l_multiple_lines := l_json_array.count >= array_count_inlining or across l_json_array as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
|
||||
output.append ("[")
|
||||
l_multiple_lines := l_json_array.count >= array_count_inlining
|
||||
or across l_json_array as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
|
||||
l_output.append_code (91) -- '[' : 91
|
||||
|
||||
l_line := line_number
|
||||
indent
|
||||
from
|
||||
@@ -89,14 +130,14 @@ feature -- Visitor Pattern
|
||||
value.accept (Current)
|
||||
l_json_array.forth
|
||||
if not l_json_array.after then
|
||||
output.append (", ")
|
||||
l_output.append (", ")
|
||||
end
|
||||
end
|
||||
exdent
|
||||
if line_number > l_line or l_json_array.count >= array_count_inlining then
|
||||
new_line
|
||||
end
|
||||
output.append ("]")
|
||||
l_output.append_code (93) -- ']' : 93
|
||||
end
|
||||
|
||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
|
||||
@@ -123,10 +164,12 @@ feature -- Visitor Pattern
|
||||
l_pairs: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
l_line: like line_number
|
||||
l_multiple_lines: BOOLEAN
|
||||
l_output: like output
|
||||
do
|
||||
l_output := output
|
||||
l_pairs := a_json_object.map_representation
|
||||
l_multiple_lines := l_pairs.count >= object_count_inlining or across l_pairs as p some attached {JSON_OBJECT} p.item or attached {JSON_ARRAY} p.item end
|
||||
output.append ("{")
|
||||
l_output.append_code (123) -- '{' : 123
|
||||
l_line := line_number
|
||||
indent
|
||||
from
|
||||
@@ -138,26 +181,29 @@ feature -- Visitor Pattern
|
||||
new_line
|
||||
end
|
||||
l_pairs.key_for_iteration.accept (Current)
|
||||
output.append (": ")
|
||||
l_output.append (": ")
|
||||
l_pairs.item_for_iteration.accept (Current)
|
||||
l_pairs.forth
|
||||
if not l_pairs.after then
|
||||
output.append (", ")
|
||||
l_output.append (", ")
|
||||
end
|
||||
end
|
||||
exdent
|
||||
if line_number > l_line or l_pairs.count >= object_count_inlining then
|
||||
new_line
|
||||
end
|
||||
output.append ("}")
|
||||
l_output.append_code (125) -- '}' : 125
|
||||
end
|
||||
|
||||
visit_json_string (a_json_string: JSON_STRING)
|
||||
-- Visit `a_json_string'.
|
||||
local
|
||||
l_output: like output
|
||||
do
|
||||
output.append ("%"")
|
||||
output.append (a_json_string.item)
|
||||
output.append ("%"")
|
||||
l_output := output
|
||||
l_output.append_code (34) -- '%"' : 34
|
||||
l_output.append (a_json_string.item)
|
||||
l_output.append_code (34) -- '%"' : 34
|
||||
end
|
||||
|
||||
note
|
||||
|
||||
Reference in New Issue
Block a user