Skip to content

Commit d40131f

Browse files
committed
Updated encoder library, especially URL encoders to reuse implementation of percent_encoder.e
Fixed JSON_ENCODER for %T and related. Updated related autotest cases.
1 parent 9999b5e commit d40131f

File tree

6 files changed

+62
-407
lines changed

6 files changed

+62
-407
lines changed

library/text/encoder/src/json_encoder.e

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ feature -- Encoder
5050
inspect c
5151
when '%"' then Result.append_string ("\%"")
5252
when '\' then Result.append_string ("\\")
53-
when '%R' then Result.append_string ("\r")
53+
when '%B' then Result.append_string ("\b")
54+
when '%F' then Result.append_string ("\f")
5455
when '%N' then Result.append_string ("\n")
56+
when '%R' then Result.append_string ("\r")
57+
when '%T' then Result.append_string ("\t")
5558
else
5659
Result.extend (c)
5760
end
@@ -103,12 +106,21 @@ feature -- Decoder
103106
when '%"' then
104107
Result.append_character ('%"')
105108
i := i + 2
109+
when 'b' then
110+
Result.append_character ('%B')
111+
i := i + 2
112+
when 'f' then
113+
Result.append_character ('%F')
114+
i := i + 2
106115
when 'n' then
107116
Result.append_character ('%N')
108117
i := i + 2
109118
when 'r' then
110119
Result.append_character ('%R')
111120
i := i + 2
121+
when 't' then
122+
Result.append_character ('%T')
123+
i := i + 2
112124
when 'u' then
113125
hex := v.substring (i+2, i+2+4 - 1)
114126
if hex.count = 4 then
@@ -170,7 +182,7 @@ feature {NONE} -- Implementation
170182
end
171183

172184
note
173-
copyright: "2011-2012, Eiffel Software and others"
185+
copyright: "Copyright (c) 2011-2014, Eiffel Software and others"
174186
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
175187
source: "[
176188
Eiffel Software

library/text/encoder/src/percent_encoder.e

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ feature -- Percent encoding
6666
end
6767
end
6868

69-
partial_encoded_string (s: READABLE_STRING_GENERAL; a_ignore: ITERABLE [CHARACTER_32]): STRING_8
69+
partial_encoded_string (s: READABLE_STRING_GENERAL; a_ignore: ITERABLE [CHARACTER]): STRING_8
7070
-- Return `s' as percent-encoded value,
7171
-- but does not escape character listed in `a_ignore'.
7272
do
7373
create Result.make (s.count)
7474
append_partial_percent_encoded_string_to (s, Result, a_ignore)
7575
end
7676

77-
append_partial_percent_encoded_string_to (s: READABLE_STRING_GENERAL; a_result: STRING_GENERAL; a_ignore: ITERABLE [CHARACTER_32])
77+
append_partial_percent_encoded_string_to (s: READABLE_STRING_GENERAL; a_result: STRING_GENERAL; a_ignore: ITERABLE [CHARACTER])
7878
-- Append `s' as percent-encoded value to `a_result',
7979
-- but does not escape character listed in `a_ignore'.
8080
local
8181
c: NATURAL_32
82-
ch: CHARACTER_32
82+
ch: CHARACTER_8
8383
i,n: INTEGER
8484
do
8585
has_error := False
@@ -109,15 +109,21 @@ feature -- Percent encoding
109109
43, 44, 59, 61, -- reserved = sub-delims: +,;=
110110
37 -- percent encoding: %
111111
then
112-
ch := c.to_character_32
112+
check c.is_valid_character_8_code end
113+
ch := c.to_character_8
113114
if across a_ignore as ic some ic.item = ch end then
114115
a_result.append_code (c)
115116
else
116117
append_percent_encoded_character_code_to (c, a_result)
117118
end
118119
else
119-
if across a_ignore as ic some ic.item = ch end then
120-
a_result.append_code (c)
120+
if c.is_valid_character_8_code then
121+
ch := c.to_character_8
122+
if across a_ignore as ic some ic.item = ch end then
123+
a_result.append_code (c)
124+
else
125+
append_percent_encoded_character_code_to (c, a_result)
126+
end
121127
else
122128
append_percent_encoded_character_code_to (c, a_result)
123129
end

0 commit comments

Comments
 (0)