1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/utilitylibraries/libutils/src/descriptor16towstring.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +/*
1.5 +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Contains the source for Descriptor16 to wstring conversions
1.18 + *
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#include "libutils.h"
1.24 +
1.25 +
1.26 +
1.27 +
1.28 + /**
1.29 + * Converts a descriptor of type TPtrC16 to Wstring
1.30 + *
1.31 + * @param aSrc is the descriptor to be converted , aDes is the
1.32 + * reference to the Wstring array where the result of conversion
1.33 + * is stored
1.34 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.35 + * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
1.36 + */
1.37 +
1.38 +EXPORT_C int Tptrc16ToWstring(TPtrC16& aSrc, wstring& aDes)
1.39 +{
1.40 +
1.41 + unsigned int ilen = aSrc.Length();
1.42 + if (0 == ilen)
1.43 + {
1.44 + return EDescriptorNoData;
1.45 + }
1.46 +
1.47 + wchar_t* wcharString = new wchar_t[ilen+1];
1.48 + if (!wcharString)
1.49 + {
1.50 + return EInsufficientSystemMemory;
1.51 + }
1.52 +
1.53 + wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
1.54 + wcharString[ilen] = L'\0';
1.55 +
1.56 + aDes.assign(wcharString);
1.57 +
1.58 + delete []wcharString;
1.59 +
1.60 + return ESuccess;
1.61 +}
1.62 +
1.63 + /**
1.64 + * Converts a descriptor of type Tbuf16 to Wstring
1.65 + *
1.66 + * @param aSrc is the descriptor to be converted , aDes is the
1.67 + * reference to the Wstring array where the result of conversion
1.68 + * is stored
1.69 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.70 + * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
1.71 + */
1.72 +
1.73 +EXPORT_C int Tbuf16ToWstring(TDes16& aSrc, wstring& aDes)
1.74 +{
1.75 +
1.76 + unsigned int ilen = aSrc.Length();
1.77 + if (0 == ilen)
1.78 + {
1.79 + return EDescriptorNoData;
1.80 + }
1.81 +
1.82 + wchar_t* wcharString = new wchar_t[ilen+1];
1.83 + if (!wcharString)
1.84 + {
1.85 + return EInsufficientSystemMemory;
1.86 + }
1.87 +
1.88 + wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
1.89 + wcharString[ilen] = L'\0';
1.90 +
1.91 + aDes.assign(wcharString);
1.92 +
1.93 + delete []wcharString;
1.94 + return ESuccess;
1.95 +}
1.96 +
1.97 + /**
1.98 + * Converts a descriptor of type HBufc16 to Wstring
1.99 + *
1.100 + * @param aSrc is the descriptor to be converted , aDes is the
1.101 + * reference to the Wstring array where the result of conversion
1.102 + * is stored
1.103 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.104 + * -4 is EInvalidPointer , -5 is EDescriptorNoData)
1.105 + */
1.106 +EXPORT_C int Hbufc16ToWstring(HBufC16* aSrc, wstring& aDes)
1.107 +{
1.108 + unsigned int ilen = 0;
1.109 + if (!aSrc)
1.110 + {
1.111 + return EInvalidPointer;
1.112 + }
1.113 + else
1.114 + {
1.115 + ilen = aSrc->Length();
1.116 + if (0 == ilen )
1.117 + {
1.118 + return EDescriptorNoData;
1.119 + }
1.120 + }
1.121 +
1.122 + wchar_t* wcharString = new wchar_t[ilen+1];
1.123 + if (!wcharString)
1.124 + {
1.125 + return EInsufficientSystemMemory;
1.126 + }
1.127 +
1.128 + wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc->Ptr(), ilen);
1.129 + wcharString[ilen] = L'\0';
1.130 +
1.131 + aDes.assign(wcharString);
1.132 +
1.133 + delete []wcharString;
1.134 + return ESuccess;
1.135 +}
1.136 +
1.137 + /**
1.138 + * Converts a descriptor of type TPtr16 to Wstring
1.139 + *
1.140 + * @param aSrc is the descriptor to be converted , aDes is the
1.141 + * reference to the Wstring array where the result of conversion
1.142 + * is stored
1.143 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.144 + * -5 is EDescriptorNoData)
1.145 + */
1.146 +EXPORT_C int Tptr16ToWstring(TPtr16& aSrc, wstring& aDes)
1.147 +{
1.148 +
1.149 + unsigned int ilen = aSrc.Length();
1.150 +
1.151 + if (0 == ilen)
1.152 + {
1.153 + return EDescriptorNoData;
1.154 + }
1.155 +
1.156 + wchar_t* wcharString = new wchar_t[ilen+1];
1.157 + if (!wcharString)
1.158 + {
1.159 + return EInsufficientSystemMemory;
1.160 + }
1.161 +
1.162 + wmemcpy(wcharString, (wchar_t *)aSrc.Ptr(), ilen);
1.163 + wcharString[ilen] = L'\0';
1.164 +
1.165 + aDes.assign(wcharString);
1.166 +
1.167 + delete []wcharString;
1.168 + return ESuccess;
1.169 +}
1.170 +
1.171 +
1.172 + /**
1.173 + * Converts a descriptor of type RBuf16 to Wstring
1.174 + *
1.175 + * @param aSrc is the descriptor to be converted , aDes is the
1.176 + * reference to the Wstring array where the result of conversion
1.177 + * is stored
1.178 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.179 + * -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
1.180 + */
1.181 +EXPORT_C int Rbuf16ToWstring(TDes16& aSrc, wstring& aDes)
1.182 +{
1.183 + unsigned int ilen = aSrc.Length();
1.184 + if (0 == ilen)
1.185 + {
1.186 + return EDescriptorNoData;
1.187 + }
1.188 +
1.189 + wchar_t* buf = new wchar_t[ilen+1];
1.190 + if(!buf)
1.191 + {
1.192 + return EInsufficientSystemMemory;
1.193 + }
1.194 +
1.195 + wmemcpy (buf,(wchar_t *)aSrc.Ptr(), ilen);
1.196 + buf[ilen]=L'\0';
1.197 +
1.198 + aDes.assign(buf);
1.199 + delete[] buf;
1.200 +
1.201 + return ESuccess;
1.202 +}
1.203 +
1.204 + /**
1.205 + * Converts a descriptor of type TLitc16 to Wstring
1.206 + *
1.207 + * @param aSrc is the descriptor to be converted , aDes is the
1.208 + * reference to the Wstring array where the result of conversion
1.209 + * is stored
1.210 + * @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
1.211 + * -5 is EDescriptorNoData)
1.212 + */
1.213 +EXPORT_C int Tlitc16ToWstring(TDesC16& aSrc, wstring& aDes)
1.214 +{
1.215 +
1.216 + unsigned int ilen = aSrc.Length();
1.217 + if (0 == ilen)
1.218 + {
1.219 + return EDescriptorNoData;
1.220 + }
1.221 +
1.222 + wchar_t* wcharString = new wchar_t[ilen+1];
1.223 + if (!wcharString)
1.224 + {
1.225 + return EInsufficientSystemMemory;
1.226 + }
1.227 +
1.228 + wmemcpy((wchar_t*)wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
1.229 + wcharString[ilen] = L'\0';
1.230 +
1.231 + aDes.assign(wcharString);
1.232 +
1.233 + delete []wcharString;
1.234 + return ESuccess;
1.235 +}