Added visitor patterns to WSF_VALUE

Handling UTF-8 unencoding for WSF_VALUE ...
Added WSF_TABLE_VALUE to handle list[]=a&list[]=b ...

Library encoder: added UTF8 facilities
This commit is contained in:
Jocelyn Fiat
2011-10-24 17:23:36 +02:00
parent 663a39d2ec
commit fb7854fbcc
27 changed files with 781 additions and 52 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="encoder" uuid="EE80E648-C64D-4802-8868-C57AAFEACC55" library_target="encoder">
<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" uuid="EE80E648-C64D-4802-8868-C57AAFEACC55" library_target="encoder">
<target name="encoder">
<root all_classes="true"/>
<file_rule>
@@ -7,18 +7,18 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
<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="encoding" location="$ISE_LIBRARY\library\encoding\encoding-safe.ecf"/>
<cluster name="src" location="src\" recursive="true">
<file_rule>
<exclude>/tests$</exclude>
</file_rule>
</cluster>
</target>
<target name="tests" extends="encoder" >
<target name="tests" extends="encoder">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
@@ -29,7 +29,6 @@
<assertions precondition="true"/>
</option>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location="./tests"/>
<tests name="tests" location=".\tests\"/>
</target>
</system>

View File

@@ -11,6 +11,7 @@
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="encoding" location="$ISE_LIBRARY\library\encoding\encoding.ecf"/>
<cluster name="src" location="src\" recursive="true">
<file_rule>
<exclude>/tests$</exclude>

View File

@@ -16,7 +16,10 @@ inherit
feature -- Access
name: STRING = "base64"
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("base64")
end
feature -- Status report

View File

@@ -5,12 +5,12 @@ note
date: "$Date$"
revision: "$Revision$"
deferred class
deferred class
ENCODER [U -> READABLE_STRING_GENERAL, E -> READABLE_STRING_GENERAL] --| U:unencoded type, E:encoded type
feature -- Access
name: STRING
name: READABLE_STRING_8
-- Encoding name.
deferred
end
@@ -61,7 +61,7 @@ feature -- Decoder
end
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -22,7 +22,10 @@ inherit
feature -- Access
name: STRING = "HTML-encoded"
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("HTML-encoded")
end
feature -- Status report
@@ -71,6 +74,7 @@ feature -- Decoder
c: CHARACTER
cl_i: CELL [INTEGER]
do
has_error := False
n := v.count
create Result.make (n)
create cl_i.put (0)
@@ -255,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -22,7 +22,10 @@ inherit
feature -- Access
name: STRING = "URL-encoded"
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("URL-encoded")
end
feature -- Status report
@@ -138,7 +141,9 @@ feature -- Decoder
c: CHARACTER
pr: CELL [INTEGER]
s32: STRING_32
changed: BOOLEAN
do
has_error := False
n := v.count
create s32.make (n)
Result := s32
@@ -148,12 +153,14 @@ feature -- Decoder
c := v.item (i)
inspect c
when '+' then
changed := True
s32.append_character ({CHARACTER_32}' ')
when '%%' then
-- An escaped character ?
if i = n then
s32.append_character (c.to_character_32)
else
changed := True
create pr.put (i)
s32.append (url_decoded_char (v, pr))
i := pr.item

View File

@@ -0,0 +1,70 @@
note
description: "[
Summary description for {UTF8_ENCODER}.
see: http://en.wikipedia.org/wiki/UTF-8
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
UTF8_ENCODER
inherit
ENCODER [STRING_32, STRING_8]
UNICODE_CONVERSION
export
{NONE} all
{ANY} is_valid_utf8
undefine
is_little_endian
end
PLATFORM
export
{NONE} all
end
feature -- Access
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("UTF8-encoded")
end
feature -- Status report
has_error: BOOLEAN
feature -- Encoder
encoded_string (s: STRING_32): STRING_8
-- UTF8-encoded value of `s'.
do
Result := utf32_to_utf8 (s)
has_error := not last_conversion_successful
end
feature -- Decoder
decoded_string (v: STRING_8): STRING_32
-- The UTF8-encoded equivalent of the given string
do
Result := utf8_to_utf32 (v)
has_error := not last_conversion_successful
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,94 @@
note
description: "[
Summary description for {URL_ENCODER}.
See: http://www.faqs.org/rfcs/rfc3986.html
]"
legal: "See notice at end of class."
status: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
class
UTF8_URL_ENCODER
inherit
URL_ENCODER
redefine
default_create,
name,
encoded_string, partial_encoded_string,
decoded_string
end
UNICODE_CONVERSION
export
{NONE} all
{ANY} is_valid_utf8
undefine
is_little_endian
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
Precursor {UNICODE_CONVERSION}
end
feature -- Access
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("UTF8-URL-encoded")
end
feature -- Encoder
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
-- URL-encoded value of `s'.
do
Result := Precursor (s)
if not has_error then
Result := utf32_to_utf8 (Result)
has_error := not last_conversion_successful
end
end
partial_encoded_string (s: READABLE_STRING_32; a_ignore: ARRAY [CHARACTER]): READABLE_STRING_8
-- URL-encoded value of `s'.
do
Result := Precursor (s, a_ignore)
if not has_error then
Result := utf32_to_utf8 (Result)
has_error := not last_conversion_successful
end
end
feature -- Decoder
decoded_string (v: READABLE_STRING_8): READABLE_STRING_32
-- The URL-encoded equivalent of the given string
do
Result := Precursor (v)
if not has_error then
if is_valid_utf8 (Result) then
Result := utf8_to_utf32 (Result)
has_error := not last_conversion_successful
end
end
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -22,7 +22,10 @@ inherit
feature -- Access
name: STRING = "XML-encoded"
name: READABLE_STRING_8
do
create {IMMUTABLE_STRING_8} Result.make_from_string ("XML-encoded")
end
feature -- Status report
@@ -71,6 +74,7 @@ feature -- Decoder
c: CHARACTER
cl_i: CELL [INTEGER]
do
has_error := False
n := v.count
create Result.make (n)
create cl_i.put (0)
@@ -255,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -20,6 +20,9 @@ feature -- Test routines
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>")
end
test_url_encoded_encoding (s: STRING_32)
@@ -31,11 +34,22 @@ feature -- Test routines
create b
e := b.encoded_string (s)
u := b.decoded_string (e)
assert ("decoded encoded string is same", u ~ s)
assert ("decoded encoded string is same for string %"" + u + "%"", u ~ s)
end
test_url_encoded_decoding (s: STRING_8; e: STRING_32)
local
u: STRING_32
b: URL_ENCODER
do
create b
u := b.decoded_string (s)
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
end
note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -0,0 +1,51 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_UTF8_ENCODER
inherit
EQA_TEST_SET
feature -- Test routines
test_url_encoded_encoder
note
testing: "url-encoded"
do
-- test_utf8_decoding ("summer=<3D>t<EFBFBD>&weird=<3D>", "summer=<3D>t<EFBFBD>&weird=<3D>")
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
end
test_utf8_decoding (s: STRING_8; e: STRING_32)
local
url: URL_ENCODER
u: STRING_32
b: UTF8_ENCODER
do
create b
create url
u := b.decoded_string (url.decoded_string (s))
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end