sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description: Contains the source for Descriptor16 to string conversions
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "libutils.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
/**
|
sl@0
|
25 |
* Converts a descriptor of type TBuf16 to string datatype
|
sl@0
|
26 |
*
|
sl@0
|
27 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
28 |
* reference to the string to which the result of conversion
|
sl@0
|
29 |
* is stored ,
|
sl@0
|
30 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory)
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
|
sl@0
|
33 |
EXPORT_C int Tbuf16ToString(TDes16& aSrc, string& aDes)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
36 |
int retval = ESuccess;
|
sl@0
|
37 |
int minusone = -1;
|
sl@0
|
38 |
char* charString = new char[ilen*2+1];
|
sl@0
|
39 |
|
sl@0
|
40 |
if (!charString)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
return EInsufficientSystemMemory;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
46 |
|
sl@0
|
47 |
if (!wcharString)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
delete []charString;
|
sl@0
|
50 |
return EInsufficientSystemMemory;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
54 |
wcharString[ilen] = L'\0';
|
sl@0
|
55 |
|
sl@0
|
56 |
if(minusone != wcstombs(charString, wcharString, ilen*2))
|
sl@0
|
57 |
{
|
sl@0
|
58 |
charString[ilen*2] = '\0';
|
sl@0
|
59 |
aDes.assign(charString);
|
sl@0
|
60 |
}
|
sl@0
|
61 |
else
|
sl@0
|
62 |
{
|
sl@0
|
63 |
retval = EInvalidWCSSequence;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
delete []charString;
|
sl@0
|
67 |
delete []wcharString;
|
sl@0
|
68 |
|
sl@0
|
69 |
return retval;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
/**
|
sl@0
|
73 |
* Converts a descriptor of type TBufC16 to string datatype
|
sl@0
|
74 |
*
|
sl@0
|
75 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
76 |
* reference to the string to which the result of conversion
|
sl@0
|
77 |
* is stored ,
|
sl@0
|
78 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory)
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
|
sl@0
|
81 |
EXPORT_C int Tbufc16ToString(TDesC16& aSrc, string& aDes)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
int ilen = aSrc.Length(), retval = ESuccess;
|
sl@0
|
84 |
int minusone = -1;
|
sl@0
|
85 |
char* charString = new char[ilen*2+1];
|
sl@0
|
86 |
|
sl@0
|
87 |
if (!charString)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
return EInsufficientSystemMemory;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
93 |
|
sl@0
|
94 |
if (!wcharString)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
delete []charString;
|
sl@0
|
97 |
return EInsufficientSystemMemory;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
101 |
wcharString[ilen] = L'\0';
|
sl@0
|
102 |
|
sl@0
|
103 |
if(minusone != wcstombs(charString, wcharString, ilen*2))
|
sl@0
|
104 |
{
|
sl@0
|
105 |
charString[ilen*2] = '\0';
|
sl@0
|
106 |
aDes.assign(charString);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
else
|
sl@0
|
109 |
{
|
sl@0
|
110 |
retval = EInvalidWCSSequence;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
delete []charString;
|
sl@0
|
114 |
delete []wcharString;
|
sl@0
|
115 |
|
sl@0
|
116 |
return retval;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
/**
|
sl@0
|
120 |
* Converts a descriptor of type TPtr16 to string datatype
|
sl@0
|
121 |
*
|
sl@0
|
122 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
123 |
* reference to the string to which the result of conversion
|
sl@0
|
124 |
* is stored ,
|
sl@0
|
125 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory)
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
|
sl@0
|
128 |
EXPORT_C int Tptr16ToString (TDes16& aSrc, string& aDes)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
int retval = ESuccess;
|
sl@0
|
131 |
unsigned int ilen= aSrc.Length();
|
sl@0
|
132 |
int minusone = -1;
|
sl@0
|
133 |
char* charString = new char[ilen*2+1];
|
sl@0
|
134 |
|
sl@0
|
135 |
if (!charString)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
return EInsufficientSystemMemory;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
140 |
|
sl@0
|
141 |
if (!wcharString)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
delete []charString;
|
sl@0
|
144 |
return EInsufficientSystemMemory;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
148 |
wcharString[ilen] = L'\0';
|
sl@0
|
149 |
|
sl@0
|
150 |
|
sl@0
|
151 |
if(minusone != wcstombs(charString, wcharString, ilen*2))
|
sl@0
|
152 |
{
|
sl@0
|
153 |
charString[ilen*2] = '\0';
|
sl@0
|
154 |
aDes.assign(charString);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
else
|
sl@0
|
157 |
{
|
sl@0
|
158 |
retval = EInvalidWCSSequence;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
delete []charString;
|
sl@0
|
162 |
delete []wcharString;
|
sl@0
|
163 |
|
sl@0
|
164 |
return retval;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
/**
|
sl@0
|
168 |
* Converts a descriptor of type TPtrC16 to string datatype
|
sl@0
|
169 |
*
|
sl@0
|
170 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
171 |
* reference to the string to which the result of conversion
|
sl@0
|
172 |
* is stored ,
|
sl@0
|
173 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory)
|
sl@0
|
174 |
*/
|
sl@0
|
175 |
|
sl@0
|
176 |
EXPORT_C int Tptrc16ToString (const TDesC16& aSrc, string& aDes)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
int retval = ESuccess;
|
sl@0
|
179 |
int ilen= aSrc.Length();
|
sl@0
|
180 |
int minusone = -1;
|
sl@0
|
181 |
char* buf = new char[ilen*2 +1];
|
sl@0
|
182 |
|
sl@0
|
183 |
if (!buf)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
return EInsufficientSystemMemory;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
189 |
|
sl@0
|
190 |
if (!wcharString)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
delete []buf;
|
sl@0
|
193 |
return EInsufficientSystemMemory;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
197 |
wcharString[ilen] = L'\0';
|
sl@0
|
198 |
|
sl@0
|
199 |
if(minusone != wcstombs(buf, wcharString, ilen*2))
|
sl@0
|
200 |
{
|
sl@0
|
201 |
buf[ilen*2] = '\0';
|
sl@0
|
202 |
aDes.assign(buf);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
else
|
sl@0
|
205 |
{
|
sl@0
|
206 |
retval = EInvalidWCSSequence;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
delete []buf;
|
sl@0
|
210 |
delete []wcharString;
|
sl@0
|
211 |
|
sl@0
|
212 |
return retval;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
* Converts a descriptor of type HbufC16 to string datatype
|
sl@0
|
217 |
*
|
sl@0
|
218 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
219 |
* reference to the string to which the result of conversion
|
sl@0
|
220 |
* is stored , n_size specifies the conversion size of the string
|
sl@0
|
221 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory)
|
sl@0
|
222 |
* -2 is EInvalidSize , -5 is EDescriptorNoData)
|
sl@0
|
223 |
*/
|
sl@0
|
224 |
|
sl@0
|
225 |
EXPORT_C int Hbufc16ToString(HBufC16* aSrc, string& aDes, int& n_size)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
int retval = ESuccess;
|
sl@0
|
228 |
unsigned int ilen=0;
|
sl@0
|
229 |
int minusone = -1;
|
sl@0
|
230 |
|
sl@0
|
231 |
if(!aSrc)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
return EInvalidPointer;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
else
|
sl@0
|
236 |
{
|
sl@0
|
237 |
ilen = aSrc->Size();
|
sl@0
|
238 |
if (0 == ilen)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
return EDescriptorNoData;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
else if (n_size < ilen)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
n_size = ilen;
|
sl@0
|
245 |
return EInvalidSize;
|
sl@0
|
246 |
}
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
char* buf = new char[ilen*2 +1];
|
sl@0
|
250 |
|
sl@0
|
251 |
if (!buf)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
return EInsufficientSystemMemory;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
257 |
|
sl@0
|
258 |
if (!wcharString)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
delete []buf;
|
sl@0
|
261 |
return EInsufficientSystemMemory;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
wmemcpy(wcharString, (const wchar_t*)aSrc->Ptr(), ilen);
|
sl@0
|
265 |
wcharString[ilen] = L'\0';
|
sl@0
|
266 |
|
sl@0
|
267 |
|
sl@0
|
268 |
if(minusone != wcstombs(buf, wcharString, ilen*2))
|
sl@0
|
269 |
{
|
sl@0
|
270 |
buf[ilen*2] = '\0';
|
sl@0
|
271 |
aDes.assign(buf, ilen*2);
|
sl@0
|
272 |
|
sl@0
|
273 |
}
|
sl@0
|
274 |
else
|
sl@0
|
275 |
{
|
sl@0
|
276 |
retval = EInvalidWCSSequence;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
delete []buf;
|
sl@0
|
280 |
delete []wcharString;
|
sl@0
|
281 |
|
sl@0
|
282 |
return retval;
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
/**
|
sl@0
|
286 |
* Converts a descriptor of type RBuf16 to string datatype
|
sl@0
|
287 |
*
|
sl@0
|
288 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
289 |
* reference to the string to which the result of conversion
|
sl@0
|
290 |
* is stored ,
|
sl@0
|
291 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory
|
sl@0
|
292 |
* -5 is EDescriptorNoData)
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
|
sl@0
|
295 |
EXPORT_C int Rbuf16ToString(TDes16& aSrc, string& aDes)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
298 |
int retval = ESuccess ;
|
sl@0
|
299 |
int minusone = -1;
|
sl@0
|
300 |
if (0 == ilen)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
return EDescriptorNoData;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
|
sl@0
|
305 |
char* buf = new char[ilen*2 +1];
|
sl@0
|
306 |
|
sl@0
|
307 |
if (!buf)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
return EInsufficientSystemMemory;
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
313 |
|
sl@0
|
314 |
if (!wcharString)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
delete []buf;
|
sl@0
|
317 |
return EInsufficientSystemMemory;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
321 |
wcharString[ilen] = L'\0';
|
sl@0
|
322 |
|
sl@0
|
323 |
|
sl@0
|
324 |
if(minusone != wcstombs(buf, wcharString, ilen*2))
|
sl@0
|
325 |
{
|
sl@0
|
326 |
buf[ilen*2] = '\0';
|
sl@0
|
327 |
aDes.assign(buf, ilen*2);
|
sl@0
|
328 |
|
sl@0
|
329 |
}
|
sl@0
|
330 |
else
|
sl@0
|
331 |
{
|
sl@0
|
332 |
retval = EInvalidWCSSequence;
|
sl@0
|
333 |
}
|
sl@0
|
334 |
|
sl@0
|
335 |
delete []buf;
|
sl@0
|
336 |
delete []wcharString;
|
sl@0
|
337 |
|
sl@0
|
338 |
return retval;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
/**
|
sl@0
|
342 |
* Converts a descriptor of type TLit16 to string datatype
|
sl@0
|
343 |
*
|
sl@0
|
344 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
345 |
* reference to the string to which the result of conversion
|
sl@0
|
346 |
* is stored ,
|
sl@0
|
347 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory
|
sl@0
|
348 |
* -5 is EDescriptorNoData)
|
sl@0
|
349 |
*/
|
sl@0
|
350 |
|
sl@0
|
351 |
EXPORT_C int Tlit16ToString(const TDesC16& aSrc, string& aDes)
|
sl@0
|
352 |
{
|
sl@0
|
353 |
unsigned int ilen = 0;
|
sl@0
|
354 |
int retval = ESuccess;
|
sl@0
|
355 |
ilen = aSrc.Length();
|
sl@0
|
356 |
int minusone = -1;
|
sl@0
|
357 |
|
sl@0
|
358 |
if (0 == ilen)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
return EDescriptorNoData;
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
char* buf = new char[ilen*2 +1];
|
sl@0
|
364 |
|
sl@0
|
365 |
if (!buf)
|
sl@0
|
366 |
{
|
sl@0
|
367 |
return EInsufficientSystemMemory;
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
wchar_t *wcharString = new wchar_t[ilen+1];
|
sl@0
|
371 |
|
sl@0
|
372 |
if (!wcharString)
|
sl@0
|
373 |
{
|
sl@0
|
374 |
delete []buf;
|
sl@0
|
375 |
return EInsufficientSystemMemory;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
|
sl@0
|
378 |
wmemcpy(wcharString, (const wchar_t*)aSrc.Ptr(), ilen);
|
sl@0
|
379 |
wcharString[ilen] = L'\0';
|
sl@0
|
380 |
|
sl@0
|
381 |
|
sl@0
|
382 |
if(minusone != wcstombs(buf, wcharString, ilen*2))
|
sl@0
|
383 |
{
|
sl@0
|
384 |
buf[ilen*2] = '\0';
|
sl@0
|
385 |
aDes.assign(buf);
|
sl@0
|
386 |
|
sl@0
|
387 |
}
|
sl@0
|
388 |
else
|
sl@0
|
389 |
{
|
sl@0
|
390 |
retval = EInvalidWCSSequence;
|
sl@0
|
391 |
}
|
sl@0
|
392 |
|
sl@0
|
393 |
delete []buf;
|
sl@0
|
394 |
delete []wcharString;
|
sl@0
|
395 |
return retval;
|
sl@0
|
396 |
}
|