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 wchar * to Descriptor16 conversions sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "libutils.h" sl@0: sl@0: sl@0: /** sl@0: * Converts a wchar to a descriptor of type TBufc16 sl@0: * sl@0: * @param aSrc is the wchar to be converted , aDes is the sl@0: * reference to the descriptor where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess,-1 is EInsufficientMemory, sl@0: * -3 is EStringNoData, -4 is EInvalidPointer ) sl@0: */ sl@0: sl@0: sl@0: EXPORT_C int WcharToTbuf16(const wchar_t* aSrc, TDes16& aDes) sl@0: { sl@0: unsigned int ilen = 0; sl@0: if ( !aSrc ) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: else sl@0: { sl@0: ilen = wcslen(aSrc); sl@0: if(ilen > aDes.MaxLength()) sl@0: { sl@0: return EInsufficientMemory; sl@0: } sl@0: } sl@0: sl@0: aDes.Copy((const TUint16*)aSrc, ilen); sl@0: return ESuccess; sl@0: } sl@0: /** sl@0: * Converts a wchar to a descriptor of type HBufc16 sl@0: * sl@0: * @param aSrc is the Wstring to be converted , aDes is the sl@0: * reference to the descriptor where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, sl@0: * -3 is EStringNoData, -6 is EUseNewMaxL ) sl@0: */ sl@0: sl@0: EXPORT_C int WcharToHbufc16 (const wchar_t* aSrc ,HBufC16* aDes ) sl@0: { sl@0: sl@0: unsigned int ilendes = 0; sl@0: if ( !aSrc || !aDes) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: sl@0: ilendes = aDes->Length(); sl@0: sl@0: if (0 == ilendes) sl@0: { sl@0: return EUseNewMaxL; sl@0: } sl@0: else if (ilendes < wcslen(aSrc)) sl@0: { sl@0: return EInsufficientMemory; sl@0: } sl@0: sl@0: *aDes = (const TUint16*)aSrc; sl@0: return ESuccess; sl@0: } sl@0: sl@0: /** sl@0: * Converts a wchar to a descriptor of type TPtr16 sl@0: * sl@0: * @param aSrc is the wchar to be converted , aDes is the sl@0: * reference to the descriptor where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess,-1 is EInsufficientMemory, sl@0: * -3 is EStringNoData, -4 is EInvalidPointer ) sl@0: */ sl@0: sl@0: EXPORT_C int WcharpToTptr16(const wchar_t* aSrc, TPtr16& aDes) sl@0: { sl@0: unsigned int ilen = 0, ilendes = 0; sl@0: if ( !aSrc ) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: sl@0: ilen = wcslen(aSrc); sl@0: ilendes = aDes.MaxLength(); sl@0: sl@0: if (ilendes < ilen) sl@0: { sl@0: return EInsufficientMemory; sl@0: } sl@0: sl@0: aDes.Set((unsigned short*) aSrc, ilen, ilendes); sl@0: sl@0: return ESuccess; sl@0: } sl@0: sl@0: /** sl@0: * Converts a wchar to a descriptor of type TPtrC16 sl@0: * sl@0: * @param aSrc is the wchar to be converted , aDes is the sl@0: * reference to the descriptor where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess,-1 is EInsufficientMemory, sl@0: * -3 is EStringNoData, -4 is EInvalidPointer ) sl@0: */ sl@0: EXPORT_C int WcharpToTptrc16(const wchar_t* aSrc, TPtrC16& aDes) sl@0: sl@0: { sl@0: if (!aSrc) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: sl@0: aDes.Set((TUint16 *)(aSrc), wcslen(aSrc)); sl@0: sl@0: return ESuccess; sl@0: } sl@0: sl@0: /** sl@0: * Converts a wchar to a descriptor of type RBuf16 sl@0: * sl@0: * @param aSrc is the wchar to be converted , aDes is the sl@0: * reference to the descriptor where the result of conversion sl@0: * is stored sl@0: * @return Status code (0 is ESuccess ,-1 is EInsufficientMemory, sl@0: * -3 is EStringNoData, -4 is EInvalidPointer ) sl@0: */ sl@0: sl@0: EXPORT_C int WcharToRbuf16(const wchar_t* aSrc, RBuf16& aDes) sl@0: { sl@0: sl@0: int retval = ESuccess; sl@0: unsigned int wlen = 0; sl@0: if ( !aSrc ) sl@0: { sl@0: return EInvalidPointer; sl@0: } sl@0: sl@0: wlen = wcslen(aSrc); sl@0: sl@0: aDes.Copy((const unsigned short *)aSrc, wlen); sl@0: sl@0: return retval; sl@0: }