Better signature for encoders
Split library .ecf and the autotest .ecf
This commit is contained in:
@@ -13,7 +13,7 @@ class
|
|||||||
HTML_ENCODER
|
HTML_ENCODER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
ENCODER [STRING_32, STRING_8]
|
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||||
|
|
||||||
PLATFORM
|
PLATFORM
|
||||||
export
|
export
|
||||||
@@ -33,7 +33,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: STRING_32): STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- HTML-encoded value of `s'.
|
-- HTML-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
@@ -67,7 +67,7 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: STRING_8): STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The HTML-encoded equivalent of the given string
|
-- The HTML-encoded equivalent of the given string
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2012, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class
|
|||||||
JSON_ENCODER
|
JSON_ENCODER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
ENCODER [STRING_32, STRING_8]
|
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||||
|
|
||||||
PLATFORM
|
PLATFORM
|
||||||
export
|
export
|
||||||
@@ -32,7 +32,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: STRING_32): STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- JSON-encoded value of `s'.
|
-- JSON-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, j, n: INTEGER
|
i, j, n: INTEGER
|
||||||
@@ -82,7 +82,7 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: STRING_8): STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The JSON-encoded equivalent of the given string
|
-- The JSON-encoded equivalent of the given string
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
|
|||||||
@@ -33,17 +33,15 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- URL-encoded value of `s'.
|
-- URL-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
uc: CHARACTER_32
|
uc: CHARACTER_32
|
||||||
c: CHARACTER_8
|
c: CHARACTER_8
|
||||||
s8: STRING_8
|
|
||||||
do
|
do
|
||||||
has_error := False
|
has_error := False
|
||||||
create s8.make (s.count + s.count // 10)
|
create Result.make (s.count + s.count // 10)
|
||||||
Result := s8
|
|
||||||
n := s.count
|
n := s.count
|
||||||
from i := 1 until i > n loop
|
from i := 1 until i > n loop
|
||||||
uc := s.item (i)
|
uc := s.item (i)
|
||||||
@@ -55,14 +53,14 @@ feature -- Encoder
|
|||||||
'a' .. 'z', '0' .. '9',
|
'a' .. 'z', '0' .. '9',
|
||||||
'.', '-', '~', '_'
|
'.', '-', '~', '_'
|
||||||
then
|
then
|
||||||
s8.extend (c)
|
Result.extend (c)
|
||||||
when ' ' then
|
when ' ' then
|
||||||
s8.extend ('+')
|
Result.extend ('+')
|
||||||
else
|
else
|
||||||
s8.append (url_encoded_char (uc))
|
Result.append (url_encoded_char (uc))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
s8.append (url_encoded_char (uc))
|
Result.append (url_encoded_char (uc))
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
@@ -134,19 +132,17 @@ feature {NONE} -- encoder character
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: READABLE_STRING_8): READABLE_STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The URL-encoded equivalent of the given string
|
-- The URL-encoded equivalent of the given string
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
c: CHARACTER
|
c: CHARACTER
|
||||||
pr: CELL [INTEGER]
|
pr: CELL [INTEGER]
|
||||||
s32: STRING_32
|
|
||||||
changed: BOOLEAN
|
changed: BOOLEAN
|
||||||
do
|
do
|
||||||
has_error := False
|
has_error := False
|
||||||
n := v.count
|
n := v.count
|
||||||
create s32.make (n)
|
create Result.make (n)
|
||||||
Result := s32
|
|
||||||
from i := 1
|
from i := 1
|
||||||
until i > n
|
until i > n
|
||||||
loop
|
loop
|
||||||
@@ -154,19 +150,19 @@ feature -- Decoder
|
|||||||
inspect c
|
inspect c
|
||||||
when '+' then
|
when '+' then
|
||||||
changed := True
|
changed := True
|
||||||
s32.append_character ({CHARACTER_32}' ')
|
Result.append_character ({CHARACTER_32}' ')
|
||||||
when '%%' then
|
when '%%' then
|
||||||
-- An escaped character ?
|
-- An escaped character ?
|
||||||
if i = n then
|
if i = n then
|
||||||
s32.append_character (c.to_character_32)
|
Result.append_character (c.to_character_32)
|
||||||
else
|
else
|
||||||
changed := True
|
changed := True
|
||||||
create pr.put (i)
|
create pr.put (i)
|
||||||
s32.append (url_decoded_char (v, pr))
|
Result.append (url_decoded_char (v, pr))
|
||||||
i := pr.item
|
i := pr.item
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
s32.append_character (c.to_character_32)
|
Result.append_character (c.to_character_32)
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
@@ -367,7 +363,7 @@ feature {NONE} -- Hexadecimal and strings
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2012, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class
|
|||||||
UTF8_ENCODER
|
UTF8_ENCODER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
ENCODER [STRING_32, STRING_8]
|
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||||
|
|
||||||
UTF8_ENCODER_HELPER
|
UTF8_ENCODER_HELPER
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: STRING_32): STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- UTF8-encoded value of `s'.
|
-- UTF8-encoded value of `s'.
|
||||||
do
|
do
|
||||||
Result := utf32_to_utf8 (s)
|
Result := utf32_to_utf8 (s)
|
||||||
@@ -44,7 +44,7 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: STRING_8): STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The UTF8-encoded equivalent of the given string
|
-- The UTF8-encoded equivalent of the given string
|
||||||
do
|
do
|
||||||
Result := utf8_to_utf32 (v)
|
Result := utf8_to_utf32 (v)
|
||||||
@@ -52,7 +52,7 @@ feature -- Decoder
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2012, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- URL-encoded value of `s'.
|
-- URL-encoded value of `s'.
|
||||||
do
|
do
|
||||||
Result := Precursor (s)
|
Result := Precursor (s)
|
||||||
@@ -64,7 +64,7 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: READABLE_STRING_8): READABLE_STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The URL-encoded equivalent of the given string
|
-- The URL-encoded equivalent of the given string
|
||||||
do
|
do
|
||||||
Result := Precursor (v)
|
Result := Precursor (v)
|
||||||
@@ -77,7 +77,7 @@ feature -- Decoder
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2012, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class
|
|||||||
XML_ENCODER
|
XML_ENCODER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
ENCODER [STRING_32, STRING_8]
|
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||||
|
|
||||||
PLATFORM
|
PLATFORM
|
||||||
export
|
export
|
||||||
@@ -33,7 +33,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Encoder
|
feature -- Encoder
|
||||||
|
|
||||||
encoded_string (s: STRING_32): STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- XML-encoded value of `s'.
|
-- XML-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
@@ -67,7 +67,7 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature -- Decoder
|
feature -- Decoder
|
||||||
|
|
||||||
decoded_string (v: STRING_8): STRING_32
|
decoded_string (v: READABLE_STRING_8): STRING_32
|
||||||
-- The XML-encoded equivalent of the given string
|
-- The XML-encoded equivalent of the given string
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
|
|||||||
end
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2012, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ feature -- Test routines
|
|||||||
note
|
note
|
||||||
testing: "url-encoded"
|
testing: "url-encoded"
|
||||||
do
|
do
|
||||||
test_url_encoded_encoding ("http://domain.tld/foo/bar/script.php?test='toto'&foo=bar&title=il <20>tait une fois")
|
test_url_encoded_encoding ({STRING_32}"http://domain.tld/foo/bar/script.php?test='toto'&foo=bar&title=il <20>tait une fois")
|
||||||
test_url_encoded_encoding ("<22>t<EFBFBD>")
|
test_url_encoded_encoding ({STRING_32}"<22>t<EFBFBD>")
|
||||||
test_url_encoded_decoding ("%%E9t%%E9", "<22>t<EFBFBD>")
|
test_url_encoded_decoding ({STRING_8}"%%E9t%%E9", {STRING_32}"<22>t<EFBFBD>")
|
||||||
test_url_encoded_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
|
|
||||||
|
test_utf8_url_encoded_decoding ({STRING_8}"%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
|
||||||
end
|
end
|
||||||
|
|
||||||
test_url_encoded_encoding (s: STRING_32)
|
test_url_encoded_encoding (s: STRING_32)
|
||||||
@@ -47,6 +48,16 @@ feature -- Test routines
|
|||||||
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
|
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_utf8_url_encoded_decoding (s: STRING_8; e: STRING_32)
|
||||||
|
local
|
||||||
|
u: STRING_32
|
||||||
|
b: UTF8_URL_ENCODER
|
||||||
|
do
|
||||||
|
create b
|
||||||
|
u := b.decoded_string (s)
|
||||||
|
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Eiffel Software and others"
|
copyright: "2011-2011, Eiffel Software and others"
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ feature -- Test routines
|
|||||||
note
|
note
|
||||||
testing: "url-encoded"
|
testing: "url-encoded"
|
||||||
do
|
do
|
||||||
-- test_utf8_decoding ("summer=<3D>t<EFBFBD>&weird=<3D>", "summer=<3D>t<EFBFBD>&weird=<EFBFBD>")
|
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
|
||||||
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test_utf8_decoding (s: STRING_8; e: STRING_32)
|
test_utf8_decoding (s: STRING_8; e: STRING_32)
|
||||||
|
|||||||
18
library/text/encoder/tests/tests-safe.ecf
Normal file
18
library/text/encoder/tests/tests-safe.ecf
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="encoder_tests" uuid="C6F56AE3-8E9C-4568-85CA-CA5F1EF15DCE">
|
||||||
|
<target name="encoder_tests">
|
||||||
|
<root class="ANY" feature="default_create"/>
|
||||||
|
<file_rule>
|
||||||
|
<exclude>/.git$</exclude>
|
||||||
|
<exclude>/EIFGENs$</exclude>
|
||||||
|
<exclude>/.svn$</exclude>
|
||||||
|
</file_rule>
|
||||||
|
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
|
||||||
|
<assertions precondition="true"/>
|
||||||
|
</option>
|
||||||
|
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||||
|
<library name="encoder" location="../encoder-safe.ecf" readonly="false"/>
|
||||||
|
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||||
|
<tests name="tests" location="."/>
|
||||||
|
</target>
|
||||||
|
</system>
|
||||||
Reference in New Issue
Block a user