0
|
1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\common\des8.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "common.h"
|
|
19 |
#include <e32des8_private.h>
|
|
20 |
#ifndef __KERNEL_MODE__
|
|
21 |
#include <collate.h>
|
|
22 |
#else
|
|
23 |
#include <kernel/kern_priv.h>
|
|
24 |
#endif
|
|
25 |
#include <unicode.h>
|
|
26 |
|
|
27 |
// Folding/Collation for 8 bit characters
|
|
28 |
|
|
29 |
extern const TUint8 __FoldCollTab8[256];
|
|
30 |
|
|
31 |
const TUint8 __FoldCollTab8[256] =
|
|
32 |
{
|
|
33 |
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, // 0x00
|
|
34 |
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
|
|
35 |
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, // 0x10
|
|
36 |
0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
|
37 |
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, // 0x20
|
|
38 |
0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
|
|
39 |
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, // 0x30
|
|
40 |
0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
|
|
41 |
0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67, // 0x40
|
|
42 |
0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
|
|
43 |
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, // 0x50
|
|
44 |
0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
|
|
45 |
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67, // 0x60
|
|
46 |
0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
|
|
47 |
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, // 0x70
|
|
48 |
0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
|
|
49 |
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, // 0x80
|
|
50 |
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
|
|
51 |
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, // 0x90
|
|
52 |
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
|
|
53 |
0x20,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7, // 0xa0
|
|
54 |
0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
|
|
55 |
0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7, // 0xb0
|
|
56 |
0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
|
|
57 |
0x61,0x61,0x61,0x61,0x61,0x61,0xe6,0x63, // 0xc0
|
|
58 |
0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
|
|
59 |
0xf0,0x6e,0x6f,0x6f,0x6f,0x6f,0x6f,0xd7, // 0xd0
|
|
60 |
0xf8,0x75,0x75,0x75,0x75,0x79,0xfe,0xdf,
|
|
61 |
0x61,0x61,0x61,0x61,0x61,0x61,0xe6,0x63, // 0xe0
|
|
62 |
0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
|
|
63 |
0xf0,0x6e,0x6f,0x6f,0x6f,0x6f,0x6f,0xf7, // 0xf0
|
|
64 |
0xf8,0x75,0x75,0x75,0x75,0x79,0xfe,0x79
|
|
65 |
};
|
|
66 |
|
|
67 |
#ifndef __KERNEL_MODE__
|
|
68 |
inline TUint8* memCopy(TUint8* aPtr, const TUint8* aSrc, TInt aLength)
|
|
69 |
//
|
|
70 |
// Copy 8 bit values.
|
|
71 |
//
|
|
72 |
{
|
|
73 |
|
|
74 |
return Mem::Copy(aPtr, aSrc, aLength);
|
|
75 |
}
|
|
76 |
#endif
|
|
77 |
|
|
78 |
#if (defined(__KERNEL_MODE__) && !defined(__DES8_MACHINE_CODED__)) | defined(__EABI_CTORS__)
|
|
79 |
inline TInt StringLength(const TUint8* aPtr)
|
|
80 |
{
|
|
81 |
const TUint8* p = aPtr;
|
|
82 |
while (*p)
|
|
83 |
++p;
|
|
84 |
return p-aPtr;
|
|
85 |
}
|
|
86 |
#endif
|
|
87 |
|
|
88 |
inline TDesC8::TDesC8(TInt aType,TInt aLength)
|
|
89 |
:iLength(aLength|(aType<<KShiftDesType8))
|
|
90 |
{}
|
|
91 |
inline TInt TDesC8::Type() const
|
|
92 |
//
|
|
93 |
// Return the descriptor type
|
|
94 |
//
|
|
95 |
{
|
|
96 |
return(iLength>>KShiftDesType8);
|
|
97 |
}
|
|
98 |
|
|
99 |
inline TDes8::TDes8(TInt aType,TInt aLength,TInt aMaxLength)
|
|
100 |
: TDesC8(aType,aLength),iMaxLength(aMaxLength)
|
|
101 |
{}
|
|
102 |
|
|
103 |
// Class TBufCBase8
|
|
104 |
inline TBufCBase8::TBufCBase8(TInt aLength)
|
|
105 |
:TDesC8(EBufC,aLength)
|
|
106 |
{}
|
|
107 |
|
|
108 |
inline TUint8* TBufCBase8::WPtr() const
|
|
109 |
{return const_cast<TUint8*>(Ptr());}
|
|
110 |
|
|
111 |
|
|
112 |
#ifndef __DES8_MACHINE_CODED__
|
|
113 |
EXPORT_C const TUint8* TDesC8::Ptr() const
|
|
114 |
/**
|
|
115 |
Gets a pointer to the data represented by the descriptor.
|
|
116 |
|
|
117 |
The data cannot be changed through the returned pointer.
|
|
118 |
|
|
119 |
@return A pointer to the data
|
|
120 |
*/
|
|
121 |
{
|
|
122 |
|
|
123 |
switch (Type())
|
|
124 |
{
|
|
125 |
case EBufC:
|
|
126 |
return(&((SBufC8 *)this)->buf[0]);
|
|
127 |
case EPtrC:
|
|
128 |
return(((SPtrC8 *)this)->ptr);
|
|
129 |
case EPtr:
|
|
130 |
return(((SPtr8 *)this)->ptr);
|
|
131 |
case EBuf:
|
|
132 |
return(&((SBuf8 *)this)->buf[0]);
|
|
133 |
case EBufCPtr:
|
|
134 |
return(&((SBufCPtr8 *)this)->ptr->buf[0]);
|
|
135 |
}
|
|
136 |
Panic(ETDes8BadDescriptorType);
|
|
137 |
return(NULL);
|
|
138 |
}
|
|
139 |
|
|
140 |
EXPORT_C const TUint8 &TDesC8::AtC(TInt anIndex) const
|
|
141 |
//
|
|
142 |
// Return a reference to the character in the buffer.
|
|
143 |
//
|
|
144 |
{
|
|
145 |
|
|
146 |
__ASSERT_ALWAYS(anIndex>=0 && anIndex<Length(),Panic(ETDes8IndexOutOfRange));
|
|
147 |
return(Ptr()[anIndex]);
|
|
148 |
}
|
|
149 |
|
|
150 |
EXPORT_C TInt TDesC8::Compare(const TDesC8 &aDes) const
|
|
151 |
/**
|
|
152 |
Compares this descriptor's data with the specified descriptor's data.
|
|
153 |
|
|
154 |
The comparison proceeds on a byte for byte basis. The result of the comparison
|
|
155 |
is based on the difference of the first bytes to disagree.
|
|
156 |
|
|
157 |
Two descriptors are equal if they have the same length and content. Where
|
|
158 |
two descriptors have different lengths and the shorter descriptor's data
|
|
159 |
matches the first part of the longer descriptor's data, the shorter is
|
|
160 |
considered to be less than the longer.
|
|
161 |
|
|
162 |
@param aDes The 8-bit non-modifable descriptor whose data is to be compared
|
|
163 |
with this descriptor's data.
|
|
164 |
|
|
165 |
@return Positive, if this descriptor is greater than the specified descriptor.
|
|
166 |
Negative, if this descriptor is less than the specified descriptor.
|
|
167 |
Zero, if both descriptors have the same length and the their contents
|
|
168 |
are the same.
|
|
169 |
*/
|
|
170 |
{
|
|
171 |
|
|
172 |
return memcompare(Ptr(), Length(), aDes.Ptr(), aDes.Length());
|
|
173 |
}
|
|
174 |
|
|
175 |
#ifndef __KERNEL_MODE__
|
|
176 |
EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
|
|
177 |
/**
|
|
178 |
Compares this descriptor's folded data with the specified descriptor's folded
|
|
179 |
data.
|
|
180 |
|
|
181 |
Note that folding is locale-independent behaviour. It is also important to
|
|
182 |
note that there can be no guarantee that folding is in any way culturally
|
|
183 |
appropriate, and should not be used for comparing strings in natural language;
|
|
184 |
use CompareC() for this.
|
|
185 |
|
|
186 |
@param aDes The 8-bit non modifable descriptor whose data is to be compared
|
|
187 |
with this descriptor's data.
|
|
188 |
|
|
189 |
@return Positive, if this descriptor is greater than the specified descriptor.
|
|
190 |
Negative, if this descriptor is less than the specified descriptor.
|
|
191 |
Zero, if both descriptors have the same length and the their contents
|
|
192 |
are the same.
|
|
193 |
|
|
194 |
@see TDesC8::Compare()
|
|
195 |
*/
|
|
196 |
{
|
|
197 |
|
|
198 |
return(Mem::CompareF(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
|
|
199 |
}
|
|
200 |
|
|
201 |
EXPORT_C TInt TDesC8::CompareC(const TDesC8 &aDes) const
|
|
202 |
/**
|
|
203 |
Compares this descriptor's data with the specified descriptor's data using
|
|
204 |
the standard collation method for narrow text appropriate to the current locale.
|
|
205 |
|
|
206 |
@param aDes The 8-bit non modifable descriptor whose data is to be compared
|
|
207 |
with this descriptor's data.
|
|
208 |
|
|
209 |
@return Positive, if this descriptor is greater than the specified descriptor.
|
|
210 |
Negative, if this descriptor is less than the specified descriptor.
|
|
211 |
Zero, if both descriptors have the same length and the their contents
|
|
212 |
are the same.
|
|
213 |
|
|
214 |
@see TDesC8::Compare()
|
|
215 |
@deprecated
|
|
216 |
*/
|
|
217 |
{
|
|
218 |
|
|
219 |
return(Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
|
|
220 |
}
|
|
221 |
#endif
|
|
222 |
#endif
|
|
223 |
|
|
224 |
EXPORT_C TInt TDesC8::Find(const TUint8 *pS,TInt aLenS) const
|
|
225 |
/**
|
|
226 |
Searches for the first occurrence of the specified data sequence within this
|
|
227 |
descriptor.
|
|
228 |
|
|
229 |
Searching always starts at the beginning of this descriptor's data.
|
|
230 |
|
|
231 |
@param pS A pointer to a location containing the data sequence to be searched
|
|
232 |
for.
|
|
233 |
@param aLenS The length of the data sequence to be searched for. This value
|
|
234 |
must not be negative, otherwise the function raises a panic.
|
|
235 |
|
|
236 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
237 |
data. KErrNotFound, if the data sequence cannot be found.
|
|
238 |
|
|
239 |
@panic USER 29 if aLenS is negative.
|
|
240 |
*/
|
|
241 |
{
|
|
242 |
|
|
243 |
if (!aLenS)
|
|
244 |
return(0);
|
|
245 |
__ASSERT_ALWAYS(aLenS>0,Panic(ETDes8LengthNegative));
|
|
246 |
const TUint8 *pB=Ptr();
|
|
247 |
TInt aLenB=Length();
|
|
248 |
const TUint8 *pC=pB-1; // using pre-increment addressing
|
|
249 |
TInt i=aLenB-aLenS;
|
|
250 |
if (i>=0)
|
|
251 |
{
|
|
252 |
const TUint8* pEndS=pS+aLenS-1; // using pre-increment addressing
|
|
253 |
const TUint8 *pEndB=pB+i; // using pre-increment addressing
|
|
254 |
TUint s=*pS;
|
|
255 |
for (;;)
|
|
256 |
{
|
|
257 |
do
|
|
258 |
{
|
|
259 |
if (pC==pEndB)
|
|
260 |
return KErrNotFound;
|
|
261 |
} while (*++pC!=s);
|
|
262 |
const TUint8 *p1=pC;
|
|
263 |
const TUint8 *p2=pS;
|
|
264 |
do
|
|
265 |
{
|
|
266 |
if (p2==pEndS)
|
|
267 |
return (pC-pB);
|
|
268 |
} while (*++p1==*++p2);
|
|
269 |
}
|
|
270 |
}
|
|
271 |
return(KErrNotFound);
|
|
272 |
}
|
|
273 |
|
|
274 |
EXPORT_C TInt TDesC8::Find(const TDesC8 &aDes) const
|
|
275 |
/**
|
|
276 |
Searches for the first occurrence of the specified data sequence within this
|
|
277 |
descriptor.
|
|
278 |
|
|
279 |
Searching always starts at the beginning of this descriptor's data.
|
|
280 |
|
|
281 |
@param aDes The 8-bit non modifable descriptor containing the data sequence
|
|
282 |
to be searched for.
|
|
283 |
|
|
284 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
285 |
data. KErrNotFound, if the data sequence cannot be found.
|
|
286 |
*/
|
|
287 |
{
|
|
288 |
|
|
289 |
return(Find(aDes.Ptr(),aDes.Length()));
|
|
290 |
}
|
|
291 |
|
|
292 |
const TUint8* convTable(TMatchType aType)
|
|
293 |
{
|
|
294 |
switch (aType)
|
|
295 |
{
|
|
296 |
case EMatchFolded:
|
|
297 |
case EMatchCollated: return __FoldCollTab8;
|
|
298 |
default: return NULL;
|
|
299 |
}
|
|
300 |
}
|
|
301 |
|
|
302 |
inline TUint conv(const TUint8* aStr,const TUint8* aConv)
|
|
303 |
{
|
|
304 |
TUint c=*aStr;
|
|
305 |
return aConv ? aConv[c] : c;
|
|
306 |
}
|
|
307 |
|
|
308 |
|
|
309 |
inline TUint lookup(const TUint8* aStr,const TUint8* aConv)
|
|
310 |
{
|
|
311 |
return aConv[*aStr];
|
|
312 |
}
|
|
313 |
|
|
314 |
TInt DoMatch8(const TDesC8 &aLeftD,const TDesC8 &aRightD,TMatchType aType)
|
|
315 |
{
|
|
316 |
const TUint8* table=convTable(aType);
|
|
317 |
const TUint8* pRight=aRightD.Ptr();
|
|
318 |
const TUint8* pM=pRight-1; // pre-increment addressing
|
|
319 |
const TUint8* pP=pM+aRightD.Length();
|
|
320 |
const TUint8* pLeft=aLeftD.Ptr()-1; // pre-increment addressing
|
|
321 |
const TUint8* pB=pLeft;
|
|
322 |
const TUint8* pE=pB+aLeftD.Length();
|
|
323 |
|
|
324 |
// Match any pattern up to the first star
|
|
325 |
TUint c;
|
|
326 |
for (;;)
|
|
327 |
{
|
|
328 |
if (pM==pP) // exhausted the pattern
|
|
329 |
return pB==pE ? 0 : KErrNotFound;
|
|
330 |
TUint c=conv(++pM,table);
|
|
331 |
if (c==KMatchAny)
|
|
332 |
break;
|
|
333 |
if (pB==pE) // no more input
|
|
334 |
return KErrNotFound;
|
|
335 |
if (c!=conv(++pB,table) && c!=KMatchOne) // match failed
|
|
336 |
return KErrNotFound;
|
|
337 |
}
|
|
338 |
// reached a star
|
|
339 |
if (pM==pP)
|
|
340 |
return 0;
|
|
341 |
TInt r=pM==pRight ? -1 : 0;
|
|
342 |
for (;;)
|
|
343 |
{
|
|
344 |
c=conv(++pM,table);
|
|
345 |
if (c==KMatchAny)
|
|
346 |
{
|
|
347 |
star: if (pM==pP) // star at end of pattern, always matches
|
|
348 |
return Max(r,0);
|
|
349 |
if (r<-1) // skipped some '?', matches at beginning
|
|
350 |
r=0;
|
|
351 |
continue;
|
|
352 |
}
|
|
353 |
if (pB==pE) // no more input
|
|
354 |
return KErrNotFound;
|
|
355 |
if (c==KMatchOne)
|
|
356 |
{ // skip a character in the input
|
|
357 |
if (pM==pP)
|
|
358 |
return r+((r>=0) ? 0 : (pE-pLeft));
|
|
359 |
++pB;
|
|
360 |
if (r<0)
|
|
361 |
--r;
|
|
362 |
continue;
|
|
363 |
}
|
|
364 |
// Matching a non-wild character
|
|
365 |
for (;;)
|
|
366 |
{
|
|
367 |
if (table) // pull this test out of the tight loop (10-20% faster)
|
|
368 |
{
|
|
369 |
while (lookup(++pB,table)!=c)
|
|
370 |
{
|
|
371 |
if (pB==pE) // no more input
|
|
372 |
return KErrNotFound;
|
|
373 |
}
|
|
374 |
}
|
|
375 |
else
|
|
376 |
{
|
|
377 |
while (*++pB!=c)
|
|
378 |
{
|
|
379 |
if (pB==pE) // no more input
|
|
380 |
return KErrNotFound;
|
|
381 |
}
|
|
382 |
}
|
|
383 |
// Try to match up to the next star
|
|
384 |
const TUint8* pb=pB;
|
|
385 |
const TUint8* pm=pM;
|
|
386 |
for (;;)
|
|
387 |
{
|
|
388 |
if (pm<pP)
|
|
389 |
{
|
|
390 |
TUint cc=conv(++pm,table);
|
|
391 |
if (cc==KMatchAny)
|
|
392 |
{ // sub-match successful, back to main loop
|
|
393 |
r+=(r>=0 ? 0 : pB-pLeft);
|
|
394 |
pB=pb;
|
|
395 |
pM=pm;
|
|
396 |
goto star;
|
|
397 |
}
|
|
398 |
if (pb==pE)
|
|
399 |
return KErrNotFound; // no more input
|
|
400 |
if (cc!=conv(++pb,table) && cc!=KMatchOne)
|
|
401 |
break; // sub-match failed, try next input character
|
|
402 |
}
|
|
403 |
else if (pb==pE) // end of matching pattern
|
|
404 |
return r+(r>=0 ? 0 : pB-pLeft); // end of input, so have a match
|
|
405 |
else
|
|
406 |
break; // try next input character
|
|
407 |
}
|
|
408 |
}
|
|
409 |
}
|
|
410 |
}
|
|
411 |
|
|
412 |
EXPORT_C TInt TDesC8::Match(const TDesC8 &aDes) const
|
|
413 |
/**
|
|
414 |
Searches this descriptor's data for a match with the match pattern supplied
|
|
415 |
in the specified descriptor.
|
|
416 |
|
|
417 |
The match pattern can contain the wildcard characters "*" and "?", where "*"
|
|
418 |
matches zero or more consecutive occurrences of any character and "?" matches
|
|
419 |
a single occurrence of any character.
|
|
420 |
|
|
421 |
Note that there is no 'escape character', which means that it is not possible
|
|
422 |
to match either the "*" character itself or the "?" character itself using
|
|
423 |
this function.
|
|
424 |
|
|
425 |
@param aDes An 8-bit non-modifable descriptor containing the match pattern.
|
|
426 |
|
|
427 |
@return If a match is found, the offset within this descriptor's data where
|
|
428 |
the match first occurs. KErrNotFound, if there is no match.
|
|
429 |
*/
|
|
430 |
{
|
|
431 |
|
|
432 |
return DoMatch8(*this,aDes,EMatchNormal);
|
|
433 |
}
|
|
434 |
|
|
435 |
EXPORT_C TInt TDesC8::MatchF(const TDesC8 &aDes) const
|
|
436 |
/**
|
|
437 |
Searches this descriptor's folded data for a match with the folded match
|
|
438 |
pattern supplied in the specified descriptor.
|
|
439 |
|
|
440 |
The match pattern can contain the wildcard characters "*" and "?", where "*"
|
|
441 |
matches zero or more consecutive occurrences of any character and "?" matches
|
|
442 |
a single occurrence of any character.
|
|
443 |
|
|
444 |
Note that folding is locale-independent behaviour. It is also important to
|
|
445 |
note that there can be no guarantee that folding is in any way culturally
|
|
446 |
appropriate, and should not be used for matching strings in natural language;
|
|
447 |
use MatchC() for this.
|
|
448 |
|
|
449 |
Note that there is no 'escape character', which means that it is not possible
|
|
450 |
to match either the "*" character itself or the "?" character itself using
|
|
451 |
this function.
|
|
452 |
|
|
453 |
@param aDes An 8-bit non-modifable descriptor containing the match pattern.
|
|
454 |
|
|
455 |
@return If a match is found, the offset within this descriptor's data where
|
|
456 |
the match first occurs. KErrNotFound, if there is no match.
|
|
457 |
|
|
458 |
@see TDesC8::MatchC()
|
|
459 |
*/
|
|
460 |
{
|
|
461 |
|
|
462 |
return DoMatch8(*this,aDes,EMatchFolded);
|
|
463 |
}
|
|
464 |
|
|
465 |
EXPORT_C TInt TDesC8::MatchC(const TDesC8 &aPattern) const
|
|
466 |
/**
|
|
467 |
Searches this descriptor's collated data for a match with the collated match
|
|
468 |
pattern supplied in the specified descriptor.
|
|
469 |
|
|
470 |
The function uses the standard collation method for narrow text appropriate to
|
|
471 |
the current locale.
|
|
472 |
|
|
473 |
The match pattern can contain the wildcard characters "*" and "?", where "*"
|
|
474 |
matches zero or more consecutive occurrences of any character and "?" matches
|
|
475 |
a single occurrence of any character.
|
|
476 |
|
|
477 |
Note that there is no 'escape character', which means that it is not possible
|
|
478 |
to match either the "*" character itself or the "?" character itself using
|
|
479 |
this function.
|
|
480 |
|
|
481 |
@param aPattern An 8-bit non-modifable descriptor containing the match pattern.
|
|
482 |
|
|
483 |
@return If a match is found, the offset within this descriptor's data where
|
|
484 |
the match first occurs. KErrNotFound, if there is no match.
|
|
485 |
@deprecated
|
|
486 |
*/
|
|
487 |
{
|
|
488 |
#ifndef __KERNEL_MODE__
|
|
489 |
return MatchF(aPattern);
|
|
490 |
#else
|
|
491 |
return DoMatch8(*this,aPattern,EMatchCollated);
|
|
492 |
#endif
|
|
493 |
}
|
|
494 |
|
|
495 |
#ifndef __KERNEL_MODE__
|
|
496 |
|
|
497 |
EXPORT_C TInt TDesC8::FindF(const TUint8 *pS,TInt aLenS) const
|
|
498 |
/**
|
|
499 |
Searches for the first occurrence of the specified folded data sequence within
|
|
500 |
this descriptor's folded data.
|
|
501 |
|
|
502 |
Searching always starts at the beginning of this descriptor's data.
|
|
503 |
|
|
504 |
Note that folding is locale-independent behaviour. It is also important to
|
|
505 |
note that there can be no guarantee that folding is in any way culturally
|
|
506 |
appropriate, and should not be used for finding strings in natural language;
|
|
507 |
use FindC() for this.
|
|
508 |
|
|
509 |
@param pS A pointer to a location containing the data sequence to be
|
|
510 |
searched for.
|
|
511 |
@param aLenS The length of the data sequence to be searched for. This value
|
|
512 |
must not be negative, otherwise the function raises a panic.
|
|
513 |
|
|
514 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
515 |
data. KErrNotFound, if the data sequence cannot be found. Zero, if the
|
|
516 |
length of the search data sequence is zero.
|
|
517 |
|
|
518 |
@panic USER 29 if aLenS is negative
|
|
519 |
|
|
520 |
@see TDesC8::FindC()
|
|
521 |
*/
|
|
522 |
{
|
|
523 |
if (!aLenS)
|
|
524 |
return(0);
|
|
525 |
const TUint8* table=convTable(EMatchFolded);
|
|
526 |
const TUint8 *pB=Ptr();
|
|
527 |
TInt aLenB=Length();
|
|
528 |
const TUint8 *pC=pB-1; // using pre-increment addressing
|
|
529 |
TInt i=aLenB-aLenS;
|
|
530 |
if (i>=0)
|
|
531 |
{
|
|
532 |
const TUint8* pEndS=pS+aLenS-1; // using pre-increment addressing
|
|
533 |
const TUint8 *pEndB=pB+i; // using pre-increment addressing
|
|
534 |
TUint s=lookup(pS,table);
|
|
535 |
for (;;)
|
|
536 |
{
|
|
537 |
do
|
|
538 |
{
|
|
539 |
if (pC==pEndB)
|
|
540 |
return KErrNotFound;
|
|
541 |
} while (lookup(++pC,table)!=s);
|
|
542 |
const TUint8 *p1=pC;
|
|
543 |
const TUint8 *p2=pS;
|
|
544 |
do
|
|
545 |
{
|
|
546 |
if (p2==pEndS)
|
|
547 |
return (pC-pB);
|
|
548 |
} while (lookup(++p1,table)==lookup(++p2,table));
|
|
549 |
}
|
|
550 |
}
|
|
551 |
return(KErrNotFound);
|
|
552 |
}
|
|
553 |
|
|
554 |
EXPORT_C TInt TDesC8::FindF(const TDesC8 &aDes) const
|
|
555 |
/**
|
|
556 |
Searches for the first occurrence of the specified folded data sequence within
|
|
557 |
this descriptor's folded data.
|
|
558 |
|
|
559 |
Searching always starts at the beginning of this descriptor's data.
|
|
560 |
|
|
561 |
Note that folding is locale-independent behaviour. It is also important to
|
|
562 |
note that there can be no guarantee that folding is in any way culturally
|
|
563 |
appropriate, and should not be used for finding strings in natural language;
|
|
564 |
use FindC() for this.
|
|
565 |
|
|
566 |
@param aDes The 8-bit non-modifable descriptor containing the data sequence
|
|
567 |
to be searched for.
|
|
568 |
|
|
569 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
570 |
data. KErrNotFound, if the data sequence cannot be found. Zero, if the
|
|
571 |
length of the search data sequence is zero.
|
|
572 |
|
|
573 |
@see TDesC8::FindC()
|
|
574 |
*/
|
|
575 |
{
|
|
576 |
|
|
577 |
return(FindF(aDes.Ptr(),aDes.Length()));
|
|
578 |
}
|
|
579 |
|
|
580 |
EXPORT_C TInt TDesC8::FindC(const TUint8* aText,TInt aLength) const
|
|
581 |
/**
|
|
582 |
Searches for the first occurrence of the specified collated data sequence within
|
|
583 |
this descriptor's collated data.
|
|
584 |
|
|
585 |
Searching always starts at the beginning of this descriptor's data. The function
|
|
586 |
uses the standard collation method for narrow text appropriate to the current
|
|
587 |
locale.
|
|
588 |
|
|
589 |
@param aText A pointer to a location containing the data sequence to be
|
|
590 |
searched for.
|
|
591 |
@param aLength The length of the data sequence to be searched for.
|
|
592 |
|
|
593 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
594 |
data. KErrNotFound, if the data sequence cannot be found.
|
|
595 |
|
|
596 |
@panic USER 29 if aLength is negative.
|
|
597 |
@deprecated
|
|
598 |
*/
|
|
599 |
{
|
|
600 |
return FindF(aText, aLength);
|
|
601 |
}
|
|
602 |
|
|
603 |
EXPORT_C TInt TDesC8::FindC(const TDesC8 &aDes) const
|
|
604 |
/**
|
|
605 |
Searches for the first occurrence of the specified collated data sequence within
|
|
606 |
this descriptor's collated data.
|
|
607 |
|
|
608 |
Searching always starts at the beginning of this descriptor's data. The function
|
|
609 |
uses the standard collation method for narrow text appropriate to the current
|
|
610 |
locale.
|
|
611 |
|
|
612 |
@param aDes The 8-bit non-modifable descriptor containing the data sequence
|
|
613 |
to be searched for.
|
|
614 |
|
|
615 |
@return The offset of the data sequence from the beginning of this descriptor's
|
|
616 |
data. KErrNotFound, if the data sequence cannot be found.
|
|
617 |
@deprecated
|
|
618 |
*/
|
|
619 |
{
|
|
620 |
|
|
621 |
return(FindC(aDes.Ptr(),aDes.Length()));
|
|
622 |
}
|
|
623 |
|
|
624 |
EXPORT_C TInt TDesC8::LocateF(TChar aChar) const
|
|
625 |
/**
|
|
626 |
Searches for the first occurrence of a folded character within this
|
|
627 |
descriptor's folded data.
|
|
628 |
|
|
629 |
The search starts at the beginning of the data,i.e. at the leftmost position.
|
|
630 |
|
|
631 |
Note that folding is locale-independent behaviour. It is also important to
|
|
632 |
note that there can be no guarantee that folding is in any way culturally
|
|
633 |
appropriate, and should not be used for searching strings in natural language.
|
|
634 |
|
|
635 |
@param aChar The character to be found.
|
|
636 |
|
|
637 |
@return The offset of the character position from the beginning of the data.
|
|
638 |
KErrNotFound, if no matching character can be found.
|
|
639 |
*/
|
|
640 |
{
|
|
641 |
TUint c = User::Fold(aChar);
|
|
642 |
if(c>=0x100)
|
|
643 |
return KErrNotFound;
|
|
644 |
const TUint8 *pBuf=Ptr();
|
|
645 |
const TUint8 *pB=pBuf-1;
|
|
646 |
const TUint8 *pE=pB+Length();
|
|
647 |
const TUint8* table=__FoldCollTab8;
|
|
648 |
do
|
|
649 |
{
|
|
650 |
if (pB==pE)
|
|
651 |
return KErrNotFound;
|
|
652 |
} while (table[*++pB]!=c);
|
|
653 |
return pB-pBuf;
|
|
654 |
}
|
|
655 |
#endif // __KERNEL_MODE__
|
|
656 |
|
|
657 |
#ifndef __DES8_MACHINE_CODED__
|
|
658 |
EXPORT_C TInt TDesC8::Locate(TChar aChar) const
|
|
659 |
/**
|
|
660 |
Searches for the first occurrence of a character within this descriptor's
|
|
661 |
data.
|
|
662 |
|
|
663 |
The search starts at the beginning of the data, i.e. at the leftmost position.
|
|
664 |
|
|
665 |
@param aChar The character to be found.
|
|
666 |
|
|
667 |
@return The offset of the character position from the beginning of the data.
|
|
668 |
KErrNotFound, if no matching character can be found.
|
|
669 |
*/
|
|
670 |
{
|
|
671 |
|
|
672 |
const TUint8 *pBuf=Ptr();
|
|
673 |
const TUint8 *pB=pBuf-1;
|
|
674 |
const TUint8 *pE=pB+Length();
|
|
675 |
do
|
|
676 |
{
|
|
677 |
if (pB==pE)
|
|
678 |
return KErrNotFound;
|
|
679 |
} while (*++pB!=aChar);
|
|
680 |
return pB-pBuf;
|
|
681 |
}
|
|
682 |
#endif
|
|
683 |
|
|
684 |
#ifndef __DES8_MACHINE_CODED__
|
|
685 |
EXPORT_C TInt TDesC8::LocateReverse(TChar aChar) const
|
|
686 |
/**
|
|
687 |
Searches for the first occurrence of a character within this descriptor's data,
|
|
688 |
searching from the end of the data.
|
|
689 |
|
|
690 |
The search starts at the rightmost position.
|
|
691 |
|
|
692 |
@param aChar The character to be found.
|
|
693 |
|
|
694 |
@return The offset of the character position from the beginning of the data.
|
|
695 |
KErrNotFound, if no matching character can be found.
|
|
696 |
*/
|
|
697 |
{
|
|
698 |
|
|
699 |
TInt len=Length();
|
|
700 |
if (len==0)
|
|
701 |
return(KErrNotFound);
|
|
702 |
const TUint8 *pB=Ptr();
|
|
703 |
const TUint8 *pE=pB+len-1;
|
|
704 |
while (pE>=pB)
|
|
705 |
{
|
|
706 |
if (*pE==aChar)
|
|
707 |
break;
|
|
708 |
pE--;
|
|
709 |
}
|
|
710 |
return(pE<pB ? KErrNotFound : pE-pB);
|
|
711 |
}
|
|
712 |
#endif
|
|
713 |
|
|
714 |
#ifndef __KERNEL_MODE__
|
|
715 |
EXPORT_C TInt TDesC8::LocateReverseF(TChar aChar) const
|
|
716 |
/**
|
|
717 |
Searches for the first occurrence of a folded character within this descriptor's
|
|
718 |
folded data, searching from the end of the data.
|
|
719 |
|
|
720 |
The search starts at the rightmost position.
|
|
721 |
|
|
722 |
Note that folding is locale-independent behaviour. It is also important to
|
|
723 |
note that there can be no guarantee that folding is in any way culturally
|
|
724 |
appropriate, and should not be used for searching strings in natural language.
|
|
725 |
|
|
726 |
@param aChar The character to be found
|
|
727 |
|
|
728 |
@return The offset of the character position from the beginning of the data.
|
|
729 |
KErrNotFound, if no matching character can be found
|
|
730 |
*/
|
|
731 |
{
|
|
732 |
|
|
733 |
TInt len=Length();
|
|
734 |
if (len==0)
|
|
735 |
return(KErrNotFound);
|
|
736 |
const TUint8 *pB=Ptr();
|
|
737 |
const TUint8 *pE=pB+len-1;
|
|
738 |
const TUint8* table=__FoldCollTab8;
|
|
739 |
TUint c = table[aChar];
|
|
740 |
while (pE>=pB)
|
|
741 |
{
|
|
742 |
if (table[*pE]==c)
|
|
743 |
break;
|
|
744 |
pE--;
|
|
745 |
}
|
|
746 |
return(pE<pB ? KErrNotFound : pE-pB);
|
|
747 |
}
|
|
748 |
|
|
749 |
EXPORT_C HBufC8 *TDesC8::Alloc() const
|
|
750 |
/**
|
|
751 |
Creates a new 8-bit heap descriptor and initialises it with a copy of this
|
|
752 |
descriptor's data.
|
|
753 |
|
|
754 |
@return A pointer to the new 8 bit heap descriptor, if creation is successful.
|
|
755 |
NULL, if creation of the descriptor fails.
|
|
756 |
*/
|
|
757 |
{
|
|
758 |
|
|
759 |
HBufC8 *pH=HBufC8::New(Length());
|
|
760 |
if (pH)
|
|
761 |
*pH=(*this);
|
|
762 |
return(pH);
|
|
763 |
}
|
|
764 |
|
|
765 |
EXPORT_C HBufC8 *TDesC8::AllocL() const
|
|
766 |
/**
|
|
767 |
Creates a new 8-bit heap descriptor and initialises it with a copy of this
|
|
768 |
descriptor's data.
|
|
769 |
|
|
770 |
The function leaves, if creation of the descriptor fails.
|
|
771 |
|
|
772 |
@return A pointer to the 8-bit heap descriptor, if creation is successful.
|
|
773 |
*/
|
|
774 |
{
|
|
775 |
|
|
776 |
HBufC8 *pH=HBufC8::NewL(Length());
|
|
777 |
*pH=(*this);
|
|
778 |
return(pH);
|
|
779 |
}
|
|
780 |
|
|
781 |
EXPORT_C HBufC8 *TDesC8::AllocLC() const
|
|
782 |
/**
|
|
783 |
Creates a new 8-bit heap descriptor, initialises it with a copy of this
|
|
784 |
descriptor's data, and puts a pointer to the descriptor onto the cleanup stack.
|
|
785 |
|
|
786 |
The function leaves, if creation of the descriptor fails.
|
|
787 |
|
|
788 |
@return A pointer to the 8 bit heap descriptor, if creation is successful.
|
|
789 |
The pointer is also put onto the cleanup stack.
|
|
790 |
*/
|
|
791 |
{
|
|
792 |
|
|
793 |
HBufC8 *pH=HBufC8::NewLC(Length());
|
|
794 |
*pH=(*this);
|
|
795 |
return(pH);
|
|
796 |
}
|
|
797 |
#endif // __KERNEL_MODE__
|
|
798 |
|
|
799 |
#if !defined(__DES8_MACHINE_CODED__)
|
|
800 |
|
|
801 |
EXPORT_C TPtrC8 TDesC8::Left(TInt aLength) const
|
|
802 |
/**
|
|
803 |
Extracts the leftmost part of the data.
|
|
804 |
|
|
805 |
The function does not cut or remove any data but constructs a non-modifiable
|
|
806 |
pointer descriptor to represent the leftmost part of the data.
|
|
807 |
|
|
808 |
@param aLength The length of the data to be extracted. If this value
|
|
809 |
is greater than the length of the descriptor, the function
|
|
810 |
extracts the whole of the descriptor.
|
|
811 |
|
|
812 |
@return The 8-bit non-modifiable pointer descriptor representing the leftmost
|
|
813 |
part of the data.
|
|
814 |
|
|
815 |
@panic USER 22 if aLength is negative.
|
|
816 |
*/
|
|
817 |
{
|
|
818 |
|
|
819 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
|
|
820 |
return(TPtrC8(Ptr(),Min(aLength,Length())));
|
|
821 |
}
|
|
822 |
|
|
823 |
EXPORT_C TPtrC8 TDesC8::Right(TInt aLength) const
|
|
824 |
/**
|
|
825 |
Extracts the rightmost part of the data.
|
|
826 |
|
|
827 |
The function does not cut or remove any data but constructs a non-modifiable
|
|
828 |
pointer descriptor to represent the rightmost part of the data.
|
|
829 |
|
|
830 |
@param aLength The length of data to be extracted. If this value
|
|
831 |
is greater than the length of the descriptor, the function
|
|
832 |
extracts the whole of the descriptor.
|
|
833 |
|
|
834 |
@return The 8 bit non-modifiable pointer descriptor representing the rightmost
|
|
835 |
part of the data.
|
|
836 |
|
|
837 |
@panic USER 22 if aLength is negative.
|
|
838 |
*/
|
|
839 |
{
|
|
840 |
|
|
841 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
|
|
842 |
TInt len=Length();
|
|
843 |
if (aLength>len)
|
|
844 |
aLength=len;
|
|
845 |
return(TPtrC8(Ptr()+len-aLength,aLength));
|
|
846 |
}
|
|
847 |
|
|
848 |
EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos) const
|
|
849 |
/**
|
|
850 |
Extracts a portion of the data.
|
|
851 |
|
|
852 |
The function does not cut or remove any data but constructs a non-modifiable
|
|
853 |
pointer descriptor to represent the defined portion.
|
|
854 |
|
|
855 |
The portion is identified by its starting position and by the length of the
|
|
856 |
remainder of the data starting from the specified position.
|
|
857 |
|
|
858 |
@param aPos The starting position of the data to be extracted. This is an
|
|
859 |
offset value; a zero value refers to the leftmost data position.
|
|
860 |
|
|
861 |
@return The 8-bit non-modifiable pointer descriptor representing the specified
|
|
862 |
portion of the data.
|
|
863 |
|
|
864 |
@panic USER 22 if aPos is negative or aPos is greater than the
|
|
865 |
length of the descriptor.
|
|
866 |
*/
|
|
867 |
{
|
|
868 |
|
|
869 |
TInt len=Length();
|
|
870 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
|
|
871 |
return(TPtrC8(Ptr()+aPos,len-aPos));
|
|
872 |
}
|
|
873 |
|
|
874 |
EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos,TInt aLength) const
|
|
875 |
/**
|
|
876 |
Extracts a portion of the data.
|
|
877 |
|
|
878 |
The function does not cut or remove any data but constructs a non-modifiable
|
|
879 |
pointer descriptor to represent the defined portion.
|
|
880 |
|
|
881 |
The portion is identified by its starting position and by its length.
|
|
882 |
|
|
883 |
@param aPos The starting position of the data to be extracted. This is an
|
|
884 |
offset value; a zero value refers to the leftmost data position.
|
|
885 |
@param aLength The length of data to be extracted.
|
|
886 |
|
|
887 |
@return The 8 bit non-modifiable pointer descriptor representing the specified
|
|
888 |
portion of the data.
|
|
889 |
|
|
890 |
@panic USER 22 if aPos is negative or aPos plus aLength is greater than the
|
|
891 |
length of the descriptor.
|
|
892 |
*/
|
|
893 |
{
|
|
894 |
|
|
895 |
__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
|
|
896 |
return(TPtrC8(Ptr()+aPos,aLength));
|
|
897 |
}
|
|
898 |
|
|
899 |
#endif // !defined(__DES8_MACHINE_CODED__)
|
|
900 |
|
|
901 |
#if !defined( __DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
|
|
902 |
EXPORT_C TBufCBase8::TBufCBase8()
|
|
903 |
//
|
|
904 |
// Constructor
|
|
905 |
//
|
|
906 |
: TDesC8(EBufC,0)
|
|
907 |
{}
|
|
908 |
|
|
909 |
EXPORT_C TBufCBase8::TBufCBase8(const TUint8 *aString,TInt aMaxLength)
|
|
910 |
//
|
|
911 |
// Constructor
|
|
912 |
//
|
|
913 |
: TDesC8(EBufC,0)
|
|
914 |
{
|
|
915 |
Copy(aString,aMaxLength);
|
|
916 |
}
|
|
917 |
|
|
918 |
EXPORT_C TBufCBase8::TBufCBase8(const TDesC8 &aDes,TInt aMaxLength)
|
|
919 |
//
|
|
920 |
// Constructor
|
|
921 |
//
|
|
922 |
: TDesC8(EBufC,0)
|
|
923 |
{
|
|
924 |
Copy(aDes,aMaxLength);
|
|
925 |
}
|
|
926 |
#endif
|
|
927 |
|
|
928 |
#ifndef __DES8_MACHINE_CODED__
|
|
929 |
EXPORT_C void TBufCBase8::Copy(const TUint8 *aString,TInt aMaxLength)
|
|
930 |
//
|
|
931 |
// Copy from a string.
|
|
932 |
//
|
|
933 |
{
|
|
934 |
|
|
935 |
TInt len=STRING_LENGTH(aString);
|
|
936 |
__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
|
|
937 |
memmove(WPtr(), aString, len);
|
|
938 |
DoSetLength(len);
|
|
939 |
}
|
|
940 |
|
|
941 |
EXPORT_C void TBufCBase8::Copy(const TDesC8 &aDes,TInt aMaxLength)
|
|
942 |
//
|
|
943 |
// Copy from a descriptor.
|
|
944 |
//
|
|
945 |
{
|
|
946 |
|
|
947 |
TInt len=aDes.Length();
|
|
948 |
__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
|
|
949 |
memmove(WPtr(), aDes.Ptr(), len);
|
|
950 |
DoSetLength(len);
|
|
951 |
}
|
|
952 |
#endif
|
|
953 |
|
|
954 |
#ifndef __KERNEL_MODE__
|
|
955 |
inline HBufC8::HBufC8(TInt aLength)
|
|
956 |
:TBufCBase8(aLength)
|
|
957 |
{}
|
|
958 |
|
|
959 |
EXPORT_C HBufC8 *HBufC8::New(TInt aMaxLength)
|
|
960 |
/**
|
|
961 |
Creates, and returns a pointer to, a new 8-bit heap descriptor.
|
|
962 |
|
|
963 |
The heap descriptor is empty and its length is zero.
|
|
964 |
|
|
965 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
966 |
|
|
967 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
968 |
the resulting heap cell size and, therefore, the resulting
|
|
969 |
maximum length of the descriptor may be larger
|
|
970 |
than requested.
|
|
971 |
|
|
972 |
@return A pointer to the new 8-bit heap descriptor. NULL, if the 8-bit heap
|
|
973 |
descriptor cannot be created.
|
|
974 |
|
|
975 |
@panic USER 30 if aMaxLength is negative.
|
|
976 |
|
|
977 |
@see HBufC8::operator=()
|
|
978 |
*/
|
|
979 |
{
|
|
980 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
981 |
return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(0);
|
|
982 |
}
|
|
983 |
|
|
984 |
EXPORT_C HBufC8 *HBufC8::NewL(TInt aMaxLength)
|
|
985 |
/**
|
|
986 |
Creates, and returns a pointer to, a new 8-bit heap descriptor, and leaves
|
|
987 |
on failure.
|
|
988 |
|
|
989 |
The heap descriptor is empty and its length is zero.
|
|
990 |
|
|
991 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
992 |
|
|
993 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
994 |
the resulting heap cell size and, therefore, the resulting
|
|
995 |
maximum length of the descriptor may be larger
|
|
996 |
than requested.
|
|
997 |
|
|
998 |
@return A pointer to the new 8 bit heap descriptor. The function leaves, if
|
|
999 |
the new 8-bit heap descriptor cannot be created.
|
|
1000 |
|
|
1001 |
@panic USER 30 if aMaxLength is negative.
|
|
1002 |
|
|
1003 |
@see HBufC8::operator=()
|
|
1004 |
*/
|
|
1005 |
{
|
|
1006 |
return static_cast<HBufC8*>(User::LeaveIfNull(New(aMaxLength)));
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
EXPORT_C HBufC8 *HBufC8::NewLC(TInt aMaxLength)
|
|
1010 |
/**
|
|
1011 |
Creates, adds a pointer onto the cleanup stack, and returns a pointer to, a
|
|
1012 |
new 8 bit heap descriptor; leaves on failure.
|
|
1013 |
|
|
1014 |
The heap descriptor is empty and its length is zero.
|
|
1015 |
|
|
1016 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
1017 |
|
|
1018 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
1019 |
the resulting heap cell size and, therefore, the resulting
|
|
1020 |
maximum length of the descriptor may be larger
|
|
1021 |
than requested.
|
|
1022 |
|
|
1023 |
@return A pointer to the new 8-bit heap descriptor. The function leaves, if
|
|
1024 |
the new 8-bit heap descriptor cannot be created.
|
|
1025 |
|
|
1026 |
@panic USER 30 if aMaxLength is negative.
|
|
1027 |
|
|
1028 |
@see HBufC8::operator=()
|
|
1029 |
*/
|
|
1030 |
{
|
|
1031 |
HBufC8* buf=NewL(aMaxLength);
|
|
1032 |
CleanupStack::PushL(buf);
|
|
1033 |
return buf;
|
|
1034 |
}
|
|
1035 |
|
|
1036 |
EXPORT_C HBufC8 *HBufC8::NewMax(TInt aMaxLength)
|
|
1037 |
/**
|
|
1038 |
Creates, and returns a pointer to, a new 8-bit heap descriptor.
|
|
1039 |
|
|
1040 |
No data is assigned into the new descriptor but its length
|
|
1041 |
is set to aMaxLength.
|
|
1042 |
|
|
1043 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
1044 |
|
|
1045 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
1046 |
the resulting heap cell size and, therefore, the resulting
|
|
1047 |
maximum length of the descriptor may be larger
|
|
1048 |
than requested. This also means that the resulting maximum
|
|
1049 |
length of the descriptor may be greater than its length.
|
|
1050 |
|
|
1051 |
@return A pointer to the new 8-bit heap descriptor. NULL, if the new 8-bit
|
|
1052 |
heap descriptor cannot be created.
|
|
1053 |
|
|
1054 |
@panic USER 30 if aMaxLength is negative.
|
|
1055 |
|
|
1056 |
@see HBufC8::operator=()
|
|
1057 |
*/
|
|
1058 |
{
|
|
1059 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
1060 |
return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(aMaxLength);
|
|
1061 |
}
|
|
1062 |
|
|
1063 |
EXPORT_C HBufC8 *HBufC8::NewMaxL(TInt aMaxLength)
|
|
1064 |
/**
|
|
1065 |
Creates, and returns a pointer to, a new 8-bit heap descriptor;
|
|
1066 |
leaves on failure.
|
|
1067 |
|
|
1068 |
No data is assigned into the new descriptor but its length
|
|
1069 |
is set to aMaxLength.
|
|
1070 |
|
|
1071 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
1072 |
|
|
1073 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
1074 |
the resulting heap cell size and, therefore, the resulting
|
|
1075 |
maximum length of the descriptor may be larger
|
|
1076 |
than requested. This also means that the resulting maximum
|
|
1077 |
length of the descriptor may be greater than its length.
|
|
1078 |
|
|
1079 |
@return A pointer to the new 8-bit heap descriptor. The function leaves, if
|
|
1080 |
the new 8-bit heap descriptor cannot be created.
|
|
1081 |
|
|
1082 |
@panic USER 30 if aMaxLength is negative.
|
|
1083 |
|
|
1084 |
@see HBufC8::operator=()
|
|
1085 |
*/
|
|
1086 |
{
|
|
1087 |
return static_cast<HBufC8*>(User::LeaveIfNull(NewMax(aMaxLength)));
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
EXPORT_C HBufC8 *HBufC8::NewMaxLC(TInt aMaxLength)
|
|
1091 |
/**
|
|
1092 |
Creates, adds a pointer onto the cleanup stack and returns a pointer to, a
|
|
1093 |
new 8-bit heap descriptor; leaves on failure.
|
|
1094 |
|
|
1095 |
No data is assigned into the new descriptor but its length
|
|
1096 |
is set to aMaxLength.
|
|
1097 |
|
|
1098 |
Data can, subsequently, be assigned into it using the assignment operators.
|
|
1099 |
|
|
1100 |
@param aMaxLength The requested maximum length of the descriptor. Note that
|
|
1101 |
the resulting heap cell size and, therefore, the resulting
|
|
1102 |
maximum length of the descriptor may be larger than requested.
|
|
1103 |
This also means that the resulting maximum
|
|
1104 |
length of the descriptor may be greater than its length.
|
|
1105 |
|
|
1106 |
@return A pointer to the new 8-bit heap descriptor. This is also put onto the
|
|
1107 |
cleanup stack. The function leaves, if the new 8-bit heap descriptor
|
|
1108 |
cannot be created.
|
|
1109 |
|
|
1110 |
@panic USER 30 if aMaxLength is negative.
|
|
1111 |
|
|
1112 |
@see HBufC8::operator=()
|
|
1113 |
*/
|
|
1114 |
{
|
|
1115 |
HBufC8* buf=NewMaxL(aMaxLength);
|
|
1116 |
CleanupStack::PushL(buf);
|
|
1117 |
return buf;
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
EXPORT_C HBufC8 &HBufC8::operator=(const TUint8 *aString)
|
|
1121 |
/**
|
|
1122 |
Copies data into this 8-bit heap descriptor replacing any existing data.
|
|
1123 |
|
|
1124 |
The length of this descriptor is set to reflect the new data.
|
|
1125 |
|
|
1126 |
Note that the maximum length of this (target) descriptor is the length
|
|
1127 |
of the descriptor buffer in the allocated host heap cell; this may be greater
|
|
1128 |
than the maximum length specified when this descriptor was created or
|
|
1129 |
last re-allocated.
|
|
1130 |
|
|
1131 |
@param aString A pointer to a zero-terminated string.
|
|
1132 |
|
|
1133 |
@return A reference to this 8 bit heap descriptor.
|
|
1134 |
|
|
1135 |
@panic USER 23 if the length of the string, excluding the zero terminator,
|
|
1136 |
is greater than the maximum length of this (target) descriptor,
|
|
1137 |
*/
|
|
1138 |
{
|
|
1139 |
|
|
1140 |
Copy(aString,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
|
|
1141 |
return(*this);
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
EXPORT_C HBufC8 &HBufC8::operator=(const TDesC8 &aDes)
|
|
1145 |
/**
|
|
1146 |
Copies data into this 8-bit heap descriptor replacing any existing data.
|
|
1147 |
|
|
1148 |
The length of this descriptor is set to reflect the new data.
|
|
1149 |
|
|
1150 |
Note that the maximum length of this (target) descriptor is the length
|
|
1151 |
of the descriptor buffer in the allocated host heap cell; this may be greater
|
|
1152 |
than the maximum length specified when this descriptor was created or last
|
|
1153 |
re-allocated.
|
|
1154 |
|
|
1155 |
@param aDes An 8-bit non-modifiable descriptor.
|
|
1156 |
|
|
1157 |
@return A reference to this 8-bit heap descriptor.
|
|
1158 |
|
|
1159 |
@panic USER 23 if the length of the descriptor aDes is greater than the
|
|
1160 |
maximum length of this (target) descriptor
|
|
1161 |
*/
|
|
1162 |
{
|
|
1163 |
|
|
1164 |
Copy(aDes,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
|
|
1165 |
return(*this);
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
EXPORT_C HBufC8 *HBufC8::ReAlloc(TInt aMaxLength)
|
|
1169 |
/**
|
|
1170 |
Expands or contracts the heap descriptor.
|
|
1171 |
|
|
1172 |
This is done by:
|
|
1173 |
|
|
1174 |
1. creating a new heap descriptor.
|
|
1175 |
|
|
1176 |
2. copying the original data into the new descriptor.
|
|
1177 |
|
|
1178 |
3. deleting the original descriptor.
|
|
1179 |
|
|
1180 |
@param aMaxLength The new requested maximum length of the descriptor.
|
|
1181 |
Note that the resulting heap cell size and, therefore,
|
|
1182 |
the resulting maximum length of the descriptor may be
|
|
1183 |
larger than requested.
|
|
1184 |
|
|
1185 |
@return A pointer to the new expanded or contracted 8 bit heap descriptor -
|
|
1186 |
the original descriptor is deleted. NULL, if the new 8-bit heap descriptor
|
|
1187 |
cannot be created - the original descriptor remains unchanged
|
|
1188 |
|
|
1189 |
@panic USER 26 if aMaxLength is less than the length of the existing data.
|
|
1190 |
@panic USER 30 if aMaxLength is negative.
|
|
1191 |
*/
|
|
1192 |
{
|
|
1193 |
|
|
1194 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
1195 |
__ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes8ReAllocTooSmall));
|
|
1196 |
return((HBufC8 *)STD_CLASS::ReAlloc(this,(aMaxLength*sizeof(TUint8))+sizeof(TDesC8)));
|
|
1197 |
}
|
|
1198 |
|
|
1199 |
EXPORT_C HBufC8 *HBufC8::ReAllocL(TInt aMaxLength)
|
|
1200 |
/**
|
|
1201 |
Expands or contracts the descriptor; leaves on failure.
|
|
1202 |
|
|
1203 |
This is done by:
|
|
1204 |
|
|
1205 |
1. creating a new heap descriptor.
|
|
1206 |
|
|
1207 |
2. copying the original data into the new descriptor.
|
|
1208 |
|
|
1209 |
3. deleting the original descriptor.
|
|
1210 |
|
|
1211 |
@param aMaxLength The new requested maximum length of the descriptor.
|
|
1212 |
Note that the resulting heap cell size and, therefore,
|
|
1213 |
the resulting maximum length of the descriptor may be
|
|
1214 |
larger than requested.
|
|
1215 |
|
|
1216 |
@return A pointer to the new expanded or contracted 8 bit heap descriptor -
|
|
1217 |
the original descriptor is deleted. NULL, if the new 8-bit heap descriptor
|
|
1218 |
cannot be created - the original descriptor remains unchanged
|
|
1219 |
|
|
1220 |
@panic USER 26 if aMaxLength is less than the length of the existing data.
|
|
1221 |
@panic USER 30 if aMaxLength is negative.
|
|
1222 |
*/
|
|
1223 |
{
|
|
1224 |
|
|
1225 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
1226 |
__ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes8ReAllocTooSmall));
|
|
1227 |
return((HBufC8 *)STD_CLASS::ReAllocL(this,(aMaxLength*sizeof(TUint8))+sizeof(TDesC8)));
|
|
1228 |
}
|
|
1229 |
|
|
1230 |
EXPORT_C TPtr8 HBufC8::Des()
|
|
1231 |
/**
|
|
1232 |
Creates and returns an 8-bit modifiable pointer descriptor for the data
|
|
1233 |
represented by this 8-bit heap descriptor.
|
|
1234 |
|
|
1235 |
The content of a heap descriptor normally cannot be altered, other than by
|
|
1236 |
complete replacement of the data. Creating a modifiable pointer descriptor
|
|
1237 |
provides a way of changing the data.
|
|
1238 |
|
|
1239 |
The modifiable pointer descriptor is set to point to this heap descriptor's
|
|
1240 |
data.
|
|
1241 |
|
|
1242 |
The length of the modifiable pointer descriptor is set to the length of this
|
|
1243 |
heap descriptor.
|
|
1244 |
|
|
1245 |
The maximum length of the modifiable pointer descriptor is set to the length
|
|
1246 |
of the heap descriptor's buffer. Note that the maximum length is the length
|
|
1247 |
of the descriptor buffer in the allocated host heap cell; this may be greater
|
|
1248 |
than the maximum length requested when this descriptor was originally created
|
|
1249 |
or last re-allocated.
|
|
1250 |
|
|
1251 |
When data is modified through this new pointer descriptor, the lengths of
|
|
1252 |
both it and this heap descriptor are changed.
|
|
1253 |
|
|
1254 |
Note that it is a common mistake to use Des() to create a TDesC8& reference.
|
|
1255 |
While not incorrect, it is simpler and much more efficient to simply dereference
|
|
1256 |
the heap descriptor.
|
|
1257 |
|
|
1258 |
@return An 8-bit modifiable pointer descriptor representing the data in this
|
|
1259 |
8-bit heap descriptor.
|
|
1260 |
*/
|
|
1261 |
{
|
|
1262 |
return DoDes((STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
|
|
1263 |
}
|
|
1264 |
#endif // __KERNEL_MODE__
|
|
1265 |
|
|
1266 |
#ifndef __DES8_MACHINE_CODED__
|
|
1267 |
EXPORT_C void TDes8::SetLength(TInt aLength)
|
|
1268 |
/**
|
|
1269 |
Sets the length of the data represented by the descriptor to the
|
|
1270 |
specified value.
|
|
1271 |
|
|
1272 |
@param aLength The new length of the descriptor.
|
|
1273 |
|
|
1274 |
@panic USER 23 if alength is negative or is greater than the maximum length of
|
|
1275 |
this (target) descriptor.
|
|
1276 |
*/
|
|
1277 |
{
|
|
1278 |
|
|
1279 |
__ASSERT_ALWAYS(TUint(aLength)<=TUint(MaxLength()),Panic(ETDes8Overflow));
|
|
1280 |
DoSetLength(aLength);
|
|
1281 |
if (Type()==EBufCPtr)
|
|
1282 |
((SBufCPtr8 *)this)->ptr->length=aLength; // Relies on iType==0 for an TBufC
|
|
1283 |
}
|
|
1284 |
|
|
1285 |
EXPORT_C void TDes8::SetMax()
|
|
1286 |
/**
|
|
1287 |
Sets the length of the data to the maximum length of the descriptor.
|
|
1288 |
*/
|
|
1289 |
{
|
|
1290 |
|
|
1291 |
SetLength(iMaxLength);
|
|
1292 |
}
|
|
1293 |
|
|
1294 |
EXPORT_C void TDes8::Copy(const TUint8 *aString)
|
|
1295 |
/**
|
|
1296 |
Copies data into this descriptor replacing any existing data.
|
|
1297 |
|
|
1298 |
The length of this descriptor is set to reflect the new data.
|
|
1299 |
|
|
1300 |
@param aString A pointer to a zero-terminated string.
|
|
1301 |
|
|
1302 |
@panic USER 23 if the length of aString, excluding the zero terminator, is
|
|
1303 |
greater than the maximum length of this (target) descriptor.
|
|
1304 |
*/
|
|
1305 |
{
|
|
1306 |
|
|
1307 |
TInt len=STRING_LENGTH(aString);
|
|
1308 |
SetLength(len);
|
|
1309 |
memmove(WPtr(), aString, len);
|
|
1310 |
}
|
|
1311 |
|
|
1312 |
EXPORT_C void TDes8::Copy(const TUint8 *aBuf,TInt aLength)
|
|
1313 |
/**
|
|
1314 |
Copies data into this descriptor replacing any existing data.
|
|
1315 |
|
|
1316 |
The length of this descriptor is set to reflect the new data.
|
|
1317 |
|
|
1318 |
@param aBuf The start address of data to be copied.
|
|
1319 |
@param aLength The length of data to be copied.
|
|
1320 |
|
|
1321 |
@panic USER 23 if aLength is greater than the maximum length of
|
|
1322 |
this (target) descriptor.
|
|
1323 |
*/
|
|
1324 |
{
|
|
1325 |
|
|
1326 |
SetLength(aLength);
|
|
1327 |
memmove(WPtr(), aBuf, aLength);
|
|
1328 |
}
|
|
1329 |
|
|
1330 |
EXPORT_C void TDes8::Copy(const TDesC8 &aDes)
|
|
1331 |
/**
|
|
1332 |
Copies data into this descriptor replacing any existing data.
|
|
1333 |
|
|
1334 |
The length of this descriptor is set to reflect the new data.
|
|
1335 |
|
|
1336 |
@param aDes An 8-bit non-modifiable descriptor. The length of the data cannot
|
|
1337 |
be greater than the maximum length of the target descriptor.
|
|
1338 |
|
|
1339 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1340 |
this (target) descriptor.
|
|
1341 |
*/
|
|
1342 |
{
|
|
1343 |
|
|
1344 |
TInt len=aDes.Length();
|
|
1345 |
SetLength(len);
|
|
1346 |
memmove(WPtr(), aDes.Ptr(), len);
|
|
1347 |
}
|
|
1348 |
#endif
|
|
1349 |
|
|
1350 |
#ifndef __KERNEL_MODE__
|
|
1351 |
EXPORT_C void TDes8::Copy(const TDesC16 &aDes)
|
|
1352 |
/**
|
|
1353 |
Copies data into this descriptor replacing any existing data.
|
|
1354 |
|
|
1355 |
The length of this descriptor is set to reflect the new data.
|
|
1356 |
|
|
1357 |
@param aDes A 16-bit non-modifiable descriptor. Each double-byte value can
|
|
1358 |
only be copied into the corresponding single byte when the
|
|
1359 |
double-byte value is less than decimal 256. A double-byte value of
|
|
1360 |
256 or greater cannot be copied and the corresponding single byte
|
|
1361 |
is set to a value of decimal 1.
|
|
1362 |
|
|
1363 |
@panic USER 23 if the length of the aDes is greater than the maximum length
|
|
1364 |
of this (target) descriptor.
|
|
1365 |
*/
|
|
1366 |
{
|
|
1367 |
|
|
1368 |
TInt len=aDes.Length();
|
|
1369 |
SetLength(len);
|
|
1370 |
const TUint16 *pS=aDes.Ptr();
|
|
1371 |
const TUint16 *pE=pS+len;
|
|
1372 |
TUint8 *pT=WPtr();
|
|
1373 |
while (pS<pE)
|
|
1374 |
{
|
|
1375 |
TUint c=(*pS++);
|
|
1376 |
if (c>=0x100)
|
|
1377 |
c=1;
|
|
1378 |
*pT++=(TUint8)c;
|
|
1379 |
}
|
|
1380 |
}
|
|
1381 |
#endif
|
|
1382 |
|
|
1383 |
#ifndef __DES8_MACHINE_CODED__
|
|
1384 |
EXPORT_C void TDes8::Append(TChar aChar)
|
|
1385 |
/**
|
|
1386 |
Appends a character onto the end of this descriptor's data.
|
|
1387 |
|
|
1388 |
The length of this descriptor is incremented to reflect the new content.
|
|
1389 |
|
|
1390 |
@param aChar The single character to be appended. The length of the descriptor
|
|
1391 |
is incremented by one. The function assumes that the character
|
|
1392 |
is non-Unicode and that it can be represented by a single byte.
|
|
1393 |
|
|
1394 |
@panic USER 23 if the resulting new length of this descriptor is greater than
|
|
1395 |
its maximum length.
|
|
1396 |
*/
|
|
1397 |
{
|
|
1398 |
|
|
1399 |
TInt len=Length();
|
|
1400 |
TUint8 *pB=WPtr()+len;
|
|
1401 |
SetLength(len+1);
|
|
1402 |
*pB++=(TUint8)aChar;
|
|
1403 |
}
|
|
1404 |
|
|
1405 |
EXPORT_C void TDes8::Append(const TUint8 *aBuf,TInt aLength)
|
|
1406 |
/**
|
|
1407 |
Appends data onto the end of this descriptor's data.
|
|
1408 |
|
|
1409 |
The length of this descriptor is incremented to reflect the new content.
|
|
1410 |
|
|
1411 |
@param aBuf A pointer to the data to be copied.
|
|
1412 |
@param aLength The length of the data to be copied.
|
|
1413 |
|
|
1414 |
@panic USER 23 if the resulting new length of this descriptor is greater than
|
|
1415 |
its maximum length.
|
|
1416 |
@panic USER 29 if aLength is negative.
|
|
1417 |
*/
|
|
1418 |
{
|
|
1419 |
|
|
1420 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
|
|
1421 |
TInt len=Length();
|
|
1422 |
SetLength(len+aLength);
|
|
1423 |
memmove(WPtr()+len, aBuf, aLength);
|
|
1424 |
}
|
|
1425 |
|
|
1426 |
EXPORT_C void TDes8::Append(const TDesC8 &aDes)
|
|
1427 |
/**
|
|
1428 |
Appends data onto the end of this descriptor's data.
|
|
1429 |
|
|
1430 |
The length of this descriptor is incremented to reflect the new content.
|
|
1431 |
|
|
1432 |
@param aDes An 8-bit non-modifiable descriptor whose data is to be appended.
|
|
1433 |
|
|
1434 |
@panic USER 23 if the resulting new length of this descriptor is greater than
|
|
1435 |
its maximum length.
|
|
1436 |
*/
|
|
1437 |
{
|
|
1438 |
|
|
1439 |
TInt len=Length();
|
|
1440 |
TInt n=aDes.Length();
|
|
1441 |
SetLength(len+n);
|
|
1442 |
memmove(WPtr()+len, aDes.Ptr(), n);
|
|
1443 |
}
|
|
1444 |
#endif
|
|
1445 |
|
|
1446 |
#ifndef __KERNEL_MODE__
|
|
1447 |
EXPORT_C void TDes8::Append(const TDesC16 &aDes)
|
|
1448 |
/**
|
|
1449 |
Appends data onto the end of this descriptor's data.
|
|
1450 |
|
|
1451 |
The length of this descriptor is incremented to reflect the new content.
|
|
1452 |
|
|
1453 |
@param aDes A 16-bit non-modifiable descriptor whose data is to be appended.
|
|
1454 |
Each double-byte value can only be appended as a single byte when
|
|
1455 |
the double-byte value is less than decimal 256. A double-byte value
|
|
1456 |
of 256 or greater cannot be appended and the corresponding single
|
|
1457 |
byte is set to a value of decimal 1.
|
|
1458 |
|
|
1459 |
@panic USER 23 if the resulting new length of this descriptor is greater than
|
|
1460 |
its maximum length.
|
|
1461 |
*/
|
|
1462 |
{
|
|
1463 |
|
|
1464 |
TInt len=Length();
|
|
1465 |
TInt n=aDes.Length();
|
|
1466 |
const TUint16* pS=aDes.Ptr();
|
|
1467 |
const TUint16* pE=pS+n;
|
|
1468 |
TUint8 *pT=WPtr()+len;
|
|
1469 |
SetLength(len+n);
|
|
1470 |
while (pS<pE)
|
|
1471 |
{
|
|
1472 |
TUint c=(*pS++);
|
|
1473 |
if (c>=0x100)
|
|
1474 |
c=1;
|
|
1475 |
*pT++=(TUint8)c;
|
|
1476 |
}
|
|
1477 |
}
|
|
1478 |
#endif
|
|
1479 |
|
|
1480 |
#ifndef __KERNEL_MODE__
|
|
1481 |
EXPORT_C void TDes8::Swap(TDes8 &aDes)
|
|
1482 |
/**
|
|
1483 |
Swaps the data represented by this descriptor with the data represented by
|
|
1484 |
the specified descriptor.
|
|
1485 |
|
|
1486 |
The lengths of both descriptors are swapped to reflect the change.
|
|
1487 |
|
|
1488 |
Note that each descriptor must be capable of accommodating the contents of
|
|
1489 |
the other descriptor.
|
|
1490 |
|
|
1491 |
@param aDes The 8-bit modifiable descriptor whose data is to be swapped with
|
|
1492 |
the data of this descriptor.
|
|
1493 |
|
|
1494 |
@panic USER 23 if the maximum length of either descriptor is smaller than the
|
|
1495 |
length of the other descriptor.
|
|
1496 |
*/
|
|
1497 |
{
|
|
1498 |
|
|
1499 |
TInt l=Length();
|
|
1500 |
TInt r=aDes.Length();
|
|
1501 |
aDes.SetLength(l);
|
|
1502 |
SetLength(r);
|
|
1503 |
TInt s=Min(l,r);
|
|
1504 |
l-=s;
|
|
1505 |
r-=s;
|
|
1506 |
TUint8 *pL=WPtr();
|
|
1507 |
TUint8 *pR=aDes.WPtr();
|
|
1508 |
while (s--)
|
|
1509 |
{
|
|
1510 |
TChar a=(*pL);
|
|
1511 |
*pL++=(*pR);
|
|
1512 |
*pR++=(TUint8)a;
|
|
1513 |
}
|
|
1514 |
while (l--)
|
|
1515 |
*pR++=(*pL++);
|
|
1516 |
while (r--)
|
|
1517 |
*pL++=(*pR++);
|
|
1518 |
}
|
|
1519 |
#endif
|
|
1520 |
|
|
1521 |
#ifndef __DES8_MACHINE_CODED__
|
|
1522 |
EXPORT_C void TDes8::Fill(TChar aChar)
|
|
1523 |
/**
|
|
1524 |
Fills the descriptor's data area with the specified character, replacing any
|
|
1525 |
existing data.
|
|
1526 |
|
|
1527 |
The descriptor is filled from the beginning up to its current length. The
|
|
1528 |
descriptor's length does not change. It is not filled to its maximum length.
|
|
1529 |
|
|
1530 |
@param aChar The fill character. The function assumes that the character is
|
|
1531 |
non-Unicode, and that it can be represented by a single byte.
|
|
1532 |
*/
|
|
1533 |
{
|
|
1534 |
|
|
1535 |
memset(WPtr(), (TInt)(aChar.operator TUint()), Length());
|
|
1536 |
}
|
|
1537 |
#endif
|
|
1538 |
|
|
1539 |
EXPORT_C void TDes8::Fill(TChar aChar,TInt aLength)
|
|
1540 |
/**
|
|
1541 |
Fills the descriptor's data area with the specified character, replacing any
|
|
1542 |
existing data.
|
|
1543 |
|
|
1544 |
The descriptor is filled with the specified number of characters.
|
|
1545 |
and its length is changed to reflect this.
|
|
1546 |
|
|
1547 |
@param aChar The fill character. The function assumes that the character is
|
|
1548 |
non-Unicode, and that it can be represented by a single byte.
|
|
1549 |
@param aLength The new length of the descriptor and the number of fill
|
|
1550 |
characters to be copied into it.
|
|
1551 |
|
|
1552 |
@panic USER 23 if aLength is negative or is greater than the maximum length
|
|
1553 |
of this descriptor.
|
|
1554 |
*/
|
|
1555 |
{
|
|
1556 |
|
|
1557 |
SetLength(aLength);
|
|
1558 |
memset(WPtr(), (TInt)(aChar.operator TUint()), aLength);
|
|
1559 |
}
|
|
1560 |
|
|
1561 |
#ifndef __KERNEL_MODE__
|
|
1562 |
EXPORT_C void TDes8::AppendFill(TChar aChar,TInt aLength)
|
|
1563 |
/**
|
|
1564 |
Appends and fills this descriptor with the specified character.
|
|
1565 |
|
|
1566 |
The descriptor is appended with the specified number of characters.
|
|
1567 |
and its length is changed to reflect this.
|
|
1568 |
|
|
1569 |
@param aChar The fill character. The function assumes that the character
|
|
1570 |
is non-Unicode and that it can be represented by a single byte.
|
|
1571 |
@param aLength The number of fill characters to be appended.
|
|
1572 |
|
|
1573 |
@panic USER 23 if aLength is negative, or the resulting length of this
|
|
1574 |
descriptor is greater than its maximum length.
|
|
1575 |
*/
|
|
1576 |
{
|
|
1577 |
|
|
1578 |
TInt len=Length();
|
|
1579 |
SetLength(len+aLength);
|
|
1580 |
memset(WPtr()+len, (TInt)(aChar.operator TUint()), aLength);
|
|
1581 |
}
|
|
1582 |
#endif
|
|
1583 |
|
|
1584 |
#ifndef __DES8_MACHINE_CODED__
|
|
1585 |
#ifndef __KERNEL_MODE__
|
|
1586 |
EXPORT_C void TDes8::ZeroTerminate()
|
|
1587 |
/**
|
|
1588 |
Appends a zero terminator onto the end of this descriptor's data.
|
|
1589 |
|
|
1590 |
The length of the descriptor is not changed. It must, however, be strictly
|
|
1591 |
less than the descriptor's maximum length.
|
|
1592 |
This condition guarantees that there is sufficient space for the
|
|
1593 |
zero terminator.
|
|
1594 |
|
|
1595 |
@panic USER 23 if the descriptor's length is not strictly less than its
|
|
1596 |
maximum length.
|
|
1597 |
*/
|
|
1598 |
{
|
|
1599 |
|
|
1600 |
TInt len=Length();
|
|
1601 |
__ASSERT_ALWAYS(len<MaxLength(),Panic(ETDes8Overflow));
|
|
1602 |
WPtr()[len]=0;
|
|
1603 |
}
|
|
1604 |
|
|
1605 |
EXPORT_C const TUint8 *TDes8::PtrZ()
|
|
1606 |
/**
|
|
1607 |
Appends a zero terminator onto the end of this descriptor's data and returns
|
|
1608 |
a pointer to the data.
|
|
1609 |
|
|
1610 |
The length of the descriptor is not changed. It must, however, be strictly
|
|
1611 |
less than the descriptor's maximum length.
|
|
1612 |
This condition guarantees that there is sufficient space for the
|
|
1613 |
zero terminator.
|
|
1614 |
|
|
1615 |
@return A pointer to the descriptor's zero terminated data.
|
|
1616 |
|
|
1617 |
@panic USER 23 if the descriptor's length is not strictly less than its
|
|
1618 |
maximum length.
|
|
1619 |
*/
|
|
1620 |
{
|
|
1621 |
|
|
1622 |
ZeroTerminate();
|
|
1623 |
return(Ptr());
|
|
1624 |
}
|
|
1625 |
#endif
|
|
1626 |
|
|
1627 |
EXPORT_C void TDes8::Zero()
|
|
1628 |
/**
|
|
1629 |
Sets the length of the data to zero.
|
|
1630 |
*/
|
|
1631 |
{
|
|
1632 |
|
|
1633 |
SetLength(0);
|
|
1634 |
}
|
|
1635 |
|
|
1636 |
EXPORT_C void TDes8::FillZ()
|
|
1637 |
/**
|
|
1638 |
Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any
|
|
1639 |
existing data.
|
|
1640 |
|
|
1641 |
The descriptor is filled from the beginning up to its current length. The
|
|
1642 |
descriptor's length does not change. It is not filled to its maximum length.
|
|
1643 |
*/
|
|
1644 |
{
|
|
1645 |
|
|
1646 |
memclr(WPtr(), Length());
|
|
1647 |
}
|
|
1648 |
#endif
|
|
1649 |
|
|
1650 |
EXPORT_C void TDes8::FillZ(TInt aLength)
|
|
1651 |
/**
|
|
1652 |
Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any
|
|
1653 |
existing data, and changes its length.
|
|
1654 |
|
|
1655 |
The descriptor is filled with the specified number of binary zeroes.
|
|
1656 |
The descriptor's length is changed to reflect this.
|
|
1657 |
|
|
1658 |
@param aLength The new length of the descriptor and the number of binary zeroes
|
|
1659 |
to be copied into it.
|
|
1660 |
|
|
1661 |
@panic USER 23 if aLength is negative, or is greater than the maximum length
|
|
1662 |
of this descriptor.
|
|
1663 |
*/
|
|
1664 |
{
|
|
1665 |
|
|
1666 |
SetLength(aLength);
|
|
1667 |
memclr(WPtr(), aLength);
|
|
1668 |
}
|
|
1669 |
|
|
1670 |
#ifndef __KERNEL_MODE__
|
|
1671 |
EXPORT_C void TDes8::Fold()
|
|
1672 |
/**
|
|
1673 |
Performs folding on the content of this descriptor.
|
|
1674 |
|
|
1675 |
Note that folding is locale-independent behaviour. It is also important to
|
|
1676 |
note that there can be no guarantee that folding is in any way culturally
|
|
1677 |
appropriate, and should not be used when dealing with strings in natural
|
|
1678 |
language.
|
|
1679 |
*/
|
|
1680 |
{
|
|
1681 |
|
|
1682 |
TUint8 *pB=WPtr();
|
|
1683 |
TInt len=Length();
|
|
1684 |
const TUint8* table=__FoldCollTab8;
|
|
1685 |
while (len--)
|
|
1686 |
{
|
|
1687 |
*pB=table[*pB];
|
|
1688 |
pB++;
|
|
1689 |
}
|
|
1690 |
}
|
|
1691 |
|
|
1692 |
EXPORT_C void TDes8::Collate()
|
|
1693 |
/**
|
|
1694 |
Performs collation on the content of this descriptor.
|
|
1695 |
@deprecated
|
|
1696 |
*/
|
|
1697 |
{
|
|
1698 |
|
|
1699 |
TUint8 *pB=WPtr();
|
|
1700 |
TInt len=Length();
|
|
1701 |
while (len--)
|
|
1702 |
{
|
|
1703 |
TChar c=User::Collate(*pB);
|
|
1704 |
*pB++=(TUint8)c;
|
|
1705 |
}
|
|
1706 |
}
|
|
1707 |
|
|
1708 |
EXPORT_C void TDes8::LowerCase()
|
|
1709 |
/**
|
|
1710 |
Converts the content of this descriptor to lower case.
|
|
1711 |
|
|
1712 |
Conversion is implemented as appropriate to the current locale.
|
|
1713 |
*/
|
|
1714 |
{
|
|
1715 |
|
|
1716 |
TUint8 *pB=WPtr();
|
|
1717 |
TInt len=Length();
|
|
1718 |
while (len--)
|
|
1719 |
{
|
|
1720 |
TCharLC c(*pB);
|
|
1721 |
*pB++=(TUint8)c;
|
|
1722 |
}
|
|
1723 |
}
|
|
1724 |
|
|
1725 |
EXPORT_C void TDes8::UpperCase()
|
|
1726 |
/**
|
|
1727 |
Converts the content of this descriptor to upper case.
|
|
1728 |
|
|
1729 |
Conversion is implemented as appropriate to the current locale.
|
|
1730 |
*/
|
|
1731 |
{
|
|
1732 |
|
|
1733 |
TUint8 *pB=WPtr();
|
|
1734 |
TInt len=Length();
|
|
1735 |
while (len--)
|
|
1736 |
{
|
|
1737 |
TCharUC c(*pB);
|
|
1738 |
*pB++=(TUint8)c;
|
|
1739 |
}
|
|
1740 |
}
|
|
1741 |
|
|
1742 |
EXPORT_C void TDes8::Capitalize()
|
|
1743 |
/**
|
|
1744 |
Capitalises the content of this descriptor.
|
|
1745 |
|
|
1746 |
Capitalisation is implemented as appropriate to the current locale.
|
|
1747 |
*/
|
|
1748 |
{
|
|
1749 |
|
|
1750 |
TUint8 *pB=WPtr();
|
|
1751 |
TInt len=Length();
|
|
1752 |
if (len--)
|
|
1753 |
{
|
|
1754 |
*pB=(TUint8)User::TitleCase(*pB);
|
|
1755 |
++pB;
|
|
1756 |
while (len--)
|
|
1757 |
{
|
|
1758 |
*pB=(TUint8)User::LowerCase(*pB);
|
|
1759 |
++pB;
|
|
1760 |
}
|
|
1761 |
}
|
|
1762 |
}
|
|
1763 |
|
|
1764 |
EXPORT_C void TDes8::CopyF(const TDesC8 &aDes)
|
|
1765 |
/**
|
|
1766 |
Copies and folds data from the specified descriptor into this descriptor
|
|
1767 |
replacing any existing data.
|
|
1768 |
|
|
1769 |
The length of this descriptor is set to reflect the new
|
|
1770 |
data.
|
|
1771 |
|
|
1772 |
Note that folding is locale-independent behaviour. It is also important to
|
|
1773 |
note that there can be no guarantee that folding is in any way culturally
|
|
1774 |
appropriate, and should not be used when dealing with strings in natural
|
|
1775 |
language.
|
|
1776 |
|
|
1777 |
@param aDes An 8-bit non-modifiable descriptor.
|
|
1778 |
|
|
1779 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1780 |
this target descriptor.
|
|
1781 |
*/
|
|
1782 |
{
|
|
1783 |
|
|
1784 |
TInt len=aDes.Length();
|
|
1785 |
SetLength(len);
|
|
1786 |
const TUint8 *pS=aDes.Ptr();
|
|
1787 |
TUint8 *pT=WPtr();
|
|
1788 |
const TUint8* table=__FoldCollTab8;
|
|
1789 |
while (len--)
|
|
1790 |
{
|
|
1791 |
*pT++=table[*pS++];
|
|
1792 |
}
|
|
1793 |
}
|
|
1794 |
|
|
1795 |
EXPORT_C void TDes8::CopyC(const TDesC8 &aDes)
|
|
1796 |
/**
|
|
1797 |
Copies and collates data from the specified descriptor
|
|
1798 |
into this descriptor replacing any existing data.
|
|
1799 |
|
|
1800 |
The length of this descriptor is set to reflect the new data.
|
|
1801 |
|
|
1802 |
@param aDes An 8 bit non-modifiable descriptor.
|
|
1803 |
|
|
1804 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1805 |
this target descriptor.
|
|
1806 |
@deprecated
|
|
1807 |
*/
|
|
1808 |
{
|
|
1809 |
|
|
1810 |
TInt len=aDes.Length();
|
|
1811 |
SetLength(len);
|
|
1812 |
const TUint8 *pS=aDes.Ptr();
|
|
1813 |
TUint8 *pT=WPtr();
|
|
1814 |
while (len--)
|
|
1815 |
{
|
|
1816 |
TChar c=User::Collate(*pS++);
|
|
1817 |
*pT++=(TUint8)c;
|
|
1818 |
}
|
|
1819 |
}
|
|
1820 |
|
|
1821 |
EXPORT_C void TDes8::CopyLC(const TDesC8 &aDes)
|
|
1822 |
/**
|
|
1823 |
Copies text from the specified descriptor and converts it to lower case before
|
|
1824 |
putting it into this descriptor, replacing any existing data.
|
|
1825 |
|
|
1826 |
The length of this descriptor is set to reflect the new data.
|
|
1827 |
|
|
1828 |
Conversion to lower case is implemented as appropriate to the current locale.
|
|
1829 |
|
|
1830 |
@param aDes An 8-bit non-modifiable descriptor.
|
|
1831 |
|
|
1832 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1833 |
this target descriptor.
|
|
1834 |
*/
|
|
1835 |
{
|
|
1836 |
|
|
1837 |
TInt len=aDes.Length();
|
|
1838 |
SetLength(len);
|
|
1839 |
const TUint8 *pS=aDes.Ptr();
|
|
1840 |
TUint8 *pT=WPtr();
|
|
1841 |
while (len--)
|
|
1842 |
{
|
|
1843 |
TCharLC c(*pS++);
|
|
1844 |
*pT++=(TUint8)c;
|
|
1845 |
}
|
|
1846 |
}
|
|
1847 |
|
|
1848 |
EXPORT_C void TDes8::CopyUC(const TDesC8 &aDes)
|
|
1849 |
/**
|
|
1850 |
Copies text from the specified descriptor and converts it to upper case before
|
|
1851 |
putting it into this descriptor, replacing any existing data.
|
|
1852 |
|
|
1853 |
The length of this descriptor is set to reflect the new data.
|
|
1854 |
|
|
1855 |
Conversion to upper case is implemented as appropriate to the current locale.
|
|
1856 |
|
|
1857 |
@param aDes An 8-bit non-modifiable descriptor.
|
|
1858 |
|
|
1859 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1860 |
this target descriptor.
|
|
1861 |
*/
|
|
1862 |
{
|
|
1863 |
|
|
1864 |
TInt len=aDes.Length();
|
|
1865 |
SetLength(len);
|
|
1866 |
const TUint8 *pS=aDes.Ptr();
|
|
1867 |
TUint8 *pT=WPtr();
|
|
1868 |
while (len--)
|
|
1869 |
{
|
|
1870 |
TCharUC c(*pS++);
|
|
1871 |
*pT++=(TUint8)c;
|
|
1872 |
}
|
|
1873 |
}
|
|
1874 |
|
|
1875 |
EXPORT_C void TDes8::CopyCP(const TDesC8 &aDes)
|
|
1876 |
/**
|
|
1877 |
Copies text from the specified descriptor and capitalises it before putting
|
|
1878 |
it into this descriptor, replacing any existing data.
|
|
1879 |
|
|
1880 |
The length of this descriptor is set to reflect the new data.
|
|
1881 |
|
|
1882 |
Capitalisation is implemented as appropriate to the current locale.
|
|
1883 |
|
|
1884 |
@param aDes An 8-bit non-modifiable descriptor.
|
|
1885 |
|
|
1886 |
@panic USER 23 if the length of aDes is greater than the maximum length of
|
|
1887 |
this target descriptor.
|
|
1888 |
*/
|
|
1889 |
{
|
|
1890 |
|
|
1891 |
TInt len=aDes.Length();
|
|
1892 |
SetLength(len);
|
|
1893 |
const TUint8 *pS=aDes.Ptr();
|
|
1894 |
TUint8 *pT=WPtr();
|
|
1895 |
if (len--)
|
|
1896 |
{
|
|
1897 |
TChar c(*pS++);
|
|
1898 |
#ifdef _UNICODE
|
|
1899 |
c.TitleCase();
|
|
1900 |
#else
|
|
1901 |
c.UpperCase();
|
|
1902 |
#endif
|
|
1903 |
*pT++=(TUint8)c;
|
|
1904 |
while (len--)
|
|
1905 |
{
|
|
1906 |
TCharLC c=(*pS++);
|
|
1907 |
*pT++=(TUint8)c;
|
|
1908 |
}
|
|
1909 |
}
|
|
1910 |
}
|
|
1911 |
|
|
1912 |
EXPORT_C void TDes8::Repeat(const TUint8 *aBuf,TInt aLength)
|
|
1913 |
/**
|
|
1914 |
Copies data with repetition into this descriptor, from a memory location
|
|
1915 |
specified by pointer, replacing any existing data.
|
|
1916 |
|
|
1917 |
Copying proceeds until this descriptor is filled up to its current length.
|
|
1918 |
If it cannot contain a whole number of copies of the source data, then the
|
|
1919 |
last copy is truncated.
|
|
1920 |
|
|
1921 |
@param aBuf A pointer to data to be repeatedly copied.
|
|
1922 |
@param aLength The length of data to be copied.
|
|
1923 |
|
|
1924 |
@panic USER 29 if aLength is negative.
|
|
1925 |
*/
|
|
1926 |
{
|
|
1927 |
|
|
1928 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
|
|
1929 |
TUint8 *pB=WPtr();
|
|
1930 |
TInt len=Length();
|
|
1931 |
if (len && aLength)
|
|
1932 |
{
|
|
1933 |
while (len)
|
|
1934 |
{
|
|
1935 |
TInt i=Min(len,aLength);
|
|
1936 |
pB=memCopy(pB,aBuf,i);
|
|
1937 |
len-=i;
|
|
1938 |
}
|
|
1939 |
}
|
|
1940 |
}
|
|
1941 |
|
|
1942 |
EXPORT_C void TDes8::Repeat(const TDesC8 &aDes)
|
|
1943 |
/**
|
|
1944 |
Copies data with repetition into this descriptor, from another descriptor,
|
|
1945 |
replacing any existing data.
|
|
1946 |
|
|
1947 |
Copying proceeds until this descriptor is filled up to its current length.
|
|
1948 |
If it cannot contain a whole number of copies of the source data, then the
|
|
1949 |
last copy is truncated.
|
|
1950 |
|
|
1951 |
@param aDes An 8-bit non-modifiable descriptor whose data is to be repeatedly
|
|
1952 |
copied.
|
|
1953 |
*/
|
|
1954 |
{
|
|
1955 |
|
|
1956 |
Repeat(aDes.Ptr(),aDes.Length());
|
|
1957 |
}
|
|
1958 |
|
|
1959 |
EXPORT_C void TDes8::Trim()
|
|
1960 |
/**
|
|
1961 |
Deletes leading and trailing whitespace characters from the descriptor's data.
|
|
1962 |
|
|
1963 |
The length of the descriptor is reduced to reflect the loss of the whitespace characters.
|
|
1964 |
|
|
1965 |
@see TDes8::TrimLeft()
|
|
1966 |
@see TDes8::TrimRight()
|
|
1967 |
*/
|
|
1968 |
{
|
|
1969 |
|
|
1970 |
TrimLeft();
|
|
1971 |
TrimRight();
|
|
1972 |
}
|
|
1973 |
|
|
1974 |
EXPORT_C void TDes8::TrimAll()
|
|
1975 |
/**
|
|
1976 |
Deletes leading and trailing whitespace characters from the descriptor's data and
|
|
1977 |
replaces each contiguous set of whitespace characters within the data by one whitespace
|
|
1978 |
character.
|
|
1979 |
|
|
1980 |
The length of the descriptor is reduced to reflect the loss of the whitespace
|
|
1981 |
characters.
|
|
1982 |
|
|
1983 |
@see TDes8::Trim()
|
|
1984 |
*/
|
|
1985 |
{
|
|
1986 |
|
|
1987 |
TrimLeft();
|
|
1988 |
TrimRight();
|
|
1989 |
TUint8 *pBuf=(TUint8 *)Ptr();
|
|
1990 |
TUint8 *pSrc=pBuf;
|
|
1991 |
TUint8 *pDst=pBuf;
|
|
1992 |
TInt len=Length();
|
|
1993 |
TInt spaces=0;
|
|
1994 |
while (len--)
|
|
1995 |
{
|
|
1996 |
TChar c=*pSrc;
|
|
1997 |
if (c.IsSpace())
|
|
1998 |
{
|
|
1999 |
if (spaces++==0)
|
|
2000 |
{
|
|
2001 |
if (pDst!=pSrc)
|
|
2002 |
*pDst=*pSrc;
|
|
2003 |
pDst++;
|
|
2004 |
}
|
|
2005 |
}
|
|
2006 |
else
|
|
2007 |
{
|
|
2008 |
spaces=0;
|
|
2009 |
if (pDst!=pSrc)
|
|
2010 |
*pDst=*pSrc;
|
|
2011 |
pDst++;
|
|
2012 |
}
|
|
2013 |
pSrc++;
|
|
2014 |
}
|
|
2015 |
Delete(pDst-pBuf, pSrc-pDst);
|
|
2016 |
}
|
|
2017 |
|
|
2018 |
EXPORT_C void TDes8::TrimLeft()
|
|
2019 |
/**
|
|
2020 |
Deletes leading whitespace characters from the descriptor's data.
|
|
2021 |
|
|
2022 |
All whitespace characters up to, but not including the first non-whitespace
|
|
2023 |
character, are deleted.
|
|
2024 |
|
|
2025 |
The length of the descriptor is reduced to reflect the loss of the
|
|
2026 |
whitespace characters.
|
|
2027 |
*/
|
|
2028 |
{
|
|
2029 |
|
|
2030 |
const TUint8 *pBuf=Ptr();
|
|
2031 |
const TUint8 *pB=pBuf;
|
|
2032 |
TInt len=Length();
|
|
2033 |
while (len--)
|
|
2034 |
{
|
|
2035 |
TChar c=(*pB);
|
|
2036 |
if (!c.IsSpace())
|
|
2037 |
break;
|
|
2038 |
pB++;
|
|
2039 |
}
|
|
2040 |
Delete(0,pB-pBuf);
|
|
2041 |
}
|
|
2042 |
|
|
2043 |
EXPORT_C void TDes8::TrimRight()
|
|
2044 |
/**
|
|
2045 |
Deletes trailing whitespace characters from the descriptor's data.
|
|
2046 |
|
|
2047 |
The process starts on the right hand side of the descriptor's data
|
|
2048 |
and proceeds to the left.
|
|
2049 |
|
|
2050 |
All whitespace characters up to, but not including the first non-whitespace character,
|
|
2051 |
are deleted.
|
|
2052 |
|
|
2053 |
The length of the descriptor is reduced to reflect the loss of the whitespace
|
|
2054 |
characters.
|
|
2055 |
*/
|
|
2056 |
{
|
|
2057 |
|
|
2058 |
TInt len=Length();
|
|
2059 |
if (len==0)
|
|
2060 |
return;
|
|
2061 |
const TUint8 *pB=Ptr()+len-1;
|
|
2062 |
TInt s=len;
|
|
2063 |
while (s)
|
|
2064 |
{
|
|
2065 |
TChar c=(*pB--);
|
|
2066 |
if (!c.IsSpace())
|
|
2067 |
break;
|
|
2068 |
s--;
|
|
2069 |
}
|
|
2070 |
Delete(s,len-s);
|
|
2071 |
}
|
|
2072 |
|
|
2073 |
EXPORT_C void TDes8::Insert(TInt aPos,const TDesC8 &aDes)
|
|
2074 |
/**
|
|
2075 |
Inserts data into this descriptor.
|
|
2076 |
|
|
2077 |
The length of this descriptor is changed to reflect the extra data.
|
|
2078 |
|
|
2079 |
@param aPos The position within the data where insertion is to start. This
|
|
2080 |
is an offset value; a zero value refers to the leftmost data
|
|
2081 |
position.
|
|
2082 |
|
|
2083 |
@param aDes An 8 bit non modifiable descriptor whose data is to be inserted.
|
|
2084 |
|
|
2085 |
@panic USER 22 if aPos is negative or is greater than the length of this
|
|
2086 |
descriptor.
|
|
2087 |
@panic USER 23 if the resulting length of this descriptor is greater than its
|
|
2088 |
maximum length.
|
|
2089 |
*/
|
|
2090 |
{
|
|
2091 |
|
|
2092 |
TInt len=Length();
|
|
2093 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
|
|
2094 |
TInt s=aDes.Length();
|
|
2095 |
__ASSERT_ALWAYS((len+s)<=MaxLength(),Panic(ETDes8Overflow));
|
|
2096 |
TUint8 *pB=WPtr();
|
|
2097 |
memmove(pB+aPos+s,pB+aPos,len-aPos);
|
|
2098 |
memmove(pB+aPos,aDes.Ptr(),aDes.Length());
|
|
2099 |
SetLength(len+s);
|
|
2100 |
}
|
|
2101 |
|
|
2102 |
EXPORT_C void TDes8::Delete(TInt aPos,TInt aLength)
|
|
2103 |
/**
|
|
2104 |
Deletes data from this descriptor.
|
|
2105 |
|
|
2106 |
The length of this descriptor is changed to reflect the loss of data.
|
|
2107 |
|
|
2108 |
@param aPos The position within the data where deletion is to start. This
|
|
2109 |
is an offset value; a zero value refers to the leftmost data
|
|
2110 |
position.
|
|
2111 |
|
|
2112 |
@param aLength The length of data to be deleted. If necessary, the function
|
|
2113 |
adjusts this value to ensure that no data beyond the end of the
|
|
2114 |
descriptor data area is deleted.
|
|
2115 |
|
|
2116 |
@panic USER 22 if aPos is negative or is greater than the length of this
|
|
2117 |
descriptor.
|
|
2118 |
*/
|
|
2119 |
{
|
|
2120 |
|
|
2121 |
TInt len=Length();
|
|
2122 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
|
|
2123 |
TInt d=Min(len-aPos,aLength);
|
|
2124 |
TUint8 *pB=WPtr();
|
|
2125 |
memmove(pB+aPos,pB+aPos+d,len-aPos-d);
|
|
2126 |
SetLength(len-d);
|
|
2127 |
}
|
|
2128 |
|
|
2129 |
EXPORT_C void TDes8::Replace(TInt aPos,TInt aLength,const TDesC8 &aDes)
|
|
2130 |
/**
|
|
2131 |
Replaces data in this descriptor.
|
|
2132 |
|
|
2133 |
The specified length can be different to the length of the replacement data.
|
|
2134 |
The length of this descriptor changes to reflect the change of data.
|
|
2135 |
|
|
2136 |
@param aPos The position within the data where replacement is to start.
|
|
2137 |
This is an offset value; a zero value refers to the leftmost
|
|
2138 |
data position.
|
|
2139 |
|
|
2140 |
@param aLength The length of data to be replaced.
|
|
2141 |
|
|
2142 |
@param aDes The source 8-bit non-modifiable descriptor whose data is to
|
|
2143 |
replace the target descriptor's data at aPos.
|
|
2144 |
|
|
2145 |
@panic USER 20 if aLength is negative or the sum of aLength and aPos is
|
|
2146 |
greater than the length of this descriptor.
|
|
2147 |
|
|
2148 |
@panic USER 22 if aPos is negative or is greater than the length of this
|
|
2149 |
descriptor.
|
|
2150 |
|
|
2151 |
@panic USER 23 if the resulting length of this descriptor is greater than its
|
|
2152 |
maximum length.
|
|
2153 |
|
|
2154 |
@panic USER 28 if the length of the source descriptor aDes is negative or is
|
|
2155 |
greater than the maximum length of this target descriptor,
|
|
2156 |
*/
|
|
2157 |
{
|
|
2158 |
|
|
2159 |
TInt len=Length();
|
|
2160 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
|
|
2161 |
__ASSERT_ALWAYS(aLength>=0 && aPos+aLength<=len,Panic(ETDes8LengthOutOfRange));
|
|
2162 |
TInt s=aDes.Length();
|
|
2163 |
TInt maxlen=MaxLength();
|
|
2164 |
__ASSERT_ALWAYS(s>=0 && s<=maxlen,Panic(ETDes8RemoteLengthOutOfRange));
|
|
2165 |
__ASSERT_ALWAYS((len+s-aLength)<=maxlen,Panic(ETDes8Overflow));
|
|
2166 |
TUint8 *pB=WPtr();
|
|
2167 |
memmove(pB+aPos+s,pB+aPos+aLength,len-aPos-aLength);
|
|
2168 |
memmove(pB+aPos,aDes.Ptr(),s);
|
|
2169 |
SetLength(len+s-aLength);
|
|
2170 |
}
|
|
2171 |
|
|
2172 |
EXPORT_C void TDes8::Justify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
|
|
2173 |
/**
|
|
2174 |
Copies data into this descriptor and justifies it, replacing any existing data.
|
|
2175 |
|
|
2176 |
The length of this descriptor is set to reflect the new data.
|
|
2177 |
|
|
2178 |
The target area is considered to be an area of specified width positioned at
|
|
2179 |
the beginning of this descriptor's data area. Source data is copied into, and
|
|
2180 |
aligned within this target area according to the specified alignment
|
|
2181 |
instruction.
|
|
2182 |
|
|
2183 |
If the length of the target area is larger than the length of the source, then
|
|
2184 |
spare space within the target area is padded with the fill character.
|
|
2185 |
|
|
2186 |
@param aDes An 8-bit non-modifiable descriptor containing the source data.
|
|
2187 |
The length of the data to be copied is the smaller of:
|
|
2188 |
the length of the source descriptor, and
|
|
2189 |
the width of the target area (only if this is not the
|
|
2190 |
explicit negative value KDefaultJustifyWidth).
|
|
2191 |
|
|
2192 |
@param aWidth The width of the target area. If this has the specific
|
|
2193 |
negative value KDefaultJustifyWidth, then the width is
|
|
2194 |
re-set to the length of the data source.
|
|
2195 |
|
|
2196 |
@param anAlignment The alignment of the data within the target area
|
|
2197 |
|
|
2198 |
@param aFill The fill character used to pad the target area.
|
|
2199 |
|
|
2200 |
@panic USER 23 if the resulting length of this descriptor is greater than
|
|
2201 |
its maximum length or aWidth has a negative value other
|
|
2202 |
than KDefaultJustifyWidth.
|
|
2203 |
*/
|
|
2204 |
{
|
|
2205 |
|
|
2206 |
Zero();
|
|
2207 |
AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
|
|
2208 |
}
|
|
2209 |
|
|
2210 |
EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
|
|
2211 |
/**
|
|
2212 |
Appends data onto the end of this descriptor's data and justifies it.
|
|
2213 |
|
|
2214 |
The source of the appended data is an existing descriptor.
|
|
2215 |
|
|
2216 |
The target area is considered to be an area of specified width, immediately
|
|
2217 |
following this descriptor's existing data. Source data is copied into, and
|
|
2218 |
aligned within this target area according to the specified alignment instruction.
|
|
2219 |
|
|
2220 |
If the length of the target area is larger than the length of the source,
|
|
2221 |
then spare space within the target area is padded with the fill character.
|
|
2222 |
|
|
2223 |
@param aDes An 8-bit non-modifiable descriptor containing the source
|
|
2224 |
data. The length of the data to be copied is the smaller of:
|
|
2225 |
the length of the source descriptor, and
|
|
2226 |
the width of the target area (only if this is not the
|
|
2227 |
explicit negative value KDefaultJustifyWidth).
|
|
2228 |
|
|
2229 |
@param aWidth The width of the target area. If this has the specific
|
|
2230 |
negative value KDefaultJustifyWidth, then the width is
|
|
2231 |
re-set to the length of the data source.
|
|
2232 |
|
|
2233 |
@param anAlignment The alignment of the data within the target area.
|
|
2234 |
|
|
2235 |
@param aFill The fill character used to pad the target area.
|
|
2236 |
|
|
2237 |
@panic USER 23 if the resulting length of this descriptor is greater than
|
|
2238 |
its maximum length or aWidth has a negative value other
|
|
2239 |
than KDefaultJustifyWidth.
|
|
2240 |
*/
|
|
2241 |
{
|
|
2242 |
|
|
2243 |
AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
|
|
2244 |
}
|
|
2245 |
|
|
2246 |
EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
|
|
2247 |
/**
|
|
2248 |
Appends data onto the end of this descriptor's data and justifies it.
|
|
2249 |
|
|
2250 |
The source of the appended data is an existing descriptor.
|
|
2251 |
|
|
2252 |
The target area is considered to be an area of specified width, immediately
|
|
2253 |
following this descriptor's existing data. Source data is copied into, and
|
|
2254 |
aligned within this target area according to the specified alignment instruction.
|
|
2255 |
|
|
2256 |
If the length of the target area is larger than the length of the source,
|
|
2257 |
then spare space within the target area is padded with the fill character.
|
|
2258 |
|
|
2259 |
@param aDes An 8-bit non-modifiable descriptor containing the source data.
|
|
2260 |
|
|
2261 |
@param aLength The length of data to be copied from the source descriptor.
|
|
2262 |
If this is greater than the width of the target area, then
|
|
2263 |
the length of data copied is limited to the width.
|
|
2264 |
The length of data to be copied must not be greater than
|
|
2265 |
the length of the source descriptor. Note that this
|
|
2266 |
condition is not automatically tested.
|
|
2267 |
|
|
2268 |
@param aWidth The width of the target area. If this has the specific negative
|
|
2269 |
value KDefaultJustifyWidth, then the width is
|
|
2270 |
re-set to the length of the data source.
|
|
2271 |
|
|
2272 |
@param anAlignment The alignment of the data within the target area.
|
|
2273 |
|
|
2274 |
@param aFill The fill character used to pad the target area.
|
|
2275 |
|
|
2276 |
@panic USER 23 if the resulting length of this descriptor is greater than
|
|
2277 |
its maximum length or aWidth has a negative value other
|
|
2278 |
than KDefaultJustifyWidth.
|
|
2279 |
*/
|
|
2280 |
{
|
|
2281 |
|
|
2282 |
AppendJustify(aDes.Ptr(),aLength,aWidth,anAlignment,aFill);
|
|
2283 |
}
|
|
2284 |
|
|
2285 |
EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aWidth,TAlign anAlignment,TChar aFill)
|
|
2286 |
/**
|
|
2287 |
Appends a zero terminated string onto the end of this descriptor's data and
|
|
2288 |
justifies it.
|
|
2289 |
|
|
2290 |
The zero terminator is not copied.
|
|
2291 |
|
|
2292 |
The target area is considered to be an area of specified width, immediately
|
|
2293 |
following this descriptor's existing data. Source data is copied into, and
|
|
2294 |
aligned within, this target area according to the specified alignment instruction.
|
|
2295 |
|
|
2296 |
If the length of the target area is larger than the length of the source,
|
|
2297 |
then spare space within the target area is padded with the fill character.
|
|
2298 |
|
|
2299 |
@param aString A pointer to a zero terminated string. The length of the
|
|
2300 |
data to be copied is the smaller of:
|
|
2301 |
the length of the string (excluding the zero terminator),
|
|
2302 |
and the width of the target area (only if this is not the
|
|
2303 |
explicit negative value KDefaultJustifyWidth).
|
|
2304 |
|
|
2305 |
@param aWidth The width of the target area. If this has the specific
|
|
2306 |
negative value KDefaultJustifyWidth, then the width
|
|
2307 |
is re-set to the length of the zero terminated string
|
|
2308 |
(excluding the zero terminator).
|
|
2309 |
|
|
2310 |
@param anAlignment The alignment of the data within the target area.
|
|
2311 |
|
|
2312 |
@param aFill The fill character used to pad the target area.
|
|
2313 |
|
|
2314 |
@panic USER 23 if the resulting length of this descriptor is greater than
|
|
2315 |
its maximum length or aWidth has a negative value other
|
|
2316 |
than KDefaultJustifyWidth.
|
|
2317 |
*/
|
|
2318 |
{
|
|
2319 |
|
|
2320 |
AppendJustify(aString,STRING_LENGTH(aString),aWidth,anAlignment,aFill);
|
|
2321 |
}
|
|
2322 |
|
|
2323 |
EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
|
|
2324 |
/**
|
|
2325 |
Appends data onto the end of this descriptor's data and justifies it.
|
|
2326 |
|
|
2327 |
The source of the appended data is a memory location.
|
|
2328 |
|
|
2329 |
The target area is considered to be an area of specified width, immediately
|
|
2330 |
following this descriptor's existing data. Source data is copied into, and
|
|
2331 |
aligned within, this target area according to the specified alignment instruction.
|
|
2332 |
|
|
2333 |
If the length of the target area is larger than the length of the source,
|
|
2334 |
then spare space within the target area is padded with the fill character.
|
|
2335 |
|
|
2336 |
@param aString A pointer to a source memory location.
|
|
2337 |
|
|
2338 |
@param aLength The length of data to be copied. If this is greater than the
|
|
2339 |
width of the target area, then the length of data copied is
|
|
2340 |
limited to the width.
|
|
2341 |
|
|
2342 |
@param aWidth The width of the target area. If this has the specific
|
|
2343 |
negative value KDefaultJustifyWidth, then the width is
|
|
2344 |
re-set to the length of the data source.
|
|
2345 |
|
|
2346 |
@param anAlignment The alignment of the data within the target area.
|
|
2347 |
|
|
2348 |
@param aFill The fill character used to pad the target area.
|
|
2349 |
|
|
2350 |
@panic USER 23 if the resulting length of this descriptor is greater than
|
|
2351 |
its maximum length or aWidth has a negative value other
|
|
2352 |
than KDefaultJustifyWidth.
|
|
2353 |
|
|
2354 |
@panic USER 29 if aLength is negative.
|
|
2355 |
*/
|
|
2356 |
{
|
|
2357 |
|
|
2358 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
|
|
2359 |
if (aWidth==KDefaultJustifyWidth)
|
|
2360 |
aWidth=aLength;
|
|
2361 |
if (aLength>aWidth)
|
|
2362 |
aLength=aWidth;
|
|
2363 |
TInt offset=Length();
|
|
2364 |
AppendFill(aFill,aWidth);
|
|
2365 |
TInt r=aWidth-aLength;
|
|
2366 |
if (anAlignment==ECenter)
|
|
2367 |
r>>=1;
|
|
2368 |
else if (anAlignment==ELeft)
|
|
2369 |
r=0;
|
|
2370 |
memmove(WPtr()+offset+r,aString,aLength);
|
|
2371 |
}
|
|
2372 |
#endif // __KERNEL_MODE__
|
|
2373 |
|
|
2374 |
EXPORT_C void TDes8::Num(TInt64 aVal)
|
|
2375 |
//
|
|
2376 |
// Convert a TInt64 to the descriptor.
|
|
2377 |
//
|
|
2378 |
/**
|
|
2379 |
Converts the 64-bit signed integer into a decimal character representation
|
|
2380 |
and copies the conversion into this descriptor, replacing any existing data.
|
|
2381 |
|
|
2382 |
The length of this descriptor is set to reflect the new data.
|
|
2383 |
|
|
2384 |
If the integer is negative, the character representation is prefixed by a
|
|
2385 |
minus sign.
|
|
2386 |
|
|
2387 |
@param aVal The 64-bit signed integer value.
|
|
2388 |
*/
|
|
2389 |
{
|
|
2390 |
Zero();
|
|
2391 |
AppendNum(aVal);
|
|
2392 |
}
|
|
2393 |
|
|
2394 |
EXPORT_C void TDes8::Num(TUint64 aVal, TRadix aRadix)
|
|
2395 |
/**
|
|
2396 |
Converts the specified 64-bit unsigned integer into a character representation
|
|
2397 |
based on the specified number system and copies the conversion into this descriptor,
|
|
2398 |
replacing any existing data.
|
|
2399 |
|
|
2400 |
The length of this descriptor is set to reflect the new data.
|
|
2401 |
|
|
2402 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2403 |
lower case.
|
|
2404 |
|
|
2405 |
@param aVal The 64-bit integer value. This is treated as an unsigned value.
|
|
2406 |
@param aRadix The number system representation for the 64-bit integer.
|
|
2407 |
*/
|
|
2408 |
{
|
|
2409 |
Zero();
|
|
2410 |
AppendNum(aVal, aRadix);
|
|
2411 |
}
|
|
2412 |
|
|
2413 |
EXPORT_C void TDes8::NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
|
|
2414 |
/**
|
|
2415 |
Converts the specified unsigned integer into a fixed width character
|
|
2416 |
representation based on the specified number system and copies the conversion
|
|
2417 |
into this descriptor, replacing any existing data.
|
|
2418 |
|
|
2419 |
The length of this descriptor is set to reflect the new data.
|
|
2420 |
|
|
2421 |
The function generates the exact number of specified characters, either padding
|
|
2422 |
to the left with character zeroes or discarding low order characters as necessary.
|
|
2423 |
|
|
2424 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2425 |
lower case.
|
|
2426 |
|
|
2427 |
This function is equivalent to using Format() with parameters which specify:
|
|
2428 |
|
|
2429 |
1. a fixed length target field
|
|
2430 |
|
|
2431 |
2. padding with zero characters, for example "%08x".
|
|
2432 |
|
|
2433 |
When this is the case, always use NumFixedWidth() in preference
|
|
2434 |
to Format() as it is more efficient.
|
|
2435 |
|
|
2436 |
@param aVal The unsigned integer value.
|
|
2437 |
@param aRadix The number system representation for the unsigned integer.
|
|
2438 |
@param aWidth The number of characters: to be used to contain the conversion,
|
|
2439 |
to be copied into this descriptor.
|
|
2440 |
|
|
2441 |
@see TDes8::Format()
|
|
2442 |
*/
|
|
2443 |
{
|
|
2444 |
|
|
2445 |
Zero();
|
|
2446 |
AppendNumFixedWidth(aVal,aRadix,aWidth);
|
|
2447 |
}
|
|
2448 |
|
|
2449 |
#ifndef __KERNEL_MODE__
|
|
2450 |
EXPORT_C void TDes8::NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
|
|
2451 |
/**
|
|
2452 |
Converts the specified unsigned integer into a fixed width character
|
|
2453 |
representation based on the specified number system and copies the conversion
|
|
2454 |
into this descriptor, replacing any existing data.
|
|
2455 |
|
|
2456 |
The length of this descriptor is set to reflect the new data.
|
|
2457 |
|
|
2458 |
The function generates the exact number of specified characters, either padding
|
|
2459 |
to the left with character zeroes or discarding low order characters as
|
|
2460 |
necessary.
|
|
2461 |
|
|
2462 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2463 |
upper case.
|
|
2464 |
|
|
2465 |
This function is equivalent to using Format() with parameters which specify:
|
|
2466 |
|
|
2467 |
1. a fixed length target field
|
|
2468 |
|
|
2469 |
2. padding with zero characters, for example "%08x".
|
|
2470 |
|
|
2471 |
When this is the case, always use NumFixedWidthUC() in
|
|
2472 |
preference to Format() as it is more efficient.
|
|
2473 |
|
|
2474 |
@param aVal The unsigned integer value.
|
|
2475 |
@param aRadix The number system representation for the unsigned integer.
|
|
2476 |
@param aWidth The number of characters to be used to contain the conversion,
|
|
2477 |
and to be copied into this descriptor.
|
|
2478 |
|
|
2479 |
@see TDes8::Format()
|
|
2480 |
*/
|
|
2481 |
{
|
|
2482 |
|
|
2483 |
Zero();
|
|
2484 |
AppendNumFixedWidthUC(aVal,aRadix,aWidth);
|
|
2485 |
}
|
|
2486 |
|
|
2487 |
EXPORT_C void TDes8::NumUC(TUint64 aVal, TRadix aRadix) //NOT __KERNEL_MODE__
|
|
2488 |
/**
|
|
2489 |
Converts the specified 64-bit unsigned integer into a character representation
|
|
2490 |
based on the specified number system and copies the conversion into this descriptor,
|
|
2491 |
replacing any existing data.
|
|
2492 |
|
|
2493 |
The length of this descriptor is set to reflect the new data.
|
|
2494 |
|
|
2495 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2496 |
upper case.
|
|
2497 |
|
|
2498 |
@param aVal The 64-bit integer value. This is treated as an unsigned value.
|
|
2499 |
@param aRadix The number system representation for the 64-bit integer. If no
|
|
2500 |
explicit value is specified, then EDecimal is the default.
|
|
2501 |
*/
|
|
2502 |
{
|
|
2503 |
Zero();
|
|
2504 |
AppendNumUC(aVal,aRadix);
|
|
2505 |
}
|
|
2506 |
#endif // __KERNEL_MODE__
|
|
2507 |
|
|
2508 |
EXPORT_C void TDes8::AppendNum(TInt64 aVal)
|
|
2509 |
/**
|
|
2510 |
Converts the 64-bit signed integer into a decimal character representation
|
|
2511 |
and appends the conversion onto the end of this descriptor's data.
|
|
2512 |
|
|
2513 |
The length of this descriptor is incremented to reflect the new content.
|
|
2514 |
|
|
2515 |
If the integer is negative, the character representation is prefixed by a
|
|
2516 |
minus sign.
|
|
2517 |
|
|
2518 |
@param aVal The 64-bit signed integer value.
|
|
2519 |
*/
|
|
2520 |
{
|
|
2521 |
if (aVal < 0)
|
|
2522 |
{
|
|
2523 |
Append('-');
|
|
2524 |
aVal = -aVal;
|
|
2525 |
}
|
|
2526 |
|
|
2527 |
AppendNum(aVal, EDecimal);
|
|
2528 |
}
|
|
2529 |
|
|
2530 |
#ifndef __DES_MACHINE_CODED__
|
|
2531 |
GLDEF_C TInt __DoConvertNum(TUint aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
|
|
2532 |
{
|
|
2533 |
__KERNEL_CHECK_RADIX(aRadix);
|
|
2534 |
TUint radix = (TUint)aRadix;
|
|
2535 |
TUint8* p = aDest;
|
|
2536 |
TBool out16 = (aA>255);
|
|
2537 |
aA &= 0xff;
|
|
2538 |
do {
|
|
2539 |
TUint q = aVal/radix;
|
|
2540 |
TUint c = aVal-q*radix;
|
|
2541 |
(c>9) ? c+=(aA-10) : c+='0';
|
|
2542 |
aVal = q;
|
|
2543 |
if (out16)
|
|
2544 |
*--p = 0;
|
|
2545 |
*--p = (TUint8)c;
|
|
2546 |
} while (aVal);
|
|
2547 |
TInt l = aDest - p;
|
|
2548 |
aDest = p;
|
|
2549 |
return l;
|
|
2550 |
}
|
|
2551 |
|
|
2552 |
GLDEF_C TInt __DoConvertNum(TUint64 aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
|
|
2553 |
{
|
|
2554 |
__KERNEL_CHECK_RADIX(aRadix);
|
|
2555 |
TUint radix = (TUint)aRadix;
|
|
2556 |
TUint8* p = aDest;
|
|
2557 |
TBool out16 = (aA>255);
|
|
2558 |
TUint8 a = static_cast<TUint8>(aA);
|
|
2559 |
while (aVal >= UI64LIT(0x100000000))
|
|
2560 |
{
|
|
2561 |
TUint8 c = static_cast<TUint8>(aVal % radix);
|
|
2562 |
aVal /= radix;
|
|
2563 |
(c > 9) ? c = static_cast<TUint8>(c + a - 10) : c = static_cast<TUint8>(c + '0');
|
|
2564 |
if (out16)
|
|
2565 |
*--p = 0;
|
|
2566 |
*--p = c;
|
|
2567 |
}
|
|
2568 |
TInt l = aDest - p;
|
|
2569 |
aDest = p;
|
|
2570 |
return l + __DoConvertNum((TUint)aVal, aRadix, aA, aDest);
|
|
2571 |
}
|
|
2572 |
#endif
|
|
2573 |
|
|
2574 |
void TDes8::DoPadAppendNum(TInt l, TInt aW, const TUint8* p)
|
|
2575 |
{
|
|
2576 |
if (aW<=0)
|
|
2577 |
{
|
|
2578 |
Append(p, l);
|
|
2579 |
return;
|
|
2580 |
}
|
|
2581 |
TInt l0 = Length();
|
|
2582 |
SetLength(l0 + aW);
|
|
2583 |
TUint8* d = WPtr() + l0;
|
|
2584 |
for (; aW>l; --aW) *d++ = (TUint8)'0';
|
|
2585 |
memcpy(d, p, aW);
|
|
2586 |
}
|
|
2587 |
|
|
2588 |
void TDes8::DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW)
|
|
2589 |
//
|
|
2590 |
// Convert a TUint64 into the descriptor.
|
|
2591 |
//
|
|
2592 |
{
|
|
2593 |
TUint8 buf[APPEND_BUF_SIZE_64];
|
|
2594 |
TUint8* p = buf + APPEND_BUF_SIZE_64;
|
|
2595 |
TInt l = __DoConvertNum(aVal, aRadix, aA, p);
|
|
2596 |
// coverity[overrun-local]
|
|
2597 |
DoPadAppendNum(l, aW, p);
|
|
2598 |
}
|
|
2599 |
|
|
2600 |
EXPORT_C void TDes8::AppendNum(TUint64 aVal, TRadix aRadix)
|
|
2601 |
/**
|
|
2602 |
Converts the specified 64-bit unsigned integer into a character representation
|
|
2603 |
based on the specified number system and appends the conversion onto the end
|
|
2604 |
of this descriptor's data. The length of this descriptor is incremented to
|
|
2605 |
reflect the new content
|
|
2606 |
|
|
2607 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2608 |
lower case.
|
|
2609 |
|
|
2610 |
@param aVal The 64-bit integer value. This is treated as an unsigned value.
|
|
2611 |
@param aRadix The number system representation for the 64-bit integer.
|
|
2612 |
*/
|
|
2613 |
{
|
|
2614 |
DoAppendNum(aVal, aRadix, 'a', 0);
|
|
2615 |
}
|
|
2616 |
|
|
2617 |
EXPORT_C void TDes8::AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
|
|
2618 |
/**
|
|
2619 |
Converts the specified unsigned integer into a fixed width character
|
|
2620 |
representation based on the specified number system and appends the conversion
|
|
2621 |
onto the end of this descriptor's data.
|
|
2622 |
|
|
2623 |
The length of this descriptor is incremented to reflect the new content.
|
|
2624 |
|
|
2625 |
The function generates the exact number of specified characters, either padding
|
|
2626 |
to the left with character zeroes or discarding low order characters as
|
|
2627 |
necessary.
|
|
2628 |
|
|
2629 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2630 |
lower case.
|
|
2631 |
|
|
2632 |
@param aVal The unsigned integer value.
|
|
2633 |
@param aRadix The number system representation for the unsigned integer.
|
|
2634 |
@param aWidth The number of characters to be used to contain the conversion,
|
|
2635 |
and to be appended to this descriptor.
|
|
2636 |
*/
|
|
2637 |
{
|
|
2638 |
DoAppendNum(aVal, aRadix, 'a', aWidth);
|
|
2639 |
}
|
|
2640 |
|
|
2641 |
#if (!defined(__DES8_MACHINE_CODED__) && !defined(__KERNEL_MODE__))
|
|
2642 |
EXPORT_C TPtr8 TDes8::LeftTPtr(TInt aLength) const
|
|
2643 |
/**
|
|
2644 |
Extracts the leftmost part of the data.
|
|
2645 |
|
|
2646 |
The function does not cut or remove any data but constructs a modifiable
|
|
2647 |
pointer descriptor to represent the leftmost part of the data.
|
|
2648 |
|
|
2649 |
@param aLength The length of the data to be extracted. If this value
|
|
2650 |
is greater than the length of the descriptor, the function
|
|
2651 |
extracts the whole of the descriptor.
|
|
2652 |
|
|
2653 |
@return The 8-bit modifiable pointer descriptor representing the leftmost
|
|
2654 |
part of the data.
|
|
2655 |
|
|
2656 |
@panic USER 22 if aLength is negative.
|
|
2657 |
*/
|
|
2658 |
{
|
|
2659 |
|
|
2660 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
|
|
2661 |
TInt len=Min(aLength,Length());
|
|
2662 |
return(TPtr8((TUint8*)Ptr(),len,len));
|
|
2663 |
}
|
|
2664 |
|
|
2665 |
EXPORT_C TPtr8 TDes8::RightTPtr(TInt aLength) const
|
|
2666 |
/**
|
|
2667 |
Extracts the rightmost part of the data.
|
|
2668 |
|
|
2669 |
The function does not cut or remove any data but constructs a modifiable
|
|
2670 |
pointer descriptor to represent the rightmost part of the data.
|
|
2671 |
|
|
2672 |
@param aLength The length of data to be extracted. If this value
|
|
2673 |
is greater than the length of the descriptor, the function
|
|
2674 |
extracts the whole of the descriptor.
|
|
2675 |
|
|
2676 |
@return The 8 bit modifiable pointer descriptor representing the rightmost
|
|
2677 |
part of the data.
|
|
2678 |
|
|
2679 |
@panic USER 22 if aLength is negative.
|
|
2680 |
*/
|
|
2681 |
{
|
|
2682 |
|
|
2683 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
|
|
2684 |
TInt len=Length();
|
|
2685 |
if (aLength>len)
|
|
2686 |
aLength=len;
|
|
2687 |
return(TPtr8((TUint8*)Ptr()+len-aLength,aLength,aLength));
|
|
2688 |
}
|
|
2689 |
|
|
2690 |
EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos) const
|
|
2691 |
/**
|
|
2692 |
Extracts a portion of the data.
|
|
2693 |
|
|
2694 |
The function does not cut or remove any data but constructs a modifiable
|
|
2695 |
pointer descriptor to represent the defined portion.
|
|
2696 |
|
|
2697 |
The portion is identified by its starting position and by the length of the
|
|
2698 |
remainder of the data starting from the specified position.
|
|
2699 |
|
|
2700 |
@param aPos The starting position of the data to be extracted. This is an
|
|
2701 |
offset value; a zero value refers to the leftmost data position.
|
|
2702 |
|
|
2703 |
@return The 8-bit modifiable pointer descriptor representing the specified
|
|
2704 |
portion of the data.
|
|
2705 |
|
|
2706 |
@panic USER 22 if aPos is negative or aPos is greater than the
|
|
2707 |
length of the descriptor.
|
|
2708 |
*/
|
|
2709 |
{
|
|
2710 |
|
|
2711 |
TInt len=Length();
|
|
2712 |
__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
|
|
2713 |
return(TPtr8((TUint8*)Ptr()+aPos,len-aPos,len-aPos));
|
|
2714 |
}
|
|
2715 |
|
|
2716 |
EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos,TInt aLength) const
|
|
2717 |
/**
|
|
2718 |
Extracts a portion of the data.
|
|
2719 |
|
|
2720 |
The function does not cut or remove any data but constructs a modifiable
|
|
2721 |
pointer descriptor to represent the defined portion.
|
|
2722 |
|
|
2723 |
The portion is identified by its starting position and by its length.
|
|
2724 |
|
|
2725 |
@param aPos The starting position of the data to be extracted. This is an
|
|
2726 |
offset value; a zero value refers to the leftmost data position.
|
|
2727 |
@param aLength The length of data to be extracted.
|
|
2728 |
|
|
2729 |
@return The 8 bit modifiable pointer descriptor representing the specified
|
|
2730 |
portion of the data.
|
|
2731 |
|
|
2732 |
@panic USER 22 if aPos is negative or aPos plus aLength is greater than the
|
|
2733 |
length of the descriptor.
|
|
2734 |
*/
|
|
2735 |
{
|
|
2736 |
|
|
2737 |
__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
|
|
2738 |
return(TPtr8((TUint8*)Ptr()+aPos,aLength,aLength));
|
|
2739 |
}
|
|
2740 |
#endif
|
|
2741 |
|
|
2742 |
#ifndef __KERNEL_MODE__
|
|
2743 |
EXPORT_C void TDes8::AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
|
|
2744 |
/**
|
|
2745 |
Converts the specified unsigned integer into a fixed width character
|
|
2746 |
representation based on the specified number system and appends the conversion
|
|
2747 |
onto the end of this descriptor's data.
|
|
2748 |
|
|
2749 |
The length of this descriptor is incremented to reflect the new content.
|
|
2750 |
|
|
2751 |
The function generates the exact number of specified characters, either
|
|
2752 |
padding to the left with character zeroes or discarding low order characters
|
|
2753 |
as necessary.
|
|
2754 |
|
|
2755 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2756 |
upper case.
|
|
2757 |
|
|
2758 |
@param aVal The unsigned integer value.
|
|
2759 |
@param aRadix The number system representation for the unsigned integer.
|
|
2760 |
@param aWidth The number of characters to be used to contain the conversion,
|
|
2761 |
and to be appended to this descriptor.
|
|
2762 |
*/
|
|
2763 |
{
|
|
2764 |
DoAppendNum(aVal, aRadix, 'A', aWidth);
|
|
2765 |
}
|
|
2766 |
|
|
2767 |
EXPORT_C void TDes8::AppendNumUC(TUint64 aVal, TRadix aRadix)
|
|
2768 |
/** Converts the specified 64-bit unsigned integer into a character
|
|
2769 |
representation based on the specified number system and appends the conversion
|
|
2770 |
onto the end of this descriptor's data.
|
|
2771 |
|
|
2772 |
The length of this descriptor is incremented to reflect the new content.
|
|
2773 |
|
|
2774 |
When a hexadecimal conversion is specified, hexadecimal characters are in
|
|
2775 |
upper case.
|
|
2776 |
|
|
2777 |
@param aVal The 64-bit integer value. This is treated as an unsigned value.
|
|
2778 |
@param aRadix The number system representation for the 64-bit integer. If no
|
|
2779 |
explicit value is specified, then EDecimal is the default.
|
|
2780 |
*/
|
|
2781 |
{
|
|
2782 |
DoAppendNum(aVal, aRadix, 'A', 0);
|
|
2783 |
}
|
|
2784 |
|
|
2785 |
EXPORT_C void TDes8::Format(TRefByValue<const TDesC8> aFmt,...)
|
|
2786 |
/**
|
|
2787 |
Formats and copies text into this descriptor, replacing any existing data.
|
|
2788 |
|
|
2789 |
The length of this descriptor is set to reflect the new data.
|
|
2790 |
|
|
2791 |
The function takes a format string and a variable number of arguments.
|
|
2792 |
The format string contains literal text embedded with directives for converting
|
|
2793 |
the trailing list of arguments into text.
|
|
2794 |
|
|
2795 |
The embedded directives are character sequences prefixed with the '%' character.
|
|
2796 |
The literal text is simply copied into this descriptor unaltered while
|
|
2797 |
the '%' directives are used to convert successive arguments from the
|
|
2798 |
trailing list.
|
|
2799 |
|
|
2800 |
The resulting stream of literal text and converted arguments is copied into
|
|
2801 |
this descriptor.
|
|
2802 |
|
|
2803 |
The syntax of the embedded directives follows one of four general patterns.
|
|
2804 |
|
|
2805 |
Note that formatting of single numerical values can be achieved more
|
|
2806 |
conveniently using the Num() and NumUC() member functions of this class.
|
|
2807 |
|
|
2808 |
The full description of the syntax of a format string cannot be included here.
|
|
2809 |
For full details, navigate to the Symbian OS guide, and follow the hierarchy of links:
|
|
2810 |
|
|
2811 |
@code
|
|
2812 |
Symbian OS Guide
|
|
2813 |
Base
|
|
2814 |
Using User Library (E32)
|
|
2815 |
Buffers and Strings
|
|
2816 |
Using Descriptors
|
|
2817 |
How to Use Descriptors
|
|
2818 |
Format string syntax
|
|
2819 |
@endcode
|
|
2820 |
|
|
2821 |
@param aFmt The descriptor containing the format string.
|
|
2822 |
The TRefByValue class provides a constructor which takes a
|
|
2823 |
TDesC8 type.
|
|
2824 |
|
|
2825 |
@param ... A variable number of arguments to be converted to text as
|
|
2826 |
dictated by the format string.
|
|
2827 |
|
|
2828 |
@panic USER 23 if the resulting length of text in this descriptor exceeds
|
|
2829 |
the descriptor's maximum length.
|
|
2830 |
@panic USER 24 if the format string has incorrect syntax.
|
|
2831 |
|
|
2832 |
@see TDes8::Num()
|
|
2833 |
@see TDes8::NumUC()
|
|
2834 |
*/
|
|
2835 |
{
|
|
2836 |
|
|
2837 |
VA_LIST list;
|
|
2838 |
VA_START(list,aFmt);
|
|
2839 |
// coverity[uninit_use_in_call]
|
|
2840 |
FormatList(aFmt,list);
|
|
2841 |
}
|
|
2842 |
|
|
2843 |
EXPORT_C void TDes8::FormatList(const TDesC8 &aFmt,VA_LIST aList)
|
|
2844 |
/**
|
|
2845 |
Formats and copies text into this descriptor, replacing any existing data.
|
|
2846 |
|
|
2847 |
The length of this descriptor is set to reflect the new data.
|
|
2848 |
|
|
2849 |
The behaviour of this function is the same as Format(). In practice, it is
|
|
2850 |
better and easier to use Format(), passing a variable number of arguments
|
|
2851 |
as required by the format string.
|
|
2852 |
|
|
2853 |
@param aFmt The descriptor containing the format string.
|
|
2854 |
@param aList A pointer to an argument list.
|
|
2855 |
|
|
2856 |
@see TDes8::Format()
|
|
2857 |
@see VA_LIST
|
|
2858 |
*/
|
|
2859 |
{
|
|
2860 |
|
|
2861 |
Zero();
|
|
2862 |
AppendFormatList(aFmt,aList);
|
|
2863 |
}
|
|
2864 |
|
|
2865 |
EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,TDes8Overflow *aOverflowHandler,...)
|
|
2866 |
/**
|
|
2867 |
Formats and appends text onto the end of this descriptor's data.
|
|
2868 |
|
|
2869 |
The length of this descriptor is incremented to reflect the new content.
|
|
2870 |
|
|
2871 |
The function takes a format string and a variable number of arguments.
|
|
2872 |
The format string contains literal text, embedded with directives,
|
|
2873 |
for converting the trailing list of arguments into text.
|
|
2874 |
|
|
2875 |
The embedded directives are character sequences prefixed with the '%' character.
|
|
2876 |
The literal text is simply copied into this descriptor unaltered while
|
|
2877 |
the '%' directives are used to convert successive arguments from the
|
|
2878 |
trailing list. See the description of the Format() function.
|
|
2879 |
|
|
2880 |
Literal text is appended on a character by character basis.
|
|
2881 |
If it results in the length of this descriptor exceeding its maximum length,
|
|
2882 |
then the function:
|
|
2883 |
|
|
2884 |
1. calls the Overflow() member function of the overflow handler, if an overflow
|
|
2885 |
handler is supplied
|
|
2886 |
2 raises a USER 23 panic, if no overflow handler is supplied.
|
|
2887 |
|
|
2888 |
As much literal text as possible will have been copied into this descriptor
|
|
2889 |
and this descriptor will have reached its maximum length.
|
|
2890 |
|
|
2891 |
Text converted from a trailing argument is appended as a complete string.
|
|
2892 |
If an attempt to append this string fails because the resulting length
|
|
2893 |
of this descriptor would exceed its maximum length, then the function:
|
|
2894 |
|
|
2895 |
1. calls the Overflow() member function of the overflow handler, if an overflow
|
|
2896 |
handler is supplied
|
|
2897 |
|
|
2898 |
2 raises a USER 23 panic, if no overflow handler is supplied.
|
|
2899 |
|
|
2900 |
None of the generated text is appended and length of this descriptor
|
|
2901 |
may be less than the maximum.
|
|
2902 |
|
|
2903 |
@param aFmt The 8-bit non-modifiable descriptor containing the
|
|
2904 |
format string. The TRefByValue class provides a
|
|
2905 |
constructor which takes a TDesC8 type.
|
|
2906 |
|
|
2907 |
@param aOverflowHandler A pointer to the overflow handler.
|
|
2908 |
|
|
2909 |
@param ... A variable number of arguments to be converted to text
|
|
2910 |
as dictated by the format string.
|
|
2911 |
|
|
2912 |
@panic USER 23 if the length of the descriptor exceeds its maximum length and
|
|
2913 |
no overflow handler has been supplied.
|
|
2914 |
@panic USER 24 if the format string has incorrect syntax.
|
|
2915 |
|
|
2916 |
@see TDes8::Format()
|
|
2917 |
@see TDes8Overflow::Overflow()
|
|
2918 |
*/
|
|
2919 |
{
|
|
2920 |
|
|
2921 |
VA_LIST list;
|
|
2922 |
VA_START(list, aOverflowHandler);
|
|
2923 |
// coverity[uninit_use_in_call]
|
|
2924 |
AppendFormatList(aFmt,list,aOverflowHandler);
|
|
2925 |
}
|
|
2926 |
|
|
2927 |
EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,...)
|
|
2928 |
/**
|
|
2929 |
Formats and appends text onto the end of this descriptor's data.
|
|
2930 |
|
|
2931 |
The length of this descriptor is incremented to reflect the new content.
|
|
2932 |
|
|
2933 |
The function takes a format string and a variable number of arguments.
|
|
2934 |
The format string contains literal text, embedded with directives,
|
|
2935 |
for converting the trailing list of arguments into text.
|
|
2936 |
|
|
2937 |
The embedded directives are character sequences prefixed with the '%' character.
|
|
2938 |
The literal text is simply copied into this descriptor unaltered while
|
|
2939 |
the '%' directives are used to convert successive arguments from the
|
|
2940 |
trailing list. See the description of the Format() function.
|
|
2941 |
|
|
2942 |
Literal text is appended on a character by character basis.
|
|
2943 |
|
|
2944 |
Text converted from a trailing argument is appended as a complete string.
|
|
2945 |
|
|
2946 |
@param aFmt The 8-bit non-modifiable descriptor containing the
|
|
2947 |
format string. The TRefByValue class provides a
|
|
2948 |
constructor which takes a TDesC8 type.
|
|
2949 |
|
|
2950 |
@param ... A variable number of arguments to be converted to text
|
|
2951 |
as dictated by the format string.
|
|
2952 |
|
|
2953 |
|
|
2954 |
@panic USER 23 if the resulting length of text in this descriptor exceeds
|
|
2955 |
the descriptor's maximum length.
|
|
2956 |
@panic USER 24 if the format string has incorrect syntax.
|
|
2957 |
|
|
2958 |
@see TDes8::Format()
|
|
2959 |
*/
|
|
2960 |
{
|
|
2961 |
|
|
2962 |
VA_LIST list;
|
|
2963 |
VA_START(list,aFmt);
|
|
2964 |
AppendFormatList(aFmt,list);
|
|
2965 |
}
|
|
2966 |
#endif // __KERNEL_MODE__
|
|
2967 |
|
|
2968 |
#if !defined(__DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
|
|
2969 |
EXPORT_C TPtrC8::TPtrC8()
|
|
2970 |
: TDesC8(EPtrC,0),iPtr(0)
|
|
2971 |
/**
|
|
2972 |
Default constructor.
|
|
2973 |
|
|
2974 |
Constructs an empty 8-bit non-modifiable pointer descriptor.
|
|
2975 |
|
|
2976 |
It represents no data and its length is zero.
|
|
2977 |
|
|
2978 |
The non-modifiable pointer descriptor can, subsequently, be set to represent
|
|
2979 |
data.
|
|
2980 |
|
|
2981 |
@see TPtrC8::Set()
|
|
2982 |
*/
|
|
2983 |
{}
|
|
2984 |
|
|
2985 |
EXPORT_C TPtrC8::TPtrC8(const TDesC8 &aDes)
|
|
2986 |
: TDesC8(EPtrC,aDes.Length()),iPtr(aDes.Ptr())
|
|
2987 |
/**
|
|
2988 |
Constructs the 8-bit non-modifiable pointer descriptor from any existing
|
|
2989 |
descriptor.
|
|
2990 |
|
|
2991 |
It is set to point to the same data and is given the same length as the source
|
|
2992 |
descriptor.
|
|
2993 |
|
|
2994 |
@param aDes A reference to an 8bit non-modifiable descriptor.
|
|
2995 |
*/
|
|
2996 |
{}
|
|
2997 |
|
|
2998 |
EXPORT_C TPtrC8::TPtrC8(const TUint8 *aString)
|
|
2999 |
: TDesC8(EPtrC,STRING_LENGTH(aString)),iPtr(aString)
|
|
3000 |
/**
|
|
3001 |
Constructs the 8-bit non-modifiable pointer descriptor to point to a zero
|
|
3002 |
terminated string, whether in RAM or ROM.
|
|
3003 |
|
|
3004 |
The length of the descriptor is set to the length of the zero terminated
|
|
3005 |
string, excluding the zero terminator.
|
|
3006 |
|
|
3007 |
@param aString A pointer to a zero terminated string.
|
|
3008 |
*/
|
|
3009 |
{}
|
|
3010 |
|
|
3011 |
EXPORT_C TPtrC8::TPtrC8(const TUint8 *aBuf,TInt aLength)
|
|
3012 |
: TDesC8(EPtrC,aLength),iPtr(aBuf)
|
|
3013 |
/**
|
|
3014 |
Constructs the 8-bit non-modifiable pointer descriptor to point to the
|
|
3015 |
specified location in memory, whether in RAM or ROM.
|
|
3016 |
|
|
3017 |
The length of the descriptor is set to the specified length.
|
|
3018 |
|
|
3019 |
@param aBuf A pointer to the location that the descriptor is to represent.
|
|
3020 |
@param aLength The length of the descriptor. This value must be non-negative.
|
|
3021 |
|
|
3022 |
@panic USER 29 if aLength is negative.
|
|
3023 |
*/
|
|
3024 |
{
|
|
3025 |
__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
|
|
3026 |
}
|
|
3027 |
|
|
3028 |
EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aMaxLength)
|
|
3029 |
: TDes8(EPtr,0,aMaxLength),iPtr(aBuf)
|
|
3030 |
/**
|
|
3031 |
Constructs the 8-bit modifiable pointer descriptor to point to the specified
|
|
3032 |
location in memory, whether in RAM or ROM.
|
|
3033 |
|
|
3034 |
The length of the descriptor is set to zero and its maximum length is set
|
|
3035 |
to the specified value.
|
|
3036 |
|
|
3037 |
@param aBuf A pointer to the location that the descriptor is to
|
|
3038 |
represent.
|
|
3039 |
|
|
3040 |
@param aMaxLength The maximum length of the descriptor.
|
|
3041 |
|
|
3042 |
@panic USER 30 if aMaxLength is negative.
|
|
3043 |
*/
|
|
3044 |
{
|
|
3045 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3046 |
}
|
|
3047 |
|
|
3048 |
EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aLength,TInt aMaxLength)
|
|
3049 |
: TDes8(EPtr,aLength,aMaxLength),iPtr(aBuf)
|
|
3050 |
/**
|
|
3051 |
Constructs the 8-bit modifiable pointer descriptor to point to the specified
|
|
3052 |
location in memory, whether in RAM or ROM.
|
|
3053 |
|
|
3054 |
The length of the descriptor and its maximum length are set to the specified
|
|
3055 |
values.
|
|
3056 |
|
|
3057 |
@param aBuf A pointer to the location that the descriptor is
|
|
3058 |
to represent.
|
|
3059 |
@param aLength The length of the descriptor.
|
|
3060 |
@param aMaxLength The maximum length of the descriptor.
|
|
3061 |
|
|
3062 |
@panic USER 20 if aLength is negative, or is greater than the descriptor's
|
|
3063 |
maximum length,
|
|
3064 |
@panic USER 30 if aMaxLength is negative.
|
|
3065 |
*/
|
|
3066 |
{
|
|
3067 |
__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3068 |
__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
|
|
3069 |
}
|
|
3070 |
|
|
3071 |
EXPORT_C TPtr8::TPtr8(TBufCBase8 &aLcb,TInt aMaxLength)
|
|
3072 |
: TDes8(EBufCPtr,aLcb.Length(),aMaxLength),iPtr((TUint8*)&aLcb)
|
|
3073 |
{
|
|
3074 |
__ASSERT_DEBUG(aLcb.Length()<=aMaxLength,Panic(ETDes8LengthOutOfRange));
|
|
3075 |
}
|
|
3076 |
|
|
3077 |
EXPORT_C TBufBase8::TBufBase8(TInt aMaxLength)
|
|
3078 |
:TDes8(EBuf,0,aMaxLength)
|
|
3079 |
{
|
|
3080 |
__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3081 |
}
|
|
3082 |
|
|
3083 |
EXPORT_C TBufBase8::TBufBase8(TInt aLength,TInt aMaxLength)
|
|
3084 |
:TDes8(EBuf,aLength,aMaxLength)
|
|
3085 |
{
|
|
3086 |
__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3087 |
__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
|
|
3088 |
}
|
|
3089 |
|
|
3090 |
EXPORT_C TBufBase8::TBufBase8(const TUint8* aString,TInt aMaxLength)
|
|
3091 |
:TDes8(EBuf,0,aMaxLength)
|
|
3092 |
{
|
|
3093 |
__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3094 |
Copy(aString);
|
|
3095 |
}
|
|
3096 |
|
|
3097 |
EXPORT_C TBufBase8::TBufBase8(const TDesC8& aDes,TInt aMaxLength)
|
|
3098 |
:TDes8(EBuf,0,aMaxLength)
|
|
3099 |
{
|
|
3100 |
__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
|
|
3101 |
Copy(aDes);
|
|
3102 |
}
|
|
3103 |
|
|
3104 |
#endif
|
|
3105 |
|
|
3106 |
// Truncate literal string to fit into descriptor
|
|
3107 |
EXPORT_C void TDes8IgnoreOverflow::Overflow(TDes8& /*aDes*/)
|
|
3108 |
{}
|
|
3109 |
|
|
3110 |
#ifndef __KERNEL_MODE__
|
|
3111 |
EXPORT_C void TDesC8::__DbgTestInvariant() const
|
|
3112 |
//
|
|
3113 |
// Test that the class obeys its invariant.
|
|
3114 |
//
|
|
3115 |
{
|
|
3116 |
|
|
3117 |
#if defined(_DEBUG)
|
|
3118 |
switch (Type())
|
|
3119 |
{
|
|
3120 |
case EBufC:
|
|
3121 |
case EPtrC:
|
|
3122 |
case EPtr:
|
|
3123 |
case EBuf:
|
|
3124 |
case EBufCPtr:
|
|
3125 |
break;
|
|
3126 |
default:
|
|
3127 |
User::Invariant();
|
|
3128 |
}
|
|
3129 |
#endif
|
|
3130 |
}
|
|
3131 |
|
|
3132 |
EXPORT_C void TPtrC8::__DbgTestInvariant() const
|
|
3133 |
//
|
|
3134 |
// Test that the class obeys its invariant.
|
|
3135 |
//
|
|
3136 |
{
|
|
3137 |
|
|
3138 |
#if defined(_DEBUG)
|
|
3139 |
TDesC8::__DbgTestInvariant(); // Test base class
|
|
3140 |
if (Type()!=EPtrC)
|
|
3141 |
User::Invariant();
|
|
3142 |
#endif
|
|
3143 |
}
|
|
3144 |
|
|
3145 |
EXPORT_C void TDes8::__DbgTestInvariant() const
|
|
3146 |
//
|
|
3147 |
// Test that the class obeys its invariant.
|
|
3148 |
//
|
|
3149 |
{
|
|
3150 |
|
|
3151 |
#if defined(_DEBUG)
|
|
3152 |
TDesC8::__DbgTestInvariant(); // Test base class
|
|
3153 |
if (Length()>MaxLength() || !(Type()==EPtr || Type()==EBufCPtr || Type()==EBuf))
|
|
3154 |
User::Invariant();
|
|
3155 |
#endif
|
|
3156 |
}
|
|
3157 |
|
|
3158 |
EXPORT_C void HBufC8::__DbgTestInvariant() const
|
|
3159 |
//
|
|
3160 |
// Test that the class obeys its invariant.
|
|
3161 |
//
|
|
3162 |
{
|
|
3163 |
|
|
3164 |
#if defined(_DEBUG)
|
|
3165 |
TDesC8::__DbgTestInvariant(); // Test base class
|
|
3166 |
if (Length()>(TInt)(User::AllocLen(this)-sizeof(TDesC8)) || Type()!=EBufC)
|
|
3167 |
User::Invariant();
|
|
3168 |
#endif
|
|
3169 |
}
|
|
3170 |
|
|
3171 |
EXPORT_C void TPtr8::__DbgTestInvariant() const
|
|
3172 |
//
|
|
3173 |
// Test that the class obeys its invariant.
|
|
3174 |
//
|
|
3175 |
{
|
|
3176 |
|
|
3177 |
#if defined(_DEBUG)
|
|
3178 |
TDes8::__DbgTestInvariant(); // Test base class
|
|
3179 |
if (!(Type()==EPtr || Type()==EBufCPtr))
|
|
3180 |
User::Invariant();
|
|
3181 |
#endif
|
|
3182 |
}
|
|
3183 |
|
|
3184 |
/** Expand all characters from 8 to 16 bits
|
|
3185 |
|
|
3186 |
@return 16-bit pointer descriptor to transformed text
|
|
3187 |
|
|
3188 |
The length of descriptor increased by 2 (length *= 2).
|
|
3189 |
|
|
3190 |
@panic USER 187 if either the descriptor length or the maximum length is odd
|
|
3191 |
or data pointer is not aligned by 2-bytes boundary
|
|
3192 |
*/
|
|
3193 |
EXPORT_C TPtr16 TDes8::Expand()
|
|
3194 |
{
|
|
3195 |
TInt l = Length();
|
|
3196 |
TInt ml = MaxLength();
|
|
3197 |
const TText8* s0 = Ptr();
|
|
3198 |
const TText8* s = s0 + l;
|
|
3199 |
__ASSERT_ALWAYS( !((ml|(TInt)s0)&1), Panic(EDes8ExpandOdd) );
|
|
3200 |
SetLength(l<<1);
|
|
3201 |
TText16* d = ((TText16*)s0) + l;
|
|
3202 |
while (s > s0)
|
|
3203 |
*--d = *--s;
|
|
3204 |
return TPtr16(d, l, ml>>1);
|
|
3205 |
}
|
|
3206 |
|
|
3207 |
|
|
3208 |
/** Collapse all characters from 16 to 8 bits
|
|
3209 |
|
|
3210 |
The length of descriptor truncated by 2 (length /= 2).
|
|
3211 |
|
|
3212 |
@panic USER 188 if either the descriptor length or the maximum length is odd
|
|
3213 |
or data pointer is not aligned by 2-bytes boundary.
|
|
3214 |
*/
|
|
3215 |
|
|
3216 |
EXPORT_C void TDes8::Collapse()
|
|
3217 |
{
|
|
3218 |
TInt l = Length();
|
|
3219 |
TInt ml = MaxLength();
|
|
3220 |
TText8* d = (TText8*)Ptr();
|
|
3221 |
__ASSERT_ALWAYS( !((l|ml|(TInt)d)&1), Panic(EDes8CollapseOdd) );
|
|
3222 |
const TText16* s = (const TText16*)d;
|
|
3223 |
const TText16* sE = s + (l>>1);
|
|
3224 |
while (s < sE)
|
|
3225 |
*d++ = (TText8)*s++;
|
|
3226 |
SetLength(l>>1);
|
|
3227 |
}
|
|
3228 |
#else // __KERNEL_MODE__
|
|
3229 |
|
|
3230 |
EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
|
|
3231 |
/**
|
|
3232 |
Compares this descriptor's folded data with the specified descriptor's folded
|
|
3233 |
data.
|
|
3234 |
|
|
3235 |
Note that folding is locale-independent behaviour. It is also important to
|
|
3236 |
note that there can be no guarantee that folding is in any way culturally
|
|
3237 |
appropriate, and should not be used for comparing strings in natural language;
|
|
3238 |
use CompareC() for this.
|
|
3239 |
|
|
3240 |
@param aDes The 8-bit non modifable descriptor whose data is to be compared
|
|
3241 |
with this descriptor's data.
|
|
3242 |
|
|
3243 |
@return Positive, if this descriptor is greater than the specified descriptor.
|
|
3244 |
Negative, if this descriptor is less than the specified descriptor.
|
|
3245 |
Zero, if both descriptors have the same length and the their contents
|
|
3246 |
are the same.
|
|
3247 |
|
|
3248 |
@see TDesC8::Compare()
|
|
3249 |
*/
|
|
3250 |
{
|
|
3251 |
|
|
3252 |
TInt ll = Length();
|
|
3253 |
TInt rl = aDes.Length();
|
|
3254 |
TInt r = memicmp(Ptr(), aDes.Ptr(), Min(ll, rl));
|
|
3255 |
if (r == 0)
|
|
3256 |
r = ll - rl;
|
|
3257 |
return r;
|
|
3258 |
}
|
|
3259 |
|
|
3260 |
#endif // __KERNEL_MODE__
|
|
3261 |
|
|
3262 |
#ifndef __KERNEL_MODE__
|
|
3263 |
|
|
3264 |
/**
|
|
3265 |
Default constructor.
|
|
3266 |
|
|
3267 |
Constructs a zero-length 8-bit resizable buffer descriptor.
|
|
3268 |
|
|
3269 |
Note that the object owns no allocated memory.
|
|
3270 |
*/
|
|
3271 |
EXPORT_C RBuf8::RBuf8()
|
|
3272 |
:TDes8(EPtr,0,0),iEPtrType(NULL)
|
|
3273 |
{
|
|
3274 |
// Zero-length RBuf8 is of type EPtr with NULL pointer.
|
|
3275 |
}
|
|
3276 |
|
|
3277 |
|
|
3278 |
|
|
3279 |
|
|
3280 |
/**
|
|
3281 |
Constructor.
|
|
3282 |
|
|
3283 |
Constructs an 8-bit resizable buffer descriptor, transferring ownership of the
|
|
3284 |
specified heap descriptor to this object.
|
|
3285 |
|
|
3286 |
@param aHBuf The heap descriptor to be transferred to this object. This pointer
|
|
3287 |
can be NULL, which means that a zero length 8-bit resizable
|
|
3288 |
buffer descriptor is constructed, and the object will not own any
|
|
3289 |
allocated memory.
|
|
3290 |
*/
|
|
3291 |
EXPORT_C RBuf8::RBuf8(HBufC8* aHBuf)
|
|
3292 |
{
|
|
3293 |
if(aHBuf)
|
|
3294 |
//Create EBufCPtr type descriptor that points to aHBuf
|
|
3295 |
new(this) TPtr8(aHBuf->Des());
|
|
3296 |
else
|
|
3297 |
//Create zero-length RBuf8. It is EPtr type of descriptor that points to NULL.
|
|
3298 |
new(this) RBuf8();
|
|
3299 |
}
|
|
3300 |
|
|
3301 |
|
|
3302 |
|
|
3303 |
|
|
3304 |
/**
|
|
3305 |
Protected constructor.
|
|
3306 |
*/
|
|
3307 |
EXPORT_C RBuf8::RBuf8(TInt aType,TInt aLength,TInt aMaxLength)
|
|
3308 |
:TDes8(aType,aLength,aMaxLength)
|
|
3309 |
{
|
|
3310 |
}
|
|
3311 |
|
|
3312 |
|
|
3313 |
|
|
3314 |
|
|
3315 |
/**
|
|
3316 |
Transfers ownership of the specified 8-bit resizable buffer descriptor's
|
|
3317 |
buffer to this object.
|
|
3318 |
|
|
3319 |
Note that the function assumes that this descriptor does not already own any
|
|
3320 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3321 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3322 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3323 |
invoked.
|
|
3324 |
|
|
3325 |
@param aRBuf The source 8-bit resizable buffer. The ownership of this
|
|
3326 |
object's buffer is to be transferred.
|
|
3327 |
|
|
3328 |
@see RBuf8::Close()
|
|
3329 |
*/
|
|
3330 |
EXPORT_C void RBuf8::Assign(const RBuf8& aRBuf)
|
|
3331 |
{
|
|
3332 |
Mem::Copy(this, &aRBuf, sizeof(RBuf8));
|
|
3333 |
__TEST_INVARIANT;
|
|
3334 |
}
|
|
3335 |
|
|
3336 |
|
|
3337 |
|
|
3338 |
|
|
3339 |
/**
|
|
3340 |
Assigns ownership of the specified allocated memory to this object.
|
|
3341 |
|
|
3342 |
The allocated memory forms the buffer for this descriptor. The current length
|
|
3343 |
of the descriptor is set to zero.
|
|
3344 |
|
|
3345 |
Note that the function assumes that this descriptor does not already own any
|
|
3346 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3347 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3348 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3349 |
invoked.
|
|
3350 |
|
|
3351 |
@param aHeapCell The allocated memory to be assigned to this object. This
|
|
3352 |
pointer can be NULL, which means that a zero length 8-bit
|
|
3353 |
resizable buffer descriptor is created.
|
|
3354 |
@param aMaxLength The maximum length of the descriptor.
|
|
3355 |
|
|
3356 |
@panic USER 20 If the specified maximum length is greater then the size of
|
|
3357 |
the allocated heap cell, or the specified maximum length
|
|
3358 |
is NOT zero when the pointer to the heap cell is NULL.
|
|
3359 |
|
|
3360 |
@see TDesC8::Length()
|
|
3361 |
@see TDes8::MaxLength()
|
|
3362 |
@see RBuf8::Close()
|
|
3363 |
*/
|
|
3364 |
EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aMaxLength)
|
|
3365 |
{
|
|
3366 |
Assign(aHeapCell,0,aMaxLength);
|
|
3367 |
}
|
|
3368 |
|
|
3369 |
|
|
3370 |
|
|
3371 |
|
|
3372 |
/**
|
|
3373 |
Assigns ownership of the specified allocated memory to this object.
|
|
3374 |
|
|
3375 |
The allocated memory forms the buffer for this descriptor. The current length
|
|
3376 |
of the descriptor is set to the value of the second parameter.
|
|
3377 |
|
|
3378 |
Note that the function assumes that this descriptor does not already own any
|
|
3379 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3380 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3381 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3382 |
invoked.
|
|
3383 |
|
|
3384 |
@param aHeapCell The allocated memory to be assigned to this object.
|
|
3385 |
@param aLength The length of the descriptor.
|
|
3386 |
@param aMaxLength The maximum length of the descriptor.
|
|
3387 |
|
|
3388 |
@panic USER 20 If the specified maximum length is greater then the size of
|
|
3389 |
the allocated heap cell, or the specified length is greater then
|
|
3390 |
the specified maximum length, or the specified maximum length
|
|
3391 |
is NOT zero when the pointer to the heap cell is NULL.
|
|
3392 |
|
|
3393 |
@see TDesC8::Length()
|
|
3394 |
@see TDes8::MaxLength()
|
|
3395 |
@see RBuf8::Close()
|
|
3396 |
*/
|
|
3397 |
EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aLength,TInt aMaxLength)
|
|
3398 |
{
|
|
3399 |
__ASSERT_ALWAYS(aLength<=aMaxLength, Panic(ETDes8LengthOutOfRange));
|
|
3400 |
if(aHeapCell)
|
|
3401 |
{
|
|
3402 |
__ASSERT_ALWAYS(User::AllocLen(aHeapCell) >= aMaxLength * (TInt)sizeof(TUint8), Panic(ETDes8LengthOutOfRange));
|
|
3403 |
//Create EPtr type descriptor that points to aHeapCell
|
|
3404 |
new(this) TPtr8(aHeapCell,aLength,aMaxLength);
|
|
3405 |
}
|
|
3406 |
else
|
|
3407 |
{
|
|
3408 |
__ASSERT_ALWAYS(aMaxLength == 0, Panic(ETDes8LengthOutOfRange));
|
|
3409 |
//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
|
|
3410 |
new(this) RBuf8();
|
|
3411 |
}
|
|
3412 |
__TEST_INVARIANT;
|
|
3413 |
}
|
|
3414 |
|
|
3415 |
|
|
3416 |
|
|
3417 |
|
|
3418 |
/**
|
|
3419 |
Transfers ownership of the specified heap descriptor to this object.
|
|
3420 |
|
|
3421 |
Note that the function assumes that this descriptor does not already own any
|
|
3422 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3423 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3424 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3425 |
invoked.
|
|
3426 |
|
|
3427 |
@param aHBuf The heap descriptor to be transferred to this object.
|
|
3428 |
This pointer can be NULL, which means that a zero length
|
|
3429 |
8-bit resizable buffer descriptor is created.
|
|
3430 |
@see RBuf8::Close()
|
|
3431 |
*/
|
|
3432 |
EXPORT_C void RBuf8::Assign(HBufC8* aHBuf)
|
|
3433 |
{
|
|
3434 |
new(this) RBuf8(aHBuf);
|
|
3435 |
}
|
|
3436 |
|
|
3437 |
|
|
3438 |
|
|
3439 |
|
|
3440 |
/**
|
|
3441 |
Swaps the content of two 8-bit resizable buffer descriptors.
|
|
3442 |
|
|
3443 |
@param aRBuf The 8-bit resizable buffer descriptor whose contents are to be
|
|
3444 |
swapped with this one.
|
|
3445 |
*/
|
|
3446 |
EXPORT_C void RBuf8::Swap(RBuf8& aRBuf)
|
|
3447 |
{
|
|
3448 |
Mem::Swap(this,&aRBuf,sizeof(*this));
|
|
3449 |
}
|
|
3450 |
|
|
3451 |
|
|
3452 |
|
|
3453 |
|
|
3454 |
/**
|
|
3455 |
Creates an 8-bit resizable buffer descriptor.
|
|
3456 |
|
|
3457 |
The function allocates sufficient memory to contain descriptor data up to
|
|
3458 |
the specified maximum length.
|
|
3459 |
|
|
3460 |
The current length of the descriptor is set to zero. The maximum length of
|
|
3461 |
the descriptor is set to the specified value.
|
|
3462 |
|
|
3463 |
Note that the function assumes that this descriptor does not already own any
|
|
3464 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3465 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3466 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3467 |
invoked.
|
|
3468 |
|
|
3469 |
@param aMaxLength The maximum length of the descriptor.
|
|
3470 |
|
|
3471 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3472 |
|
|
3473 |
@see TDesC8::Length()
|
|
3474 |
@see TDes8::MaxLength()
|
|
3475 |
@see RBuf8::Close()
|
|
3476 |
*/
|
|
3477 |
EXPORT_C TInt RBuf8::Create(TInt aMaxLength)
|
|
3478 |
{
|
|
3479 |
if (aMaxLength)
|
|
3480 |
{
|
|
3481 |
//Allocate memory
|
|
3482 |
TUint8* buf=(TUint8*)User::Alloc(aMaxLength*sizeof(TUint8));
|
|
3483 |
if(!buf) return KErrNoMemory;
|
|
3484 |
iEPtrType = buf;
|
|
3485 |
}
|
|
3486 |
else
|
|
3487 |
iEPtrType = NULL; //Zero-length descriptor.
|
|
3488 |
|
|
3489 |
|
|
3490 |
//Create EPtr type descriptor.
|
|
3491 |
new(this) RBuf8(EPtr,0,aMaxLength);
|
|
3492 |
__TEST_INVARIANT;
|
|
3493 |
return KErrNone;
|
|
3494 |
}
|
|
3495 |
|
|
3496 |
|
|
3497 |
|
|
3498 |
|
|
3499 |
/**
|
|
3500 |
Creates an 8-bit resizable buffer descriptor, and leaves on failure.
|
|
3501 |
|
|
3502 |
The function allocates sufficient memory to contain descriptor data up to
|
|
3503 |
the specified maximum length.
|
|
3504 |
|
|
3505 |
The current length of the descriptor is set to zero. The maximum length of
|
|
3506 |
the descriptor is set to the specified value.
|
|
3507 |
|
|
3508 |
Note that the function assumes that this descriptor does not already own any
|
|
3509 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3510 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3511 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3512 |
invoked.
|
|
3513 |
|
|
3514 |
@param aMaxLength The length and the maximum length of the descriptor.
|
|
3515 |
|
|
3516 |
@leave KErrNoMemory If there is insufficient memory.
|
|
3517 |
|
|
3518 |
@see TDesC8::Length()
|
|
3519 |
@see TDes8::MaxLength()
|
|
3520 |
@see RBuf8::Close()
|
|
3521 |
*/
|
|
3522 |
EXPORT_C void RBuf8::CreateL(TInt aMaxLength)
|
|
3523 |
{
|
|
3524 |
User::LeaveIfError(Create(aMaxLength));
|
|
3525 |
}
|
|
3526 |
|
|
3527 |
|
|
3528 |
|
|
3529 |
|
|
3530 |
/**
|
|
3531 |
Creates an 8-bit resizable buffer descriptor.
|
|
3532 |
|
|
3533 |
The function allocates sufficient memory to contain descriptor data up to
|
|
3534 |
the specified maximum length.
|
|
3535 |
|
|
3536 |
Both the current length and the maximum length of the descriptor are set to
|
|
3537 |
the specified value.
|
|
3538 |
|
|
3539 |
Note that the function assumes that this descriptor does not already own any
|
|
3540 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3541 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3542 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3543 |
invoked.
|
|
3544 |
|
|
3545 |
@param aMaxLength The length and the maximum length of the descriptor.
|
|
3546 |
|
|
3547 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3548 |
|
|
3549 |
@see RBuf8::Close()
|
|
3550 |
*/
|
|
3551 |
EXPORT_C TInt RBuf8::CreateMax(TInt aMaxLength)
|
|
3552 |
{
|
|
3553 |
TInt err=Create(aMaxLength);
|
|
3554 |
if(err==KErrNone)
|
|
3555 |
SetMax();
|
|
3556 |
return err;
|
|
3557 |
}
|
|
3558 |
|
|
3559 |
|
|
3560 |
|
|
3561 |
|
|
3562 |
/**
|
|
3563 |
Creates an 8-bit resizable buffer descriptor, and leaves on failure.
|
|
3564 |
|
|
3565 |
The function allocates sufficient memory to contain descriptor data up to
|
|
3566 |
the specified maximum length.
|
|
3567 |
|
|
3568 |
Both the current length and the maximum length of the descriptor are set to
|
|
3569 |
the specified value.
|
|
3570 |
|
|
3571 |
Note that the function assumes that this descriptor does not already own any
|
|
3572 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3573 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3574 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3575 |
invoked.
|
|
3576 |
|
|
3577 |
@param aMaxLength The length and the maximum length of the descriptor.
|
|
3578 |
|
|
3579 |
@leave KErrNoMemory If there is insufficient memory.
|
|
3580 |
|
|
3581 |
@see TDesC8::Length()
|
|
3582 |
@see TDes8::MaxLength()
|
|
3583 |
@see RBuf8::Close()
|
|
3584 |
*/
|
|
3585 |
EXPORT_C void RBuf8::CreateMaxL(TInt aMaxLength)
|
|
3586 |
{
|
|
3587 |
User::LeaveIfError(CreateMax(aMaxLength));
|
|
3588 |
}
|
|
3589 |
|
|
3590 |
|
|
3591 |
|
|
3592 |
|
|
3593 |
/**
|
|
3594 |
Creates a 8-bit resizable buffer descriptor to contain a copy of the
|
|
3595 |
specified (source) descriptor.
|
|
3596 |
|
|
3597 |
The function allocates sufficient memory so that this descriptor's maximum
|
|
3598 |
length is the same as the length of the source descriptor. Both the current
|
|
3599 |
length and the maximum length of this descriptor are set to
|
|
3600 |
the length of the source descriptor.
|
|
3601 |
|
|
3602 |
The data contained in the source descriptor is copied into this
|
|
3603 |
descriptor.
|
|
3604 |
|
|
3605 |
Note that the function assumes that this descriptor does not
|
|
3606 |
already own any allocated memory. It does not check, nor does it free any
|
|
3607 |
pre-existing owned allocated memory. If this descriptor does already own
|
|
3608 |
allocated memory, RBuf8::Close() should be invoked on this descriptor before
|
|
3609 |
this function is invoked.
|
|
3610 |
|
|
3611 |
@param aDes Source descriptor to be copied into this object.
|
|
3612 |
|
|
3613 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3614 |
|
|
3615 |
@see TDesC8::Length()
|
|
3616 |
@see TDes8::MaxLength()
|
|
3617 |
@see TDes8::Copy()
|
|
3618 |
@see RBuf8::Close()
|
|
3619 |
*/
|
|
3620 |
EXPORT_C TInt RBuf8::Create(const TDesC8& aDes)
|
|
3621 |
{
|
|
3622 |
return Create(aDes,aDes.Length());
|
|
3623 |
}
|
|
3624 |
|
|
3625 |
|
|
3626 |
|
|
3627 |
|
|
3628 |
/**
|
|
3629 |
Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
|
|
3630 |
(source) descriptor, and leaves on failure.
|
|
3631 |
|
|
3632 |
The function allocates sufficient memory so that this descriptor's maximum
|
|
3633 |
length is the same as the length of the source descriptor.Both the current
|
|
3634 |
length and the maximum length of this descriptor are set to the length
|
|
3635 |
of the source descriptor.
|
|
3636 |
|
|
3637 |
The data contained in the source descriptor is copied into this descriptor.
|
|
3638 |
|
|
3639 |
Note that the function assumes that this descriptor does not already own any
|
|
3640 |
allocated memory. It does not check, nor does it free any
|
|
3641 |
pre-existing owned allocated memory. If this descriptor does already own
|
|
3642 |
allocated memory, RBuf8::Close() should be invoked on this descriptor before
|
|
3643 |
this function is invoked.
|
|
3644 |
|
|
3645 |
@param aDes Source descriptor to be copied into this object.
|
|
3646 |
|
|
3647 |
@leave KErrNoMemory If there is insufficient memory.
|
|
3648 |
|
|
3649 |
@see TDesC8::Length()
|
|
3650 |
@see TDes8::MaxLength()
|
|
3651 |
@see TDes8::Copy()
|
|
3652 |
@see RBuf8::Close()
|
|
3653 |
*/
|
|
3654 |
EXPORT_C void RBuf8::CreateL(const TDesC8& aDes)
|
|
3655 |
{
|
|
3656 |
CreateL(aDes,aDes.Length());
|
|
3657 |
}
|
|
3658 |
|
|
3659 |
|
|
3660 |
|
|
3661 |
|
|
3662 |
/**
|
|
3663 |
Creates an 8-bit resizable buffer descriptor to contain a copy of the
|
|
3664 |
specified (source) descriptor.
|
|
3665 |
|
|
3666 |
The function allocates sufficient memory so that this descriptor's maximum length
|
|
3667 |
is the same as the value of the aMaxLength parameter.
|
|
3668 |
|
|
3669 |
The data contained in the source descriptor is copied into this descriptor.
|
|
3670 |
The length of data copied is either
|
|
3671 |
|
|
3672 |
- the length of the source descriptor aDes
|
|
3673 |
|
|
3674 |
or
|
|
3675 |
|
|
3676 |
- the value of the aMaxLength parameter
|
|
3677 |
|
|
3678 |
whichever is the smaller value. The current length of this descriptor is also
|
|
3679 |
set to the smaller value.
|
|
3680 |
|
|
3681 |
Note that the function assumes that this descriptor does not already own any
|
|
3682 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3683 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3684 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3685 |
invoked.
|
|
3686 |
|
|
3687 |
@param aDes Source descriptor to be copied into this object.
|
|
3688 |
|
|
3689 |
@param aMaxLength The maximum length of this descriptor.
|
|
3690 |
|
|
3691 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3692 |
|
|
3693 |
@see TDesC8::Length()
|
|
3694 |
@see TDes8::MaxLength()
|
|
3695 |
@see TDes8::Copy()
|
|
3696 |
@see RBuf8::Close()
|
|
3697 |
*/
|
|
3698 |
EXPORT_C TInt RBuf8::Create(const TDesC8& aDes,TInt aMaxLength)
|
|
3699 |
{
|
|
3700 |
TInt err=Create(aMaxLength);
|
|
3701 |
if(err==KErrNone)
|
|
3702 |
Copy(aDes.Left(aMaxLength));
|
|
3703 |
return err;
|
|
3704 |
}
|
|
3705 |
|
|
3706 |
|
|
3707 |
|
|
3708 |
|
|
3709 |
/**
|
|
3710 |
Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
|
|
3711 |
(source) descriptor, and leaves on failure.
|
|
3712 |
|
|
3713 |
The function allocates sufficient memory so that this descriptor's maximum
|
|
3714 |
length is the same as the value of the aMaxLength parameter.
|
|
3715 |
|
|
3716 |
The data contained in the source descriptor is copied into this descriptor.
|
|
3717 |
The length of data copied is either
|
|
3718 |
|
|
3719 |
- the length of the source descriptor aDes
|
|
3720 |
|
|
3721 |
or
|
|
3722 |
|
|
3723 |
- the value of the aMaxLength parameter
|
|
3724 |
|
|
3725 |
whichever is the smaller value. The current length of this descriptor is also
|
|
3726 |
set to the smaller value.
|
|
3727 |
|
|
3728 |
Note that the function assumes that this descriptor does not already own any
|
|
3729 |
allocated memory. It does not check, nor does it free any pre-existing owned
|
|
3730 |
allocated memory. If this descriptor does already own allocated memory,
|
|
3731 |
RBuf8::Close() should be invoked on this descriptor before this function is
|
|
3732 |
invoked.
|
|
3733 |
|
|
3734 |
@param aDes Source descriptor to be copied into this object.
|
|
3735 |
|
|
3736 |
@param aMaxLength The maximum length of this descriptor.
|
|
3737 |
|
|
3738 |
@leave KErrNoMemory If there is insufficient memory.
|
|
3739 |
|
|
3740 |
@see TDesC8::Length()
|
|
3741 |
@see TDes8::MaxLength()
|
|
3742 |
@see TDes8::Copy()
|
|
3743 |
@see RBuf8::Close()
|
|
3744 |
*/
|
|
3745 |
EXPORT_C void RBuf8::CreateL(const TDesC8& aDes,TInt aMaxLength)
|
|
3746 |
{
|
|
3747 |
CreateL(aMaxLength);
|
|
3748 |
Copy(aDes.Left(aMaxLength));
|
|
3749 |
}
|
|
3750 |
|
|
3751 |
|
|
3752 |
|
|
3753 |
|
|
3754 |
/**
|
|
3755 |
Resizes this 8-bit resizable buffer descriptor.
|
|
3756 |
|
|
3757 |
The length and contents of the descriptor are unchanged.
|
|
3758 |
|
|
3759 |
If the buffer descriptor was created from a zero-length heap descriptor
|
|
3760 |
HBufC, this method might leak memory (the heap descriptor is not freed).
|
|
3761 |
It is possible to avoid this by calling the Close() method prior to ReAlloc(),
|
|
3762 |
but this should be done only in this situation (otherwise the buffer contents
|
|
3763 |
will be lost).
|
|
3764 |
|
|
3765 |
For example, add
|
|
3766 |
@code
|
|
3767 |
if (desc.MaxLength() == 0) desc.Close();
|
|
3768 |
@endcode
|
|
3769 |
before the call to ReAlloc().
|
|
3770 |
|
|
3771 |
@param aMaxLength The new maximum length of the descriptor. This can be zero,
|
|
3772 |
which results in a descriptor with zero maximum length and no
|
|
3773 |
allocated memory.
|
|
3774 |
|
|
3775 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3776 |
|
|
3777 |
@panic USER 26 If the new maximum length is less then the current descriptor length.
|
|
3778 |
*/
|
|
3779 |
EXPORT_C TInt RBuf8::ReAlloc(TInt aMaxLength)
|
|
3780 |
{
|
|
3781 |
__ASSERT_ALWAYS(Length()<=aMaxLength, Panic(ETDes8ReAllocTooSmall));
|
|
3782 |
__TEST_INVARIANT;
|
|
3783 |
|
|
3784 |
if (!aMaxLength) //Reallocation to zero length
|
|
3785 |
{
|
|
3786 |
User::Free(iEPtrType); //Free memory
|
|
3787 |
new (this) RBuf8(); //Create zero-length RBuf
|
|
3788 |
return KErrNone;
|
|
3789 |
}
|
|
3790 |
|
|
3791 |
if (!iMaxLength) //Reallocation from zero length
|
|
3792 |
return Create(aMaxLength);
|
|
3793 |
|
|
3794 |
switch(Type())
|
|
3795 |
{
|
|
3796 |
case EPtr:
|
|
3797 |
{
|
|
3798 |
TUint8* buf = (TUint8*)User::ReAlloc(iEPtrType,aMaxLength*sizeof(TUint8));
|
|
3799 |
if(!buf) return KErrNoMemory;
|
|
3800 |
iEPtrType = buf;
|
|
3801 |
iMaxLength = aMaxLength;
|
|
3802 |
break;
|
|
3803 |
}
|
|
3804 |
case EBufCPtr:
|
|
3805 |
{
|
|
3806 |
HBufC8* hbufc = iEBufCPtrType->ReAlloc(aMaxLength);
|
|
3807 |
if(!hbufc) return KErrNoMemory;
|
|
3808 |
Assign(hbufc);
|
|
3809 |
break;
|
|
3810 |
}
|
|
3811 |
}
|
|
3812 |
|
|
3813 |
__TEST_INVARIANT;
|
|
3814 |
return KErrNone;
|
|
3815 |
}
|
|
3816 |
|
|
3817 |
|
|
3818 |
|
|
3819 |
|
|
3820 |
/**
|
|
3821 |
Resizes this 8-bit resizable buffer descriptor, leaving on failure.
|
|
3822 |
|
|
3823 |
The length and contents of the descriptor are unchanged.
|
|
3824 |
|
|
3825 |
If the buffer descriptor was created from a zero-length heap descriptor
|
|
3826 |
HBufC, this method might leak memory (the heap descriptor is not freed).
|
|
3827 |
It is possible to avoid this by calling the Close() method prior to ReAllocL(),
|
|
3828 |
but this should be done only in this situation (otherwise the buffer contents
|
|
3829 |
will be lost).
|
|
3830 |
|
|
3831 |
For example, add
|
|
3832 |
@code
|
|
3833 |
if (desc.MaxLength() == 0) desc.Close();
|
|
3834 |
@endcode
|
|
3835 |
before the call to ReAlloc().
|
|
3836 |
|
|
3837 |
@param aMaxLength The new maximum length of the descriptor. This can be zero,
|
|
3838 |
which results in a descriptor with zero maximum length and no
|
|
3839 |
allocated memory.
|
|
3840 |
|
|
3841 |
@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
|
|
3842 |
|
|
3843 |
@panic USER 26 If the new maximum length is less then the current descriptor length.
|
|
3844 |
*/
|
|
3845 |
EXPORT_C void RBuf8::ReAllocL(TInt aMaxLength)
|
|
3846 |
{
|
|
3847 |
User::LeaveIfError(ReAlloc(aMaxLength));
|
|
3848 |
}
|
|
3849 |
|
|
3850 |
|
|
3851 |
|
|
3852 |
|
|
3853 |
/**
|
|
3854 |
Deallocates memory assigned to this object, and re-initializes the object as
|
|
3855 |
a zero-length descriptor.
|
|
3856 |
*/
|
|
3857 |
EXPORT_C void RBuf8::Close()
|
|
3858 |
{
|
|
3859 |
User::Free(iEPtrType);
|
|
3860 |
//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
|
|
3861 |
new(this) RBuf8();
|
|
3862 |
}
|
|
3863 |
|
|
3864 |
|
|
3865 |
|
|
3866 |
|
|
3867 |
/**
|
|
3868 |
Pushes a cleanup item for this object onto the cleanup stack.
|
|
3869 |
|
|
3870 |
The effect of this is to cause Close() to be called on this 8-bit resizable
|
|
3871 |
buffer descriptor, when CleanupStack::PopAndDestroy() is called at some later time.
|
|
3872 |
|
|
3873 |
@code
|
|
3874 |
...
|
|
3875 |
RBuf8 x;
|
|
3876 |
....
|
|
3877 |
x.CleanupClosePushL();
|
|
3878 |
...
|
|
3879 |
CleanupStack::PopAndDestroy();
|
|
3880 |
...
|
|
3881 |
@endcode
|
|
3882 |
|
|
3883 |
@see RBuf8::Close()
|
|
3884 |
*/
|
|
3885 |
EXPORT_C void RBuf8::CleanupClosePushL()
|
|
3886 |
{
|
|
3887 |
::CleanupClosePushL(*this);
|
|
3888 |
}
|
|
3889 |
|
|
3890 |
|
|
3891 |
|
|
3892 |
|
|
3893 |
/**
|
|
3894 |
Tests that the class obeys its invariant.
|
|
3895 |
*/
|
|
3896 |
EXPORT_C void RBuf8::__DbgTestInvariant() const
|
|
3897 |
{
|
|
3898 |
#ifdef _DEBUG
|
|
3899 |
TDes8::__DbgTestInvariant();
|
|
3900 |
switch(Type())
|
|
3901 |
{
|
|
3902 |
case EPtr:
|
|
3903 |
if (iEPtrType)
|
|
3904 |
{
|
|
3905 |
__ASSERT_DEBUG(User::AllocLen(iEPtrType) >= iMaxLength*(TInt)sizeof(TUint8), Panic(EInvariantFalse));
|
|
3906 |
}
|
|
3907 |
break;
|
|
3908 |
case EBufCPtr:
|
|
3909 |
iEBufCPtrType->__DbgTestInvariant();
|
|
3910 |
__ASSERT_DEBUG(iEBufCPtrType->Des().MaxLength() == iMaxLength, Panic(EInvariantFalse));
|
|
3911 |
__ASSERT_DEBUG(iEBufCPtrType->Length() == Length(), Panic(EInvariantFalse));
|
|
3912 |
break;
|
|
3913 |
default:
|
|
3914 |
User::Invariant();
|
|
3915 |
}
|
|
3916 |
#endif // _DEBUG
|
|
3917 |
}
|
|
3918 |
|
|
3919 |
#endif // __KERNEL_MODE__
|
|
3920 |
|
|
3921 |
|
|
3922 |
#if defined(__DES8_MACHINE_CODED__) || defined(__EABI__)
|
|
3923 |
GLDEF_C void Des8PanicBadDesType()
|
|
3924 |
{
|
|
3925 |
Panic(ETDes8BadDescriptorType);
|
|
3926 |
}
|
|
3927 |
|
|
3928 |
GLDEF_C void Des8PanicPosOutOfRange()
|
|
3929 |
{
|
|
3930 |
Panic(ETDes8PosOutOfRange);
|
|
3931 |
}
|
|
3932 |
#endif
|
|
3933 |
|
|
3934 |
#ifdef __DES8_MACHINE_CODED__
|
|
3935 |
GLDEF_C void Des8PanicLengthNegative()
|
|
3936 |
{
|
|
3937 |
Panic(ETDes8LengthNegative);
|
|
3938 |
}
|
|
3939 |
|
|
3940 |
GLDEF_C void Des8PanicMaxLengthNegative()
|
|
3941 |
{
|
|
3942 |
Panic(ETDes8MaxLengthNegative);
|
|
3943 |
}
|
|
3944 |
|
|
3945 |
GLDEF_C void Des8PanicLengthOutOfRange()
|
|
3946 |
{
|
|
3947 |
Panic(ETDes8LengthOutOfRange);
|
|
3948 |
}
|
|
3949 |
|
|
3950 |
GLDEF_C void Des8PanicDesOverflow()
|
|
3951 |
{
|
|
3952 |
Panic(ETDes8Overflow);
|
|
3953 |
}
|
|
3954 |
|
|
3955 |
GLDEF_C void Des8PanicDesIndexOutOfRange()
|
|
3956 |
{
|
|
3957 |
Panic(ETDes8IndexOutOfRange);
|
|
3958 |
}
|
|
3959 |
#endif
|
|
3960 |
|