From 95fd5f93fcb1bba3c93a8d01e973848877abbede Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Tue, 24 Sep 2013 21:50:36 +0200 Subject: [PATCH 1/6] Simplify the json object by adding type specific put and replace --- library/kernel/json_object.e | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index 7085a258..01cd4e65 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -52,6 +52,57 @@ feature -- Change Element object.extend (l_value, key) end + put_string (value: detachable JSON_STRING; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + require + key_not_present: not has_key (key) + do + put (value, key) + end + + put_integer (value: detachable 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: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_integer (v) + end + put (l_value, key) + end + + put_natural (value: detachable 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: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_natural (v) + end + put (l_value, key) + end + + put_real (value: detachable 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: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_real (v) + end + 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 +116,49 @@ feature -- Change Element object.force (l_value, key) end + replace_string (value: detachable JSON_STRING; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + do + replace (value, key) + end + + replace_integer (value: detachable INTEGER_64; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_integer (v) + end + replace (l_value, key) + end + + replace_natural (value: detachable NATURAL_64; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_natural (v) + end + replace (l_value, key) + end + + replace_real (value: detachable DOUBLE; key: JSON_STRING) + -- Assuming there is no item of key `key', + -- insert `value' with `key'. + local + l_value: detachable JSON_NUMBER + do + if attached value as v then + create l_value.make_real (v) + end + replace (l_value, key) + end + remove (key: JSON_STRING) -- Remove item indexed by `key' if any. do From 4d0dc964daefa37e3ad9517a2c97dd565b47a59d Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 25 Sep 2013 10:03:38 +0200 Subject: [PATCH 2/6] Rename procedures. Change input type of replace_with_string and put_string --- library/kernel/json_object.e | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index 01cd4e65..d0d094d5 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -52,15 +52,21 @@ feature -- Change Element object.extend (l_value, key) end - put_string (value: detachable JSON_STRING; key: JSON_STRING) + put_string (value: detachable 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: detachable JSON_STRING do - put (value, key) + if attached value as v then + create l_value.make_json_from_string_32 (v.as_string_32) + end + put (l_value, key) end + put_integer (value: detachable INTEGER_64; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. @@ -116,14 +122,19 @@ feature -- Change Element object.force (l_value, key) end - replace_string (value: detachable JSON_STRING; key: JSON_STRING) + replace_with_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. + local + l_value: detachable JSON_STRING do - replace (value, key) + if attached value as v then + create l_value.make_json_from_string_32 (v.as_string_32) + end + replace (l_value, key) end - replace_integer (value: detachable INTEGER_64; key: JSON_STRING) + replace_with_integer (value: detachable INTEGER_64; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. local @@ -135,7 +146,7 @@ feature -- Change Element replace (l_value, key) end - replace_natural (value: detachable NATURAL_64; key: JSON_STRING) + replace_with_with_natural (value: detachable NATURAL_64; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. local @@ -147,7 +158,7 @@ feature -- Change Element replace (l_value, key) end - replace_real (value: detachable DOUBLE; key: JSON_STRING) + replace_with_real (value: detachable DOUBLE; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. local From 7b0d264aabd811a58c83b2829fd687d79a309dd9 Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 25 Sep 2013 10:08:10 +0200 Subject: [PATCH 3/6] Fix formating --- library/kernel/json_object.e | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index d0d094d5..e2712274 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -58,11 +58,11 @@ feature -- Change Element require key_not_present: not has_key (key) local - l_value: detachable JSON_STRING + l_value: detachable JSON_STRING do - if attached value as v then - create l_value.make_json_from_string_32 (v.as_string_32) - end + if attached value as v then + create l_value.make_json_from_string_32 (v.as_string_32) + end put (l_value, key) end @@ -126,11 +126,11 @@ feature -- Change Element -- Assuming there is no item of key `key', -- insert `value' with `key'. local - l_value: detachable JSON_STRING + l_value: detachable JSON_STRING do - if attached value as v then - create l_value.make_json_from_string_32 (v.as_string_32) - end + if attached value as v then + create l_value.make_json_from_string_32 (v.as_string_32) + end replace (l_value, key) end From 93f8cd789f7cd3d5090999b6a263d3d134c9a13f Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 25 Sep 2013 12:50:17 +0200 Subject: [PATCH 4/6] Make types attached --- library/kernel/json_object.e | 54 +++++++++++++----------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index e2712274..614365bd 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -52,7 +52,7 @@ feature -- Change Element object.extend (l_value, key) end - put_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING) + put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. require @@ -60,9 +60,7 @@ feature -- Change Element local l_value: detachable JSON_STRING do - if attached value as v then - create l_value.make_json_from_string_32 (v.as_string_32) - end + create l_value.make_json_from_string_32 (value.as_string_32) put (l_value, key) end @@ -75,9 +73,7 @@ feature -- Change Element local l_value: detachable JSON_NUMBER do - if attached value as v then - create l_value.make_integer (v) - end + create l_value.make_integer (value) put (l_value, key) end @@ -87,25 +83,21 @@ feature -- Change Element require key_not_present: not has_key (key) local - l_value: detachable JSON_NUMBER + l_value: JSON_NUMBER do - if attached value as v then - create l_value.make_natural (v) - end + create l_value.make_natural (value) put (l_value, key) end - put_real (value: detachable DOUBLE; key: JSON_STRING) + 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: detachable JSON_NUMBER + l_value: JSON_NUMBER do - if attached value as v then - create l_value.make_real (v) - end + create l_value.make_real (value) put (l_value, key) end @@ -122,51 +114,43 @@ feature -- Change Element object.force (l_value, key) end - replace_with_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING) + 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: detachable JSON_STRING + l_value: JSON_STRING do - if attached value as v then - create l_value.make_json_from_string_32 (v.as_string_32) - end + create l_value.make_json_from_string_32 (value.as_string_32) replace (l_value, key) end - replace_with_integer (value: detachable INTEGER_64; key: JSON_STRING) + replace_with_integer (value: INTEGER_64; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. local l_value: detachable JSON_NUMBER do - if attached value as v then - create l_value.make_integer (v) - end + create l_value.make_integer (value) replace (l_value, key) end - replace_with_with_natural (value: detachable NATURAL_64; key: JSON_STRING) + 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: detachable JSON_NUMBER + l_value: JSON_NUMBER do - if attached value as v then - create l_value.make_natural (v) - end + create l_value.make_natural (value) replace (l_value, key) end - replace_with_real (value: detachable DOUBLE; key: JSON_STRING) + replace_with_real (value: DOUBLE; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. local - l_value: detachable JSON_NUMBER + l_value: JSON_NUMBER do - if attached value as v then - create l_value.make_real (v) - end + create l_value.make_real (value) replace (l_value, key) end From 805ac5dacf9836a5434091cb0c797dd0454ce89f Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 25 Sep 2013 12:52:17 +0200 Subject: [PATCH 5/6] Remove remaining `detachable` variables --- library/kernel/json_object.e | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index 614365bd..7994cc5c 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -58,26 +58,26 @@ feature -- Change Element require key_not_present: not has_key (key) local - l_value: detachable JSON_STRING + 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: detachable INTEGER_64; key: JSON_STRING) + 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: detachable JSON_NUMBER + l_value: JSON_NUMBER do create l_value.make_integer (value) put (l_value, key) end - put_natural (value: detachable NATURAL_64; key: JSON_STRING) + put_natural (value: NATURAL_64; key: JSON_STRING) -- Assuming there is no item of key `key', -- insert `value' with `key'. require @@ -128,7 +128,7 @@ feature -- Change Element -- Assuming there is no item of key `key', -- insert `value' with `key'. local - l_value: detachable JSON_NUMBER + l_value: JSON_NUMBER do create l_value.make_integer (value) replace (l_value, key) From 48251fb872d52df3c1ba1b77dd972cf7b4160668 Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Fri, 27 Sep 2013 10:25:36 +0200 Subject: [PATCH 6/6] Add boolean --- library/kernel/json_object.e | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/kernel/json_object.e b/library/kernel/json_object.e index 7994cc5c..a6fe26cd 100644 --- a/library/kernel/json_object.e +++ b/library/kernel/json_object.e @@ -101,6 +101,18 @@ feature -- Change Element 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'. @@ -154,6 +166,16 @@ feature -- Change Element 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