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 Descriptor8 to wchar * 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 TBuf8 to wchar sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wchar array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tbuf8ToWchar(TDes8& aSrc, wchar_t* aDes, int& n_size) 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: else if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if(n_size < ilen+1) sl@0: { sl@0: n_size = ilen+1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: *(aDes + ilen) = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TBufc8 to wchar sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wchar array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tbufc8ToWchar(TDesC8& aSrc, wchar_t* aDes, int& n_size) 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: else if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if (n_size < ilen+1) sl@0: { sl@0: n_size = ilen+1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char *)aSrc.Ptr(), ilen)) sl@0: { sl@0: aDes[ilen] = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TLitc8 to wchar sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the wchar array where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tlitc8ToWchar( const TDesC8& aSrc, wchar_t* aDes, int& n_size) 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: else if ( !aDes ) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if (n_size < ilen+1) sl@0: { sl@0: n_size = ilen+1 ; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen )) sl@0: { sl@0: aDes[ilen] = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: *Converts a descriptor of type TPtr8 to Wchar sl@0: *@param aSrc is the descriptor to be converted , aDes is the sl@0: *reference to the wchar array where the result of conversion sl@0: *is stored sl@0: *@return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tptr8ToWcharp(const TPtr8& aSrc, wchar_t* aDes, int& n_size) 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: else if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if(n_size < ilen+1) sl@0: { sl@0: n_size = ilen+1 ; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: aDes[ilen] = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: *Converts a descriptor of type TPtrc to Wchar sl@0: * sl@0: *@param aSrc is the descriptor to be converted , aDes is the sl@0: *reference to the wchar array where the result of conversion sl@0: *is stored sl@0: *@return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Tptrc8ToWcharp(TPtrC8& aSrc, wchar_t* aDes, int& n_size) 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: else if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if(n_size < ilen) sl@0: { sl@0: n_size = ilen; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: aDes[ilen] = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: *Converts a descriptor of type Rbuf8 to Wchar sl@0: * sl@0: *@param aSrc is the descriptor to be converted , aDes is the sl@0: *reference to the wchar array where the result of conversion sl@0: *is stored sl@0: *@return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int Rbuf8ToWchar(TDes8& aSrc, wchar_t* aDes, int& n_size) 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: else if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if (n_size < ilen) sl@0: { sl@0: n_size = ilen + 1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen)) sl@0: { sl@0: *(aDes + ilen) = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: *Converts a descriptor of type Rbuf8 to Wchar sl@0: * sl@0: *@param aSrc is the descriptor to be converted , aDes is the sl@0: *reference to the wchar array where the result of conversion sl@0: *is stored sl@0: *@return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData) sl@0: */ sl@0: sl@0: EXPORT_C int HBufc8ToWchar(HBufC8* aSrc, wchar_t* aDes, int& n_size) sl@0: { sl@0: int retval = ESuccess; sl@0: unsigned int ilen = 0; sl@0: int minusone = -1; sl@0: sl@0: if(!aDes || !aSrc) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else sl@0: { sl@0: int ilen = aSrc->Length(); sl@0: if (0 == ilen ) sl@0: { sl@0: return EDescriptorNoData; sl@0: } sl@0: else if (n_size < ilen) sl@0: { sl@0: n_size = ilen + 1; sl@0: return EInvalidSize; sl@0: } sl@0: } sl@0: sl@0: if(minusone != mbstowcs(aDes, (const char*)aSrc->Ptr(), ilen)) sl@0: { sl@0: *(aDes + ilen) = L'\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidMBSSequence; sl@0: } sl@0: sl@0: return retval; sl@0: }