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

@@ -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