sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2008-2009 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 the License "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:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <errno.h>
|
sl@0
|
21 |
#include "stringconv.h"
|
sl@0
|
22 |
#include "logger.h"
|
sl@0
|
23 |
#include <f32file.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
void Panic(TInt aCode)
|
sl@0
|
26 |
{
|
sl@0
|
27 |
dbg << Log::Indent() << "Panic(" << aCode << ")" << Log::Endl();
|
sl@0
|
28 |
FatalError();
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
void User::LeaveIfError(TInt aError)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
if(aError<0) User::Leave(aError);
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
void User::Invariant()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
FatalError();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
void User::Panic(const TDesC &aCategory, TInt aReason)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
dbg << Log::Indent() << "User::Panic('" << stringFromUtf16(aCategory) << "'," << aReason << ") called" << Log::Endl();
|
sl@0
|
43 |
FatalError();
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
void User::Leave(TInt aReason)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
dbg << Log::Indent() << "User::Leave(" << aReason << ") - Not supported by this port" << Log::Endl();
|
sl@0
|
49 |
FatalError();
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
TDesC8::TDesC8()
|
sl@0
|
53 |
: iCurrentLength(0)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
TDesC8::TDesC8(const TDesC8 &aRef)
|
sl@0
|
58 |
: iCurrentLength(aRef.iCurrentLength)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
TDesC8::TDesC8(TInt aLength)
|
sl@0
|
63 |
: iCurrentLength(aLength)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
TBool TDesC8::operator==(const TDesC8 &aDes) const
|
sl@0
|
68 |
{
|
sl@0
|
69 |
if(Length() != aDes.Length())
|
sl@0
|
70 |
{
|
sl@0
|
71 |
return EFalse;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
if(memcmp(Ptr(), aDes.Ptr(), Length()) == 0)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
return ETrue; // Identical
|
sl@0
|
77 |
}
|
sl@0
|
78 |
return EFalse;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
|
sl@0
|
83 |
TDes8::TDes8()
|
sl@0
|
84 |
: TDesC8(0), iMaxLength(0)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
TDes8::TDes8(const TDes8 &aRef)
|
sl@0
|
89 |
: TDesC8(aRef), iMaxLength(aRef.iMaxLength)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
|
sl@0
|
94 |
|
sl@0
|
95 |
TDes8::TDes8(TInt aLength,TInt aMaxLength)
|
sl@0
|
96 |
: TDesC8(aLength), iMaxLength(aMaxLength)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
void TDes8::Copy(const TDesC16 &aDes)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt len=aDes.Length();
|
sl@0
|
103 |
SetLength(len);
|
sl@0
|
104 |
const TUint16 *pS=aDes.Ptr();
|
sl@0
|
105 |
const TUint16 *pE=pS+len;
|
sl@0
|
106 |
TUint8 *pT=const_cast<TUint8 *>(Ptr());
|
sl@0
|
107 |
while (pS<pE)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
TUint c=(*pS++);
|
sl@0
|
110 |
if (c>=0x100)
|
sl@0
|
111 |
c=1;
|
sl@0
|
112 |
*pT++=(TUint8)c;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
|
sl@0
|
117 |
|
sl@0
|
118 |
void TDes8::SetLength(TInt aLength)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
if(aLength < 0 || aLength > iMaxLength) FatalError();
|
sl@0
|
121 |
iCurrentLength = aLength;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
|
sl@0
|
125 |
TPtr8::TPtr8(const TPtr8 &aRef)
|
sl@0
|
126 |
: TDes8(aRef), iPtr(aRef.iPtr)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
TPtr8 &TPtr8::operator=(const TPtr8 &aRhs)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
if(this == &aRhs) return *this; // handle self assignment
|
sl@0
|
133 |
if(aRhs.Length() > MaxLength()) FatalError();
|
sl@0
|
134 |
memcpy(iPtr, aRhs.Ptr(), aRhs.Length());
|
sl@0
|
135 |
SetLength(aRhs.Length());
|
sl@0
|
136 |
|
sl@0
|
137 |
return *this;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
const TUint8 *TPtr8::Ptr() const
|
sl@0
|
141 |
{
|
sl@0
|
142 |
return iPtr;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
const TUint8 &TPtr8::operator[](TInt anIndex) const
|
sl@0
|
146 |
{
|
sl@0
|
147 |
if(anIndex < 0 || anIndex >= Length())
|
sl@0
|
148 |
{
|
sl@0
|
149 |
dbg << Log::Indent() << "TPtrC8 bounds check failure" << Log::Endl();
|
sl@0
|
150 |
FatalError();
|
sl@0
|
151 |
}
|
sl@0
|
152 |
return iPtr[anIndex];
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
|
sl@0
|
156 |
void TPtr8::Append(TChar aChar)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
if(iCurrentLength+1 > iMaxLength)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
dbg << Log::Indent() << "TPtr8::Append range check failure" << Log::Endl();
|
sl@0
|
161 |
FatalError();
|
sl@0
|
162 |
}
|
sl@0
|
163 |
iPtr[iCurrentLength++] = aChar;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
|
sl@0
|
167 |
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
TPtrC8::TPtrC8(const TPtrC8 &aRef)
|
sl@0
|
171 |
: TDesC8(aRef), iPtr(aRef.iPtr)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
TPtrC8 &TPtrC8::operator=(const TPtrC8 &aRhs)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
if(this == &aRhs) return *this; // handle self assignment
|
sl@0
|
178 |
if(aRhs.Length() > Length()) FatalError();
|
sl@0
|
179 |
memcpy(const_cast<TUint8 *>(iPtr), aRhs.Ptr(), aRhs.Length());
|
sl@0
|
180 |
|
sl@0
|
181 |
return *this;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
void TPtrC8::Set(TUint8 *aBuf, TInt aLength)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
iPtr = aBuf,
|
sl@0
|
187 |
iCurrentLength = aLength;
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
const TUint8 *TPtrC8::Ptr() const
|
sl@0
|
191 |
{
|
sl@0
|
192 |
return iPtr;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
const TUint8 &TPtrC8::operator[](TInt anIndex) const
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if(anIndex < 0 || anIndex >= Length())
|
sl@0
|
198 |
{
|
sl@0
|
199 |
dbg << Log::Indent() << "TPtrC8 bounds check failure" << Log::Endl();
|
sl@0
|
200 |
FatalError();
|
sl@0
|
201 |
}
|
sl@0
|
202 |
return iPtr[anIndex];
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
TDesC16::TDesC16()
|
sl@0
|
208 |
: iCurrentLength(0)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
TDesC16::TDesC16(const TDesC16 &aRef)
|
sl@0
|
213 |
: iCurrentLength(aRef.iCurrentLength)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
TDesC16::TDesC16(TInt aLength)
|
sl@0
|
218 |
: iCurrentLength(aLength)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
|
sl@0
|
223 |
TDes16::TDes16()
|
sl@0
|
224 |
: TDesC16(0), iMaxLength(0)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
TDes16::TDes16(const TDes16 &aRef)
|
sl@0
|
229 |
: TDesC16(aRef), iMaxLength(aRef.iMaxLength)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
|
sl@0
|
234 |
|
sl@0
|
235 |
TDes16::TDes16(TInt aLength,TInt aMaxLength)
|
sl@0
|
236 |
: TDesC16(aLength), iMaxLength(aMaxLength)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
|
sl@0
|
241 |
void TDes16::SetLength(TInt aLength)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
if(aLength < 0 || aLength > iMaxLength) FatalError();
|
sl@0
|
244 |
iCurrentLength = aLength;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
TBool TDesC16::operator==(const TDesC8 &aDes) const
|
sl@0
|
248 |
{
|
sl@0
|
249 |
if(Length() != aDes.Length())
|
sl@0
|
250 |
{
|
sl@0
|
251 |
return EFalse;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
if(memcmp(Ptr(), aDes.Ptr(), Length()*2) == 0)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
return ETrue; // Identical
|
sl@0
|
257 |
}
|
sl@0
|
258 |
return EFalse;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
|
sl@0
|
262 |
TPtrC16::TPtrC16(const TPtrC16 &aRef)
|
sl@0
|
263 |
: TDesC16(aRef), iPtr(aRef.iPtr)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
TPtrC16 &TPtrC16::operator=(const TPtrC16 &aRhs)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
if(this == &aRhs) return *this; // handle self assignment
|
sl@0
|
270 |
if(aRhs.Length() > Length()) FatalError();
|
sl@0
|
271 |
memcpy(const_cast<TUint16 *>(iPtr), aRhs.Ptr(), aRhs.Length()*2);
|
sl@0
|
272 |
|
sl@0
|
273 |
return *this;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
void TPtrC16::Set(TUint16 *aBuf, TInt aLength)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
iPtr = aBuf,
|
sl@0
|
279 |
iCurrentLength = aLength;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
|
sl@0
|
283 |
const TUint16 *TPtrC16::Ptr() const
|
sl@0
|
284 |
{
|
sl@0
|
285 |
return iPtr;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
const TUint16 &TPtrC16::operator[](TInt anIndex) const
|
sl@0
|
289 |
{
|
sl@0
|
290 |
if(anIndex < 0 || anIndex >= Length())
|
sl@0
|
291 |
{
|
sl@0
|
292 |
dbg << Log::Indent() << "TPtrC16 bounds check failure" << Log::Endl();
|
sl@0
|
293 |
FatalError();
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
return iPtr[anIndex];
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
|
sl@0
|
300 |
|
sl@0
|
301 |
|
sl@0
|
302 |
TPtr16::TPtr16(const TPtr16 &aRef)
|
sl@0
|
303 |
: TDes16(aRef), iPtr(aRef.iPtr)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
TPtr16 &TPtr16::operator=(const TPtr16 &aRhs)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
if(this == &aRhs) return *this; // handle self assignment
|
sl@0
|
310 |
if(aRhs.Length() > MaxLength()) FatalError();
|
sl@0
|
311 |
memcpy(iPtr, aRhs.Ptr(), aRhs.Length()*sizeof(TUint16));
|
sl@0
|
312 |
SetLength(aRhs.Length());
|
sl@0
|
313 |
|
sl@0
|
314 |
return *this;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
void TPtr16::Copy(const TDesC8 &aDes)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
// This is not quite 100% compatible because it does a correct
|
sl@0
|
320 |
// UTF-8 to UCS-2 conversion, instead of just stuffing in zeros.
|
sl@0
|
321 |
TInt outLength = 0;
|
sl@0
|
322 |
TText *outBuf = utf16FromUtf8(aDes.Ptr(), aDes.Length(), outLength);
|
sl@0
|
323 |
|
sl@0
|
324 |
if(outLength > MaxLength()) FatalError();
|
sl@0
|
325 |
memcpy(iPtr, outBuf, outLength*2);
|
sl@0
|
326 |
SetLength(outLength);
|
sl@0
|
327 |
delete [] outBuf;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
|
sl@0
|
331 |
const TUint16 *TPtr16::Ptr() const
|
sl@0
|
332 |
{
|
sl@0
|
333 |
return iPtr;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
const TUint16 &TPtr16::operator[](TInt anIndex) const
|
sl@0
|
337 |
{
|
sl@0
|
338 |
if(anIndex < 0 || anIndex >= Length())
|
sl@0
|
339 |
{
|
sl@0
|
340 |
dbg << Log::Indent() << "TPtr16 bounds check failure" << Log::Endl();
|
sl@0
|
341 |
FatalError();
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
return iPtr[anIndex];
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|
sl@0
|
347 |
void TPtr16::Append(TChar aChar)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
if(iCurrentLength+1 > iMaxLength)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
dbg << Log::Indent() << "TPtr16::Append range check failure" << Log::Endl();
|
sl@0
|
352 |
FatalError();
|
sl@0
|
353 |
}
|
sl@0
|
354 |
iPtr[iCurrentLength++] = aChar;
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
|
sl@0
|
358 |
|
sl@0
|
359 |
|
sl@0
|
360 |
|
sl@0
|
361 |
|
sl@0
|
362 |
TLIT16::TLIT16(const char *aStr)
|
sl@0
|
363 |
: iDes(0,0)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
|
sl@0
|
366 |
|
sl@0
|
367 |
// Expand UTF-8 into internal UTF-16LE representation
|
sl@0
|
368 |
TInt outputWords = 0;
|
sl@0
|
369 |
TText *outputBuf = utf16FromUtf8((TUint8 *)aStr, strlen(aStr), outputWords);
|
sl@0
|
370 |
// Work out actual string length and save the buffer and ptr in out descriptor
|
sl@0
|
371 |
iDes.Set(outputBuf, outputWords);
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
TLIT16::TLIT16(const TLIT16 &aRef)
|
sl@0
|
375 |
: iDes(aRef.iDes.Ptr(), aRef.iDes.Length())
|
sl@0
|
376 |
{
|
sl@0
|
377 |
}
|
sl@0
|
378 |
|
sl@0
|
379 |
|
sl@0
|
380 |
TLIT16::~TLIT16()
|
sl@0
|
381 |
{
|
sl@0
|
382 |
// May leak here, but TLITs should be at global scope anyway...
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
|
sl@0
|
386 |
const TDesC16* TLIT16::operator&() const
|
sl@0
|
387 |
{
|
sl@0
|
388 |
return &iDes;
|
sl@0
|
389 |
}
|
sl@0
|
390 |
|
sl@0
|
391 |
TLIT16::operator const TDesC16&() const
|
sl@0
|
392 |
{
|
sl@0
|
393 |
return iDes;
|
sl@0
|
394 |
}
|
sl@0
|
395 |
|
sl@0
|
396 |
const TDesC16& TLIT16::operator()() const
|
sl@0
|
397 |
{
|
sl@0
|
398 |
return iDes;
|
sl@0
|
399 |
}
|
sl@0
|
400 |
|
sl@0
|
401 |
|
sl@0
|
402 |
TLIT8::TLIT8(const char *aStr)
|
sl@0
|
403 |
: TPtrC8((const TUint8 *)aStr, strlen(aStr))
|
sl@0
|
404 |
{
|
sl@0
|
405 |
}
|
sl@0
|
406 |
|
sl@0
|
407 |
TLIT8::TLIT8(const TLIT8 &aRef)
|
sl@0
|
408 |
: TPtrC8(aRef)
|
sl@0
|
409 |
{
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
|
sl@0
|
413 |
|
sl@0
|
414 |
void CleanupStack::PopAndDestroy(RArrayBase *aRArray)
|
sl@0
|
415 |
{
|
sl@0
|
416 |
aRArray->Close();
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
|
sl@0
|
420 |
void CleanupStack::PopAndDestroy(RFs *aFs)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
aFs->Close();
|
sl@0
|
423 |
}
|
sl@0
|
424 |
|
sl@0
|
425 |
void PushL(void *)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
|
sl@0
|
430 |
// End of file
|