Added general_encoded_string (..) that accepts READABLE_STRING_GENERAL
This commit is contained in:
@@ -35,18 +35,24 @@ feature -- Encoder
|
|||||||
|
|
||||||
encoded_string (s: READABLE_STRING_32): STRING_8
|
encoded_string (s: READABLE_STRING_32): STRING_8
|
||||||
-- URL-encoded value of `s'.
|
-- URL-encoded value of `s'.
|
||||||
|
do
|
||||||
|
Result := general_encoded_string (s)
|
||||||
|
end
|
||||||
|
|
||||||
|
general_encoded_string (s: READABLE_STRING_GENERAL): STRING_8
|
||||||
|
-- URL-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
uc: CHARACTER_32
|
|
||||||
c: CHARACTER_8
|
c: CHARACTER_8
|
||||||
|
l_code: NATURAL_32
|
||||||
do
|
do
|
||||||
has_error := False
|
has_error := False
|
||||||
create Result.make (s.count + s.count // 10)
|
create Result.make (s.count + s.count // 10)
|
||||||
n := s.count
|
n := s.count
|
||||||
from i := 1 until i > n loop
|
from i := 1 until i > n loop
|
||||||
uc := s.item (i)
|
l_code := s.code (i)
|
||||||
if uc.is_character_8 then
|
if l_code.is_valid_character_8_code then
|
||||||
c := uc.to_character_8
|
c := l_code.to_character_8
|
||||||
inspect c
|
inspect c
|
||||||
when
|
when
|
||||||
'A' .. 'Z',
|
'A' .. 'Z',
|
||||||
@@ -55,20 +61,20 @@ feature -- Encoder
|
|||||||
then
|
then
|
||||||
Result.extend (c)
|
Result.extend (c)
|
||||||
else
|
else
|
||||||
Result.append (url_encoded_char (uc))
|
Result.append (url_encoded_char (l_code))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result.append (url_encoded_char (uc))
|
Result.append (url_encoded_char (l_code))
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
partial_encoded_string (s: READABLE_STRING_32; a_ignore: ARRAY [CHARACTER]): READABLE_STRING_8
|
partial_encoded_string (s: READABLE_STRING_GENERAL; a_ignore: ARRAY [CHARACTER]): STRING_8
|
||||||
-- URL-encoded value of `s'.
|
-- URL-encoded value of `s'.
|
||||||
local
|
local
|
||||||
i, n: INTEGER
|
i, n: INTEGER
|
||||||
uc: CHARACTER_32
|
l_code: NATURAL_32
|
||||||
c: CHARACTER_8
|
c: CHARACTER_8
|
||||||
s8: STRING_8
|
s8: STRING_8
|
||||||
do
|
do
|
||||||
@@ -77,9 +83,9 @@ feature -- Encoder
|
|||||||
Result := s8
|
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)
|
l_code := s.code (i)
|
||||||
if uc.is_character_8 then
|
if l_code.is_valid_character_8_code then
|
||||||
c := uc.to_character_8
|
c := l_code.to_character_8
|
||||||
inspect c
|
inspect c
|
||||||
when
|
when
|
||||||
'A' .. 'Z',
|
'A' .. 'Z',
|
||||||
@@ -91,14 +97,14 @@ feature -- Encoder
|
|||||||
if a_ignore.has (c) then
|
if a_ignore.has (c) then
|
||||||
s8.extend (c)
|
s8.extend (c)
|
||||||
else
|
else
|
||||||
s8.append (url_encoded_char (uc))
|
s8.append (url_encoded_char (l_code))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if a_ignore.has (c) then
|
if a_ignore.has (c) then
|
||||||
s8.extend (c)
|
s8.extend (c)
|
||||||
else
|
else
|
||||||
s8.append (url_encoded_char (uc))
|
s8.append (url_encoded_char (l_code))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
@@ -107,12 +113,12 @@ feature -- Encoder
|
|||||||
|
|
||||||
feature {NONE} -- encoder character
|
feature {NONE} -- encoder character
|
||||||
|
|
||||||
url_encoded_char (uc: CHARACTER_32): STRING_8
|
url_encoded_char (a_code: NATURAL_32): STRING_8
|
||||||
do
|
do
|
||||||
create Result.make (3)
|
create Result.make (3)
|
||||||
if uc.is_character_8 then
|
if a_code.is_valid_character_8_code then
|
||||||
Result.extend ('%%')
|
Result.extend ('%%')
|
||||||
Result.append (uc.code.to_hex_string)
|
Result.append (a_code.to_hex_string)
|
||||||
from
|
from
|
||||||
until
|
until
|
||||||
Result.count < 2 or else Result[2] /= '0'
|
Result.count < 2 or else Result[2] /= '0'
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ inherit
|
|||||||
redefine
|
redefine
|
||||||
default_create,
|
default_create,
|
||||||
name,
|
name,
|
||||||
|
general_encoded_string,
|
||||||
encoded_string, partial_encoded_string,
|
encoded_string, partial_encoded_string,
|
||||||
decoded_string
|
decoded_string
|
||||||
end
|
end
|
||||||
@@ -49,7 +50,17 @@ feature -- Encoder
|
|||||||
Result := Precursor (Result)
|
Result := Precursor (Result)
|
||||||
end
|
end
|
||||||
|
|
||||||
partial_encoded_string (s: READABLE_STRING_32; a_ignore: ARRAY [CHARACTER]): READABLE_STRING_8
|
general_encoded_string (s: READABLE_STRING_GENERAL): STRING_8
|
||||||
|
do
|
||||||
|
if attached {READABLE_STRING_32} s as s32 then
|
||||||
|
Result := utf32_to_utf8 (s32)
|
||||||
|
else
|
||||||
|
Result := s.as_string_8
|
||||||
|
end
|
||||||
|
Result := Precursor (Result)
|
||||||
|
end
|
||||||
|
|
||||||
|
partial_encoded_string (s: READABLE_STRING_GENERAL; a_ignore: ARRAY [CHARACTER]): STRING_8
|
||||||
-- URL-encoded value of `s'.
|
-- URL-encoded value of `s'.
|
||||||
do
|
do
|
||||||
Result := Precursor (s, a_ignore)
|
Result := Precursor (s, a_ignore)
|
||||||
|
|||||||
Reference in New Issue
Block a user