Better signature for encoders
Split library .ecf and the autotest .ecf
This commit is contained in:
@@ -13,7 +13,7 @@ class
|
||||
HTML_ENCODER
|
||||
|
||||
inherit
|
||||
ENCODER [STRING_32, STRING_8]
|
||||
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
PLATFORM
|
||||
export
|
||||
@@ -33,7 +33,7 @@ feature -- Status report
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: STRING_32): STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- HTML-encoded value of `s'.
|
||||
local
|
||||
i, n: INTEGER
|
||||
@@ -67,7 +67,7 @@ feature -- Encoder
|
||||
|
||||
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
|
||||
local
|
||||
i, n: INTEGER
|
||||
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
|
||||
end
|
||||
|
||||
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)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -12,7 +12,7 @@ class
|
||||
JSON_ENCODER
|
||||
|
||||
inherit
|
||||
ENCODER [STRING_32, STRING_8]
|
||||
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
PLATFORM
|
||||
export
|
||||
@@ -32,7 +32,7 @@ feature -- Status report
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: STRING_32): STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- JSON-encoded value of `s'.
|
||||
local
|
||||
i, j, n: INTEGER
|
||||
@@ -82,7 +82,7 @@ feature -- Encoder
|
||||
|
||||
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
|
||||
local
|
||||
i, n: INTEGER
|
||||
|
||||
@@ -33,17 +33,15 @@ feature -- Status report
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- URL-encoded value of `s'.
|
||||
local
|
||||
i, n: INTEGER
|
||||
uc: CHARACTER_32
|
||||
c: CHARACTER_8
|
||||
s8: STRING_8
|
||||
do
|
||||
has_error := False
|
||||
create s8.make (s.count + s.count // 10)
|
||||
Result := s8
|
||||
create Result.make (s.count + s.count // 10)
|
||||
n := s.count
|
||||
from i := 1 until i > n loop
|
||||
uc := s.item (i)
|
||||
@@ -55,14 +53,14 @@ feature -- Encoder
|
||||
'a' .. 'z', '0' .. '9',
|
||||
'.', '-', '~', '_'
|
||||
then
|
||||
s8.extend (c)
|
||||
Result.extend (c)
|
||||
when ' ' then
|
||||
s8.extend ('+')
|
||||
Result.extend ('+')
|
||||
else
|
||||
s8.append (url_encoded_char (uc))
|
||||
Result.append (url_encoded_char (uc))
|
||||
end
|
||||
else
|
||||
s8.append (url_encoded_char (uc))
|
||||
Result.append (url_encoded_char (uc))
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
@@ -134,19 +132,17 @@ feature {NONE} -- encoder character
|
||||
|
||||
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
|
||||
local
|
||||
i, n: INTEGER
|
||||
c: CHARACTER
|
||||
pr: CELL [INTEGER]
|
||||
s32: STRING_32
|
||||
changed: BOOLEAN
|
||||
do
|
||||
has_error := False
|
||||
n := v.count
|
||||
create s32.make (n)
|
||||
Result := s32
|
||||
create Result.make (n)
|
||||
from i := 1
|
||||
until i > n
|
||||
loop
|
||||
@@ -154,19 +150,19 @@ feature -- Decoder
|
||||
inspect c
|
||||
when '+' then
|
||||
changed := True
|
||||
s32.append_character ({CHARACTER_32}' ')
|
||||
Result.append_character ({CHARACTER_32}' ')
|
||||
when '%%' then
|
||||
-- An escaped character ?
|
||||
if i = n then
|
||||
s32.append_character (c.to_character_32)
|
||||
Result.append_character (c.to_character_32)
|
||||
else
|
||||
changed := True
|
||||
create pr.put (i)
|
||||
s32.append (url_decoded_char (v, pr))
|
||||
Result.append (url_decoded_char (v, pr))
|
||||
i := pr.item
|
||||
end
|
||||
else
|
||||
s32.append_character (c.to_character_32)
|
||||
Result.append_character (c.to_character_32)
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
@@ -367,7 +363,7 @@ feature {NONE} -- Hexadecimal and strings
|
||||
end
|
||||
|
||||
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)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -13,7 +13,7 @@ class
|
||||
UTF8_ENCODER
|
||||
|
||||
inherit
|
||||
ENCODER [STRING_32, STRING_8]
|
||||
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
UTF8_ENCODER_HELPER
|
||||
|
||||
@@ -35,7 +35,7 @@ feature -- Status report
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: STRING_32): STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- UTF8-encoded value of `s'.
|
||||
do
|
||||
Result := utf32_to_utf8 (s)
|
||||
@@ -44,7 +44,7 @@ feature -- Encoder
|
||||
|
||||
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
|
||||
do
|
||||
Result := utf8_to_utf32 (v)
|
||||
@@ -52,7 +52,7 @@ feature -- Decoder
|
||||
end
|
||||
|
||||
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)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -42,7 +42,7 @@ feature -- Access
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- URL-encoded value of `s'.
|
||||
do
|
||||
Result := Precursor (s)
|
||||
@@ -64,7 +64,7 @@ feature -- Encoder
|
||||
|
||||
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
|
||||
do
|
||||
Result := Precursor (v)
|
||||
@@ -77,7 +77,7 @@ feature -- Decoder
|
||||
end
|
||||
|
||||
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)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -13,7 +13,7 @@ class
|
||||
XML_ENCODER
|
||||
|
||||
inherit
|
||||
ENCODER [STRING_32, STRING_8]
|
||||
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
|
||||
|
||||
PLATFORM
|
||||
export
|
||||
@@ -33,7 +33,7 @@ feature -- Status report
|
||||
|
||||
feature -- Encoder
|
||||
|
||||
encoded_string (s: STRING_32): STRING_8
|
||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||
-- XML-encoded value of `s'.
|
||||
local
|
||||
i, n: INTEGER
|
||||
@@ -67,7 +67,7 @@ feature -- Encoder
|
||||
|
||||
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
|
||||
local
|
||||
i, n: INTEGER
|
||||
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
|
||||
end
|
||||
|
||||
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)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -19,10 +19,11 @@ feature -- Test routines
|
||||
note
|
||||
testing: "url-encoded"
|
||||
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 ("<22>t<EFBFBD>")
|
||||
test_url_encoded_decoding ("%%E9t%%E9", "<22>t<EFBFBD>")
|
||||
test_url_encoded_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
|
||||
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 ({STRING_32}"<22>t<EFBFBD>")
|
||||
test_url_encoded_decoding ({STRING_8}"%%E9t%%E9", {STRING_32}"<22>t<EFBFBD>")
|
||||
|
||||
test_utf8_url_encoded_decoding ({STRING_8}"%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
|
||||
end
|
||||
|
||||
test_url_encoded_encoding (s: STRING_32)
|
||||
@@ -47,6 +48,16 @@ feature -- Test routines
|
||||
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
|
||||
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
|
||||
copyright: "2011-2011, Eiffel Software and others"
|
||||
|
||||
@@ -19,8 +19,7 @@ feature -- Test routines
|
||||
note
|
||||
testing: "url-encoded"
|
||||
do
|
||||
-- test_utf8_decoding ("summer=<3D>t<EFBFBD>&weird=<3D>", "summer=<3D>t<EFBFBD>&weird=<EFBFBD>")
|
||||
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
|
||||
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
|
||||
end
|
||||
|
||||
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