sl@0: /* sl@0: * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Contains the source for Descriptor to wstring conversions sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "libutils.h" sl@0: sl@0: sl@0: sl@0: /** sl@0: * Converts a descriptor of type Tptrc8 to Wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tptrc8ToWstring(TPtrC8& aSrc, wstring& aDes) sl@0: { sl@0: int retval = ESuccess; sl@0: int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* wcharString = new wchar_t[ilen+1]; sl@0: sl@0: if (!wcharString) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: wcharString[ilen] = L'\0'; sl@0: aDes.assign(wcharString); sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []wcharString; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TBuf8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tbuf8ToWstring(TDes8& aSrc, wstring& aDes) sl@0: { sl@0: int retval = ESuccess; sl@0: unsigned int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* wcharString = new wchar_t[ilen+1]; sl@0: sl@0: if (!wcharString) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: wcharString[ilen] = L'\0'; sl@0: aDes.assign(wcharString); sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []wcharString; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TBufC8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tbufc8ToWstring(TDesC8& aSrc, wstring& aDes) sl@0: { sl@0: sl@0: int retval = ESuccess; sl@0: unsigned int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* wcharString = new wchar_t[ilen+1]; sl@0: sl@0: if (!wcharString) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: wcharString[ilen] = L'\0'; sl@0: aDes.assign (wcharString); sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []wcharString; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type Tptr8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tptr8ToWstring(TPtr8& aSrc, wstring& aDes) sl@0: { sl@0: int retval= ESuccess; sl@0: unsigned int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* wcharString = new wchar_t[ilen+1]; sl@0: if (!wcharString) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(wcharString, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: wcharString[ilen] = L'\0'; sl@0: aDes.assign(wcharString); sl@0: } sl@0: else sl@0: { sl@0: retval= EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []wcharString; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type RBuf8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Rbuf8ToWstring(TDes8& aSrc, wstring& aDes) sl@0: { sl@0: int retval = ESuccess; sl@0: unsigned int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* buf = new wchar_t[ilen+1]; sl@0: if(!buf) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(buf, (char *)aSrc.Ptr(), ilen)) sl@0: { sl@0: buf[ilen] = L'\0'; sl@0: aDes.assign(buf); sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []buf; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type HBuf8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -4 is EInvalidPointer , -5 is EDescriptorNoData, -7 is EInvalidMBSSequence) sl@0: */ sl@0: sl@0: EXPORT_C int Hbufc8ToWstring(HBufC8* aSrc, wstring& aDes) sl@0: { sl@0: unsigned int ilen = 0; sl@0: int retval = ESuccess; sl@0: int minusone = -1; sl@0: sl@0: if (!aSrc) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else sl@0: { sl@0: ilen = aSrc->Length(); sl@0: if (0 == ilen ) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: } sl@0: sl@0: wchar_t* buff = new wchar_t[ilen+1]; sl@0: if (!buff) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(buff, (char *)aSrc->Ptr(), ilen)) sl@0: { sl@0: buff[ilen] = L'\0'; sl@0: aDes.assign(buff); sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []buff; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type Tlitc8 to wstring sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wstring array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -5 is EDescriptorNoData, -7 is EInvalidMBSSequence) sl@0: */ sl@0: sl@0: EXPORT_C int Tlitc8ToWstring(TDes8& aSrc, wstring& aDes) sl@0: { sl@0: int retval= ESuccess; sl@0: unsigned int ilen = aSrc.Length(); sl@0: int minusone = -1; sl@0: sl@0: if (0 == ilen) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: sl@0: wchar_t* wcharString = new wchar_t[ilen+1]; sl@0: if (!wcharString) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(wcharString, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: wcharString[ilen] = L'\0'; sl@0: aDes.assign(wcharString); sl@0: } sl@0: else sl@0: { sl@0: retval= EInvalidMBSSequence; sl@0: } sl@0: sl@0: delete []wcharString; sl@0: return retval; sl@0: } sl@0: