diff --git a/library/kernel/json_string.e b/library/kernel/json_string.e index 61115f3c..ccd8e60d 100644 --- a/library/kernel/json_string.e +++ b/library/kernel/json_string.e @@ -27,40 +27,42 @@ create make_with_escaped_json convert - make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}) + make_json ({READABLE_STRING_8, STRING_8, IMMUTABLE_STRING_8}), + make_json_from_string_32 ({READABLE_STRING_32, STRING_32, IMMUTABLE_STRING_32}) feature {NONE} -- Initialization - make_json (an_item: READABLE_STRING_8) + make_json (s: READABLE_STRING_8) -- Initialize. require - item_not_void: an_item /= Void + item_not_void: s /= Void do - make_with_escaped_json (escaped_json_string (an_item)) + make_with_escaped_json (escaped_json_string (s)) end - make_json_from_string_32 (an_item: READABLE_STRING_32) - -- Initialize. + make_json_from_string_32 (s: READABLE_STRING_32) + -- Initialize from STRING_32 `s'. require - item_not_void: an_item /= Void + item_not_void: s /= Void do - make_with_escaped_json (escaped_json_string_32 (an_item)) + make_with_escaped_json (escaped_json_string_32 (s)) end - make_with_escaped_json (an_item: READABLE_STRING_8) + make_with_escaped_json (s: READABLE_STRING_8) -- Initialize with an_item already escaped require - item_not_void: an_item /= Void + item_not_void: s /= Void do - item := an_item + item := s end feature -- Access item: STRING - -- Contents + -- Contents with escaped entities if any - unescaped_string: STRING_8 + unescaped_string_8: STRING_8 + -- Unescaped string from `item' local s: like item i, n: INTEGER @@ -106,6 +108,7 @@ feature -- Access end unescaped_string_32: STRING_32 + -- Unescaped string 32 from `item' local s: like item i, n: INTEGER @@ -154,8 +157,10 @@ feature -- Access end representation: STRING + -- String representation of `item' with escaped entities if any do - Result := "%"" + create Result.make (item.count + 2) + Result.append_character ('%"') Result.append (item) Result.append_character ('%"') end @@ -175,13 +180,13 @@ feature -- Comparison -- Is JSON_STRING made of same character sequence as `other' -- (possibly with a different capacity)? do - Result := item.is_equal (other.item) + Result := item.same_string (other.item) end feature -- Change Element append (a_string: STRING) - -- Add an_item + -- Add a_string require a_string_not_void: a_string /= Void do @@ -207,6 +212,7 @@ feature -- Status report feature {NONE} -- Implementation is_hexadecimal (s: READABLE_STRING_8): BOOLEAN + -- Is `s' an hexadecimal value? do Result := across s as scur all scur.item.is_hexa_digit end end @@ -318,6 +324,6 @@ feature {NONE} -- Implementation end invariant - value_not_void: item /= Void + item_not_void: item /= Void end diff --git a/test/autotest/test_suite/test_json_core.e b/test/autotest/test_suite/test_json_core.e index ad8326b9..d2faa7e1 100644 --- a/test/autotest/test_suite/test_json_core.e +++ b/test/autotest/test_suite/test_json_core.e @@ -632,7 +632,7 @@ feature -- Test jrep := "%"foo\\bar%"" create parser.make_parser (jrep) if attached {JSON_STRING} parser.parse as jstring then - assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string.same_string ("foo\bar")) + assert ("unescaped string %"foo\\bar%" to %"foo\bar%"", jstring.unescaped_string_8.same_string ("foo\bar")) end create js.make_json_from_string_32 ({STRING_32}"%/20320/%/22909/")