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 char * 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 TBuf16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer, -8 is EInvalidWCSSequence) sl@0: */ sl@0: EXPORT_C int Tbuf16ToChar(TDes16& aSrc, char* aDes, int& n_size) sl@0: { sl@0: unsigned int ilen = aSrc.Length(); sl@0: int retval = ESuccess; sl@0: wchar_t *temp16String = NULL; 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: sl@0: else if(n_size < ilen*2+1) sl@0: { sl@0: n_size = ilen*2; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, (const wchar_t*)temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TBufC16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer, -5 is EDescriptorNoData sl@0: * -8 is EInvalidWCSSequence) sl@0: */ sl@0: EXPORT_C int Tbufc16ToChar(TDesC& aSrc, char* aDes, int& n_size) sl@0: { sl@0: int retval = ESuccess; sl@0: unsigned int ilen = 0 ; sl@0: ilen = aSrc.Length(); sl@0: wchar_t* temp16String = NULL; 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*2+1) sl@0: { sl@0: n_size = ilen*2 + 1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, (const wchar_t*)temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TLitc16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -2 is EInvalidSize sl@0: * -3 is EDescriptorNoData , -4 is EInvalidPointer, -8 is EInvalidWCSSequence) sl@0: */ sl@0: sl@0: EXPORT_C int Tlitc16ToChar(const TDesC16& aSrc, char* aDes, int& n_size) sl@0: { sl@0: unsigned int ilen = 0; sl@0: int retval = ESuccess; sl@0: ilen = aSrc.Length(); sl@0: wchar_t* temp16String = NULL; 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*2 +1) sl@0: { sl@0: n_size = ilen*2 + 1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String, (const wchar_t*)aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TPtr16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer, -8 is EInvalidWCSSequence) sl@0: */ sl@0: sl@0: EXPORT_C int Tptr16ToCharp (const TDes16& aSrc, char* aDes, int& n_size) sl@0: { sl@0: unsigned int ilen = 0 ; sl@0: int retval = ESuccess; sl@0: ilen = aSrc.Length(); sl@0: wchar_t* temp16String = NULL; sl@0: int minusone = -1; sl@0: sl@0: if ( !aDes ) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if (n_size < ilen*2+1) sl@0: { sl@0: n_size = ilen*2 + 1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type TPtrC16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer) sl@0: */ sl@0: sl@0: EXPORT_C int Tptrc16ToCharp(TPtrC16& aSrc, char* 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: wchar_t* temp16String = NULL; sl@0: sl@0: if(!aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else if (n_size < ilen*2+1) sl@0: { sl@0: n_size = ilen*2+1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String, (const wchar_t *)aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: } sl@0: sl@0: /** sl@0: * Converts a descriptor of type RBuf16 to character stream sl@0: * sl@0: * @param aSrc is the descriptor to be converted , aDes is the sl@0: * reference to the character sream where the result of conversion sl@0: * is stored , n_size specifies the conversion size of the string sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -2 is EInvalidSize , -4 is EInvalidPointer) sl@0: */ sl@0: sl@0: EXPORT_C int Rbuf16ToChar(TDes16& aSrc, char* aDes, int& n_size) sl@0: { sl@0: unsigned int ilen = aSrc.Length(); sl@0: int retval = ESuccess; sl@0: wchar_t* temp16String = NULL; 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*2+1) sl@0: { sl@0: n_size = ilen*2+1; sl@0: return EInvalidSize; sl@0: } sl@0: sl@0: temp16String = new wchar_t [ilen+1]; sl@0: if (!temp16String) sl@0: { sl@0: return EInsufficientSystemMemory; sl@0: } sl@0: sl@0: wmemcpy(temp16String,(const wchar_t *) aSrc.Ptr(), ilen); sl@0: temp16String[ilen] = L'\0'; sl@0: sl@0: if(minusone != wcstombs(aDes, temp16String, ilen*2)) sl@0: { sl@0: aDes[ilen*2] = '\0'; sl@0: } sl@0: else sl@0: { sl@0: retval = EInvalidWCSSequence; sl@0: } sl@0: sl@0: delete []temp16String; sl@0: return retval; sl@0: }