Synchronized with ejson library
Cleaned JSON_ENCODER
This commit is contained in:
Submodule contrib/library/text/parser/json updated: 24d08d4fce...168246c797
@@ -2,7 +2,6 @@ note
|
|||||||
description: "[
|
description: "[
|
||||||
Summary description for {JSON_ENCODER}.
|
Summary description for {JSON_ENCODER}.
|
||||||
|
|
||||||
see: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
|
|
||||||
]"
|
]"
|
||||||
legal: "See notice at end of class."
|
legal: "See notice at end of class."
|
||||||
status: "See notice at end of class."
|
status: "See notice at end of class."
|
||||||
@@ -42,8 +41,8 @@ feature -- Encoder
|
|||||||
h: STRING_8
|
h: STRING_8
|
||||||
do
|
do
|
||||||
has_error := False
|
has_error := False
|
||||||
create Result.make (s.count + s.count // 10)
|
|
||||||
n := s.count
|
n := s.count
|
||||||
|
create Result.make (n + n // 10)
|
||||||
from i := 1 until i > n loop
|
from i := 1 until i > n loop
|
||||||
uc := s.item (i)
|
uc := s.item (i)
|
||||||
if uc.is_character_8 then
|
if uc.is_character_8 then
|
||||||
@@ -59,10 +58,11 @@ feature -- Encoder
|
|||||||
else
|
else
|
||||||
Result.append ("\u")
|
Result.append ("\u")
|
||||||
h := uc.code.to_hex_string
|
h := uc.code.to_hex_string
|
||||||
|
-- Remove first 0 and keep 4 hexa digit
|
||||||
from
|
from
|
||||||
j := 1
|
j := 1
|
||||||
until
|
until
|
||||||
j <= h.count and then h.item (j) /= '0'
|
h.count = 4 or (j <= h.count and then h.item (j) /= '0')
|
||||||
loop
|
loop
|
||||||
j := j + 1
|
j := j + 1
|
||||||
end
|
end
|
||||||
@@ -83,18 +83,15 @@ feature -- Encoder
|
|||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: STRING_8): STRING_32
|
decoded_string (v: STRING_8): STRING_32
|
||||||
-- The XML-encoded equivalent of the given string
|
-- The JSON-encoded equivalent of the given string
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
c: CHARACTER
|
c: CHARACTER
|
||||||
cl_i: CELL [INTEGER]
|
|
||||||
hex: STRING
|
hex: STRING
|
||||||
hexconv: detachable HEXADECIMAL_STRING_TO_INTEGER_CONVERTER
|
|
||||||
do
|
do
|
||||||
has_error := False
|
has_error := False
|
||||||
n := v.count
|
n := v.count
|
||||||
create Result.make (n)
|
create Result.make (n)
|
||||||
create cl_i.put (0)
|
|
||||||
from i := 1 until i > n loop
|
from i := 1 until i > n loop
|
||||||
c := v.item (i)
|
c := v.item (i)
|
||||||
if c = '\' then
|
if c = '\' then
|
||||||
@@ -115,8 +112,7 @@ feature -- Decoder
|
|||||||
when 'u' then
|
when 'u' then
|
||||||
hex := v.substring (i+2, i+2+4 - 1)
|
hex := v.substring (i+2, i+2+4 - 1)
|
||||||
if hex.count = 4 then
|
if hex.count = 4 then
|
||||||
Result.append_code (hex_to_natural_32 (hex))
|
Result.append_code (hexadecimal_to_natural_32 (hex))
|
||||||
-- Result.append_string ("\u" + hex) --hex.to_integer_32)
|
|
||||||
end
|
end
|
||||||
i := i + 2 + 4
|
i := i + 2 + 4
|
||||||
else
|
else
|
||||||
@@ -136,10 +132,16 @@ feature -- Decoder
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
hex_to_natural_32 (s: STRING): NATURAL_32
|
is_hexadecimal (s: READABLE_STRING_8): BOOLEAN
|
||||||
|
do
|
||||||
|
Result := across s as scur all scur.item.is_hexa_digit end
|
||||||
|
end
|
||||||
|
|
||||||
|
hexadecimal_to_natural_32 (s: READABLE_STRING_8): NATURAL_32
|
||||||
-- Hexadecimal string `s' converted to NATURAL_32 value
|
-- Hexadecimal string `s' converted to NATURAL_32 value
|
||||||
require
|
require
|
||||||
s_not_void: s /= Void
|
s_not_void: s /= Void
|
||||||
|
is_hexadecimal: is_hexadecimal (s)
|
||||||
local
|
local
|
||||||
i, nb: INTEGER
|
i, nb: INTEGER
|
||||||
char: CHARACTER
|
char: CHARACTER
|
||||||
|
|||||||
Reference in New Issue
Block a user