How to convert between TDes8 and TDes16

in

Conversion between TDes8 and TDes16 is a common headache in Symbian development. At least for developpers used to work with 8 bits character coding.

Symbian's CnvUtfConverter class is a powerful framework to handle character conversions to and from UTF8 (i.e TDes8). In most cases however, you only handle plain ASCII characters, using TDes8 to read/write to a file or a socket and TDes/TDes16 for the internal handling of the data. The following usage of CnvUtfConverter is suitable in this case (KErrNone is return in case of success, a positive value represents the number of aFrom characters not converted):

#include <utf.h> // charconv.lib

TInt NNewLCUtils::ConvertTDes8ToTDes16(const TDesC8& aFrom, TDes16& aTo)
{
 return(CnvUtfConverter::ConvertToUnicodeFromUtf8(aTo,aFrom));
}

TInt NNewLCUtils::ConvertTDes16ToTDes8(const TDesC16& aFrom, TDes8& aTo)
{
 return(CnvUtfConverter::ConvertFromUnicodeToUtf8(aTo,aFrom));
}

If you are dealing with UTF-7 (RFC-2152), you can also take a look at the ConvertFromUnicodeToUtf7 / ConvertFromUnicodeToUtf7 methods (note that there is no direct convesion between UTF-7 and UTF-8).


> How to convert between TDes8 and TDes16

Hi,

In most cases, just using the Copy() function of the descriptor is enough to convert TDes8 to TDes16 and vice-versa. I think the article should mention about this.

TBuf16 <100> a; TBuf8 <100> b;

b.Copy(a);

Very useful article anyway !

 berthier

> How to convert between TDes8 and TDes16

Thanks a lot Berthier,what you said really works and its simpler too.Had to burn my brain for an hour,then had the great idea of looking for it here on newlc.com

Thanks Again

> How to convert between TDes8 and TDes16

Thanks.. This made my life much more easier.. :P

> How to convert between TDes8 and TDes16

I tried this code TBuf16<100> a; TBuf8<100> b;

b.Copy(a)

i've included #include <utf.h> and have added charconv.lib and seem to be getting a link error.

Undefined Symbol: TParse::'TParse(void) (??0TParse@@QAE@XZ)'

Could anyone tell me what i'm missing?

Thanks.

> How to convert between TDes8 and TDes16

have you ever tried this function CnvUtfConverter::ConvertFromUnicodeToUtf8() successfully? i had a link error, "unresolved external link" while linking... and another function CnvUtfConverter::ConvertToUnicodeFromUtf8() works well here... i dont know why and guess probably its a corruption of charconv.lib. would you fellows like to verify that for me or give me some suggestions if you tried succesfully, regards!

> How to convert between TDes8 and TDes16

you need to link against charconv.lib