From: Colin A. <col...@go...> - 2008-04-21 14:17:23
|
Here is the functional version. It should be straight-forward to change it to a creation procedure. Note that it is liberal on the memory creation of l_bytes, to avoid any resizing of this buffer. utf8_string (a_string: STRING_GENERAL): UC_UTF8_STRING is -- UTF-8 encoded version of `a_string' require a_string_not_void: a_string /= Void local i: INTEGER_32 l_bytes: STRING do create l_bytes.make (a_string.count * 4) from i := 1 until i > a_string.count loop utf8.append_code_to_utf8 (l_bytes, a_string.code (i).as_integer_32) i := i + 1 end create Result.make_from_utf8 (l_bytes) ensure utf8_string_not_void: Result /= Void correct_count: Result.count = a_string.count strings_equal: True -- can't be checked as STRING_GENERAL and UC_STRING lack the facilities (`for_all') end |