note description: "Unicode characters" library: "Gobo Eiffel Kernel Library" copyright: "Copyright (c) 2001, Eric Bezault and others" license: "MIT License" date: "$Date: 2016-05-06 19:15:38 +0000 (Fri, 06 May 2016) $" revision: "$Revision: 98678 $" class UC_CHARACTER inherit KL_COMPARABLE redefine out end HASHABLE undefine is_equal, out end KL_SHARED_PLATFORM undefine is_equal, out end UC_IMPORTED_UNICODE_ROUTINES undefine is_equal, out end KL_IMPORTED_INTEGER_ROUTINES undefine is_equal, out end KL_IMPORTED_STRING_ROUTINES undefine is_equal, out end create make_from_character, make_from_code feature {NONE} -- Initialization make_from_character (c: CHARACTER_8) -- Create a new unicode character from Latin-1 character c. do code := c.code ensure code_set: code = c.code end make_from_code (a_code: INTEGER_32) -- Create a new unicode character with code a_code. require valid_code: Unicode.valid_code (a_code) do code := a_code ensure code_set: code = a_code end feature -- Access code: INTEGER_32 -- Code of unicode character hash_code: INTEGER_32 -- Hash code value do Result := code end feature -- Status report is_ascii: BOOLEAN -- Is current character an ASCII character? do Result := (code <= Unicode.Maximum_ascii_character_code) ensure definition: Result = Unicode.valid_ascii_code (code) end feature -- Comparison is_less alias "<" (other: like Current): BOOLEAN -- Is current object less than other? do Result := (code < other.code) end feature -- Conversion as_lower: like Current -- Lowercase value of current character -- (Create a new object at each call.) -- Was declared in UC_CHARACTER as synonym of to_lower. do create Result.make_from_code (Unicode.lower_code (code)) ensure to_lower_not_void: Result /= Void end to_lower: like Current -- Lowercase value of current character -- (Create a new object at each call.) -- Was declared in UC_CHARACTER as synonym of as_lower. do create Result.make_from_code (Unicode.lower_code (code)) ensure to_lower_not_void: Result /= Void end as_upper: like Current -- Uppercase value of current character -- (Create a new object at each call.) -- Was declared in UC_CHARACTER as synonym of to_upper. do create Result.make_from_code (Unicode.upper_code (code)) ensure to_upper_not_void: Result /= Void end to_upper: like Current -- Uppercase value of current character -- (Create a new object at each call.) -- Was declared in UC_CHARACTER as synonym of as_upper. do create Result.make_from_code (Unicode.upper_code (code)) ensure to_upper_not_void: Result /= Void end to_character: CHARACTER_8 -- Character with code code require valid_code: code <= Platform.Maximum_character_code do Result := Integer_.to_character (code) ensure code_set: Result.code = code end feature -- Output out: STRING_8 -- New STRING containing terse printable representation -- of current character; Non-ascii characters are represented -- with the %/code/ convention. local max_ascii_code: INTEGER_32 code_out: STRING_8 do max_ascii_code := Unicode.Maximum_ascii_character_code if code <= max_ascii_code then create Result.make (1) Result.append_character (Integer_.to_character (code)) else code_out := code.out create Result.make (3 + code_out.count) Result.append_character ('%%') Result.append_character ('/') Result.append_string (code_out) Result.append_character ('/') end end invariant valid_code: Unicode.valid_code (code) end -- class UC_CHARACTER
Generated by ISE EiffelStudio