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 Descriptor8 to wchar * 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 TBuf8 to wchar
|
sl@0
|
26 |
*
|
sl@0
|
27 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
28 |
* reference to the wchar array where the result of conversion
|
sl@0
|
29 |
* is stored
|
sl@0
|
30 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
31 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
|
sl@0
|
34 |
EXPORT_C int Tbuf8ToWchar(TDes8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
int retval = ESuccess;
|
sl@0
|
37 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
38 |
int minusone = -1;
|
sl@0
|
39 |
|
sl@0
|
40 |
if(0 == ilen)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
return EDescriptorNoData;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
else if(!aDes)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
return EInvalidPointer;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
else if(n_size < ilen+1)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
n_size = ilen+1;
|
sl@0
|
51 |
return EInvalidSize;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen))
|
sl@0
|
55 |
{
|
sl@0
|
56 |
*(aDes + ilen) = L'\0';
|
sl@0
|
57 |
}
|
sl@0
|
58 |
else
|
sl@0
|
59 |
{
|
sl@0
|
60 |
retval = EInvalidMBSSequence;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
return retval;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
* Converts a descriptor of type TBufc8 to wchar
|
sl@0
|
68 |
*
|
sl@0
|
69 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
70 |
* reference to the wchar array where the result of conversion
|
sl@0
|
71 |
* is stored
|
sl@0
|
72 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
73 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
74 |
*/
|
sl@0
|
75 |
|
sl@0
|
76 |
EXPORT_C int Tbufc8ToWchar(TDesC8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
int retval = ESuccess;
|
sl@0
|
79 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
80 |
int minusone = -1;
|
sl@0
|
81 |
|
sl@0
|
82 |
if(0 == ilen)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
return EDescriptorNoData;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
else if(!aDes)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
return EInvalidPointer;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
else if (n_size < ilen+1)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
n_size = ilen+1;
|
sl@0
|
93 |
return EInvalidSize;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
if(minusone != mbstowcs(aDes, (const char *)aSrc.Ptr(), ilen))
|
sl@0
|
97 |
{
|
sl@0
|
98 |
aDes[ilen] = L'\0';
|
sl@0
|
99 |
}
|
sl@0
|
100 |
else
|
sl@0
|
101 |
{
|
sl@0
|
102 |
retval = EInvalidMBSSequence;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
return retval;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
* Converts a descriptor of type TLitc8 to wchar
|
sl@0
|
110 |
*
|
sl@0
|
111 |
* @param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
112 |
* reference to the wchar array where the result of conversion
|
sl@0
|
113 |
* is stored
|
sl@0
|
114 |
* @return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
115 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C int Tlitc8ToWchar( const TDesC8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
int retval = ESuccess;
|
sl@0
|
121 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
122 |
int minusone = -1;
|
sl@0
|
123 |
|
sl@0
|
124 |
if (0 == ilen )
|
sl@0
|
125 |
{
|
sl@0
|
126 |
return EDescriptorNoData;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
else if ( !aDes )
|
sl@0
|
129 |
{
|
sl@0
|
130 |
return EInvalidPointer;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
else if (n_size < ilen+1)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
n_size = ilen+1 ;
|
sl@0
|
135 |
return EInvalidSize;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen ))
|
sl@0
|
139 |
{
|
sl@0
|
140 |
aDes[ilen] = L'\0';
|
sl@0
|
141 |
}
|
sl@0
|
142 |
else
|
sl@0
|
143 |
{
|
sl@0
|
144 |
retval = EInvalidMBSSequence;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
return retval;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
/**
|
sl@0
|
151 |
*Converts a descriptor of type TPtr8 to Wchar
|
sl@0
|
152 |
*@param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
153 |
*reference to the wchar array where the result of conversion
|
sl@0
|
154 |
*is stored
|
sl@0
|
155 |
*@return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
156 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
|
sl@0
|
159 |
EXPORT_C int Tptr8ToWcharp(const TPtr8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
|
sl@0
|
162 |
int retval = ESuccess;
|
sl@0
|
163 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
164 |
int minusone = -1;
|
sl@0
|
165 |
|
sl@0
|
166 |
if (0 == ilen)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
return EDescriptorNoData;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
else if(!aDes)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
return EInvalidPointer;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
else if(n_size < ilen+1)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
n_size = ilen+1 ;
|
sl@0
|
177 |
return EInvalidSize;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen))
|
sl@0
|
181 |
{
|
sl@0
|
182 |
aDes[ilen] = L'\0';
|
sl@0
|
183 |
}
|
sl@0
|
184 |
else
|
sl@0
|
185 |
{
|
sl@0
|
186 |
retval = EInvalidMBSSequence;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
return retval;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
/**
|
sl@0
|
193 |
*Converts a descriptor of type TPtrc to Wchar
|
sl@0
|
194 |
*
|
sl@0
|
195 |
*@param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
196 |
*reference to the wchar array where the result of conversion
|
sl@0
|
197 |
*is stored
|
sl@0
|
198 |
*@return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
199 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
|
sl@0
|
202 |
EXPORT_C int Tptrc8ToWcharp(TPtrC8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
int retval = ESuccess;
|
sl@0
|
205 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
206 |
int minusone = -1;
|
sl@0
|
207 |
|
sl@0
|
208 |
if (0 == ilen)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
return EDescriptorNoData;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
else if(!aDes)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
return EInvalidPointer;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
else if(n_size < ilen)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
n_size = ilen;
|
sl@0
|
219 |
return EInvalidSize;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen))
|
sl@0
|
223 |
{
|
sl@0
|
224 |
aDes[ilen] = L'\0';
|
sl@0
|
225 |
}
|
sl@0
|
226 |
else
|
sl@0
|
227 |
{
|
sl@0
|
228 |
retval = EInvalidMBSSequence;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
return retval;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
/**
|
sl@0
|
235 |
*Converts a descriptor of type Rbuf8 to Wchar
|
sl@0
|
236 |
*
|
sl@0
|
237 |
*@param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
238 |
*reference to the wchar array where the result of conversion
|
sl@0
|
239 |
*is stored
|
sl@0
|
240 |
*@return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
241 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
242 |
*/
|
sl@0
|
243 |
|
sl@0
|
244 |
EXPORT_C int Rbuf8ToWchar(TDes8& aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
int retval = ESuccess;
|
sl@0
|
247 |
unsigned int ilen = aSrc.Length();
|
sl@0
|
248 |
int minusone = -1;
|
sl@0
|
249 |
|
sl@0
|
250 |
if (0 == ilen )
|
sl@0
|
251 |
{
|
sl@0
|
252 |
return EDescriptorNoData;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
else if(!aDes)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
return EInvalidPointer;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
else if (n_size < ilen)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
n_size = ilen + 1;
|
sl@0
|
261 |
return EInvalidSize;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
if(minusone != mbstowcs(aDes, (const char*)aSrc.Ptr(), ilen))
|
sl@0
|
265 |
{
|
sl@0
|
266 |
*(aDes + ilen) = L'\0';
|
sl@0
|
267 |
}
|
sl@0
|
268 |
else
|
sl@0
|
269 |
{
|
sl@0
|
270 |
retval = EInvalidMBSSequence;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
return retval;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
/**
|
sl@0
|
277 |
*Converts a descriptor of type Rbuf8 to Wchar
|
sl@0
|
278 |
*
|
sl@0
|
279 |
*@param aSrc is the descriptor to be converted , aDes is the
|
sl@0
|
280 |
*reference to the wchar array where the result of conversion
|
sl@0
|
281 |
*is stored
|
sl@0
|
282 |
*@return Status code (0 is ESuccess, -1 is EInsufficientMemory,
|
sl@0
|
283 |
* -2 is EInvalidSize , -4 is EInvalidPointer , -5 is EDescriptorNoData)
|
sl@0
|
284 |
*/
|
sl@0
|
285 |
|
sl@0
|
286 |
EXPORT_C int HBufc8ToWchar(HBufC8* aSrc, wchar_t* aDes, int& n_size)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
int retval = ESuccess;
|
sl@0
|
289 |
unsigned int ilen = 0;
|
sl@0
|
290 |
int minusone = -1;
|
sl@0
|
291 |
|
sl@0
|
292 |
if(!aDes || !aSrc)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
return EInvalidPointer;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
else
|
sl@0
|
297 |
{
|
sl@0
|
298 |
int ilen = aSrc->Length();
|
sl@0
|
299 |
if (0 == ilen )
|
sl@0
|
300 |
{
|
sl@0
|
301 |
return EDescriptorNoData;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
else if (n_size < ilen)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
n_size = ilen + 1;
|
sl@0
|
306 |
return EInvalidSize;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
if(minusone != mbstowcs(aDes, (const char*)aSrc->Ptr(), ilen))
|
sl@0
|
311 |
{
|
sl@0
|
312 |
*(aDes + ilen) = L'\0';
|
sl@0
|
313 |
}
|
sl@0
|
314 |
else
|
sl@0
|
315 |
{
|
sl@0
|
316 |
retval = EInvalidMBSSequence;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
return retval;
|
sl@0
|
320 |
}
|