views:

462

answers:

2

Hi! I'm using Carbide.c++ 2.0 to create a S60 application that consumes my own webservice. I've used the Yahoo! Image Search example as a starting point and data is shipped back and forth nicely. Problems occur when there are non-english characters in the reply so the text presented to the user in the listbox is incorrect. The XML-document the webservice replies with is UTF8 encoded and when it's parsed the text is presented in a TDesC8 parameter to a function.

  1. What datatype should I use to store the UTF8 text?
  2. How do I convert UTF8 encoded text stored in a TDesC8 variable/parameter to a variable of the datatype above?
  3. Are there perhaps other methods in the Xml-class that I can implement in order to get a differend datatype of the parameter?
+3  A: 
  1. S60 is using 16-bit unicode characters. So any subclass of TDesC16 will do.
  2. Use the native charconv library. Include charconv.h, link with charconv.lib and call e.g. CnvUtfConverter::ConvertToUnicodeFromUtf8().
  3. Depends on which "Xml-class" you are talking about.
laalto
The problem here is that the UTF8 encoded text is stored in a 8-bit string and the non-english characters takes up two characters so the convertion doesn't correct the text.I tried to change the iFeedText variable from RBuf8 to RBuf16 but the Xml::ParseL() could not take a RBuf16 as a parameter.
Karl-Otto Rosenqvist
+3  A: 

You do not state which "XML-class" you are using so it is kind of difficult to say if there are any other methods you can use.

As laalto said in his reply the answer is to use the static CnvUtfConverter::ConvertToUnicodeFromUtf8 or CnvUtfConverter::ConvertToUnicodeFromUtf8L functions:

TDesC8& utf8_from_xml = getUtf8String(); //get the utf8 string somehow
HBufC16* unicode_string = CnvUtfConverter::ConvertToUnicodeFromUtf8L(utf8_from_xml);
CleanupStack::PushL(unicode_string);

There are other variants of CnvUtfConverter::ConvertToUnicodeFromUtf8 which give you more options and results.

Googling CnvUtfConverter::ConvertToUnicodeFromUtf8 will show you several examples on how to use CnvUtfConverter::ConvertToUnicodeFromUtf8.

Ola