Hi Chengbiao,

On Thursday, 2009-02-26 17:21:45 +0800, Chengbiao Tan wrote:

> These days I am trying to implementate two related OpenFormula 
> UNICODE(Text T) and UNICHAR(Number N).

Nice to hear, welcome!

> According to the OOo native String class is implementated in UNICODE, 
> so I can use the String class's utilities to complete these functions.

Well, yes and no ;-)  While the current internal representation uses
class String (which actually is a define for class UniString), it uses
UTF-16 encoding. To implement the UNICODE() function for all required
Unicode points up to U+10FFFF, a method of class OUString comes handy:

    sal_uInt32 iterateCodePoints( sal_Int32 * indexUtf16,
                                  sal_Int32 incrementCodePoints = 1 ) const;

For a description of this method see rtl/ustring.hxx

class String and OUString have conversion ctors for each other and use
the same underlying data structure, so there's no problem using them.

For UNICHAR() a conversion from Unicode point to UTF-16 is needed, for
this use the OUString ctor

    OUString( const sal_Char * value, sal_Int32 length, rtl_TextEncoding 
encoding,
              sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS );

Use rtl_TextEncoding RTL_TEXTENCODING_UCS4 with a value buffer of one
sal_uInt32 casted down to sal_Char*, length sizeof(sal_uInt32).

> Would any one gives me some ideas about the implementation of these 
> functions. thanks! 

Hope that helps.

  Eike

-- 
 OOo/SO Calc core developer. Number formatter stricken i18n transpositionizer.
 SunSign   0x87F8D412 : 2F58 5236 DB02 F335 8304  7D6C 65C9 F9B5 87F8 D412
 OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
 Please don't send personal mail to the [email protected] account, which I use for
 mailing lists only and don't read from outside Sun. Use [email protected] Thanks.

Attachment: pgpTnVKbMNvbm.pgp
Description: PGP signature

Reply via email to