For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > Re: Is there a way to dynamically determine (in 'c') if an Tcl_Obj is in fact a Unic









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Is there a way to dynamically determine (in 'c') if an Tcl_Obj is in fact a Unic
Joe English

2007-11-25, 7:18 pm

Todd Helfter wrote:
> [...]
> Is there a way to tell if the result from Tcl_GetUnicodeFromObj() is
> actually a unicode object, meaning that it cannot be represented
> accurately by a Tcl_GetStringFromObj().


The question as posed makes no sense; I suspect a
misunderstanding somewhere.

Tcl string values are *always* Unicode. More precisely: every
character in a Tcl string is interpreted as a code point
in the Unicode character repertoire.

Internally, the primary representation of a string --
the one you get back from Tcl_GetStringFromObj() --
is encoded in UTF-8, which is a multibyte encoding.

Tcl also uses a secondary, wide character representation
for some operations. The API and man pages incorrectly call
this the "Unicode" representation, but it's really UCS-2.
Tcl_GetUnicodeFromObj() returns a pointer to a (wide-character)
string in this representation.

Any sequence of Unicode characters drawn from the BMP can be
represented equally well in either of these representations.

> Inversely, if I have a pointer to an area of memory.. casting it as
> either as a (uchar) or a (char) is easy, but again is there an easy
> way to tell if such a thing is needed.


Depends on where the contents of the memory came from,
but you probably never need to cast. You may, however,
need to perform an encoding translation.

Tcl uses ByteArray objects to represent text in non-Unicode
encodings. You can use Tcl_ExternalToUtf to convert these
into Tcl string values.


--Joe English
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com