Code cleaning, WSF_STRING is reusing WSF_PERCENT_ENCODER.

This commit is contained in:
2015-11-05 00:38:43 +01:00
parent 941281e3ed
commit 26b7052773

View File

@@ -153,161 +153,6 @@ feature -- Visitor
vis.process_string (Current) vis.process_string (Current)
end end
--feature {NONE} -- Implementation
-- utf_8_percent_encoded_string (s: READABLE_STRING_GENERAL): READABLE_STRING_8
-- -- Percent-encode the UTF-8 sequence characters from UTF-8 encoded `s' and
-- -- return the Result.
-- local
-- s8: STRING_8
-- i, n, nb: INTEGER
-- do
-- -- First check if there are such UTF-8 character
-- -- If it has, convert them and return a new object as Result
-- -- otherwise return `s' directly to avoid creating a new object
-- from
-- i := 1
-- n := s.count
-- nb := 0
-- until
-- i > n
-- loop
-- if s.code (i) > 0x7F then -- >= 128
-- nb := nb + 1
-- end
-- i := i + 1
-- end
-- if nb > 0 then
-- create s8.make (s.count + nb * 3)
-- utf_8_string_into_percent_encoded_string_8 (s, s8)
-- Result := s8
-- else
-- Result := s.to_string_8
-- end
-- end
-- utf_8_string_into_percent_encoded_string_8 (s: READABLE_STRING_GENERAL; a_result: STRING_8)
-- -- Copy STRING_32 corresponding to UTF-8 sequence `s' appended into `a_result'.
-- local
-- i: INTEGER
-- n: INTEGER
-- c: NATURAL_32
-- do
-- from
-- n := s.count
-- a_result.grow (a_result.count + n)
-- until
-- i >= n
-- loop
-- i := i + 1
-- c := s.code (i)
-- if c <= 0x7F then
-- -- 0xxxxxxx
-- a_result.append_code (c)
-- elseif c <= 0xDF then
-- -- 110xxxxx 10xxxxxx
-- url_encoder.append_percent_encoded_character_code_to (c, a_result)
-- i := i + 1
-- if i <= n then
-- url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
-- end
-- elseif c <= 0xEF then
-- -- 1110xxxx 10xxxxxx 10xxxxxx
-- url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
-- i := i + 2
-- if i <= n then
-- url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
-- url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
-- end
-- elseif c <= 0xF7 then
-- -- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-- url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
-- i := i + 3
-- if i <= n then
-- url_encoder.append_percent_encoded_character_code_to (s.code (i - 2), a_result)
-- url_encoder.append_percent_encoded_character_code_to (s.code (i - 1), a_result)
-- url_encoder.append_percent_encoded_character_code_to (s.code (i), a_result)
-- end
-- else
-- -- FIXME: unicode character, first utf8 it, then percent encode it.
-- append_percent_encoded_unicode_character_code_to (c, a_result)
---- a_result.append_code (c)
-- end
-- end
-- end
-- append_percent_encoded_ascii_character_code_to (a_code: NATURAL_32; a_result: STRING_GENERAL)
-- -- Append extended ascii character code `a_code' as percent-encoded content into `a_result'
-- -- Note: it does not UTF-8 convert this extended ASCII.
-- require
-- is_extended_ascii: a_code <= 0xFF
-- local
-- c: INTEGER
-- do
-- if a_code > 0xFF then
-- -- Unicode
-- append_percent_encoded_unicode_character_code_to (a_code, a_result)
-- else
-- -- Extended ASCII
-- c := a_code.to_integer_32
-- a_result.append_code (37) -- 37 '%%'
-- a_result.append_code (hex_digit [c |>> 4])
-- a_result.append_code (hex_digit [c & 0xF])
-- end
-- ensure
-- appended: a_result.count > old a_result.count
-- end
-- append_percent_encoded_unicode_character_code_to (a_code: NATURAL_32; a_result: STRING_GENERAL)
-- -- Append Unicode character code `a_code' as UTF-8 and percent-encoded content into `a_result'
-- -- Note: it does include UTF-8 conversion of extended ASCII and Unicode.
-- do
-- if a_code <= 0x7F then
-- -- 0xxxxxxx
-- append_percent_encoded_ascii_character_code_to (a_code, a_result)
-- elseif a_code <= 0x7FF then
-- -- 110xxxxx 10xxxxxx
-- append_percent_encoded_ascii_character_code_to ((a_code |>> 6) | 0xC0, a_result)
-- append_percent_encoded_ascii_character_code_to ((a_code & 0x3F) | 0x80, a_result)
-- elseif a_code <= 0xFFFF then
-- -- 1110xxxx 10xxxxxx 10xxxxxx
-- append_percent_encoded_ascii_character_code_to ((a_code |>> 12) | 0xE0, a_result)
-- append_percent_encoded_ascii_character_code_to (((a_code |>> 6) & 0x3F) | 0x80, a_result)
-- append_percent_encoded_ascii_character_code_to ((a_code & 0x3F) | 0x80, a_result)
-- else
-- -- c <= 1FFFFF - there are no higher code points
-- -- 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-- append_percent_encoded_ascii_character_code_to ((a_code |>> 18) | 0xF0, a_result)
-- append_percent_encoded_ascii_character_code_to (((a_code |>> 12) & 0x3F) | 0x80, a_result)
-- append_percent_encoded_ascii_character_code_to (((a_code |>> 6) & 0x3F) | 0x80, a_result)
-- append_percent_encoded_ascii_character_code_to ((a_code & 0x3F) | 0x80, a_result)
-- end
-- ensure
-- appended: a_result.count > old a_result.count
-- end
-- hex_digit: SPECIAL [NATURAL_32]
-- -- Hexadecimal digits.
-- once
-- create Result.make_filled (0, 16)
-- Result [0] := {NATURAL_32} 48 -- 48 '0'
-- Result [1] := {NATURAL_32} 49 -- 49 '1'
-- Result [2] := {NATURAL_32} 50 -- 50 '2'
-- Result [3] := {NATURAL_32} 51 -- 51 '3'
-- Result [4] := {NATURAL_32} 52 -- 52 '4'
-- Result [5] := {NATURAL_32} 53 -- 53 '5'
-- Result [6] := {NATURAL_32} 54 -- 54 '6'
-- Result [7] := {NATURAL_32} 55 -- 55 '7'
-- Result [8] := {NATURAL_32} 56 -- 56 '8'
-- Result [9] := {NATURAL_32} 57 -- 57 '9'
-- Result [10] := {NATURAL_32} 65 -- 65 'A'
-- Result [11] := {NATURAL_32} 66 -- 66 'B'
-- Result [12] := {NATURAL_32} 67 -- 67 'C'
-- Result [13] := {NATURAL_32} 68 -- 68 'D'
-- Result [14] := {NATURAL_32} 69 -- 69 'E'
-- Result [15] := {NATURAL_32} 70 -- 70 'F'
-- end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others" copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"