Merge branch 'master' of https://github.com/eiffelhub/json
This commit is contained in:
9
contrib/library/text/parser/json/.gitattributes
vendored
Normal file
9
contrib/library/text/parser/json/.gitattributes
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Set default behaviour, in case users don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files we want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.e text
|
||||
*.ecf text
|
||||
*.bat text
|
||||
*.json text
|
||||
@@ -92,6 +92,8 @@ history.txt.
|
||||
|
||||
Version Date Description
|
||||
------- ---- -----------
|
||||
0.5.0 2013-11-dd Added JSON_ITERATOR, simplified JSON_OBJECT
|
||||
0.4.0 2012-12-12 Updated documentation URI
|
||||
0.3.0 2011-07-06 JSON Factory Converters
|
||||
0.2.0 2010-02-07 Adapted to EiffelStudio 6.4 or later, supports void-safety
|
||||
0.1.0 2010-02-07 First release, Adapted to SmartEiffel 1.2r7 and EiffelStudio 6.2 or previous
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Objects that ..."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
note
|
||||
description:
|
||||
|
||||
"JSON Iterator"
|
||||
|
||||
pattern: "Iterator visitor"
|
||||
author: "Jocelyn Fiat"
|
||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||
date: "2013/08/01"
|
||||
revision: "Revision 0.1"
|
||||
|
||||
deferred class
|
||||
JSON_ITERATOR
|
||||
|
||||
inherit
|
||||
JSON_VISITOR
|
||||
|
||||
feature -- Visitor Pattern
|
||||
|
||||
visit_json_array (a_json_array: JSON_ARRAY)
|
||||
-- Visit `a_json_array'.
|
||||
do
|
||||
across
|
||||
a_json_array as c
|
||||
loop
|
||||
c.item.accept (Current)
|
||||
end
|
||||
end
|
||||
|
||||
visit_json_boolean (a_json_boolean: JSON_BOOLEAN)
|
||||
-- Visit `a_json_boolean'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_null (a_json_null: JSON_NULL)
|
||||
-- Visit `a_json_null'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_number (a_json_number: JSON_NUMBER)
|
||||
-- Visit `a_json_number'.
|
||||
do
|
||||
end
|
||||
|
||||
visit_json_object (a_json_object: JSON_OBJECT)
|
||||
-- Visit `a_json_object'.
|
||||
do
|
||||
across
|
||||
a_json_object as c
|
||||
loop
|
||||
c.item.accept (Current)
|
||||
end
|
||||
end
|
||||
|
||||
visit_json_string (a_json_string: JSON_STRING)
|
||||
-- Visit `a_json_string'.
|
||||
do
|
||||
end
|
||||
|
||||
end
|
||||
@@ -18,7 +18,9 @@ class
|
||||
inherit
|
||||
JSON_VALUE
|
||||
|
||||
DEBUG_OUTPUT
|
||||
ITERABLE [JSON_VALUE]
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make_array
|
||||
@@ -69,6 +71,14 @@ feature -- Visitor pattern
|
||||
a_visitor.visit_json_array (Current)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: ITERATION_CURSOR [JSON_VALUE]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
Result := values.new_cursor
|
||||
end
|
||||
|
||||
feature -- Mesurement
|
||||
|
||||
count: INTEGER
|
||||
@@ -87,16 +97,42 @@ feature -- Status report
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
add (value: JSON_VALUE)
|
||||
put_front (v: JSON_VALUE)
|
||||
require
|
||||
value_not_null: value /= void
|
||||
v_not_void: v /= Void
|
||||
do
|
||||
values.extend (value)
|
||||
values.put_front (v)
|
||||
ensure
|
||||
has_new_value: old values.count + 1 = values.count and
|
||||
values.has (value)
|
||||
values.first = v
|
||||
end
|
||||
|
||||
add, extend (v: JSON_VALUE)
|
||||
require
|
||||
v_not_void: v /= Void
|
||||
do
|
||||
values.extend (v)
|
||||
ensure
|
||||
has_new_value: old values.count + 1 = values.count and
|
||||
values.has (v)
|
||||
end
|
||||
|
||||
prune_all (v: JSON_VALUE)
|
||||
-- Remove all occurrences of `v'.
|
||||
require
|
||||
v_not_void: v /= Void
|
||||
do
|
||||
values.prune_all (v)
|
||||
ensure
|
||||
not_has_new_value: not values.has (v)
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Remove all items.
|
||||
do
|
||||
values.wipe_out
|
||||
end
|
||||
|
||||
feature -- Report
|
||||
|
||||
hash_code: INTEGER
|
||||
@@ -118,6 +154,7 @@ feature -- Conversion
|
||||
|
||||
array_representation: ARRAYED_LIST [JSON_VALUE]
|
||||
-- Representation as a sequences of values
|
||||
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object
|
||||
do
|
||||
Result := values
|
||||
end
|
||||
@@ -127,7 +164,7 @@ feature -- Status report
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := count.out
|
||||
Result := count.out + " item(s)"
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
@@ -8,7 +8,7 @@ note
|
||||
|
||||
object
|
||||
{}
|
||||
{"key","value"}
|
||||
{"key": "value"}
|
||||
|
||||
]"
|
||||
author: "Javier Velilla"
|
||||
@@ -22,7 +22,9 @@ class
|
||||
inherit
|
||||
JSON_VALUE
|
||||
|
||||
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
|
||||
TABLE_ITERABLE [JSON_VALUE, JSON_STRING]
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make
|
||||
@@ -52,6 +54,67 @@ feature -- Change Element
|
||||
object.extend (l_value, key)
|
||||
end
|
||||
|
||||
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_STRING
|
||||
do
|
||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
|
||||
put_integer (value: INTEGER_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_integer (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_natural (value: NATURAL_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_natural (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_real (value: DOUBLE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_real (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_BOOLEAN
|
||||
do
|
||||
create l_value.make_boolean (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
replace (value: detachable JSON_VALUE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
@@ -65,6 +128,68 @@ feature -- Change Element
|
||||
object.force (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_STRING
|
||||
do
|
||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_integer (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_natural (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_real (value: DOUBLE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_real (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_BOOLEAN
|
||||
do
|
||||
create l_value.make_boolean (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
remove (key: JSON_STRING)
|
||||
-- Remove item indexed by `key' if any.
|
||||
do
|
||||
object.remove (key)
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Reset all items to default values; reset status.
|
||||
do
|
||||
object.wipe_out
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
has_key (key: JSON_STRING): BOOLEAN
|
||||
@@ -95,7 +220,8 @@ feature -- Access
|
||||
local
|
||||
t: HASH_TABLE [JSON_VALUE, JSON_STRING]
|
||||
do
|
||||
Result := "{"
|
||||
create Result.make (2)
|
||||
Result.append_character ('{')
|
||||
from
|
||||
t := map_representation
|
||||
t.start
|
||||
@@ -103,7 +229,7 @@ feature -- Access
|
||||
t.after
|
||||
loop
|
||||
Result.append (t.key_for_iteration.representation)
|
||||
Result.append (":")
|
||||
Result.append_character (':')
|
||||
Result.append (t.item_for_iteration.representation)
|
||||
t.forth
|
||||
if not t.after then
|
||||
@@ -177,7 +303,7 @@ feature -- Status report
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := object.count.out
|
||||
Result := count.out + " item(s)"
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
@@ -186,6 +312,6 @@ feature {NONE} -- Implementation
|
||||
-- Value container
|
||||
|
||||
invariant
|
||||
object_not_null: object /= Void
|
||||
object_not_void: object /= Void
|
||||
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ feature -- Access
|
||||
Result.append_character ('%R')
|
||||
i := i + 2
|
||||
when 'u' then
|
||||
--| Leave unicode \uXXXX unescaped
|
||||
--| Leave Unicode \uXXXX unescaped
|
||||
Result.append_character ('\')
|
||||
i := i + 1
|
||||
else
|
||||
@@ -274,7 +274,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
escaped_json_string_32 (s: READABLE_STRING_32): STRING_8
|
||||
-- JSON string with '"' and '\' characters and unicode escaped
|
||||
-- JSON string with '"' and '\' characters and Unicode escaped
|
||||
require
|
||||
s_not_void: s /= Void
|
||||
local
|
||||
|
||||
@@ -357,7 +357,7 @@ feature -- Commands
|
||||
end
|
||||
|
||||
read_unicode: STRING
|
||||
-- Read unicode and return value
|
||||
-- Read Unicode and return value
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
@@ -449,7 +449,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
is_valid_unicode (a_unicode: STRING): BOOLEAN
|
||||
-- is 'a_unicode' a valid unicode based on this regular expression
|
||||
-- is 'a_unicode' a valid Unicode based on this regular expression
|
||||
-- "\\u[0-9a-fA-F]{4}"
|
||||
local
|
||||
i: INTEGER
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{"menu": {
|
||||
{ "menu": {
|
||||
"id": "file",
|
||||
"value": "File",
|
||||
"popup": {
|
||||
|
||||
Reference in New Issue
Block a user