Code to create a UC_UTF8_STRING from STRING_GENERAL

"Colin Adams" <[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.devel
Message-ID <[email protected]>
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

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.