0

I need to understand the behavior of UNICODE_STRING_SIMPLE macro when using '\uhhhh'

I have the following code:

cout<<"Char print out for À"<<endl;
SCAUString us = UNICODE_STRING_SIMPLE ("À");
cout<<"us.countChar32()="<<us.countChar32()<<endl;
for (int i=0; i<us.countChar32(); i++)
  cout<<(int)us.charAt(i)<<" ";

output: us.countChar32()=2 195 8364

But the following gives a different answer: \u00C0 is À

cout<<"\nChar print out for \\u00C0"<<endl;
us = UNICODE_STRING_SIMPLE ("\u00C0");
cout<<"us.countChar32()="<<us.countChar32()<<endl;
for (int i=0; i<us.countChar32(); i++)
  cout<<(int)us.charAt(i)<<" ";

the output here is: us.length()=1 192

Can anyone explain why the difference is?

I wrote to a file using ustream.h:

testFile<<"5:"<< UNICODE_STRING_SIMPLE ("À"); // needs ustream.h
testFile<<endl;
testFile<<"6:"<< UNICODE_STRING_SIMPLE ("\u00C0"); // needs ustream.h
testFile<<endl;

testFile is an ofstream. When I open the I see 5:À but 6 is wrong: 6:� I opened the text file in Visual Studio and that's the actual character VS showed me.

Dula
  • 1,404
  • 1
  • 14
  • 29

1 Answers1

0

What's a SCAUString?

The \u (single backslash) is interpreted by your compiler. Perhaps the compiler doesn't think that the target codepage is the same as ICU expects?

Try this:

printf("%x or %x?\n", (int)'À', (int)'\u00C0');

Steven R. Loomis
  • 4,228
  • 28
  • 39