Symbian 编码转换 GBK->Unicode 实现
2010-03-15 19:42:00 来源:WEB开发网核心提示:分享下void ConvGbk2Uni(const TDesC8& original, TDes& res){RFs rFile;rFile.Connect();CCnvCharacterSetConverter* converter=CCnvCharacterSetConverter::NewLC();if(conv
分享下
void ConvGbk2Uni(const TDesC8& original, TDes& res)
{
RFs rFile;
rFile.Connect();
CCnvCharacterSetConverter* converter=CCnvCharacterSetConverter::NewLC();
if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGbk,rFile)!=
CCnvCharacterSetConverter::EAvailable)
{
User::Leave(KErrNotSupported);
}
TInt state=CCnvCharacterSetConverter::KStateDefault;
TPtrC8 str( original );
HBufC* iInfoText = HBufC::NewL( str.Length() );
TPtr16 ptr = iInfoText->Des();
if(CCnvCharacterSetConverter::EErrorIllFormedInput ==
converter->ConvertToUnicode(ptr, str, state))
{
User::Leave(KErrArgument);
}
res.Zero() ;
res.Copy(ptr) ;
rFile.Close();
CleanupStack::PopAndDestroy();
delete iInfoText;
}
更多精彩
赞助商链接