note
	description: "UTF-32 encoding routines"
	library: "Gobo Eiffel Kernel Library"
	copyright: "Copyright (c) 2005-2018, Colin Adams and others"
	license: "MIT License"
	date: "$Date: 2019-02-07 22:54:15 +0000 (Thu, 07 Feb 2019) $"
	revision: "$Revision: 102807 $"

class interface
	UC_UTF32_ROUTINES

create 
	default_create

feature -- Status report

	valid_utf32 (a_string: STRING_8): BOOLEAN
			-- Are the bytes in a_string a valid UTF-32 encoding?
			-- 'a_string' has one byte per character.
			-- Default to big endian when no BOM.
		require
			a_string_not_void: a_string /= Void
			a_string_is_string: Any_.same_types (a_string, "")
		ensure
			instance_free: class
			empty_is_true: a_string.count = 0 implies Result
			utf32_count_multiple_of_four: Result implies ((a_string.count \\ 4) = 0)
	
feature -- Endian-ness detection

	Bom_be: STRING_8
			-- BOM in big-endian format
		ensure
			instance_free: class
			bom_be_not_void: Result /= Void
			four_bytes: Result.count = 4
			first_byte: Result.item_code (1) = 0
			second_byte: Result.item_code (2) = 0
			third_byte: Result.item_code (3) = Hex_fe
			fourth_byte: Result.item_code (4) = Hex_ff

	Bom_le: STRING_8
			-- BOM in little-endian format
		ensure
			instance_free: class
			bom_le_not_void: Result /= Void
			four_bytes: Result.count = 4
			first_byte: Result.item_code (1) = Hex_ff
			second_byte: Result.item_code (2) = Hex_fe
			third_byte: Result.item_code (3) = 0
			fourth_byte: Result.item_code (4) = 0

	is_endian_detection_character_most_first (first, second, third, fourth: INTEGER_32): BOOLEAN
			-- Do the four bytes represent the character
			-- 0xFEFF with first being the most significant byte?
		require
			first_is_byte: is_byte (first)
			second_is_byte: is_byte (second)
			third_is_byte: is_byte (third)
			fourth_is_byte: is_byte (fourth)
		ensure
			instance_free: class
			definition: Result = (first = 0 and second = 0 and third = Hex_fe and fourth = Hex_ff)

	is_endian_detection_character_least_first (first, second, third, fourth: INTEGER_32): BOOLEAN
			-- Do the four bytes represent the character
			-- 0xFEFF with first being the least significant byte?
		require
			first_is_byte: is_byte (first)
			second_is_byte: is_byte (second)
			third_is_byte: is_byte (third)
			fourth_is_byte: is_byte (fourth)
		ensure
			instance_free: class
			definition: Result = (first = Hex_ff and second = Hex_fe and third = 0 and fourth = 0)

	is_byte (a: INTEGER_32): BOOLEAN
			-- Is a a byte?
		ensure
			instance_free: class
			definition: Result = (a >= 0 and a < Hex_100)
	
feature -- Access

	code (first, second, third, fourth: INTEGER_32; least_endian: BOOLEAN): INTEGER_32
			-- Code point represented by four bytes
		require
			first_is_byte: is_byte (first)
			second_is_byte: is_byte (second)
			third_is_byte: is_byte (third)
			fourth_is_byte: is_byte (fourth)
		ensure
			instance_free: class
			code_not_negative: Result >= 0
	
end -- class UC_UTF32_ROUTINES

Generated by ISE EiffelStudio