[cfe-dev] Constant CF/NSString and Unicode
Jean-Daniel Dupas
devlists at shadowlab.org
Wed Jul 9 23:50:55 PDT 2008
Le 10 juil. 08 à 07:56, Chris Lattner a écrit :
>
> On Jul 9, 2008, at 4:10 PM, Jean-Daniel Dupas wrote:
>> I just wonder if there is some kind of unicode support in
>> __builtin___CFStringMakeConstantString.
>
> In GCC or clang? Clang doesn't have any unicode support yet.
>
>> In the current GCC version, when you compile an objc file, constant
>> strings that contains non-ascii chars are converted into utf-16
>> strings and a flag is set into the generated CFString.
>
> Ok. Fariborz implemented that fwiw.
>
>> The fact that it works only for objc file look more like a design
>> decision than a technical limit, and this feature can easily be
>> extended to c files. In fact, I managed to implement this feature in
>> cc1 and it look like it works. (if I'm wrong, feel free to correct
>> me).
>>
>> And what about clang and unicode CFString ?
>
> I'm not sure what you mean, can you explain a bit more?
>
> -Chris
Yep,
put this simple code snippet in cfstring.c :
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, char **argv) {
CFShowStr(CFSTR("hé hé hé"));
CFShow(CFSTR("hé hé hé"));
return 0;
}
if you compile this file using "gcc -o cfstring cfstring.c -framework
CoreFoundation" and run it you got:
Length 11
IsEightBit 1
HasLengthByte 0
HasNullByte 1
InlineContents 0
Allocator SystemDefault
Mutable 0
Contents 0x1ff2
h\u221a\u00a9 h\u221a\u00a9 h\u221a\u00a9
Now, if you compile this same file using
gcc -x objective-c -o cfstring cfstring.c -framework CoreFoundation
the output is:
Length 8
IsEightBit 0
HasLengthByte 0
HasNullByte 0
InlineContents 0
Allocator SystemDefault
Mutable 0
Contents 0x1fee
h\u00e9 h\u00e9 h\u00e9
Maybe I miss something, but I really do not understand the current
limitation.
As clang will probably implements this feature some day, I just wonder
if it should duplicate the GCC behavior (emitting a warning and
generating an ascii based CFString) or if it can be extended to
support also UTF-16 CFString generation in plain C file.
More information about the cfe-dev
mailing list