« Return to Thread: Code to create a UC_UTF8_STRING from STRING_GENERAL

Code to create a UC_UTF8_STRING from STRING_GENERAL

by Colin Adams-3 :: Rate this Message:

Reply to Author | View in Thread

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
_______________________________________________
gobo-eiffel-develop mailing list
gobo-eiffel-develop@...
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop

 « Return to Thread: Code to create a UC_UTF8_STRING from STRING_GENERAL

LightInTheBox - Buy quality products at wholesale price