Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\common\des8.cpp
19 #include <e32des8_private.h>
20 #ifndef __KERNEL_MODE__
23 #include <kernel/kern_priv.h>
27 // Folding/Collation for 8 bit characters
29 extern const TUint8 __FoldCollTab8[256];
31 const TUint8 __FoldCollTab8[256] =
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
67 #ifndef __KERNEL_MODE__
68 inline TUint8* memCopy(TUint8* aPtr, const TUint8* aSrc, TInt aLength)
74 return Mem::Copy(aPtr, aSrc, aLength);
78 #if (defined(__KERNEL_MODE__) && !defined(__DES8_MACHINE_CODED__)) | defined(__EABI_CTORS__)
79 inline TInt StringLength(const TUint8* aPtr)
81 const TUint8* p = aPtr;
88 inline TDesC8::TDesC8(TInt aType,TInt aLength)
89 :iLength(aLength|(aType<<KShiftDesType8))
91 inline TInt TDesC8::Type() const
93 // Return the descriptor type
96 return(iLength>>KShiftDesType8);
99 inline TDes8::TDes8(TInt aType,TInt aLength,TInt aMaxLength)
100 : TDesC8(aType,aLength),iMaxLength(aMaxLength)
104 inline TBufCBase8::TBufCBase8(TInt aLength)
105 :TDesC8(EBufC,aLength)
108 inline TUint8* TBufCBase8::WPtr() const
109 {return const_cast<TUint8*>(Ptr());}
112 #ifndef __DES8_MACHINE_CODED__
113 EXPORT_C const TUint8* TDesC8::Ptr() const
115 Gets a pointer to the data represented by the descriptor.
117 The data cannot be changed through the returned pointer.
119 @return A pointer to the data
126 return(&((SBufC8 *)this)->buf[0]);
128 return(((SPtrC8 *)this)->ptr);
130 return(((SPtr8 *)this)->ptr);
132 return(&((SBuf8 *)this)->buf[0]);
134 return(&((SBufCPtr8 *)this)->ptr->buf[0]);
136 Panic(ETDes8BadDescriptorType);
140 EXPORT_C const TUint8 &TDesC8::AtC(TInt anIndex) const
142 // Return a reference to the character in the buffer.
146 __ASSERT_ALWAYS(anIndex>=0 && anIndex<Length(),Panic(ETDes8IndexOutOfRange));
147 return(Ptr()[anIndex]);
150 EXPORT_C TInt TDesC8::Compare(const TDesC8 &aDes) const
152 Compares this descriptor's data with the specified descriptor's data.
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.
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.
162 @param aDes The 8-bit non-modifable descriptor whose data is to be compared
163 with this descriptor's data.
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
172 return memcompare(Ptr(), Length(), aDes.Ptr(), aDes.Length());
175 #ifndef __KERNEL_MODE__
176 EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
178 Compares this descriptor's folded data with the specified descriptor's folded
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.
186 @param aDes The 8-bit non modifable descriptor whose data is to be compared
187 with this descriptor's data.
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
194 @see TDesC8::Compare()
198 return(Mem::CompareF(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
201 EXPORT_C TInt TDesC8::CompareC(const TDesC8 &aDes) const
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.
206 @param aDes The 8-bit non modifable descriptor whose data is to be compared
207 with this descriptor's data.
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
214 @see TDesC8::Compare()
219 return(Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
224 EXPORT_C TInt TDesC8::Find(const TUint8 *pS,TInt aLenS) const
226 Searches for the first occurrence of the specified data sequence within this
229 Searching always starts at the beginning of this descriptor's data.
231 @param pS A pointer to a location containing the data sequence to be searched
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.
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.
239 @panic USER 29 if aLenS is negative.
245 __ASSERT_ALWAYS(aLenS>0,Panic(ETDes8LengthNegative));
246 const TUint8 *pB=Ptr();
248 const TUint8 *pC=pB-1; // using pre-increment addressing
252 const TUint8* pEndS=pS+aLenS-1; // using pre-increment addressing
253 const TUint8 *pEndB=pB+i; // using pre-increment addressing
268 } while (*++p1==*++p2);
271 return(KErrNotFound);
274 EXPORT_C TInt TDesC8::Find(const TDesC8 &aDes) const
276 Searches for the first occurrence of the specified data sequence within this
279 Searching always starts at the beginning of this descriptor's data.
281 @param aDes The 8-bit non modifable descriptor containing the data sequence
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.
289 return(Find(aDes.Ptr(),aDes.Length()));
292 const TUint8* convTable(TMatchType aType)
297 case EMatchCollated: return __FoldCollTab8;
298 default: return NULL;
302 inline TUint conv(const TUint8* aStr,const TUint8* aConv)
305 return aConv ? aConv[c] : c;
309 inline TUint lookup(const TUint8* aStr,const TUint8* aConv)
314 TInt DoMatch8(const TDesC8 &aLeftD,const TDesC8 &aRightD,TMatchType aType)
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();
324 // Match any pattern up to the first star
328 if (pM==pP) // exhausted the pattern
329 return pB==pE ? 0 : KErrNotFound;
330 TUint c=conv(++pM,table);
333 if (pB==pE) // no more input
335 if (c!=conv(++pB,table) && c!=KMatchOne) // match failed
341 TInt r=pM==pRight ? -1 : 0;
347 star: if (pM==pP) // star at end of pattern, always matches
349 if (r<-1) // skipped some '?', matches at beginning
353 if (pB==pE) // no more input
356 { // skip a character in the input
358 return r+((r>=0) ? 0 : (pE-pLeft));
364 // Matching a non-wild character
367 if (table) // pull this test out of the tight loop (10-20% faster)
369 while (lookup(++pB,table)!=c)
371 if (pB==pE) // no more input
379 if (pB==pE) // no more input
383 // Try to match up to the next star
390 TUint cc=conv(++pm,table);
392 { // sub-match successful, back to main loop
393 r+=(r>=0 ? 0 : pB-pLeft);
399 return KErrNotFound; // no more input
400 if (cc!=conv(++pb,table) && cc!=KMatchOne)
401 break; // sub-match failed, try next input character
403 else if (pb==pE) // end of matching pattern
404 return r+(r>=0 ? 0 : pB-pLeft); // end of input, so have a match
406 break; // try next input character
412 EXPORT_C TInt TDesC8::Match(const TDesC8 &aDes) const
414 Searches this descriptor's data for a match with the match pattern supplied
415 in the specified descriptor.
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.
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
425 @param aDes An 8-bit non-modifable descriptor containing the match pattern.
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.
432 return DoMatch8(*this,aDes,EMatchNormal);
435 EXPORT_C TInt TDesC8::MatchF(const TDesC8 &aDes) const
437 Searches this descriptor's folded data for a match with the folded match
438 pattern supplied in the specified descriptor.
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.
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.
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
453 @param aDes An 8-bit non-modifable descriptor containing the match pattern.
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.
458 @see TDesC8::MatchC()
462 return DoMatch8(*this,aDes,EMatchFolded);
465 EXPORT_C TInt TDesC8::MatchC(const TDesC8 &aPattern) const
467 Searches this descriptor's collated data for a match with the collated match
468 pattern supplied in the specified descriptor.
470 The function uses the standard collation method for narrow text appropriate to
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.
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
481 @param aPattern An 8-bit non-modifable descriptor containing the match pattern.
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.
488 #ifndef __KERNEL_MODE__
489 return MatchF(aPattern);
491 return DoMatch8(*this,aPattern,EMatchCollated);
495 #ifndef __KERNEL_MODE__
497 EXPORT_C TInt TDesC8::FindF(const TUint8 *pS,TInt aLenS) const
499 Searches for the first occurrence of the specified folded data sequence within
500 this descriptor's folded data.
502 Searching always starts at the beginning of this descriptor's data.
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.
509 @param pS A pointer to a location containing the data sequence to be
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.
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.
518 @panic USER 29 if aLenS is negative
525 const TUint8* table=convTable(EMatchFolded);
526 const TUint8 *pB=Ptr();
528 const TUint8 *pC=pB-1; // using pre-increment addressing
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);
541 } while (lookup(++pC,table)!=s);
548 } while (lookup(++p1,table)==lookup(++p2,table));
551 return(KErrNotFound);
554 EXPORT_C TInt TDesC8::FindF(const TDesC8 &aDes) const
556 Searches for the first occurrence of the specified folded data sequence within
557 this descriptor's folded data.
559 Searching always starts at the beginning of this descriptor's data.
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.
566 @param aDes The 8-bit non-modifable descriptor containing the data sequence
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.
577 return(FindF(aDes.Ptr(),aDes.Length()));
580 EXPORT_C TInt TDesC8::FindC(const TUint8* aText,TInt aLength) const
582 Searches for the first occurrence of the specified collated data sequence within
583 this descriptor's collated data.
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
589 @param aText A pointer to a location containing the data sequence to be
591 @param aLength The length of the data sequence to be searched for.
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.
596 @panic USER 29 if aLength is negative.
600 return FindF(aText, aLength);
603 EXPORT_C TInt TDesC8::FindC(const TDesC8 &aDes) const
605 Searches for the first occurrence of the specified collated data sequence within
606 this descriptor's collated data.
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
612 @param aDes The 8-bit non-modifable descriptor containing the data sequence
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.
621 return(FindC(aDes.Ptr(),aDes.Length()));
624 EXPORT_C TInt TDesC8::LocateF(TChar aChar) const
626 Searches for the first occurrence of a folded character within this
627 descriptor's folded data.
629 The search starts at the beginning of the data,i.e. at the leftmost position.
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.
635 @param aChar The character to be found.
637 @return The offset of the character position from the beginning of the data.
638 KErrNotFound, if no matching character can be found.
641 TUint c = User::Fold(aChar);
644 const TUint8 *pBuf=Ptr();
645 const TUint8 *pB=pBuf-1;
646 const TUint8 *pE=pB+Length();
647 const TUint8* table=__FoldCollTab8;
652 } while (table[*++pB]!=c);
655 #endif // __KERNEL_MODE__
657 #ifndef __DES8_MACHINE_CODED__
658 EXPORT_C TInt TDesC8::Locate(TChar aChar) const
660 Searches for the first occurrence of a character within this descriptor's
663 The search starts at the beginning of the data, i.e. at the leftmost position.
665 @param aChar The character to be found.
667 @return The offset of the character position from the beginning of the data.
668 KErrNotFound, if no matching character can be found.
672 const TUint8 *pBuf=Ptr();
673 const TUint8 *pB=pBuf-1;
674 const TUint8 *pE=pB+Length();
679 } while (*++pB!=aChar);
684 #ifndef __DES8_MACHINE_CODED__
685 EXPORT_C TInt TDesC8::LocateReverse(TChar aChar) const
687 Searches for the first occurrence of a character within this descriptor's data,
688 searching from the end of the data.
690 The search starts at the rightmost position.
692 @param aChar The character to be found.
694 @return The offset of the character position from the beginning of the data.
695 KErrNotFound, if no matching character can be found.
701 return(KErrNotFound);
702 const TUint8 *pB=Ptr();
703 const TUint8 *pE=pB+len-1;
710 return(pE<pB ? KErrNotFound : pE-pB);
714 #ifndef __KERNEL_MODE__
715 EXPORT_C TInt TDesC8::LocateReverseF(TChar aChar) const
717 Searches for the first occurrence of a folded character within this descriptor's
718 folded data, searching from the end of the data.
720 The search starts at the rightmost position.
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.
726 @param aChar The character to be found
728 @return The offset of the character position from the beginning of the data.
729 KErrNotFound, if no matching character can be found
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];
746 return(pE<pB ? KErrNotFound : pE-pB);
749 EXPORT_C HBufC8 *TDesC8::Alloc() const
751 Creates a new 8-bit heap descriptor and initialises it with a copy of this
754 @return A pointer to the new 8 bit heap descriptor, if creation is successful.
755 NULL, if creation of the descriptor fails.
759 HBufC8 *pH=HBufC8::New(Length());
765 EXPORT_C HBufC8 *TDesC8::AllocL() const
767 Creates a new 8-bit heap descriptor and initialises it with a copy of this
770 The function leaves, if creation of the descriptor fails.
772 @return A pointer to the 8-bit heap descriptor, if creation is successful.
776 HBufC8 *pH=HBufC8::NewL(Length());
781 EXPORT_C HBufC8 *TDesC8::AllocLC() const
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.
786 The function leaves, if creation of the descriptor fails.
788 @return A pointer to the 8 bit heap descriptor, if creation is successful.
789 The pointer is also put onto the cleanup stack.
793 HBufC8 *pH=HBufC8::NewLC(Length());
797 #endif // __KERNEL_MODE__
799 #if !defined(__DES8_MACHINE_CODED__)
801 EXPORT_C TPtrC8 TDesC8::Left(TInt aLength) const
803 Extracts the leftmost part of the data.
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.
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.
812 @return The 8-bit non-modifiable pointer descriptor representing the leftmost
815 @panic USER 22 if aLength is negative.
819 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
820 return(TPtrC8(Ptr(),Min(aLength,Length())));
823 EXPORT_C TPtrC8 TDesC8::Right(TInt aLength) const
825 Extracts the rightmost part of the data.
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.
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.
834 @return The 8 bit non-modifiable pointer descriptor representing the rightmost
837 @panic USER 22 if aLength is negative.
841 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
845 return(TPtrC8(Ptr()+len-aLength,aLength));
848 EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos) const
850 Extracts a portion of the data.
852 The function does not cut or remove any data but constructs a non-modifiable
853 pointer descriptor to represent the defined portion.
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.
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.
861 @return The 8-bit non-modifiable pointer descriptor representing the specified
864 @panic USER 22 if aPos is negative or aPos is greater than the
865 length of the descriptor.
870 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
871 return(TPtrC8(Ptr()+aPos,len-aPos));
874 EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos,TInt aLength) const
876 Extracts a portion of the data.
878 The function does not cut or remove any data but constructs a non-modifiable
879 pointer descriptor to represent the defined portion.
881 The portion is identified by its starting position and by its length.
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.
887 @return The 8 bit non-modifiable pointer descriptor representing the specified
890 @panic USER 22 if aPos is negative or aPos plus aLength is greater than the
891 length of the descriptor.
895 __ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
896 return(TPtrC8(Ptr()+aPos,aLength));
899 #endif // !defined(__DES8_MACHINE_CODED__)
901 #if !defined( __DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
902 EXPORT_C TBufCBase8::TBufCBase8()
909 EXPORT_C TBufCBase8::TBufCBase8(const TUint8 *aString,TInt aMaxLength)
915 Copy(aString,aMaxLength);
918 EXPORT_C TBufCBase8::TBufCBase8(const TDesC8 &aDes,TInt aMaxLength)
924 Copy(aDes,aMaxLength);
928 #ifndef __DES8_MACHINE_CODED__
929 EXPORT_C void TBufCBase8::Copy(const TUint8 *aString,TInt aMaxLength)
931 // Copy from a string.
935 TInt len=STRING_LENGTH(aString);
936 __ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
937 memmove(WPtr(), aString, len);
941 EXPORT_C void TBufCBase8::Copy(const TDesC8 &aDes,TInt aMaxLength)
943 // Copy from a descriptor.
947 TInt len=aDes.Length();
948 __ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
949 memmove(WPtr(), aDes.Ptr(), len);
954 #ifndef __KERNEL_MODE__
955 inline HBufC8::HBufC8(TInt aLength)
959 EXPORT_C HBufC8 *HBufC8::New(TInt aMaxLength)
961 Creates, and returns a pointer to, a new 8-bit heap descriptor.
963 The heap descriptor is empty and its length is zero.
965 Data can, subsequently, be assigned into it using the assignment operators.
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
972 @return A pointer to the new 8-bit heap descriptor. NULL, if the 8-bit heap
973 descriptor cannot be created.
975 @panic USER 30 if aMaxLength is negative.
977 @see HBufC8::operator=()
980 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
981 return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(0);
984 EXPORT_C HBufC8 *HBufC8::NewL(TInt aMaxLength)
986 Creates, and returns a pointer to, a new 8-bit heap descriptor, and leaves
989 The heap descriptor is empty and its length is zero.
991 Data can, subsequently, be assigned into it using the assignment operators.
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
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.
1001 @panic USER 30 if aMaxLength is negative.
1003 @see HBufC8::operator=()
1006 return static_cast<HBufC8*>(User::LeaveIfNull(New(aMaxLength)));
1009 EXPORT_C HBufC8 *HBufC8::NewLC(TInt aMaxLength)
1011 Creates, adds a pointer onto the cleanup stack, and returns a pointer to, a
1012 new 8 bit heap descriptor; leaves on failure.
1014 The heap descriptor is empty and its length is zero.
1016 Data can, subsequently, be assigned into it using the assignment operators.
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
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.
1026 @panic USER 30 if aMaxLength is negative.
1028 @see HBufC8::operator=()
1031 HBufC8* buf=NewL(aMaxLength);
1032 CleanupStack::PushL(buf);
1036 EXPORT_C HBufC8 *HBufC8::NewMax(TInt aMaxLength)
1038 Creates, and returns a pointer to, a new 8-bit heap descriptor.
1040 No data is assigned into the new descriptor but its length
1041 is set to aMaxLength.
1043 Data can, subsequently, be assigned into it using the assignment operators.
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.
1051 @return A pointer to the new 8-bit heap descriptor. NULL, if the new 8-bit
1052 heap descriptor cannot be created.
1054 @panic USER 30 if aMaxLength is negative.
1056 @see HBufC8::operator=()
1059 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
1060 return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(aMaxLength);
1063 EXPORT_C HBufC8 *HBufC8::NewMaxL(TInt aMaxLength)
1065 Creates, and returns a pointer to, a new 8-bit heap descriptor;
1068 No data is assigned into the new descriptor but its length
1069 is set to aMaxLength.
1071 Data can, subsequently, be assigned into it using the assignment operators.
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.
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.
1082 @panic USER 30 if aMaxLength is negative.
1084 @see HBufC8::operator=()
1087 return static_cast<HBufC8*>(User::LeaveIfNull(NewMax(aMaxLength)));
1090 EXPORT_C HBufC8 *HBufC8::NewMaxLC(TInt aMaxLength)
1092 Creates, adds a pointer onto the cleanup stack and returns a pointer to, a
1093 new 8-bit heap descriptor; leaves on failure.
1095 No data is assigned into the new descriptor but its length
1096 is set to aMaxLength.
1098 Data can, subsequently, be assigned into it using the assignment operators.
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.
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
1110 @panic USER 30 if aMaxLength is negative.
1112 @see HBufC8::operator=()
1115 HBufC8* buf=NewMaxL(aMaxLength);
1116 CleanupStack::PushL(buf);
1120 EXPORT_C HBufC8 &HBufC8::operator=(const TUint8 *aString)
1122 Copies data into this 8-bit heap descriptor replacing any existing data.
1124 The length of this descriptor is set to reflect the new data.
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
1131 @param aString A pointer to a zero-terminated string.
1133 @return A reference to this 8 bit heap descriptor.
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,
1140 Copy(aString,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
1144 EXPORT_C HBufC8 &HBufC8::operator=(const TDesC8 &aDes)
1146 Copies data into this 8-bit heap descriptor replacing any existing data.
1148 The length of this descriptor is set to reflect the new data.
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
1155 @param aDes An 8-bit non-modifiable descriptor.
1157 @return A reference to this 8-bit heap descriptor.
1159 @panic USER 23 if the length of the descriptor aDes is greater than the
1160 maximum length of this (target) descriptor
1164 Copy(aDes,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
1168 EXPORT_C HBufC8 *HBufC8::ReAlloc(TInt aMaxLength)
1170 Expands or contracts the heap descriptor.
1174 1. creating a new heap descriptor.
1176 2. copying the original data into the new descriptor.
1178 3. deleting the original descriptor.
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.
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
1189 @panic USER 26 if aMaxLength is less than the length of the existing data.
1190 @panic USER 30 if aMaxLength is negative.
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)));
1199 EXPORT_C HBufC8 *HBufC8::ReAllocL(TInt aMaxLength)
1201 Expands or contracts the descriptor; leaves on failure.
1205 1. creating a new heap descriptor.
1207 2. copying the original data into the new descriptor.
1209 3. deleting the original descriptor.
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.
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
1220 @panic USER 26 if aMaxLength is less than the length of the existing data.
1221 @panic USER 30 if aMaxLength is negative.
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)));
1230 EXPORT_C TPtr8 HBufC8::Des()
1232 Creates and returns an 8-bit modifiable pointer descriptor for the data
1233 represented by this 8-bit heap descriptor.
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.
1239 The modifiable pointer descriptor is set to point to this heap descriptor's
1242 The length of the modifiable pointer descriptor is set to the length of this
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.
1251 When data is modified through this new pointer descriptor, the lengths of
1252 both it and this heap descriptor are changed.
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.
1258 @return An 8-bit modifiable pointer descriptor representing the data in this
1259 8-bit heap descriptor.
1262 return DoDes((STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
1264 #endif // __KERNEL_MODE__
1266 #ifndef __DES8_MACHINE_CODED__
1267 EXPORT_C void TDes8::SetLength(TInt aLength)
1269 Sets the length of the data represented by the descriptor to the
1272 @param aLength The new length of the descriptor.
1274 @panic USER 23 if alength is negative or is greater than the maximum length of
1275 this (target) descriptor.
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
1285 EXPORT_C void TDes8::SetMax()
1287 Sets the length of the data to the maximum length of the descriptor.
1291 SetLength(iMaxLength);
1294 EXPORT_C void TDes8::Copy(const TUint8 *aString)
1296 Copies data into this descriptor replacing any existing data.
1298 The length of this descriptor is set to reflect the new data.
1300 @param aString A pointer to a zero-terminated string.
1302 @panic USER 23 if the length of aString, excluding the zero terminator, is
1303 greater than the maximum length of this (target) descriptor.
1307 TInt len=STRING_LENGTH(aString);
1309 memmove(WPtr(), aString, len);
1312 EXPORT_C void TDes8::Copy(const TUint8 *aBuf,TInt aLength)
1314 Copies data into this descriptor replacing any existing data.
1316 The length of this descriptor is set to reflect the new data.
1318 @param aBuf The start address of data to be copied.
1319 @param aLength The length of data to be copied.
1321 @panic USER 23 if aLength is greater than the maximum length of
1322 this (target) descriptor.
1327 memmove(WPtr(), aBuf, aLength);
1330 EXPORT_C void TDes8::Copy(const TDesC8 &aDes)
1332 Copies data into this descriptor replacing any existing data.
1334 The length of this descriptor is set to reflect the new data.
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.
1339 @panic USER 23 if the length of aDes is greater than the maximum length of
1340 this (target) descriptor.
1344 TInt len=aDes.Length();
1346 memmove(WPtr(), aDes.Ptr(), len);
1350 #ifndef __KERNEL_MODE__
1351 EXPORT_C void TDes8::Copy(const TDesC16 &aDes)
1353 Copies data into this descriptor replacing any existing data.
1355 The length of this descriptor is set to reflect the new data.
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.
1363 @panic USER 23 if the length of the aDes is greater than the maximum length
1364 of this (target) descriptor.
1368 TInt len=aDes.Length();
1370 const TUint16 *pS=aDes.Ptr();
1371 const TUint16 *pE=pS+len;
1383 #ifndef __DES8_MACHINE_CODED__
1384 EXPORT_C void TDes8::Append(TChar aChar)
1386 Appends a character onto the end of this descriptor's data.
1388 The length of this descriptor is incremented to reflect the new content.
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.
1394 @panic USER 23 if the resulting new length of this descriptor is greater than
1400 TUint8 *pB=WPtr()+len;
1402 *pB++=(TUint8)aChar;
1405 EXPORT_C void TDes8::Append(const TUint8 *aBuf,TInt aLength)
1407 Appends data onto the end of this descriptor's data.
1409 The length of this descriptor is incremented to reflect the new content.
1411 @param aBuf A pointer to the data to be copied.
1412 @param aLength The length of the data to be copied.
1414 @panic USER 23 if the resulting new length of this descriptor is greater than
1416 @panic USER 29 if aLength is negative.
1420 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
1422 SetLength(len+aLength);
1423 memmove(WPtr()+len, aBuf, aLength);
1426 EXPORT_C void TDes8::Append(const TDesC8 &aDes)
1428 Appends data onto the end of this descriptor's data.
1430 The length of this descriptor is incremented to reflect the new content.
1432 @param aDes An 8-bit non-modifiable descriptor whose data is to be appended.
1434 @panic USER 23 if the resulting new length of this descriptor is greater than
1440 TInt n=aDes.Length();
1442 memmove(WPtr()+len, aDes.Ptr(), n);
1446 #ifndef __KERNEL_MODE__
1447 EXPORT_C void TDes8::Append(const TDesC16 &aDes)
1449 Appends data onto the end of this descriptor's data.
1451 The length of this descriptor is incremented to reflect the new content.
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.
1459 @panic USER 23 if the resulting new length of this descriptor is greater than
1465 TInt n=aDes.Length();
1466 const TUint16* pS=aDes.Ptr();
1467 const TUint16* pE=pS+n;
1468 TUint8 *pT=WPtr()+len;
1480 #ifndef __KERNEL_MODE__
1481 EXPORT_C void TDes8::Swap(TDes8 &aDes)
1483 Swaps the data represented by this descriptor with the data represented by
1484 the specified descriptor.
1486 The lengths of both descriptors are swapped to reflect the change.
1488 Note that each descriptor must be capable of accommodating the contents of
1489 the other descriptor.
1491 @param aDes The 8-bit modifiable descriptor whose data is to be swapped with
1492 the data of this descriptor.
1494 @panic USER 23 if the maximum length of either descriptor is smaller than the
1495 length of the other descriptor.
1500 TInt r=aDes.Length();
1507 TUint8 *pR=aDes.WPtr();
1521 #ifndef __DES8_MACHINE_CODED__
1522 EXPORT_C void TDes8::Fill(TChar aChar)
1524 Fills the descriptor's data area with the specified character, replacing any
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.
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.
1535 memset(WPtr(), (TInt)(aChar.operator TUint()), Length());
1539 EXPORT_C void TDes8::Fill(TChar aChar,TInt aLength)
1541 Fills the descriptor's data area with the specified character, replacing any
1544 The descriptor is filled with the specified number of characters.
1545 and its length is changed to reflect this.
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.
1552 @panic USER 23 if aLength is negative or is greater than the maximum length
1558 memset(WPtr(), (TInt)(aChar.operator TUint()), aLength);
1561 #ifndef __KERNEL_MODE__
1562 EXPORT_C void TDes8::AppendFill(TChar aChar,TInt aLength)
1564 Appends and fills this descriptor with the specified character.
1566 The descriptor is appended with the specified number of characters.
1567 and its length is changed to reflect this.
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.
1573 @panic USER 23 if aLength is negative, or the resulting length of this
1574 descriptor is greater than its maximum length.
1579 SetLength(len+aLength);
1580 memset(WPtr()+len, (TInt)(aChar.operator TUint()), aLength);
1584 #ifndef __DES8_MACHINE_CODED__
1585 #ifndef __KERNEL_MODE__
1586 EXPORT_C void TDes8::ZeroTerminate()
1588 Appends a zero terminator onto the end of this descriptor's data.
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
1595 @panic USER 23 if the descriptor's length is not strictly less than its
1601 __ASSERT_ALWAYS(len<MaxLength(),Panic(ETDes8Overflow));
1605 EXPORT_C const TUint8 *TDes8::PtrZ()
1607 Appends a zero terminator onto the end of this descriptor's data and returns
1608 a pointer to the data.
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
1615 @return A pointer to the descriptor's zero terminated data.
1617 @panic USER 23 if the descriptor's length is not strictly less than its
1627 EXPORT_C void TDes8::Zero()
1629 Sets the length of the data to zero.
1636 EXPORT_C void TDes8::FillZ()
1638 Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any
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.
1646 memclr(WPtr(), Length());
1650 EXPORT_C void TDes8::FillZ(TInt aLength)
1652 Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any
1653 existing data, and changes its length.
1655 The descriptor is filled with the specified number of binary zeroes.
1656 The descriptor's length is changed to reflect this.
1658 @param aLength The new length of the descriptor and the number of binary zeroes
1659 to be copied into it.
1661 @panic USER 23 if aLength is negative, or is greater than the maximum length
1667 memclr(WPtr(), aLength);
1670 #ifndef __KERNEL_MODE__
1671 EXPORT_C void TDes8::Fold()
1673 Performs folding on the content of this descriptor.
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
1684 const TUint8* table=__FoldCollTab8;
1692 EXPORT_C void TDes8::Collate()
1694 Performs collation on the content of this descriptor.
1703 TChar c=User::Collate(*pB);
1708 EXPORT_C void TDes8::LowerCase()
1710 Converts the content of this descriptor to lower case.
1712 Conversion is implemented as appropriate to the current locale.
1725 EXPORT_C void TDes8::UpperCase()
1727 Converts the content of this descriptor to upper case.
1729 Conversion is implemented as appropriate to the current locale.
1742 EXPORT_C void TDes8::Capitalize()
1744 Capitalises the content of this descriptor.
1746 Capitalisation is implemented as appropriate to the current locale.
1754 *pB=(TUint8)User::TitleCase(*pB);
1758 *pB=(TUint8)User::LowerCase(*pB);
1764 EXPORT_C void TDes8::CopyF(const TDesC8 &aDes)
1766 Copies and folds data from the specified descriptor into this descriptor
1767 replacing any existing data.
1769 The length of this descriptor is set to reflect the new
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
1777 @param aDes An 8-bit non-modifiable descriptor.
1779 @panic USER 23 if the length of aDes is greater than the maximum length of
1780 this target descriptor.
1784 TInt len=aDes.Length();
1786 const TUint8 *pS=aDes.Ptr();
1788 const TUint8* table=__FoldCollTab8;
1795 EXPORT_C void TDes8::CopyC(const TDesC8 &aDes)
1797 Copies and collates data from the specified descriptor
1798 into this descriptor replacing any existing data.
1800 The length of this descriptor is set to reflect the new data.
1802 @param aDes An 8 bit non-modifiable descriptor.
1804 @panic USER 23 if the length of aDes is greater than the maximum length of
1805 this target descriptor.
1810 TInt len=aDes.Length();
1812 const TUint8 *pS=aDes.Ptr();
1816 TChar c=User::Collate(*pS++);
1821 EXPORT_C void TDes8::CopyLC(const TDesC8 &aDes)
1823 Copies text from the specified descriptor and converts it to lower case before
1824 putting it into this descriptor, replacing any existing data.
1826 The length of this descriptor is set to reflect the new data.
1828 Conversion to lower case is implemented as appropriate to the current locale.
1830 @param aDes An 8-bit non-modifiable descriptor.
1832 @panic USER 23 if the length of aDes is greater than the maximum length of
1833 this target descriptor.
1837 TInt len=aDes.Length();
1839 const TUint8 *pS=aDes.Ptr();
1848 EXPORT_C void TDes8::CopyUC(const TDesC8 &aDes)
1850 Copies text from the specified descriptor and converts it to upper case before
1851 putting it into this descriptor, replacing any existing data.
1853 The length of this descriptor is set to reflect the new data.
1855 Conversion to upper case is implemented as appropriate to the current locale.
1857 @param aDes An 8-bit non-modifiable descriptor.
1859 @panic USER 23 if the length of aDes is greater than the maximum length of
1860 this target descriptor.
1864 TInt len=aDes.Length();
1866 const TUint8 *pS=aDes.Ptr();
1875 EXPORT_C void TDes8::CopyCP(const TDesC8 &aDes)
1877 Copies text from the specified descriptor and capitalises it before putting
1878 it into this descriptor, replacing any existing data.
1880 The length of this descriptor is set to reflect the new data.
1882 Capitalisation is implemented as appropriate to the current locale.
1884 @param aDes An 8-bit non-modifiable descriptor.
1886 @panic USER 23 if the length of aDes is greater than the maximum length of
1887 this target descriptor.
1891 TInt len=aDes.Length();
1893 const TUint8 *pS=aDes.Ptr();
1912 EXPORT_C void TDes8::Repeat(const TUint8 *aBuf,TInt aLength)
1914 Copies data with repetition into this descriptor, from a memory location
1915 specified by pointer, replacing any existing data.
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.
1921 @param aBuf A pointer to data to be repeatedly copied.
1922 @param aLength The length of data to be copied.
1924 @panic USER 29 if aLength is negative.
1928 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
1935 TInt i=Min(len,aLength);
1936 pB=memCopy(pB,aBuf,i);
1942 EXPORT_C void TDes8::Repeat(const TDesC8 &aDes)
1944 Copies data with repetition into this descriptor, from another descriptor,
1945 replacing any existing data.
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.
1951 @param aDes An 8-bit non-modifiable descriptor whose data is to be repeatedly
1956 Repeat(aDes.Ptr(),aDes.Length());
1959 EXPORT_C void TDes8::Trim()
1961 Deletes leading and trailing whitespace characters from the descriptor's data.
1963 The length of the descriptor is reduced to reflect the loss of the whitespace characters.
1965 @see TDes8::TrimLeft()
1966 @see TDes8::TrimRight()
1974 EXPORT_C void TDes8::TrimAll()
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
1980 The length of the descriptor is reduced to reflect the loss of the whitespace
1989 TUint8 *pBuf=(TUint8 *)Ptr();
2015 Delete(pDst-pBuf, pSrc-pDst);
2018 EXPORT_C void TDes8::TrimLeft()
2020 Deletes leading whitespace characters from the descriptor's data.
2022 All whitespace characters up to, but not including the first non-whitespace
2023 character, are deleted.
2025 The length of the descriptor is reduced to reflect the loss of the
2026 whitespace characters.
2030 const TUint8 *pBuf=Ptr();
2031 const TUint8 *pB=pBuf;
2043 EXPORT_C void TDes8::TrimRight()
2045 Deletes trailing whitespace characters from the descriptor's data.
2047 The process starts on the right hand side of the descriptor's data
2048 and proceeds to the left.
2050 All whitespace characters up to, but not including the first non-whitespace character,
2053 The length of the descriptor is reduced to reflect the loss of the whitespace
2061 const TUint8 *pB=Ptr()+len-1;
2073 EXPORT_C void TDes8::Insert(TInt aPos,const TDesC8 &aDes)
2075 Inserts data into this descriptor.
2077 The length of this descriptor is changed to reflect the extra data.
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
2083 @param aDes An 8 bit non modifiable descriptor whose data is to be inserted.
2085 @panic USER 22 if aPos is negative or is greater than the length of this
2087 @panic USER 23 if the resulting length of this descriptor is greater than its
2093 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
2094 TInt s=aDes.Length();
2095 __ASSERT_ALWAYS((len+s)<=MaxLength(),Panic(ETDes8Overflow));
2097 memmove(pB+aPos+s,pB+aPos,len-aPos);
2098 memmove(pB+aPos,aDes.Ptr(),aDes.Length());
2102 EXPORT_C void TDes8::Delete(TInt aPos,TInt aLength)
2104 Deletes data from this descriptor.
2106 The length of this descriptor is changed to reflect the loss of data.
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
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.
2116 @panic USER 22 if aPos is negative or is greater than the length of this
2122 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
2123 TInt d=Min(len-aPos,aLength);
2125 memmove(pB+aPos,pB+aPos+d,len-aPos-d);
2129 EXPORT_C void TDes8::Replace(TInt aPos,TInt aLength,const TDesC8 &aDes)
2131 Replaces data in this descriptor.
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.
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
2140 @param aLength The length of data to be replaced.
2142 @param aDes The source 8-bit non-modifiable descriptor whose data is to
2143 replace the target descriptor's data at aPos.
2145 @panic USER 20 if aLength is negative or the sum of aLength and aPos is
2146 greater than the length of this descriptor.
2148 @panic USER 22 if aPos is negative or is greater than the length of this
2151 @panic USER 23 if the resulting length of this descriptor is greater than its
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,
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));
2167 memmove(pB+aPos+s,pB+aPos+aLength,len-aPos-aLength);
2168 memmove(pB+aPos,aDes.Ptr(),s);
2169 SetLength(len+s-aLength);
2172 EXPORT_C void TDes8::Justify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
2174 Copies data into this descriptor and justifies it, replacing any existing data.
2176 The length of this descriptor is set to reflect the new data.
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
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.
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).
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.
2196 @param anAlignment The alignment of the data within the target area
2198 @param aFill The fill character used to pad the target area.
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.
2207 AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
2210 EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
2212 Appends data onto the end of this descriptor's data and justifies it.
2214 The source of the appended data is an existing descriptor.
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.
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.
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).
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.
2233 @param anAlignment The alignment of the data within the target area.
2235 @param aFill The fill character used to pad the target area.
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.
2243 AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
2246 EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
2248 Appends data onto the end of this descriptor's data and justifies it.
2250 The source of the appended data is an existing descriptor.
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.
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.
2259 @param aDes An 8-bit non-modifiable descriptor containing the source data.
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.
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.
2272 @param anAlignment The alignment of the data within the target area.
2274 @param aFill The fill character used to pad the target area.
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.
2282 AppendJustify(aDes.Ptr(),aLength,aWidth,anAlignment,aFill);
2285 EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aWidth,TAlign anAlignment,TChar aFill)
2287 Appends a zero terminated string onto the end of this descriptor's data and
2290 The zero terminator is not copied.
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.
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.
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).
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).
2310 @param anAlignment The alignment of the data within the target area.
2312 @param aFill The fill character used to pad the target area.
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.
2320 AppendJustify(aString,STRING_LENGTH(aString),aWidth,anAlignment,aFill);
2323 EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
2325 Appends data onto the end of this descriptor's data and justifies it.
2327 The source of the appended data is a memory location.
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.
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.
2336 @param aString A pointer to a source memory location.
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.
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.
2346 @param anAlignment The alignment of the data within the target area.
2348 @param aFill The fill character used to pad the target area.
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.
2354 @panic USER 29 if aLength is negative.
2358 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
2359 if (aWidth==KDefaultJustifyWidth)
2363 TInt offset=Length();
2364 AppendFill(aFill,aWidth);
2365 TInt r=aWidth-aLength;
2366 if (anAlignment==ECenter)
2368 else if (anAlignment==ELeft)
2370 memmove(WPtr()+offset+r,aString,aLength);
2372 #endif // __KERNEL_MODE__
2374 EXPORT_C void TDes8::Num(TInt64 aVal)
2376 // Convert a TInt64 to the descriptor.
2379 Converts the 64-bit signed integer into a decimal character representation
2380 and copies the conversion into this descriptor, replacing any existing data.
2382 The length of this descriptor is set to reflect the new data.
2384 If the integer is negative, the character representation is prefixed by a
2387 @param aVal The 64-bit signed integer value.
2394 EXPORT_C void TDes8::Num(TUint64 aVal, TRadix aRadix)
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.
2400 The length of this descriptor is set to reflect the new data.
2402 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2410 AppendNum(aVal, aRadix);
2413 EXPORT_C void TDes8::NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
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.
2419 The length of this descriptor is set to reflect the new data.
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.
2424 When a hexadecimal conversion is specified, hexadecimal characters are in
2427 This function is equivalent to using Format() with parameters which specify:
2429 1. a fixed length target field
2431 2. padding with zero characters, for example "%08x".
2433 When this is the case, always use NumFixedWidth() in preference
2434 to Format() as it is more efficient.
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.
2441 @see TDes8::Format()
2446 AppendNumFixedWidth(aVal,aRadix,aWidth);
2449 #ifndef __KERNEL_MODE__
2450 EXPORT_C void TDes8::NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
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.
2456 The length of this descriptor is set to reflect the new data.
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
2462 When a hexadecimal conversion is specified, hexadecimal characters are in
2465 This function is equivalent to using Format() with parameters which specify:
2467 1. a fixed length target field
2469 2. padding with zero characters, for example "%08x".
2471 When this is the case, always use NumFixedWidthUC() in
2472 preference to Format() as it is more efficient.
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.
2479 @see TDes8::Format()
2484 AppendNumFixedWidthUC(aVal,aRadix,aWidth);
2487 EXPORT_C void TDes8::NumUC(TUint64 aVal, TRadix aRadix) //NOT __KERNEL_MODE__
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.
2493 The length of this descriptor is set to reflect the new data.
2495 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2504 AppendNumUC(aVal,aRadix);
2506 #endif // __KERNEL_MODE__
2508 EXPORT_C void TDes8::AppendNum(TInt64 aVal)
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.
2513 The length of this descriptor is incremented to reflect the new content.
2515 If the integer is negative, the character representation is prefixed by a
2518 @param aVal The 64-bit signed integer value.
2527 AppendNum(aVal, EDecimal);
2530 #ifndef __DES_MACHINE_CODED__
2531 GLDEF_C TInt __DoConvertNum(TUint aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
2533 __KERNEL_CHECK_RADIX(aRadix);
2534 TUint radix = (TUint)aRadix;
2536 TBool out16 = (aA>255);
2539 TUint q = aVal/radix;
2540 TUint c = aVal-q*radix;
2541 (c>9) ? c+=(aA-10) : c+='0';
2552 GLDEF_C TInt __DoConvertNum(TUint64 aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
2554 __KERNEL_CHECK_RADIX(aRadix);
2555 TUint radix = (TUint)aRadix;
2557 TBool out16 = (aA>255);
2558 TUint8 a = static_cast<TUint8>(aA);
2559 while (aVal >= UI64LIT(0x100000000))
2561 TUint8 c = static_cast<TUint8>(aVal % radix);
2563 (c > 9) ? c = static_cast<TUint8>(c + a - 10) : c = static_cast<TUint8>(c + '0');
2570 return l + __DoConvertNum((TUint)aVal, aRadix, aA, aDest);
2574 void TDes8::DoPadAppendNum(TInt l, TInt aW, const TUint8* p)
2583 TUint8* d = WPtr() + l0;
2584 for (; aW>l; --aW) *d++ = (TUint8)'0';
2588 void TDes8::DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW)
2590 // Convert a TUint64 into the descriptor.
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);
2600 EXPORT_C void TDes8::AppendNum(TUint64 aVal, TRadix aRadix)
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
2607 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2614 DoAppendNum(aVal, aRadix, 'a', 0);
2617 EXPORT_C void TDes8::AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
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.
2623 The length of this descriptor is incremented to reflect the new content.
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
2629 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2638 DoAppendNum(aVal, aRadix, 'a', aWidth);
2641 #if (!defined(__DES8_MACHINE_CODED__) && !defined(__KERNEL_MODE__))
2642 EXPORT_C TPtr8 TDes8::LeftTPtr(TInt aLength) const
2644 Extracts the leftmost part of the data.
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.
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.
2653 @return The 8-bit modifiable pointer descriptor representing the leftmost
2656 @panic USER 22 if aLength is negative.
2660 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
2661 TInt len=Min(aLength,Length());
2662 return(TPtr8((TUint8*)Ptr(),len,len));
2665 EXPORT_C TPtr8 TDes8::RightTPtr(TInt aLength) const
2667 Extracts the rightmost part of the data.
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.
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.
2676 @return The 8 bit modifiable pointer descriptor representing the rightmost
2679 @panic USER 22 if aLength is negative.
2683 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
2687 return(TPtr8((TUint8*)Ptr()+len-aLength,aLength,aLength));
2690 EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos) const
2692 Extracts a portion of the data.
2694 The function does not cut or remove any data but constructs a modifiable
2695 pointer descriptor to represent the defined portion.
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.
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.
2703 @return The 8-bit modifiable pointer descriptor representing the specified
2704 portion of the data.
2706 @panic USER 22 if aPos is negative or aPos is greater than the
2707 length of the descriptor.
2712 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
2713 return(TPtr8((TUint8*)Ptr()+aPos,len-aPos,len-aPos));
2716 EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos,TInt aLength) const
2718 Extracts a portion of the data.
2720 The function does not cut or remove any data but constructs a modifiable
2721 pointer descriptor to represent the defined portion.
2723 The portion is identified by its starting position and by its length.
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.
2729 @return The 8 bit modifiable pointer descriptor representing the specified
2730 portion of the data.
2732 @panic USER 22 if aPos is negative or aPos plus aLength is greater than the
2733 length of the descriptor.
2737 __ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
2738 return(TPtr8((TUint8*)Ptr()+aPos,aLength,aLength));
2742 #ifndef __KERNEL_MODE__
2743 EXPORT_C void TDes8::AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
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.
2749 The length of this descriptor is incremented to reflect the new content.
2751 The function generates the exact number of specified characters, either
2752 padding to the left with character zeroes or discarding low order characters
2755 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2764 DoAppendNum(aVal, aRadix, 'A', aWidth);
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.
2772 The length of this descriptor is incremented to reflect the new content.
2774 When a hexadecimal conversion is specified, hexadecimal characters are in
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.
2782 DoAppendNum(aVal, aRadix, 'A', 0);
2785 EXPORT_C void TDes8::Format(TRefByValue<const TDesC8> aFmt,...)
2787 Formats and copies text into this descriptor, replacing any existing data.
2789 The length of this descriptor is set to reflect the new data.
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.
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
2800 The resulting stream of literal text and converted arguments is copied into
2803 The syntax of the embedded directives follows one of four general patterns.
2805 Note that formatting of single numerical values can be achieved more
2806 conveniently using the Num() and NumUC() member functions of this class.
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:
2814 Using User Library (E32)
2817 How to Use Descriptors
2818 Format string syntax
2821 @param aFmt The descriptor containing the format string.
2822 The TRefByValue class provides a constructor which takes a
2825 @param ... A variable number of arguments to be converted to text as
2826 dictated by the format string.
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.
2838 VA_START(list,aFmt);
2839 // coverity[uninit_use_in_call]
2840 FormatList(aFmt,list);
2843 EXPORT_C void TDes8::FormatList(const TDesC8 &aFmt,VA_LIST aList)
2845 Formats and copies text into this descriptor, replacing any existing data.
2847 The length of this descriptor is set to reflect the new data.
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.
2853 @param aFmt The descriptor containing the format string.
2854 @param aList A pointer to an argument list.
2856 @see TDes8::Format()
2862 AppendFormatList(aFmt,aList);
2865 EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,TDes8Overflow *aOverflowHandler,...)
2867 Formats and appends text onto the end of this descriptor's data.
2869 The length of this descriptor is incremented to reflect the new content.
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.
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.
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,
2884 1. calls the Overflow() member function of the overflow handler, if an overflow
2886 2 raises a USER 23 panic, if no overflow handler is supplied.
2888 As much literal text as possible will have been copied into this descriptor
2889 and this descriptor will have reached its maximum length.
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:
2895 1. calls the Overflow() member function of the overflow handler, if an overflow
2898 2 raises a USER 23 panic, if no overflow handler is supplied.
2900 None of the generated text is appended and length of this descriptor
2901 may be less than the maximum.
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.
2907 @param aOverflowHandler A pointer to the overflow handler.
2909 @param ... A variable number of arguments to be converted to text
2910 as dictated by the format string.
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.
2916 @see TDes8::Format()
2917 @see TDes8Overflow::Overflow()
2922 VA_START(list, aOverflowHandler);
2923 // coverity[uninit_use_in_call]
2924 AppendFormatList(aFmt,list,aOverflowHandler);
2927 EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,...)
2929 Formats and appends text onto the end of this descriptor's data.
2931 The length of this descriptor is incremented to reflect the new content.
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.
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.
2942 Literal text is appended on a character by character basis.
2944 Text converted from a trailing argument is appended as a complete string.
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.
2950 @param ... A variable number of arguments to be converted to text
2951 as dictated by the format string.
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.
2958 @see TDes8::Format()
2963 VA_START(list,aFmt);
2964 AppendFormatList(aFmt,list);
2966 #endif // __KERNEL_MODE__
2968 #if !defined(__DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
2969 EXPORT_C TPtrC8::TPtrC8()
2970 : TDesC8(EPtrC,0),iPtr(0)
2972 Default constructor.
2974 Constructs an empty 8-bit non-modifiable pointer descriptor.
2976 It represents no data and its length is zero.
2978 The non-modifiable pointer descriptor can, subsequently, be set to represent
2985 EXPORT_C TPtrC8::TPtrC8(const TDesC8 &aDes)
2986 : TDesC8(EPtrC,aDes.Length()),iPtr(aDes.Ptr())
2988 Constructs the 8-bit non-modifiable pointer descriptor from any existing
2991 It is set to point to the same data and is given the same length as the source
2994 @param aDes A reference to an 8bit non-modifiable descriptor.
2998 EXPORT_C TPtrC8::TPtrC8(const TUint8 *aString)
2999 : TDesC8(EPtrC,STRING_LENGTH(aString)),iPtr(aString)
3001 Constructs the 8-bit non-modifiable pointer descriptor to point to a zero
3002 terminated string, whether in RAM or ROM.
3004 The length of the descriptor is set to the length of the zero terminated
3005 string, excluding the zero terminator.
3007 @param aString A pointer to a zero terminated string.
3011 EXPORT_C TPtrC8::TPtrC8(const TUint8 *aBuf,TInt aLength)
3012 : TDesC8(EPtrC,aLength),iPtr(aBuf)
3014 Constructs the 8-bit non-modifiable pointer descriptor to point to the
3015 specified location in memory, whether in RAM or ROM.
3017 The length of the descriptor is set to the specified length.
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.
3022 @panic USER 29 if aLength is negative.
3025 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
3028 EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aMaxLength)
3029 : TDes8(EPtr,0,aMaxLength),iPtr(aBuf)
3031 Constructs the 8-bit modifiable pointer descriptor to point to the specified
3032 location in memory, whether in RAM or ROM.
3034 The length of the descriptor is set to zero and its maximum length is set
3035 to the specified value.
3037 @param aBuf A pointer to the location that the descriptor is to
3040 @param aMaxLength The maximum length of the descriptor.
3042 @panic USER 30 if aMaxLength is negative.
3045 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3048 EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aLength,TInt aMaxLength)
3049 : TDes8(EPtr,aLength,aMaxLength),iPtr(aBuf)
3051 Constructs the 8-bit modifiable pointer descriptor to point to the specified
3052 location in memory, whether in RAM or ROM.
3054 The length of the descriptor and its maximum length are set to the specified
3057 @param aBuf A pointer to the location that the descriptor is
3059 @param aLength The length of the descriptor.
3060 @param aMaxLength The maximum length of the descriptor.
3062 @panic USER 20 if aLength is negative, or is greater than the descriptor's
3064 @panic USER 30 if aMaxLength is negative.
3067 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3068 __ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
3071 EXPORT_C TPtr8::TPtr8(TBufCBase8 &aLcb,TInt aMaxLength)
3072 : TDes8(EBufCPtr,aLcb.Length(),aMaxLength),iPtr((TUint8*)&aLcb)
3074 __ASSERT_DEBUG(aLcb.Length()<=aMaxLength,Panic(ETDes8LengthOutOfRange));
3077 EXPORT_C TBufBase8::TBufBase8(TInt aMaxLength)
3078 :TDes8(EBuf,0,aMaxLength)
3080 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3083 EXPORT_C TBufBase8::TBufBase8(TInt aLength,TInt aMaxLength)
3084 :TDes8(EBuf,aLength,aMaxLength)
3086 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3087 __ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
3090 EXPORT_C TBufBase8::TBufBase8(const TUint8* aString,TInt aMaxLength)
3091 :TDes8(EBuf,0,aMaxLength)
3093 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3097 EXPORT_C TBufBase8::TBufBase8(const TDesC8& aDes,TInt aMaxLength)
3098 :TDes8(EBuf,0,aMaxLength)
3100 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
3106 // Truncate literal string to fit into descriptor
3107 EXPORT_C void TDes8IgnoreOverflow::Overflow(TDes8& /*aDes*/)
3110 #ifndef __KERNEL_MODE__
3111 EXPORT_C void TDesC8::__DbgTestInvariant() const
3113 // Test that the class obeys its invariant.
3132 EXPORT_C void TPtrC8::__DbgTestInvariant() const
3134 // Test that the class obeys its invariant.
3139 TDesC8::__DbgTestInvariant(); // Test base class
3145 EXPORT_C void TDes8::__DbgTestInvariant() const
3147 // Test that the class obeys its invariant.
3152 TDesC8::__DbgTestInvariant(); // Test base class
3153 if (Length()>MaxLength() || !(Type()==EPtr || Type()==EBufCPtr || Type()==EBuf))
3158 EXPORT_C void HBufC8::__DbgTestInvariant() const
3160 // Test that the class obeys its invariant.
3165 TDesC8::__DbgTestInvariant(); // Test base class
3166 if (Length()>(TInt)(User::AllocLen(this)-sizeof(TDesC8)) || Type()!=EBufC)
3171 EXPORT_C void TPtr8::__DbgTestInvariant() const
3173 // Test that the class obeys its invariant.
3178 TDes8::__DbgTestInvariant(); // Test base class
3179 if (!(Type()==EPtr || Type()==EBufCPtr))
3184 /** Expand all characters from 8 to 16 bits
3186 @return 16-bit pointer descriptor to transformed text
3188 The length of descriptor increased by 2 (length *= 2).
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
3193 EXPORT_C TPtr16 TDes8::Expand()
3196 TInt ml = MaxLength();
3197 const TText8* s0 = Ptr();
3198 const TText8* s = s0 + l;
3199 __ASSERT_ALWAYS( !((ml|(TInt)s0)&1), Panic(EDes8ExpandOdd) );
3201 TText16* d = ((TText16*)s0) + l;
3204 return TPtr16(d, l, ml>>1);
3208 /** Collapse all characters from 16 to 8 bits
3210 The length of descriptor truncated by 2 (length /= 2).
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.
3216 EXPORT_C void TDes8::Collapse()
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);
3225 *d++ = (TText8)*s++;
3228 #else // __KERNEL_MODE__
3230 EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
3232 Compares this descriptor's folded data with the specified descriptor's folded
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.
3240 @param aDes The 8-bit non modifable descriptor whose data is to be compared
3241 with this descriptor's data.
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
3248 @see TDesC8::Compare()
3253 TInt rl = aDes.Length();
3254 TInt r = memicmp(Ptr(), aDes.Ptr(), Min(ll, rl));
3260 #endif // __KERNEL_MODE__
3262 #ifndef __KERNEL_MODE__
3265 Default constructor.
3267 Constructs a zero-length 8-bit resizable buffer descriptor.
3269 Note that the object owns no allocated memory.
3271 EXPORT_C RBuf8::RBuf8()
3272 :TDes8(EPtr,0,0),iEPtrType(NULL)
3274 // Zero-length RBuf8 is of type EPtr with NULL pointer.
3283 Constructs an 8-bit resizable buffer descriptor, transferring ownership of the
3284 specified heap descriptor to this object.
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
3291 EXPORT_C RBuf8::RBuf8(HBufC8* aHBuf)
3294 //Create EBufCPtr type descriptor that points to aHBuf
3295 new(this) TPtr8(aHBuf->Des());
3297 //Create zero-length RBuf8. It is EPtr type of descriptor that points to NULL.
3305 Protected constructor.
3307 EXPORT_C RBuf8::RBuf8(TInt aType,TInt aLength,TInt aMaxLength)
3308 :TDes8(aType,aLength,aMaxLength)
3316 Transfers ownership of the specified 8-bit resizable buffer descriptor's
3317 buffer to this object.
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
3325 @param aRBuf The source 8-bit resizable buffer. The ownership of this
3326 object's buffer is to be transferred.
3330 EXPORT_C void RBuf8::Assign(const RBuf8& aRBuf)
3332 Mem::Copy(this, &aRBuf, sizeof(RBuf8));
3340 Assigns ownership of the specified allocated memory to this object.
3342 The allocated memory forms the buffer for this descriptor. The current length
3343 of the descriptor is set to zero.
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
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.
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.
3360 @see TDesC8::Length()
3361 @see TDes8::MaxLength()
3364 EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aMaxLength)
3366 Assign(aHeapCell,0,aMaxLength);
3373 Assigns ownership of the specified allocated memory to this object.
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.
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
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.
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.
3393 @see TDesC8::Length()
3394 @see TDes8::MaxLength()
3397 EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aLength,TInt aMaxLength)
3399 __ASSERT_ALWAYS(aLength<=aMaxLength, Panic(ETDes8LengthOutOfRange));
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);
3408 __ASSERT_ALWAYS(aMaxLength == 0, Panic(ETDes8LengthOutOfRange));
3409 //Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
3419 Transfers ownership of the specified heap descriptor to this object.
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
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.
3432 EXPORT_C void RBuf8::Assign(HBufC8* aHBuf)
3434 new(this) RBuf8(aHBuf);
3441 Swaps the content of two 8-bit resizable buffer descriptors.
3443 @param aRBuf The 8-bit resizable buffer descriptor whose contents are to be
3444 swapped with this one.
3446 EXPORT_C void RBuf8::Swap(RBuf8& aRBuf)
3448 Mem::Swap(this,&aRBuf,sizeof(*this));
3455 Creates an 8-bit resizable buffer descriptor.
3457 The function allocates sufficient memory to contain descriptor data up to
3458 the specified maximum length.
3460 The current length of the descriptor is set to zero. The maximum length of
3461 the descriptor is set to the specified value.
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
3469 @param aMaxLength The maximum length of the descriptor.
3471 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3473 @see TDesC8::Length()
3474 @see TDes8::MaxLength()
3477 EXPORT_C TInt RBuf8::Create(TInt aMaxLength)
3482 TUint8* buf=(TUint8*)User::Alloc(aMaxLength*sizeof(TUint8));
3483 if(!buf) return KErrNoMemory;
3487 iEPtrType = NULL; //Zero-length descriptor.
3490 //Create EPtr type descriptor.
3491 new(this) RBuf8(EPtr,0,aMaxLength);
3500 Creates an 8-bit resizable buffer descriptor, and leaves on failure.
3502 The function allocates sufficient memory to contain descriptor data up to
3503 the specified maximum length.
3505 The current length of the descriptor is set to zero. The maximum length of
3506 the descriptor is set to the specified value.
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
3514 @param aMaxLength The length and the maximum length of the descriptor.
3516 @leave KErrNoMemory If there is insufficient memory.
3518 @see TDesC8::Length()
3519 @see TDes8::MaxLength()
3522 EXPORT_C void RBuf8::CreateL(TInt aMaxLength)
3524 User::LeaveIfError(Create(aMaxLength));
3531 Creates an 8-bit resizable buffer descriptor.
3533 The function allocates sufficient memory to contain descriptor data up to
3534 the specified maximum length.
3536 Both the current length and the maximum length of the descriptor are set to
3537 the specified value.
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
3545 @param aMaxLength The length and the maximum length of the descriptor.
3547 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3551 EXPORT_C TInt RBuf8::CreateMax(TInt aMaxLength)
3553 TInt err=Create(aMaxLength);
3563 Creates an 8-bit resizable buffer descriptor, and leaves on failure.
3565 The function allocates sufficient memory to contain descriptor data up to
3566 the specified maximum length.
3568 Both the current length and the maximum length of the descriptor are set to
3569 the specified value.
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
3577 @param aMaxLength The length and the maximum length of the descriptor.
3579 @leave KErrNoMemory If there is insufficient memory.
3581 @see TDesC8::Length()
3582 @see TDes8::MaxLength()
3585 EXPORT_C void RBuf8::CreateMaxL(TInt aMaxLength)
3587 User::LeaveIfError(CreateMax(aMaxLength));
3594 Creates a 8-bit resizable buffer descriptor to contain a copy of the
3595 specified (source) descriptor.
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.
3602 The data contained in the source descriptor is copied into this
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.
3611 @param aDes Source descriptor to be copied into this object.
3613 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3615 @see TDesC8::Length()
3616 @see TDes8::MaxLength()
3620 EXPORT_C TInt RBuf8::Create(const TDesC8& aDes)
3622 return Create(aDes,aDes.Length());
3629 Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
3630 (source) descriptor, and leaves on failure.
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.
3637 The data contained in the source descriptor is copied into this descriptor.
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.
3645 @param aDes Source descriptor to be copied into this object.
3647 @leave KErrNoMemory If there is insufficient memory.
3649 @see TDesC8::Length()
3650 @see TDes8::MaxLength()
3654 EXPORT_C void RBuf8::CreateL(const TDesC8& aDes)
3656 CreateL(aDes,aDes.Length());
3663 Creates an 8-bit resizable buffer descriptor to contain a copy of the
3664 specified (source) descriptor.
3666 The function allocates sufficient memory so that this descriptor's maximum length
3667 is the same as the value of the aMaxLength parameter.
3669 The data contained in the source descriptor is copied into this descriptor.
3670 The length of data copied is either
3672 - the length of the source descriptor aDes
3676 - the value of the aMaxLength parameter
3678 whichever is the smaller value. The current length of this descriptor is also
3679 set to the smaller value.
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
3687 @param aDes Source descriptor to be copied into this object.
3689 @param aMaxLength The maximum length of this descriptor.
3691 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3693 @see TDesC8::Length()
3694 @see TDes8::MaxLength()
3698 EXPORT_C TInt RBuf8::Create(const TDesC8& aDes,TInt aMaxLength)
3700 TInt err=Create(aMaxLength);
3702 Copy(aDes.Left(aMaxLength));
3710 Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
3711 (source) descriptor, and leaves on failure.
3713 The function allocates sufficient memory so that this descriptor's maximum
3714 length is the same as the value of the aMaxLength parameter.
3716 The data contained in the source descriptor is copied into this descriptor.
3717 The length of data copied is either
3719 - the length of the source descriptor aDes
3723 - the value of the aMaxLength parameter
3725 whichever is the smaller value. The current length of this descriptor is also
3726 set to the smaller value.
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
3734 @param aDes Source descriptor to be copied into this object.
3736 @param aMaxLength The maximum length of this descriptor.
3738 @leave KErrNoMemory If there is insufficient memory.
3740 @see TDesC8::Length()
3741 @see TDes8::MaxLength()
3745 EXPORT_C void RBuf8::CreateL(const TDesC8& aDes,TInt aMaxLength)
3747 CreateL(aMaxLength);
3748 Copy(aDes.Left(aMaxLength));
3755 Resizes this 8-bit resizable buffer descriptor.
3757 The length and contents of the descriptor are unchanged.
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
3767 if (desc.MaxLength() == 0) desc.Close();
3769 before the call to ReAlloc().
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
3775 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3777 @panic USER 26 If the new maximum length is less then the current descriptor length.
3779 EXPORT_C TInt RBuf8::ReAlloc(TInt aMaxLength)
3781 __ASSERT_ALWAYS(Length()<=aMaxLength, Panic(ETDes8ReAllocTooSmall));
3784 if (!aMaxLength) //Reallocation to zero length
3786 User::Free(iEPtrType); //Free memory
3787 new (this) RBuf8(); //Create zero-length RBuf
3791 if (!iMaxLength) //Reallocation from zero length
3792 return Create(aMaxLength);
3798 TUint8* buf = (TUint8*)User::ReAlloc(iEPtrType,aMaxLength*sizeof(TUint8));
3799 if(!buf) return KErrNoMemory;
3801 iMaxLength = aMaxLength;
3806 HBufC8* hbufc = iEBufCPtrType->ReAlloc(aMaxLength);
3807 if(!hbufc) return KErrNoMemory;
3821 Resizes this 8-bit resizable buffer descriptor, leaving on failure.
3823 The length and contents of the descriptor are unchanged.
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
3833 if (desc.MaxLength() == 0) desc.Close();
3835 before the call to ReAlloc().
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
3841 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3843 @panic USER 26 If the new maximum length is less then the current descriptor length.
3845 EXPORT_C void RBuf8::ReAllocL(TInt aMaxLength)
3847 User::LeaveIfError(ReAlloc(aMaxLength));
3854 Deallocates memory assigned to this object, and re-initializes the object as
3855 a zero-length descriptor.
3857 EXPORT_C void RBuf8::Close()
3859 User::Free(iEPtrType);
3860 //Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
3868 Pushes a cleanup item for this object onto the cleanup stack.
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.
3877 x.CleanupClosePushL();
3879 CleanupStack::PopAndDestroy();
3885 EXPORT_C void RBuf8::CleanupClosePushL()
3887 ::CleanupClosePushL(*this);
3894 Tests that the class obeys its invariant.
3896 EXPORT_C void RBuf8::__DbgTestInvariant() const
3899 TDes8::__DbgTestInvariant();
3905 __ASSERT_DEBUG(User::AllocLen(iEPtrType) >= iMaxLength*(TInt)sizeof(TUint8), Panic(EInvariantFalse));
3909 iEBufCPtrType->__DbgTestInvariant();
3910 __ASSERT_DEBUG(iEBufCPtrType->Des().MaxLength() == iMaxLength, Panic(EInvariantFalse));
3911 __ASSERT_DEBUG(iEBufCPtrType->Length() == Length(), Panic(EInvariantFalse));
3919 #endif // __KERNEL_MODE__
3922 #if defined(__DES8_MACHINE_CODED__) || defined(__EABI__)
3923 GLDEF_C void Des8PanicBadDesType()
3925 Panic(ETDes8BadDescriptorType);
3928 GLDEF_C void Des8PanicPosOutOfRange()
3930 Panic(ETDes8PosOutOfRange);
3934 #ifdef __DES8_MACHINE_CODED__
3935 GLDEF_C void Des8PanicLengthNegative()
3937 Panic(ETDes8LengthNegative);
3940 GLDEF_C void Des8PanicMaxLengthNegative()
3942 Panic(ETDes8MaxLengthNegative);
3945 GLDEF_C void Des8PanicLengthOutOfRange()
3947 Panic(ETDes8LengthOutOfRange);
3950 GLDEF_C void Des8PanicDesOverflow()
3952 Panic(ETDes8Overflow);
3955 GLDEF_C void Des8PanicDesIndexOutOfRange()
3957 Panic(ETDes8IndexOutOfRange);