Better signature for encoders

Split library .ecf and the autotest .ecf
This commit is contained in:
Jocelyn Fiat
2012-02-14 18:03:42 +01:00
parent f59d5cac32
commit fbec89f354
9 changed files with 66 additions and 42 deletions

View File

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

View File

@@ -1,7 +1,7 @@
note
description: "[
Summary description for {JSON_ENCODER}.
]"
legal: "See notice at end of class."
status: "See notice at end of class."
@@ -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

View File

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

View File

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

View File

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

View File

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