note description: "Eiffel implementations for Unicode encoding conversion." legal: "See notice at end of class." status: "See notice at end of class." date: "$Date: 2020-05-20 11:14:50 +0000 (Wed, 20 May 2020) $" revision: "$Revision: 104299 $" class interface UNICODE_CONVERSION create {ENCODING} default_create feature -- Query is_code_page_valid (a_code_page: READABLE_STRING_8): BOOLEAN -- Is a_code_page valid? is_code_page_convertible (a_from_code_page, a_to_code_page: READABLE_STRING_8): BOOLEAN -- Is a_from_code_page convertible to a_to_code_page. Last_conversion_lost_data: BOOLEAN = False -- Has last conversion between two encodings lost data? is_valid_utf8 (a_string: READABLE_STRING_8): BOOLEAN -- Is a_string valid UTF-8 string? require a_string_not_void: a_string /= Void is_valid_as_string_16 (a_string: READABLE_STRING_GENERAL): BOOLEAN -- Check high 16 bit of any char in a_string is zero. feature -- Conversion convert_to (a_from_code_page: READABLE_STRING_8; a_from_string: READABLE_STRING_GENERAL; a_to_code_page: READABLE_STRING_8) -- Convert between Unicode encodings. feature -- Explicit Conversion utf8_to_utf32 (a_string: READABLE_STRING_8): STRING_32 -- UTF8 to UTF32 conversion, Eiffel implementation. require a_string_not_void: a_string /= Void ensure result_not_void: Result /= Void utf32_to_utf8 (a_string: READABLE_STRING_32): STRING_8 -- Convert UTF32 to UTF8. require a_string_not_void: a_string /= Void ensure result_not_void: Result /= Void utf32_to_utf16 (a_str: READABLE_STRING_32): STRING_32 -- Convert utf32 to utf16 without data lose. require a_str_not_void: a_str /= Void ensure instance_free: class result_not_void: Result /= Void utf16_to_utf32 (a_str: READABLE_STRING_32): STRING_32 -- Convert utf16 to utf32. require a_str_not_void: a_str /= Void ensure instance_free: class result_not_void: Result /= Void append_code_point_to_utf8 (a_code: NATURAL_32; a_string: STRING_8) -- Append a Unicode code point a_code to a UTF-8 stream. require a_string_not_void: a_string /= Void a_code_is_valid: a_code >= 0 and then a_code <= 1114111 ensure a_string_appended: (a_code <= 127 implies a_string.count = old a_string.count + 1) and ((a_code > 127 and a_code <= 2047) implies a_string.count = old a_string.count + 2) and ((a_code > 2047 and a_code <= 65535) implies a_string.count = old a_string.count + 3) and ((a_code > 65535 and a_code <= 1114111) implies a_string.count = old a_string.count + 4) read_character_from_utf8 (a_position: INTEGER_32; a_read_bytes: detachable INTEGER_32_REF; a_string: READABLE_STRING_8): CHARACTER_32 -- Read a Unicode character from UTF-8 string. -- a_string is in UTF-8. -- a_position is the starting byte point of a character. -- a_read_bytes is the number of bytes read. require a_string_not_void: a_string /= Void a_position_in_range: a_position > 0 and a_position <= a_string.count a_position_valid: a_string.code (a_position).to_natural_8 <= 127 or (a_string.code (a_position).to_natural_8 & 224) = 192 or (a_string.code (a_position).to_natural_8 & 240) = 224 or (a_string.code (a_position).to_natural_8 & 248) = 240 or (a_string.code (a_position).to_natural_8 & 252) = 248 or (a_string.code (a_position).to_natural_8 & 254) = 252 note library: "Encoding: Library of reusable components for Eiffel." copyright: "Copyright (c) 1984-2020, 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 -- class UNICODE_CONVERSION
Generated by ISE EiffelStudio