First public contribution.
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\des16.cpp
19 #include <e32des16_private.h>
23 #include "collateimp.h"
25 #include "CompareImp.h"
28 #define __CHECK_ALIGNMENT(p,c) __ASSERT_DEBUG(!(TUint(p)&1),Des16Panic(c))
32 ETDesC16ConstructCString=0,
33 ETDesC16ConstructBufLength=1,
34 ETDesC16ConstructBufLengthMax=2,
36 ETDesC16FindFPtrLen=4,
37 ETDesC16FindCPtrLen=5,
38 ETBufCBase16CopyStringMax=6,
39 EHBufC16AssignCString=7,
40 ETDes16AssignCString=8,
42 ETDes16CopyBufLength=10,
43 ETDes16AppendBufLength=11,
44 ETDes16RepeatBufLength=12,
45 ETDes16AppendJustify1=13,
46 ETDes16AppendJustify2=14,
47 ETPtrC16SetBufLength=15,
48 ETPtr16SetBufLengthMax=16,
54 _LIT(KLitDes16Align,"Des16Align");
55 void Des16Panic(TDes16Panic aPanic)
57 PANIC_CURRENT_THREAD(KLitDes16Align,aPanic);
61 inline TUint16* memCopy(TUint16* aPtr, const TUint16* aSrc, TInt aLength)
63 return (TUint16 *)Mem::Copy(aPtr,aSrc,aLength<<1);
66 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
67 inline TInt StringLength(const TUint16* aPtr)
69 const TUint16* p = aPtr;
76 inline TDesC16::TDesC16(TInt aType,TInt aLength)
77 :iLength(aLength|(aType<<KShiftDesType16))
79 inline TInt TDesC16::Type() const
81 // Return the descriptor type
84 return(iLength>>KShiftDesType16);
87 inline TDes16::TDes16(TInt aType,TInt aLength,TInt aMaxLength)
88 : TDesC16(aType,aLength),iMaxLength(aMaxLength)
92 inline TBufCBase16::TBufCBase16(TInt aLength)
93 :TDesC16(EBufC,aLength)
95 inline TUint16* TBufCBase16::WPtr() const
96 {return const_cast<TUint16*>(Ptr());}
98 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
99 EXPORT_C TPtr16::TPtr16(TBufCBase16& aLcb, TInt aMaxLength)
100 : TDes16(EBufCPtr,aLcb.Length(),aMaxLength),iPtr((TUint16*)&aLcb)
102 __ASSERT_DEBUG(aLcb.Length()<=aMaxLength,Panic(ETDes16LengthOutOfRange));
106 #if !defined( __DES16_MACHINE_CODED__)
108 Gets a pointer to the data represented by the descriptor.
110 The data cannot be changed through the returned pointer.
112 @return A pointer to the data
114 EXPORT_C const TUint16 *TDesC16::Ptr() const
117 const TUint16* p=NULL;
121 p=(&((SBufC16 *)this)->buf[0]); break;
123 p=(((SPtrC16 *)this)->ptr); break;
125 p=(((SPtr16 *)this)->ptr); break;
127 p=(&((SBuf16 *)this)->buf[0]); break;
129 p=(&((SBufCPtr16 *)this)->ptr->buf[0]); break;
131 Panic(ETDes16BadDescriptorType);
133 __CHECK_ALIGNMENT(p,ETDesC16Ptr);
137 EXPORT_C const TUint16 &TDesC16::AtC(TInt anIndex) const
139 // Return a reference to the character in the buffer.
143 __ASSERT_ALWAYS(anIndex>=0 && anIndex<Length(),Panic(ETDes16IndexOutOfRange));
144 return(Ptr()[anIndex]);
151 Compares this descriptor's data with the specified descriptor's data.
153 The comparison proceeds on a double-byte for double byte basis.
154 The result of the comparison is based on the difference of the first pair
155 of 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 16-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
170 EXPORT_C TInt TDesC16::Compare(const TDesC16 &aDes) const
172 return MEM_COMPARE_16(Ptr(),Length(),aDes.Ptr(),aDes.Length());
179 Compares this descriptor's folded data with the specified descriptor's folded
182 Note that folding is locale-independent behaviour. It is also important to
183 note that there can be no guarantee that folding is in any way culturally
184 appropriate, and should not be used for comparing strings in natural language;
185 use CompareC() for this.
187 @param aDes The 16-bit non-modifable descriptor whose data is to be compared
188 with this descriptor's data.
190 @return Positive, if this descriptor is greater than the specified descriptor.
191 Negative, if this descriptor is less than the specified descriptor.
192 Zero, if both descriptors have the same length and the their contents
195 @see TDesC16::Compare()
197 EXPORT_C TInt TDesC16::CompareF(const TDesC16 &aDes) const
200 return(Mem::CompareF(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
207 Compares this descriptor's data with the specified descriptor's data using
208 the standard collation method appropriate to the current locale.
210 @param aDes The 16-bit non-modifable descriptor whose data is to be compared
211 with this descriptor's data.
213 @return Positive, if this descriptor is greater than the specified descriptor.
214 Negative, if this descriptor is less than the specified descriptor.
215 Zero, if the content of both descriptors match.
217 @see TDesC16::Compare()
219 EXPORT_C TInt TDesC16::CompareC(const TDesC16 &aDes) const
222 return(Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
231 Compares this descriptor's data with the specified descriptor's data to the
232 specified maximum collation level and using the specified collation method.
234 If no collation method is supplied, a default method is used that uses a
235 locale-independent collation table. This means that sorting and matching will
236 not be based on the current locale.
238 This function is only defined for 16-bit (Unicode) build variants. This means
239 that the function is not defined for 8-bit build variants, even when an
240 explicit 16-bit descriptor is used.
242 Strings may match even if the lengths of their respective descriptors are
245 @param aDes The 16-bit non-modifable descriptor whose data is to
246 be compared with this descriptor's data.
248 @param aMaxLevel The maximum collation level. This is an integer with
249 values: 0, 1, 2 or 3, which, effectively, determines
250 how 'tight' the matching should be. Level 3 is always
251 used if the aim is to sort strings.
253 @param aCollationMethod A pointer to the collation method or NULL. Collation
254 methods can be retrieved by calls to
255 Mem::CollationMethodByIndex()
256 and Mem::CollationMethodById().
257 Specifying NULL means that the default method is used.
259 @return Positive, if this descriptor is greater than the specified descriptor.
260 Negative, if this descriptor is less than the specified descriptor.
261 Zero, if the content of both descriptors match.
263 @see Mem::CollationMethodByIndex()
264 @see Mem::CollationMethodById()
265 @see TDesC16::Compare()
267 EXPORT_C TInt TDesC16::CompareC(const TDesC16& aDes, TInt aMaxLevel, const TCollationMethod* aCollationMethod) const
269 return Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length(),aMaxLevel,aCollationMethod);
273 Get the normalized decomposed form of this 16 bit descriptor
274 @return A pointer to the 16-bit heap buffer containing normalized decomposed form
275 if creation is successful
276 @leave KErrNoMemory if not enough memory to construct the output buffer
278 EXPORT_C HBufC16* TDesC16::GetNormalizedDecomposedFormL() const
280 //pre create a buffer with of size Length
281 TInt strLength=Length();
282 HBufC16* outBuf=HBufC16::NewL(strLength);
284 TUTF32Iterator input(Ptr(),Ptr()+strLength);
285 TCanonicalDecompositionIterator output;
288 TInt currentAllocateCount=0;
289 TUint16* outPtr = (TUint16* )outBuf->Des().Ptr();
290 TInt preAllocateCount= outBuf->Des().MaxLength();
292 for (;!output.AtEnd();output.Next(),currentAllocateCount++)
294 if (currentAllocateCount>=preAllocateCount)
296 const TInt KMaxGrowSize=16;
297 HBufC16* newOutBuf = outBuf->ReAlloc(preAllocateCount+KMaxGrowSize);
301 User::Leave(KErrNoMemory);
304 outPtr = (TUint16* )outBuf->Des().Ptr();
305 preAllocateCount = outBuf->Des().MaxLength();
307 outPtr[currentAllocateCount] = (TUint16)(TUint)(output.Current());
309 // update the length of the buffer...
310 outBuf->Des().SetLength(currentAllocateCount);
312 //compress the unused slot
313 if (currentAllocateCount<preAllocateCount)
314 outBuf = outBuf->ReAlloc(currentAllocateCount); // can't fail to shrink memory
319 Get the folded decomposed form of this 16 bit descriptor
320 @return A pointer to the 16-bit heap buffer containing folded decomposed form
321 if creation is succesful
322 @leave KErrNoMemory if not enough memory to construct the output buffer
324 EXPORT_C HBufC16* TDesC16::GetFoldedDecomposedFormL() const
326 //pre create a buffer with of size Length
327 TInt strLength=Length();
328 HBufC16* outBuf=HBufC16::NewL(strLength);
330 TUTF32Iterator input(Ptr(),Ptr()+strLength);
331 TFoldedCanonicalIterator output (input);
333 TInt currentAllocateCount=0;
334 TUint16* outPtr = (TUint16* )outBuf->Des().Ptr();
335 TInt preAllocateCount= outBuf->Des().MaxLength();
336 const TUnicodeDataSet* charDataSet = GetLocaleCharSet()->iCharDataSet;
337 for (;!output.AtEnd();output.Next(charDataSet),currentAllocateCount++)
339 if (currentAllocateCount>=preAllocateCount)
341 const TInt KMaxGrowSize=16;
342 HBufC16* newOutBuf = outBuf->ReAlloc(preAllocateCount+KMaxGrowSize);
346 User::Leave(KErrNoMemory);
349 outPtr = (TUint16* )outBuf->Des().Ptr();
350 preAllocateCount = outBuf->Des().MaxLength();
352 outPtr[currentAllocateCount] = (TUint16)(TUint)(output.Current());
354 // update the length of the buffer...
355 outBuf->Des().SetLength(currentAllocateCount);
357 //compress the unused slot
358 if (currentAllocateCount<preAllocateCount)
359 outBuf = outBuf->ReAlloc(currentAllocateCount); // can't fail to shrink memory
363 //some utils function
364 static void ResetAndDestroyArray(TAny* aPtr)
366 (STATIC_CAST(RPointerArray<HBufC8>*,aPtr))->ResetAndDestroy();
370 Get the collation keys of this 16 bit descriptor for a given collation level
371 If no collation method is supplied, a default method is used that uses a
372 locale-independent collation table.
373 @param aMaxLevel The maximum collation level. This is an integer with
374 values: 0, 1, 2 or 3. Level 3 is always
375 used if the aim is to sort strings.
376 @param aCollationMethod A pointer to the collation method or NULL. Collation
377 methods can be retrieved by calls to
378 Mem::CollationMethodByIndex()
379 and Mem::CollationMethodById().
380 Specifying NULL means that the default method is used.
381 @return A pointer to the 8-bit heap buffer containing the collation keys if
382 creation is succesful
383 @leave KErrNoMemory if not enough memory to construct the output buffer
385 EXPORT_C HBufC8* TDesC16::GetCollationKeysL(TInt aMaxLevel,const TCollationMethod* aCollationMethod) const
387 // Clamp the maximum level of the comparison.
393 RPointerArray<HBufC8> levelBuffer;
394 CleanupStack::PushL(TCleanupItem(ResetAndDestroyArray, &levelBuffer));
395 TInt strLength=Length();
396 TInt outputBufferSize=0;
398 //preallocate some initial buffer size as it is not possible to determine the max buffer
399 //required as a character can be further decomposed and each character can possibly
400 //have up to 8 collation keys and this limit might still change.
401 for (TInt i=0;i<=aMaxLevel;i++)
403 TInt levelKeySize=TCollationKey::MaxSizePerKey(i);
404 HBufC8* buffer=HBufC8::NewLC(strLength*levelKeySize);
405 levelBuffer.AppendL(buffer);
407 outputBufferSize+=levelKeySize;
409 TCollationMethod clm;
411 //if collationMethod is NULL, use the default one
412 if (aCollationMethod==NULL)
414 clm=*(GetLocaleCharSet()->iCollationDataSet->iMethod);
418 clm = *aCollationMethod;
420 //if the main table is empty use the standard table
421 if (clm.iMainTable==NULL)
422 clm.iMainTable=StandardCollationMethod();
424 TCollationValueIterator tvi(clm);
425 TUTF32Iterator input(Ptr(),Ptr()+strLength);
426 tvi.SetSourceIt(input);
428 //Expand the buffer by 16 bytes if buffer is exhausted
429 const TInt KMaxBufferGrowSize=16;
430 TInt currentKeyCount=0;
431 TInt preAllocateCount=strLength;
432 TCollationKey collateKey;
433 for (;tvi.GetCurrentKey(collateKey);tvi.Increment(),currentKeyCount++)
435 for (TInt i=0;i<=aMaxLevel;i++)
437 if (currentKeyCount==preAllocateCount)
438 levelBuffer[i]=levelBuffer[i]->ReAllocL((currentKeyCount+KMaxBufferGrowSize)*TCollationKey::MaxSizePerKey(i));
440 collateKey.AppendToDescriptor(levelBuffer[i]->Des(),i);
442 if (currentKeyCount==preAllocateCount)
443 preAllocateCount+=KMaxBufferGrowSize;
445 //append the level separator which is a "\x00\x00" for level 0 and \x00 for other level
446 outputBufferSize=(outputBufferSize*currentKeyCount)+(aMaxLevel==0?0:4+(aMaxLevel-1)*2);
447 HBufC8* outputResult=HBufC8::NewL(outputBufferSize);
448 TPtr8 outputResultPtr(outputResult->Des());
449 for (TInt count=0;count<=aMaxLevel;count++)
451 outputResultPtr.Append(*levelBuffer[count]);
452 if (count!=aMaxLevel)
455 outputResultPtr.Append(0);
456 outputResultPtr.Append(0);
459 CleanupStack::PopAndDestroy();
466 Searches for the first occurrence of the specified data sequence within this
469 Searching always starts at the beginning of this descriptor's data.
471 @param pS A pointer to a location containing the data sequence to be searched
474 @param aLenS The length of the data sequence to be searched for. This value
475 must not be negative, otherwise the function raises a panic.
477 @return The offset of the data sequence from the beginning of this descriptor's
478 data. KErrNotFound, if the data sequence cannot be found.
480 @panic USER 17 if aLenS is negative.
482 EXPORT_C TInt TDesC16::Find(const TUint16 *pS,TInt aLenS) const
487 __ASSERT_ALWAYS(aLenS>0,Panic(ETDes16LengthNegative));
488 __CHECK_ALIGNMENT(pS,ETDesC16FindPtrLen);
489 const TUint16 *pB=Ptr();
491 const TUint16 *pC=pB-1; // using pre-increment addressing
495 const TUint16* pEndS=pS+aLenS-1; // using pre-increment addressing
496 const TUint16 *pEndB=pB+i; // using pre-increment addressing
505 const TUint16 *p1=pC;
506 const TUint16 *p2=pS;
511 } while (*++p1==*++p2);
514 return(KErrNotFound);
521 Searches for the first occurrence of the specified data sequence within this
524 Searching always starts at the beginning of this descriptor's
527 @param aDes The 16-bit non-modifiable descriptor containing the data sequence
530 @return The offset of the data sequence from the beginning of this descriptor's
531 data. KErrNotFound, if the data sequence cannot be found.
533 EXPORT_C TInt TDesC16::Find(const TDesC16 &aDes) const
536 return(Find(aDes.Ptr(),aDes.Length()));
543 Searches for the first occurrence of the specified folded data sequence within
544 this descriptor's folded data.
546 Searching always starts at the beginning of this descriptor's data.
548 Note that folding is locale-independent behaviour. It is also important to
549 note that there can be no guarantee that folding is in any way culturally
550 appropriate, and should not be used for finding strings in natural language;
551 use FindC() for this.
553 @param pS A pointer to a location containing the data sequence to be
555 @param aLenS The length of the data sequence to be searched for. This value
556 must not be negative, otherwise the function raises a panic.
558 @return The offset of the data sequence from the beginning of this descriptor's
559 data. KErrNotFound, if the data sequence cannot be found. Zero, if the
560 length of the search data sequence is zero.
562 @panic USER 17 if aLenS is negative
564 @see TDesC16::FindC()
566 EXPORT_C TInt TDesC16::FindF(const TUint16 *pS,TInt aLenS) const
568 __CHECK_ALIGNMENT(pS,ETDesC16FindFPtrLen);
569 TUTF32Iterator candidateStrIt(Ptr(), Ptr() + Length());
570 TUTF32Iterator searchTermIt(pS, pS + aLenS);
571 return ::FindFolded(candidateStrIt, searchTermIt);
578 Searches for the first occurrence of the specified folded data sequence within
579 this descriptor's folded data.
581 Searching always starts at the beginning of this descriptor's data.
583 Note that folding is locale-independent behaviour. It is also important to
584 note that there can be no guarantee that folding is in any way culturally
585 appropriate, and should not be used for finding strings in natural language;
586 use FindC() for this.
588 @param aDes The 16-bit non-modifable descriptor containing the data sequence
591 @return The offset of the data sequence from the beginning of this descriptor's
592 data. KErrNotFound, if the data sequence cannot be found.
593 Zero, if the length of the search data sequence is zero.
595 @see TDesC16::FindC()
597 EXPORT_C TInt TDesC16::FindF(const TDesC16 &aDes) const
599 TUTF32Iterator candidateStrIt(Ptr(), Ptr() + Length());
600 TUTF32Iterator searchTermIt(aDes.Ptr(), aDes.Ptr() + aDes.Length());
601 return ::FindFolded(candidateStrIt, searchTermIt);
608 Searches for the first occurrence of the specified collated data sequence within
609 this descriptor's collated data.
611 Searching always starts at the beginning of this descriptor's data. The function
612 uses the standard collation method appropriate to the current locale.
614 @param aText A pointer to a location containing the data sequence to be
616 @param aLength The length of the data sequence to be searched for.
618 @return The offset of the data sequence from the beginning of this descriptor's data.
619 KErrNotFound, if the data sequence cannot be found.
621 @panic USER 17 if aLength is negative.
623 EXPORT_C TInt TDesC16::FindC(const TUint16 *aText,TInt aLength) const
625 __CHECK_ALIGNMENT(aText,ETDesC16FindCPtrLen);
627 TCollate c(GetLocaleCharSet(),TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
628 return c.Find(Ptr(),Length(),aText,aLength,1);
635 Searches for the first occurrence of the specified collated data sequence
636 within this descriptor's collated data to the specified maximum collation
639 @param aText A pointer to a location containing the data sequence to
642 @param aLength The length of the data sequence to be searched for.
644 @param aMaxLevel The maximum collation level. This is an integer with
645 values: 0, 1, 2 or 3, which, effectively, determines
646 how 'tight' the matching should be. Level 3 is always
647 used if the aim is to sort strings.
649 @return The offset of the data sequence from the beginning of this descriptor's data.
650 KErrNotFound, if the data sequence cannot be found.
652 EXPORT_C TInt TDesC16::FindC(const TUint16 *aText,TInt aLength, TInt aMaxLevel) const
655 __CHECK_ALIGNMENT(aText,ETDesC16FindCPtrLen);
657 TCollate c(GetLocaleCharSet(),TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
658 return c.Find(Ptr(),Length(),aText,aLength,aMaxLevel);
665 Searches for the first occurrence of the specified collated data sequence
666 within this descriptor's collated data.
668 Searching always starts at the beginning of this descriptor's data. The
669 function uses the standard collation method appropriate to the current
672 @param aDes The 16-bit non-modifable descriptor containing the data sequence
675 @return The offset of the data sequence from the beginning of this descriptor's
676 data. KErrNotFound, if the data sequence cannot be found.
678 EXPORT_C TInt TDesC16::FindC(const TDesC16 &aDes) const
681 return(FindC(aDes.Ptr(),aDes.Length()));
685 Searches for the first occurrence of the specified collated data sequence
686 within this descriptor's collated data.
688 Searching always starts at the beginning of this descriptor's data. The
689 function uses the standard collation method appropriate to the current
692 @param aDes The 16-bit non-modifable descriptor containing the data sequence
695 @param aLengthFound A refernce to the maximal length of the match found in the candidate
696 string. KErrNotFound, if the data sequence cannot be found.
698 @param aCollationMethod A pointer to the collation method or NULL. Collation
699 methods can be retrieved by calls to
700 Mem::CollationMethodByIndex()
701 and Mem::CollationMethodById().
702 Specifying NULL means that the default method is used.
704 @param aMaxLevel The maximum collation level. This is an integer with
705 values: 0, 1, 2 or 3, which, effectively, determines
706 how 'tight' the matching should be. Level 3 is always
707 used if the aim is to sort strings.
709 @return The offset of the data sequence from the beginning of this descriptor's
710 data. KErrNotFound, if the data sequence cannot be found.
712 EXPORT_C TInt TDesC16::FindC(const TDesC16 &aDes, TInt &aLengthFound, const TCollationMethod &aMethod, TInt aMaxLevel) const
715 return c.Find(Ptr(),Length(),aDes.Ptr(),aDes.Length(),aLengthFound,aMaxLevel);
720 LOCAL_C const TText* convTable(TMatchType aType)
724 case EMatchFolded: // at present, folding is...
725 case EMatchCollated: return (const TText *)(TChar::EFoldStandard); // ...the same as collation: use all folding methods
730 LOCAL_C const TText* convTable(TMatchType aType)
734 case EMatchFolded: return Locl::FoldTable();
735 case EMatchCollated: return Locl::CollTable();
736 default: return NULL;
741 inline TUint conv(const TUint16* aStr,const TText *aConv, const TUnicodeDataSet* aCharDataSet)
743 // If aConv is not NULL then convert the character.
749 return TUnicode(*aStr).Fold((TInt)aConv, aCharDataSet);
754 return aConv && c<0x100 ? aConv[c] : c;
758 inline TUint lookup(const TUint16* aStr,const TText *aConv)
761 return TUnicode(*aStr).Fold((TInt)aConv,GetLocaleCharSet()->iCharDataSet);
764 return c<0x100 ? aConv[c] : c;
768 TInt DoMatch16(const TDesC16 &aLeftD,const TDesC16 &aRightD,TMatchType aType)
770 const TText* table=convTable(aType);
771 const TUint16* pRight=aRightD.Ptr();
772 const TUint16* pM=pRight-1; // pre-increment addressing
773 const TUint16* pP=pM+aRightD.Length();
774 const TUint16* pLeft=aLeftD.Ptr()-1; // pre-increment addressing
775 const TUint16* pB=pLeft;
776 const TUint16* pE=pB+aLeftD.Length();
779 const TUnicodeDataSet* charDataSet = GetLocaleCharSet()->iCharDataSet;
781 // Match any pattern up to the first star
785 if (pM==pP) // exhausted the pattern
786 return pB==pE ? 0 : KErrNotFound;
787 TUint c=conv(++pM,table, charDataSet);
790 if (pB==pE) // no more input
792 if (c!=conv(++pB,table, charDataSet) && c!=KMatchOne) // match failed
798 TInt r=pM==pRight ? -1 : 0;
801 c=conv(++pM,table, charDataSet);
804 star: if (pM==pP) // star at end of pattern, always matches
806 if (r<-1) // skipped some '?', matches at beginning
810 if (pB==pE) // no more input
813 { // skip a character in the input
815 return r+((r>=0) ? 0 : (pE-pLeft));
821 // Matching a non-wild character
826 while (lookup(++pB,table)!=c)
828 if (pB==pE) // no more input
836 if (pB==pE) // no more input
840 // Try to match up to the next star
841 const TUint16* pb=pB;
842 const TUint16* pm=pM;
847 TUint cc=conv(++pm,table, charDataSet);
849 { // sub-match successful, back to main loop
850 r+=(r>=0 ? 0 : pB-pLeft);
856 return KErrNotFound; // no more input
857 if (cc!=conv(++pb,table, charDataSet) && cc!=KMatchOne)
858 break; // sub-match failed, try next input character
860 else if (pb==pE) // end of matching pattern
861 return r+(r>=0 ? 0 : pB-pLeft); // end of input, so have a match
863 break; // try next input character
871 EXPORT_C TDesC16::TPrefix TDesC16::HasPrefixC(const TDesC16& aPossiblePrefix,
872 TInt aLevel, const TCollationMethod* aCollationMethod) const
874 Compares aPossiblePrefix against the start of the descriptor, using a
877 @param aLevel The maximum level at which to perform the collation.
879 0: Only check character identities.
881 1: Check accents as well.
883 2: Check case as well.
885 3: Check Unicode values.
887 Currently only level 0 is supported.
889 @param aCollationMethod The collation method to be used for the matching.
891 @return EIsPrefix, if aPossiblePrefix can be extended to
892 be equivalent to the text at the start of this descriptor.
893 EIsNotPrefix if aPossiblePrefix cannot
894 be extended to be equivalent to the text at the start of this descriptor.
895 EMightBePrefix if it currently does not seem to be a prefix, but it
896 is possible that it could be extended to become equivalent to text at
897 the start of this descriptor.
898 EMightBePrefix is returned in cases where it would be expensive
899 to determine for sure.
902 const TText16* lp = aPossiblePrefix.Ptr();
903 const TText16* rp = Ptr();
904 TInt ll = aPossiblePrefix.Length();
907 if (!aCollationMethod)
909 TCollate c(GetLocaleCharSet());
910 r = c.Compare(rp, rl, lp, ll, aLevel);
914 TCollate c(*aCollationMethod);
915 r = c.Compare(rp, rl, lp, ll, aLevel);
917 return r == 1 || r == 0? EIsPrefix : EIsNotPrefix;
920 EXPORT_C TInt TDesC16::Match(const TDesC16 &aDes) const
922 Searches this descriptor's data for a match with the match pattern supplied
923 in the specified descriptor.
925 The match pattern can contain the wildcard characters "*" and "?", where "*"
926 matches zero or more consecutive occurrences of any character and "?" matches
927 a single occurrence of any character.
929 Note that there is no 'escape character', which means that it is not possible
930 to match either the "*" character itself or the "?" character itself using
933 @param aDes A 16-bit non-modifable descriptor containing the match pattern.
935 @return If a match is found, the offset within this descriptor's data where
936 the match first occurs. KErrNotFound, if there is no match.
940 return DoMatch16(*this,aDes,EMatchNormal);
944 EXPORT_C TInt TDesC16::MatchF(const TDesC16 &aDes) const
946 Searches this descriptor's folded data for a match with the folded match pattern
947 supplied in the specified descriptor.
949 The match pattern can contain the wildcard characters "*" and "?", where "*"
950 matches zero or more consecutive occurrences of any character and "?" matches
951 a single occurrence of any character.
953 Note that folding is locale-independent behaviour. It is also important to
954 note that there can be no guarantee that folding is in any way culturally
955 appropriate, and should not be used for matching strings in natural language;
956 use MatchC() for this.
958 Note that there is no 'escape character', which means that it is not possible
959 to match either the "*" character itself or the "?" character itself using
962 @param aDes A 16-bit non-modifable descriptor containing the match pattern.
964 @return If a match is found, the offset within this descriptor's data where
965 the match first occurs. KErrNotFound, if there is no match.
967 @see TDesC16::MatchC()
970 const TText16* csp = Ptr();
971 const TText16* stp = aDes.Ptr();
972 return LocateMatchStringFolded(csp, csp + Length(), stp, stp + aDes.Length());
975 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern) const
977 Searches this descriptor's collated data for a match with the collated match
978 pattern supplied in the specified descriptor.
980 The function uses the standard collation method appropriate to
983 The match pattern can contain the wildcard characters "*" and "?", where "*"
984 matches zero or more consecutive occurrences of any character and "?" matches
985 a single occurrence of any character.
987 Note that there is no 'escape character', which means that it is not possible
988 to match either the "*" character itself or the "?" character itself using
991 @param aPattern A 16-bit non-modifable descriptor containing the match pattern.
993 @return If a match is found, the offset within this descriptor's data where
994 the match first occurs. KErrNotFound, if there is no match.
997 TCollationMethod m=*Mem::GetDefaultMatchingTable();
998 m.iFlags |= (TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
1000 return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), 0, '?', '*');
1004 Searches this descriptor's collated data for a match with the collated match
1005 pattern supplied in the specified descriptor.
1007 The function uses the standard collation method appropriate to
1010 The match pattern can contain the wildcard characters specified by aWildChar and aWildSequenceChar
1011 parameters, where aWildSequenceChar matches zero or more consecutive occurrences of any character and
1012 aWildChar matches a single occurrence of any character.
1014 @param aPattern A 16-bit non-modifable descriptor containing the match pattern.
1015 @param aWildChar Wild card character which may be specified for aSearchTerm.
1016 @param aWildSequenceChar Wild card sequence character which may be specified for aSearchTerm.
1017 @param aEscapeChar The escape character, or 0 if there is to be none. The escape character removes any
1018 special meaning from the subsequent character. For example, if the escape, wild card
1019 and wild sequence characters are \, ? And * respectively, the search term "\?\*\\" matches
1020 only the candidate string "?*\";
1021 @param aMaxLevel Determines the tightness of the collation. At level 0, only
1022 character identities are distinguished. At level 1 accents are
1023 distinguished as well. At level 2 case is distinguishes as well. At
1024 level 3 all valid different Unicode characters are considered different.
1025 @param aCollationMethod A pointer to the collation method or NULL. Collation methods can be retrieved by calls to
1026 Mem::CollationMethodByIndex() and Mem::CollationMethodById().
1027 Specifying NULL means that the default method is used.
1029 @return If a match is found, the offset within this descriptor's data where
1030 the match first occurs. KErrNotFound, if there is no match.
1032 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern, TInt aWildChar, TInt aWildSequenceChar,
1033 TInt aEscapeChar, TInt aMaxLevel, const TCollationMethod* aCollationMethod) const
1035 TCollationMethod m(aCollationMethod ? *aCollationMethod : *Mem::GetDefaultMatchingTable());
1036 m.iFlags |= (TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
1038 return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), aMaxLevel, aWildChar, aWildSequenceChar, aEscapeChar);
1043 Searches this descriptor's collated data for a match with the collated match
1044 pattern supplied in the specified descriptor.
1046 The function uses the standard collation method appropriate to
1049 The match pattern can contain the wildcard characters specified by aWildChar and aWildSequenceChar
1050 parameters, where aWildSequenceChar matches zero or more consecutive occurrences of any character and
1051 aWildChar matches a single occurrence of any character.
1053 @param aPattern A 16-bit non-modifable descriptor containing the match pattern.
1054 @param aFlags Flags providing advanced control of the collation algorithm @see TCollationFlag
1055 @param aWildChar Wild card character which may be specified for aSearchTerm. Defaulted to '?' if omitted.
1056 @param aWildSequenceChar Wild card sequence character which may be specified for aSearchTerm.
1057 Defaulted to '*' if omitted.
1058 @param aEscapeChar The escape character, or 0 if there is to be none. The escape character removes any
1059 special meaning from the subsequent character. For example, if the escape, wild card
1060 and wild sequence characters are \, ? And * respectively, the search term "\?\*\\" matches
1061 only the candidate string "?*\". Defaulted to 0 if omitted.
1062 @param aMaxLevel Determines the tightness of the collation. Defaulted to 3 if omitted. At level 0, only
1063 character identities are distinguished. At level 1 accents are
1064 distinguished as well. At level 2 case is distinguishes as well. At
1065 level 3 all valid different Unicode characters are considered different.
1066 @param aCollationMethod A pointer to the collation method. Collation methods can be retrieved by calls to
1067 Mem::CollationMethodByIndex(), Mem::CollationMethodById() or by custom defined name.
1068 Flags can be set on definition of the custom TCollationMethod, or by const_cast-ing
1069 the returned pointer and setting the iFlags field directly. @see TCollationMethod
1070 @return If a match is found, the offset within this descriptor's data where
1071 the match first occurs. KErrNotFound, if there is no match.
1073 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern, const TCollationMethod* aCollationMethod,
1074 TInt aMaxLevel, TInt aWildChar, TInt aWildSequenceChar, TInt aEscapeChar) const
1076 TCollate c(*aCollationMethod);
1077 return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), aMaxLevel, aWildChar, aWildSequenceChar, aEscapeChar);
1081 #ifndef __DES16_MACHINE_CODED_HWORD__
1082 EXPORT_C TInt TDesC16::Locate(TChar aChar) const
1084 Searches for the first occurrence of a character within this descriptor's
1087 The search starts at the beginning of the data, i.e. at the leftmost
1090 @param aChar The character to be found.
1092 @return The offset of the character position from the beginning of the data.
1093 KErrNotFound, if no matching character can be found.
1097 const TUint16 *pBuf=Ptr();
1098 const TUint16 *pB=pBuf-1;
1099 const TUint16 *pE=pB+Length();
1103 return KErrNotFound;
1104 } while (TUint(*++pB)!=aChar);
1109 LOCAL_C TInt DoLocateF16(const TDesC16& aDes,TUint aChar)
1111 // Locate character aChar in the descriptor folded.
1115 const TText* table = convTable(EMatchFolded);
1116 TUint16 aChar16 = (TUint16)aChar;
1117 aChar = lookup(&aChar16,table);
1119 const TText* table=Locl::FoldTable;
1123 const TUint16 *pBuf=aDes.Ptr();
1124 const TUint16 *pB=pBuf-1;
1125 const TUint16 *pE=pB+aDes.Length();
1129 return KErrNotFound;
1130 } while (lookup(++pB,table)!=aChar);
1134 EXPORT_C TInt TDesC16::LocateF(TChar aChar) const
1136 Searches for the first occurrence of a folded character within this
1137 descriptor's folded data.
1139 The search starts at the beginning of the data, i.e. at the leftmost
1142 Note that folding is locale-independent behaviour. It is also important to
1143 note that there can be no guarantee that folding is in any way culturally
1144 appropriate, and should not be used for searching strings in natural language.
1146 @param aChar The character to be found.
1148 @return The offset of the character position from the beginning of the data.
1149 KErrNotFound, if no matching character can be found.
1153 return DoLocateF16(*this,aChar);
1157 #ifndef __DES16_MACHINE_CODED_HWORD__
1158 EXPORT_C TInt TDesC16::LocateReverse(TChar aChar) const
1160 Searches for the first occurrence of a character within this descriptor's
1161 data, searching from the end of the data.
1163 The search starts at the rightmost position.
1165 @param aChar The character to be found.
1167 @return The offset of the character position from the beginning of the data.
1168 KErrNotFound, if no matching character can be found.
1174 return(KErrNotFound);
1175 const TUint16 *pB=Ptr();
1176 const TUint16 *pE=pB+len-1;
1179 if (TUint(*pE)==aChar)
1183 return(pE<pB ? KErrNotFound : pE-pB);
1187 EXPORT_C TInt TDesC16::LocateReverseF(TChar aChar) const
1189 Searches for the first occurrence of a folded character within this descriptor's
1190 folded data, searching from the end of the data.
1192 The search starts at the rightmost position.
1194 Note that folding is locale-independent behaviour. It is also important to
1195 note that there can be no guarantee that folding is in any way culturally
1196 appropriate, and should not be used for searching strings in natural language.
1198 @param aChar The character to be found
1199 @return The offset of the character position from the beginning of the data.
1200 KErrNotFound, if no matching character can be found.
1206 return(KErrNotFound);
1207 const TUint16 *pB=Ptr();
1208 const TUint16 *pE=pB+len-1;
1217 return(pE<pB ? KErrNotFound : pE-pB);
1220 EXPORT_C HBufC16 *TDesC16::Alloc() const
1222 Creates a new 16-bit heap descriptor and initialises it with a copy of this
1225 @return A pointer to the new 16-bit heap descriptor, if creation is successful.
1226 NULL, if creation of the descriptor fails.
1230 HBufC16 *pH=HBufC16::New(Length());
1236 EXPORT_C HBufC16 *TDesC16::AllocL() const
1238 Creates a new 16-bit heap descriptor and initialises it with a copy of this
1241 The function leaves, if creation of the descriptor fails.
1243 @return A pointer to the 16-bit heap descriptor, if creation is successful.
1247 HBufC16 *pH=HBufC16::NewL(Length());
1252 EXPORT_C HBufC16 *TDesC16::AllocLC() const
1254 Creates a new 16-bit heap descriptor, initialises it with a copy of this
1255 descriptor's data, and puts a pointer to the descriptor onto the cleanup stack.
1257 The function leaves, if creation of the descriptor fails.
1259 @return A pointer to the 16-bit heap descriptor, if creation is successful.
1260 The pointer is also put onto the cleanup stack.
1264 HBufC16 *pH=HBufC16::NewLC(Length());
1269 #if !defined(__DES16_MACHINE_CODED__)
1271 EXPORT_C TPtrC16 TDesC16::Left(TInt aLength) const
1273 Extracts the leftmost part of the data.
1275 The function does not cut or remove any data but constructs a non-modifiable
1276 pointer descriptor to represent the leftmost part of the data.
1278 @param aLength The length of the data to be extracted. If this value is
1279 greater than the length of the descriptor, the function
1280 extracts the whole of the descriptor.
1282 @return The 16-bit non-modifiable pointer descriptor representing the leftmost
1285 @panic USER 10 if aLength is negative.
1289 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
1290 return(TPtrC16(Ptr(),Min(aLength,Length())));
1293 EXPORT_C TPtrC16 TDesC16::Right(TInt aLength) const
1295 Extracts the rightmost part of the data.
1297 The function does not cut or remove any data but constructs a non-modifiable
1298 pointer descriptor to represent the rightmost part of the data.
1300 @param aLength The length of data to be extracted. If this value
1301 is greater than the length of the descriptor, the function
1302 extracts the whole of the descriptor.
1304 @return The 16-bit non-modifiable pointer descriptor representing the rightmost
1307 @panic USER 10 if aLength is negative.
1311 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
1315 return(TPtrC16(Ptr()+len-aLength,aLength));
1318 EXPORT_C TPtrC16 TDesC16::Mid(TInt aPos) const
1320 Extracts a portion of the data.
1322 The function does not cut or remove any data but constructs a non-modifiable
1323 pointer descriptor to represent the defined portion.
1325 The portion is identified by its starting position and by the length of the
1326 remainder of the data starting from the specified position.
1328 @param aPos The starting position of the data to be extracted. This is an
1329 offset value; a zero value refers to the leftmost data position.
1331 @return The 16-bit non-modifiable pointer descriptor representing the specified
1332 portion of the data.
1334 @panic USER 10 if aPos is negative or aPos is greater than the
1335 length of the descriptor.
1340 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
1341 return(TPtrC16(Ptr()+aPos,len-aPos));
1344 EXPORT_C TPtrC16 TDesC16::Mid(TInt aPos,TInt aLength) const
1346 Extracts a portion of the data.
1348 The function does not cut or remove any data but constructs a non-modifiable
1349 pointer descriptor to represent the defined portion.
1351 The portion is identified by its starting position and by its length.
1353 @param aPos The starting position of the data to be extracted. This is an
1354 offset value; a zero value refers to the leftmost data position.
1355 @param aLength The length of data to be extracted.
1357 @return The 16-bit non-modifiable pointer descriptor representing the specified
1358 portion of the data.
1360 @panic USER 10 if aPos is negative or aPos plus aLength is greater than the
1361 length of the descriptor.
1365 __ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes16PosOutOfRange));
1366 return(TPtrC16(Ptr()+aPos,aLength));
1369 #endif // !defined(__DES16_MACHINE_CODED__)
1371 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
1372 EXPORT_C TBufCBase16::TBufCBase16()
1380 #if !defined( __DES16_MACHINE_CODED_HWORD__) | defined(__EABI_CTORS__)
1381 EXPORT_C TBufCBase16::TBufCBase16(const TUint16 *aString,TInt aMaxLength)
1387 Copy(aString,aMaxLength);
1391 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
1392 EXPORT_C TBufCBase16::TBufCBase16(const TDesC16 &aDes,TInt aMaxLength)
1398 Copy(aDes,aMaxLength);
1402 #ifndef __DES16_MACHINE_CODED_HWORD__
1403 EXPORT_C void TBufCBase16::Copy(const TUint16 *aString,TInt aMaxLength)
1405 // Copy from a string.
1409 __CHECK_ALIGNMENT(aString,ETBufCBase16CopyStringMax);
1410 TInt len=STRING_LENGTH_16(aString);
1411 __ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes16Overflow));
1412 memCopy(WPtr(),aString,len);
1417 #ifndef __DES16_MACHINE_CODED__
1418 EXPORT_C void TBufCBase16::Copy(const TDesC16 &aDes,TInt aMaxLength)
1420 // Copy from a descriptor.
1424 TInt len=aDes.Length();
1425 __ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes16Overflow));
1426 memCopy(WPtr(),aDes.Ptr(),len);
1431 inline HBufC16::HBufC16(TInt aLength)
1432 :TBufCBase16(aLength)
1435 EXPORT_C HBufC16 *HBufC16::New(TInt aMaxLength)
1437 Creates, and returns a pointer to, a new 16-bit heap descriptor.
1439 The heap descriptor is empty and its length is zero.
1441 Data can, subsequently, be assigned into it using the assignment operators.
1443 @param aMaxLength The requested maximum length of the descriptor. Note that
1444 the resulting heap cell size and, therefore, the resulting
1445 maximum length of the descriptor may be larger than
1448 @return A pointer to the new 16-bit heap descriptor. NULL, if the 16-bit heap
1449 descriptor cannot be created.
1451 @panic USER 18 if aMaxLength is negative.
1453 @see HBufC16::operator=()
1456 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
1457 return new(STD_CLASS::Alloc(_FOFF(HBufC16,iBuf[aMaxLength]))) HBufC16(0);
1460 EXPORT_C HBufC16 *HBufC16::NewL(TInt aMaxLength)
1462 Creates, and returns a pointer to, a new 16-bit heap descriptor, and leaves
1465 The heap descriptor is empty and its length is zero.
1467 Data can, subsequently, be assigned into it using the assignment operators.
1469 @param aMaxLength The requested maximum length of the descriptor. Note that
1470 the resulting heap cell size and, therefore, the resulting
1471 maximum length of the descriptor may be larger
1474 @return A pointer to the new 16-bit heap descriptor. The function leaves, if
1475 the new 16-bit heap descriptor cannot be created.
1478 @panic USER 18 if aMaxLength is negative.
1480 @see HBufC16::operator=()
1483 return static_cast<HBufC16*>(User::LeaveIfNull(New(aMaxLength)));
1486 EXPORT_C HBufC16 *HBufC16::NewLC(TInt aMaxLength)
1488 Creates, adds a pointer onto the cleanup stack and returns a pointer to, a
1489 new 16-bit heap descriptor; leaves on failure.
1491 The heap descriptor is empty and its length is zero.
1493 Data can, subsequently, be assigned into it using the assignment operators.
1495 @param aMaxLength The requested maximum length of the descriptor. Note that
1496 the resulting heap cell size and, therefore, the resulting
1497 maximum length of the descriptor may be larger
1500 @return A pointer to the new 16-bit heap descriptor. The function leaves, if
1501 the new 16-bit heap descriptor cannot be created.
1503 @panic USER 18 if aMaxLength is negative.
1505 @see HBufC16::operator=()
1508 HBufC16* buf=NewL(aMaxLength);
1509 CleanupStack::PushL(buf);
1513 EXPORT_C HBufC16 *HBufC16::NewMax(TInt aMaxLength)
1515 Creates, and returns a pointer to, a new 16-bit heap descriptor.
1517 No data is assigned into the new descriptor but its length
1518 is set to aMaxLength.
1520 Data can, subsequently, be assigned into it using the assignment operators.
1522 @param aMaxLength The requested maximum length of the descriptor. Note that
1523 the resulting heap cell size and, therefore, the resulting
1524 maximum length of the descriptor may be larger
1525 than requested. This also means that the resulting maximum
1526 length of the descriptor may be greater than its length.
1527 @return A pointer to the new 16-bit heap descriptor. NULL, if the new 16-bit
1528 heap descriptor cannot be created.
1530 @panic USER 18 if aMaxLength is negative.
1532 @see HBufC16::operator=()
1535 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
1536 return new(STD_CLASS::Alloc(_FOFF(HBufC16,iBuf[aMaxLength]))) HBufC16(aMaxLength);
1539 EXPORT_C HBufC16 *HBufC16::NewMaxL(TInt aMaxLength)
1541 Creates, and returns a pointer to, a new 16-bit heap descriptor;
1544 No data is assigned into the new descriptor but its length is set
1547 Data can, subsequently, be assigned into it using the assignment operators.
1549 @param aMaxLength The requested maximum length of the descriptor. Note that
1550 the resulting heap cell size and, therefore, the resulting
1551 maximum length of the descriptor may be larger
1552 than requested. This also means that the resulting
1553 maximum length of the descriptor may be greater than its length.
1555 @return A pointer to the new 16-bit heap descriptor. The function leaves, if
1556 the new 16-bit heap descriptor cannot be created.
1558 @panic USER 18 if aMaxLength is negative.
1560 @see HBufC16::operator=()
1563 return static_cast<HBufC16*>(User::LeaveIfNull(NewMax(aMaxLength)));
1566 EXPORT_C HBufC16 *HBufC16::NewMaxLC(TInt aMaxLength)
1568 Creates, adds a pointer onto the cleanup stack and returns a pointer to, a
1569 new 16-bit heap descriptor; leaves on failure.
1571 No data is assigned into the new descriptor but its length
1572 is set to aMaxLength.
1574 Data can, subsequently, be assigned into it using the assignment operators.
1576 @param aMaxLength The requested maximum length of the descriptor. Note that
1577 the resulting heap cell size and, therefore, the resulting
1578 maximum length of the descriptor may be larger than requested.
1580 @return A pointer to the new 16-bit heap descriptor. This is also put onto
1581 the cleanup stack. The function leaves, if the new 16-bit heap descriptor
1584 @panic USER 18 if aMaxLength is negative.
1586 @see HBufC16::operator=()
1589 HBufC16* buf=NewMaxL(aMaxLength);
1590 CleanupStack::PushL(buf);
1594 EXPORT_C HBufC16 &HBufC16::operator=(const TUint16 *aString)
1596 Copies data into this 16-bit heap descriptor replacing any existing data.
1598 The length of this descriptor is set to reflect the new data.
1600 Note that the maximum length of this (target) descriptor is the length
1601 of the descriptor buffer in the allocated host heap cell; this may be greater
1602 than the maximum length specified when this descriptor was created or
1605 @param aString A pointer to a zero-terminated string.
1607 @return A reference to this 16-bit heap descriptor.
1609 @panic USER 11 if the length of the string, excluding the zero terminator,
1610 is greater than the maximum length of this (target) descriptor.
1614 __CHECK_ALIGNMENT(aString,EHBufC16AssignCString);
1615 Copy(aString,(STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
1619 EXPORT_C HBufC16 &HBufC16::operator=(const TDesC16 &aDes)
1621 Copies data into this 16-bit heap descriptor replacing any existing data.
1623 The length of this descriptor is set to reflect the new data.
1625 Note that the maximum length of this (target) descriptor is the length
1626 of the descriptor buffer in the allocated host heap cell; this may be greater
1627 than the maximum length specified when this descriptor was created or
1630 @param aDes A 16-bit non-modifiable descriptor.
1632 @return A reference to this 16-bit heap descriptor.
1634 @panic USER 11 if the length of the descriptor aDes is greater than the
1635 maximum length of this (target) descriptor
1639 Copy(aDes,(STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
1643 EXPORT_C HBufC16 *HBufC16::ReAlloc(TInt aMaxLength)
1645 Expands or contracts this 16-bit heap descriptor.
1649 1. creating a new heap descriptor.
1651 2. copying the original data into the new descriptor.
1653 3. deleting the original descriptor.
1655 @param aMaxLength The new requested maximum length of the descriptor.
1656 Note that the resulting heap cell size and, therefore,
1657 the resulting maximum length of the descriptor may be
1658 larger than requested.
1660 @return A pointer to the new expanded or contracted 16-bit heap descriptor -
1661 the original descriptor is deleted. NULL, if the new 16-bit heap descriptor
1662 cannot be created - the original descriptor remains unchanged.
1664 @panic USER 14 if aMaxLength is less than the length of the existing data.
1665 @panic USER 18 if aMaxLength is negative.
1669 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
1670 __ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes16ReAllocTooSmall));
1671 return((HBufC16 *)STD_CLASS::ReAlloc(this,(aMaxLength*sizeof(TUint16))+sizeof(TDesC16)));
1674 EXPORT_C HBufC16 *HBufC16::ReAllocL(TInt aMaxLength)
1676 Expands or contracts this 16-bit heap descriptor; leaves on failure.
1680 1. creating a new heap descriptor.
1682 2. copying the original data into the new descriptor.
1684 3. deleting the original descriptor.
1686 @param aMaxLength The new requested maximum length of the descriptor.
1687 Note that the resulting heap cell size and, therefore,
1688 the resulting maximum length of the descriptor may be
1689 larger than requested.
1691 @return A pointer to the new expanded or contracted 16-bit heap descriptor -
1692 the original descriptor is deleted. The function leaves, if the new
1693 16-bit heap descriptor cannot be created - the original descriptor
1696 @panic USER 14 if aMaxLength is less than the length of the existing data.
1697 @panic USER 18 if aMaxLength is negative.
1701 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
1702 __ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes16ReAllocTooSmall));
1703 return((HBufC16 *)STD_CLASS::ReAllocL(this,(aMaxLength*sizeof(TUint16))+sizeof(TDesC16)));
1706 EXPORT_C TPtr16 HBufC16::Des()
1708 Creates and returns a 16-bit modifiable pointer descriptor for the data
1709 represented by this 16-bit heap descriptor.
1711 The content of a heap descriptor normally cannot be altered, other than by
1712 complete replacement of the data. Creating a modifiable pointer descriptor
1713 provides a way of changing the data.
1715 The modifiable pointer descriptor is set to point to this heap descriptor's
1718 The length of the modifiable pointer descriptor is set to the length of this
1721 The maximum length of the modifiable pointer descriptor is set to the length
1722 of the heap descriptor's buffer. Note that the maximum length is the length
1723 of the descriptor buffer in the allocated host heap cell; this may be greater
1724 than the maximum length requested when this descriptor was originally created
1725 or last re-allocated.
1727 When data is modified through this new pointer descriptor, the lengths of
1728 both it and this heap descriptor are changed.
1730 Note that it is a common mistake to use Des() to create a TDesC16& reference.
1731 While not incorrect, it is simpler and much more efficient to simply dereference
1732 the heap descriptor.
1734 @return A 16-bit modifiable pointer descriptor representing the data in this
1735 16-bit heap descriptor.
1739 return DoDes((STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
1742 #ifndef __DES16_MACHINE_CODED__
1743 EXPORT_C void TDes16::SetLength(TInt aLength)
1745 Sets the length of the data represented by the descriptor to the
1748 @param aLength The new length of the descriptor.
1750 @panic USER 11 if aLength is negative or is greater than the maximum length of
1751 this (target) descriptor.
1755 __ASSERT_ALWAYS(TUint(aLength)<=TUint(MaxLength()),Panic(ETDes16Overflow));
1756 DoSetLength(aLength);
1757 if (Type()==EBufCPtr)
1758 ((SBufCPtr16 *)this)->ptr->length=aLength; // Relies on iType==0 for an TBufC
1761 EXPORT_C void TDes16::SetMax()
1763 Sets the length of the data to the maximum length of the descriptor.
1767 SetLength(iMaxLength);
1771 #ifndef __DES16_MACHINE_CODED_HWORD__
1772 EXPORT_C void TDes16::Copy(const TUint16 *aString)
1774 Copies data into this descriptor replacing any existing data.
1776 The length of this descriptor is set to reflect the new data.
1778 @param aString A pointer to a zero-terminated string.
1780 @panic USER 11 if the length of aString, excluding the zero terminator, is
1781 greater than the maximum length of this (target) descriptor.
1785 __CHECK_ALIGNMENT(aString,ETDes16CopyCString);
1786 TInt len=STRING_LENGTH_16(aString);
1788 memCopy(WPtr(),aString,len);
1792 #ifndef __DES16_MACHINE_CODED__
1793 EXPORT_C void TDes16::Copy(const TUint16 *aBuf,TInt aLength)
1795 Copies data into this descriptor replacing any existing data.
1797 The length of this descriptor is set to reflect the new data.
1799 @param aBuf The start address of data to be copied.
1800 @param aLength The length of data to be copied.
1802 @panic USER 11 if aLength is negative or is greater than maximum length
1803 of this (target) descriptor.
1807 __CHECK_ALIGNMENT(aBuf,ETDes16CopyBufLength);
1809 memCopy(WPtr(),aBuf,aLength);
1812 EXPORT_C void TDes16::Copy(const TDesC16 &aDes)
1814 Copies data into this descriptor replacing any existing data.
1816 The length of this descriptor is set to reflect the new data.
1818 @param aDes A 16-bit non modifiable descriptor.
1820 @panic USER 11 if the length of aDes is greater than the maximum length
1821 of this (target) descriptor.
1825 TInt len=aDes.Length();
1827 memCopy(WPtr(),aDes.Ptr(),len);
1831 EXPORT_C void TDes16::Copy(const TDesC8 &aDes)
1833 Copies data into this descriptor replacing any existing data.
1835 The length of this descriptor is set to reflect the new data.
1837 @param aDes An 8 bit non modifiable descriptor.
1839 @panic USER 11 if the length of aDes is greater than the maximum
1840 length of this (target) descriptor.
1844 TInt len=aDes.Length();
1846 const TUint8 *pS=aDes.Ptr();
1847 const TUint8 *pE=pS+len;
1853 #ifndef __DES16_MACHINE_CODED_HWORD__
1854 EXPORT_C void TDes16::Append(TChar aChar)
1856 Appends data onto the end of this descriptor's data.
1858 The length of this descriptor is incremented to reflect the new content.
1860 @param aChar A single character to be appended. The length of the descriptor
1861 is incremented by one.
1863 @panic USER 11 if the resulting new length of this descriptor is greater than
1869 TUint16 *pB=WPtr()+len;
1871 *pB++=(TUint16)aChar;
1875 #ifndef __DES16_MACHINE_CODED__
1876 EXPORT_C void TDes16::Append(const TUint16 *aBuf,TInt aLength)
1878 Appends data onto the end of this descriptor's data.
1880 The length of this descriptor is incremented to reflect the new content.
1882 @param aBuf A pointer to the data to be copied.
1883 @param aLength The length of data to be copied.
1885 @panic USER 11 if the resulting new length of this descriptor is greater than
1887 @panic USER 17 if aLength is negative.
1891 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
1892 __CHECK_ALIGNMENT(aBuf,ETDes16AppendBufLength);
1894 SetLength(len+aLength);
1895 memCopy(WPtr()+len,aBuf,aLength);
1898 EXPORT_C void TDes16::Append(const TDesC16 &aDes)
1900 Appends data onto the end of this descriptor's data.
1902 The length of this descriptor is incremented to reflect the new content.
1904 @param aDes A 16-bit non modifiable descriptor whose data is to be appended.
1906 @panic USER 11 if the resulting new length of this descriptor is greater than
1912 TInt n=aDes.Length();
1914 memCopy(WPtr()+len,aDes.Ptr(),n);
1918 EXPORT_C void TDes16::Swap(TDes16 &aDes)
1920 Swaps the data represented by this descriptor with the data represented by
1921 the specified descriptor.
1923 The lengths of both descriptors are also swapped to reflect the change.
1925 Note that each descriptor must be capable of accommodating the contents of
1926 the other descriptor.
1928 Each descriptor must be capable of accommodating the contents of the other
1929 descriptor. If the maximum length of either descriptor is smaller than the
1930 length of the other descriptor, then the function raises a USER 11 panic.
1932 @param aDes The 16-bit modifiable descriptor whose data is to be swapped with
1933 the data of this descriptor.
1935 @panic USER 11 if the maximum length of either descriptor is smaller than the
1936 length of the other descriptor.
1941 TInt r=aDes.Length();
1948 TUint16 *pR=aDes.WPtr();
1961 #ifndef __DES16_MACHINE_CODED_HWORD__
1962 EXPORT_C void TDes16::Fill(TChar aChar)
1964 Fills the descriptor's data area with the specified character, replacing any
1967 The descriptor is filled from the beginning up to its current length. The
1968 descriptor's length does not change. It is not filled to its maximum length.
1970 @param aChar The fill character.
1975 TUint16 *pE=pB+Length();
1977 *pB++=(TUint16)aChar;
1981 EXPORT_C void TDes16::Fill(TChar aChar,TInt aLength)
1983 Fills the descriptor's data area with the specified character, replacing any
1986 The descriptor is filled with the specified number of characters,
1987 and its length is changed to reflect this.
1989 @param aChar The fill character.
1990 @param aLength The new length of the descriptor and the number of fill characters
1991 to be copied into it.
1993 @panic USER 11 if aLength is negative or is greater than the maximum length
2002 EXPORT_C void TDes16::AppendFill(TChar aChar,TInt aLength)
2004 Appends and fills this descriptor with the specified character.
2006 The descriptor is appended with the specified number of characters.
2007 and its length is changed to reflect this.
2009 @param aChar The fill character.
2010 @param aLength The number of fill characters to be appended.
2012 @panic USER 11 if aLength is negative, or the resulting length of this
2013 descriptor is greater than its maximum length.
2018 TUint16 *pB=WPtr()+len;
2019 SetLength(len+aLength);
2020 TUint16 *pE=pB+aLength;
2022 *pB++=(TUint16)aChar;
2025 #ifndef __DES16_MACHINE_CODED_HWORD__
2026 EXPORT_C void TDes16::ZeroTerminate()
2028 Appends a zero terminator onto the end of this descriptor's data.
2030 The length of the descriptor is not changed. It must, however, be strictly less than
2031 the descriptor's maximum length.
2032 This condition guarantees that there is sufficient space for the zero terminator.
2034 @panic USER 11 if the descriptor's length is not strictly less than its
2040 __ASSERT_ALWAYS(len<MaxLength(),Panic(ETDes16Overflow));
2044 EXPORT_C const TUint16 *TDes16::PtrZ()
2046 Appends a zero terminator onto the end of this descriptor's data and returns
2047 a pointer to the data.
2049 The length of the descriptor is not changed. It must be strictly less than
2050 the descriptor's maximum length.
2051 This condition guarantees that there is sufficient space for the
2054 @return A pointer to the descriptor's zero terminated data.
2056 @panic USER 11 if the descriptor's length is not strictly less than its
2066 #ifndef __DES16_MACHINE_CODED__
2067 EXPORT_C void TDes16::Zero()
2069 Sets the length of the data to zero.
2077 #ifndef __DES16_MACHINE_CODED__
2078 EXPORT_C void TDes16::FillZ()
2080 Fills the descriptor's data area with binary zeroes, i.e.0x0000, replacing any
2083 The descriptor is filled from the beginning up to its current length. The
2084 descriptor's length does not change. It is not filled to its maximum length.
2088 memclr(WPtr(),Length()*2);
2092 EXPORT_C void TDes16::FillZ(TInt aLength)
2094 Fills the descriptor's data area with binary zeroes, i.e. 0x0000, replacing any
2095 existing data, and changes its length.
2097 The descriptor is filled with the specified number of binary zeroes.
2098 The descriptor's length is changed to reflect this.
2100 @param aLength The new length of the descriptor and the number of binary zeroes
2101 to be copied into it.
2103 @panic USER 11 if aLength is negative, or is greater than the maximum length
2112 EXPORT_C void TDes16::Fold()
2114 Performs folding on the content of this descriptor.
2116 Note that folding is locale-independent behaviour. It is also important to
2117 note that there can be no guarantee that folding is in any way culturally
2118 appropriate, and should not be used when dealing with strings in natural
2132 EXPORT_C void TDes16::Collate()
2134 Performs collation on the content of this descriptor.
2142 TChar c=User::Collate(*pB);
2147 EXPORT_C void TDes16::LowerCase()
2149 Converts the content of this descriptor to lower case.
2151 Conversion is implemented as appropriate to the current locale.
2164 EXPORT_C void TDes16::UpperCase()
2166 Converts the content of this descriptor to upper case.
2168 Conversion is implemented as appropriate to the current locale.
2181 EXPORT_C void TDes16::Capitalize()
2183 Capitalises the content of this descriptor.
2185 Capitalisation is implemented as appropriate to the current locale.
2193 *pB=(TUint16)User::TitleCase(*pB);
2197 *pB=(TUint16)User::LowerCase(*pB);
2203 EXPORT_C void TDes16::CopyF(const TDesC16 &aDes)
2205 Copies and folds data from the specified descriptor into this descriptor replacing
2208 The length of this descriptor is set to reflect the new
2211 Note that folding is locale-independent behaviour. It is also important to
2212 note that there can be no guarantee that folding is in any way culturally
2213 appropriate, and should not be used when dealing with strings in natural
2216 @param aDes A 16-bit non-modifiable descriptor.
2218 @panic USER 11 if the length of aDes is greater than the maximum length of
2219 this target descriptor.
2223 TInt len=aDes.Length();
2225 const TUint16 *pS=aDes.Ptr();
2234 EXPORT_C void TDes16::CopyC(const TDesC16 &aDes)
2236 Copies and collates data from the specified descriptor
2237 into this descriptor replacing any existing data.
2239 The length of this descriptor is set to reflect the new data.
2241 @param aDes A 16-bit non-modifiable descriptor.
2243 @panic USER 11 if the length of aDes is greater than the maximum length of
2244 this target descriptor.
2248 TInt len=aDes.Length();
2250 const TUint16 *pS=aDes.Ptr();
2254 TChar c=User::Collate(*pS++);
2259 EXPORT_C void TDes16::CopyLC(const TDesC16 &aDes)
2261 Copies text from the specified descriptor and converts it to lower case before
2262 putting it into this descriptor, replacing any existing data.
2264 The length of this descriptor is set to reflect the new data.
2266 Conversion to lower case is implemented as appropriate to the current locale.
2268 @param aDes A 16-bit non modifiable descriptor.
2270 @panic USER 11 if the length of aDes is greater than the maximum length of
2271 this target descriptor.
2275 TInt len=aDes.Length();
2277 const TUint16 *pS=aDes.Ptr();
2286 EXPORT_C void TDes16::CopyUC(const TDesC16 &aDes)
2288 Copies text from the specified descriptor and converts it to upper case before
2289 putting it into this descriptor, replacing any existing data.
2291 The length of this descriptor is set to reflect the new data.
2293 Conversion to upper case is implemented as appropriate to the current locale.
2295 @param aDes A 16-bit non modifiable descriptor.
2297 @panic USER 11 if the length of aDes is greater than the maximum length of
2298 this target descriptor.
2302 TInt len=aDes.Length();
2304 const TUint16 *pS=aDes.Ptr();
2313 EXPORT_C void TDes16::CopyCP(const TDesC16 &aDes)
2315 Copies text from the specified descriptor and capitalises it before putting
2316 it into this descriptor, replacing any existing data.
2318 The length of this descriptor is set to reflect the new data.
2320 Capitalisation is implemented as appropriate to the current locale.
2322 @param aDes A 16-bit non-modifiable descriptor.
2324 @panic USER 11 if the length of aDes is greater than the maximum length of
2325 this target descriptor.
2329 TInt len=aDes.Length();
2331 const TUint16 *pS=aDes.Ptr();
2350 EXPORT_C void TDes16::Repeat(const TUint16 *aBuf,TInt aLength)
2352 Copies data with repetition into this descriptor, from a memory location
2353 specified by pointer, replacing any existing data.
2355 Copying proceeds until this descriptor is filled up to its current length.
2356 If it cannot contain a whole number of copies of the source data, then the
2357 last copy is truncated.
2359 @param aBuf A pointer to data to be repeatedly copied.
2360 @param aLength The length of data to be copied.
2362 @panic USER 17 if aLength is negative.
2366 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
2367 __CHECK_ALIGNMENT(aBuf,ETDes16RepeatBufLength);
2374 TInt i=Min(len,aLength);
2375 pB=memCopy(pB,aBuf,i);
2381 EXPORT_C void TDes16::Repeat(const TDesC16 &aDes)
2383 Copies data with repetition into this descriptor, from another descriptor,
2384 replacing any existing data.
2386 Copying proceeds until this descriptor is filled up to its current length.
2387 If it cannot contain a whole number of copies of the source data, then the
2388 last copy is truncated.
2390 @param aDes A 16-bit non modifiable descriptor whose data is to be repeatedly
2395 Repeat(aDes.Ptr(),aDes.Length());
2398 EXPORT_C void TDes16::Trim()
2400 Deletes leading and trailing whitespace characters from the descriptor's data.
2402 The length of the descriptor is reduced to reflect the loss of the whitespace characters.
2404 @see TDes16::TrimLeft()
2405 @see TDes16::TrimRight()
2413 EXPORT_C void TDes16::TrimAll()
2415 Deletes leading and trailing whitespace characters from the descriptor's data
2416 and replaces each contiguous set of whitespace characters within the data by one
2417 whitespace character.
2419 The length of the descriptor is reduced to reflect the loss of the whitespace
2428 TUint16 *pBuf=(TUint16 *)Ptr();
2454 Delete(pDst-pBuf, pSrc-pDst);
2457 EXPORT_C void TDes16::TrimLeft()
2459 Deletes leading whitespace characters from the descriptor's data.
2461 All whitespace characters up to, but not including the first
2462 non-whitespace character, are deleted.
2464 The length of the descriptor is reduced to reflect the loss
2465 of the whitespace characters.
2469 const TUint16 *pBuf=Ptr();
2470 const TUint16 *pB=pBuf;
2482 EXPORT_C void TDes16::TrimRight()
2484 Deletes trailing whitespace characters from the descriptor's data.
2486 The process starts on the right hand side of the descriptor's data
2487 and proceeds to the left.
2489 All whitespace characters up to, but not including the first non-whitespace character,
2492 The length of the descriptor is reduced to reflect the loss of the whitespace
2500 const TUint16 *pB=Ptr()+len-1;
2512 EXPORT_C void TDes16::Insert(TInt aPos,const TDesC16 &aDes)
2514 Inserts data into this descriptor.
2516 The length of this descriptor is changed to reflect the extra data.
2518 @param aPos The position within the data where insertion is to start. This
2519 is an offset value; a zero value refers to the leftmost data
2522 @param aDes A 16-bit non modifiable descriptor whose data is to be inserted.
2524 @panic USER 10 if aPos is negative or is greater than the length of this
2526 @panic USER 11 if the resulting length of this descriptor is greater than its
2532 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
2533 TInt s=aDes.Length();
2534 __ASSERT_ALWAYS((len+s)<=MaxLength(),Panic(ETDes16Overflow));
2536 memCopy(pB+aPos+s,pB+aPos,len-aPos);
2537 memCopy(pB+aPos,aDes.Ptr(),aDes.Length());
2541 EXPORT_C void TDes16::Delete(TInt aPos,TInt aLength)
2543 Deletes data from this descriptor.
2545 The length of this descriptor is changed to reflect the loss of data.
2547 @param aPos The position within the data where deletion is to start. This
2548 is an offset value; a zero value refers to the leftmost data
2551 @param aLength The length of data to be deleted. If necessary, the function
2552 adjusts this value to ensure that no data beyond the end of
2553 the descriptor data area is deleted.
2555 @panic USER 10 if aPos is negative or is greater than the length of this
2561 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
2562 TInt d=Min(len-aPos,aLength);
2564 memCopy(pB+aPos,pB+aPos+d,len-aPos-d);
2568 EXPORT_C void TDes16::Replace(TInt aPos,TInt aLength,const TDesC16 &aDes)
2570 Replaces data in this descriptor.
2572 The specified length can be different to the length of the replacement data.
2573 The length of this descriptor changes to reflect the change of data.
2575 @param aPos The position within the data where replacement is to start.
2576 This is an offset value; a zero value refers to the leftmost
2579 @param aLength The length of data to be replaced.
2581 @param aDes The source 16-bit non modifiable descriptor whose data is to
2582 replace the target descriptor's data at aPos.
2584 @panic USER 8 if aLength is negative or the sum of aLength and aPos is
2585 greater than the length of this descriptor.
2587 @panic USER 10 if aPos is negative or is greater than the length of this
2590 @panic USER 11 if the resulting length of this descriptor is greater than its
2593 @panic USER 16 if the length of the source descriptor aDes is negative or is
2594 greater than the maximum length of this target descriptor,
2599 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
2600 __ASSERT_ALWAYS(aLength>=0 && aPos+aLength<=len,Panic(ETDes16LengthOutOfRange));
2601 TInt s=aDes.Length();
2602 TInt maxlen=MaxLength();
2603 __ASSERT_ALWAYS(s>=0 && s<=maxlen,Panic(ETDes16RemoteLengthOutOfRange));
2604 __ASSERT_ALWAYS((len+s-aLength)<=maxlen,Panic(ETDes16Overflow));
2606 memCopy(pB+aPos+s,pB+aPos+aLength,len-aPos-aLength);
2607 memCopy(pB+aPos,aDes.Ptr(),s);
2608 SetLength(len+s-aLength);
2611 EXPORT_C void TDes16::Justify(const TDesC16 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
2613 Copies data into this descriptor and justifies it, replacing any existing data.
2615 The length of this descriptor is set to reflect the new data.
2617 The target area is considered to be an area of specified width positioned at
2618 the beginning of this descriptor's data area. Source data is copied into, and
2619 aligned within this target area according to the specified alignment
2622 If the length of the target area is larger than the length of the source, then
2623 spare space within the target area is padded with the fill character.
2625 @param aDes A 16-bit non-modifiable descriptor containing the source data.
2626 The length of the data to be copied is the smaller of:
2627 the length of the source descriptor, and
2628 the width of the target area (only if this is not the
2629 explicit negative value KDefaultJustifyWidth).
2631 @param aWidth The width of the target area. If this has the specific
2632 negative value KDefaultJustifyWidth, then the width is
2633 re-set to the length of the data source.
2635 @param anAlignment The alignment of the data within the target area
2637 @param aFill The fill character used to pad the target area.
2639 @panic USER 11 if the resulting length of this descriptor is greater than
2640 its maximum length or aWidth has a negative value other
2641 than KDefaultJustifyWidth.
2646 AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
2649 EXPORT_C void TDes16::AppendJustify(const TDesC16 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
2651 Appends data onto the end of this descriptor's data and justifies it.
2653 The source of the appended data is an existing descriptor.
2655 The target area is considered to be an area of specified width, immediately
2656 following this descriptor's existing data. Source data is copied into, and
2657 aligned within this target area according to the specified alignment instruction.
2659 If the length of the target area is larger than the length of the source,
2660 then spare space within the target area is padded with the fill character.
2662 @param aDes A 16-bit non-modifiable descriptor containing the source
2663 data. The length of the data to be copied is the smaller of:
2664 the length of the source descriptor, and
2665 the width of the target area (only if this is not the
2666 explicit negative value KDefaultJustifyWidth).
2668 @param aWidth The width of the target area. If this has the specific
2669 negative value KDefaultJustifyWidth, then the width is
2670 re-set to the length of the data source.
2672 @param anAlignment The alignment of the data within the target area.
2674 @param aFill The fill character used to pad the target area.
2676 @panic USER 11 if the resulting length of this descriptor is greater than
2677 its maximum length or aWidth has a negative value other
2678 than KDefaultJustifyWidth.
2682 AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
2685 EXPORT_C void TDes16::AppendJustify(const TDesC16 &aDes,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
2687 Appends data onto the end of this descriptor's data and justifies it.
2689 The source of the appended data is an existing descriptor.
2691 The target area is considered to be an area of specified width, immediately
2692 following this descriptor's existing data. Source data is copied into, and
2693 aligned within this target area according to the specified alignment instruction.
2695 If the length of the target area is larger than the length of the source,
2696 then spare space within the target area is padded with the fill character.
2698 @param aDes An 8-bit non-modifiable descriptor containing the source data.
2700 @param aLength The length of data to be copied from the source descriptor.
2701 If this is greater than the width of the target area, then
2702 the length of data copied is limited to the width.
2703 The length of data to be copied must not be greater than
2704 the length of the source descriptor. Note that this
2705 condition is not automatically tested.
2707 @param aWidth The width of the target area. If this has the specific negative
2708 value KDefaultJustifyWidth, then the width is
2709 re-set to the length of the data source.
2711 @param anAlignment The alignment of the data within the target area.
2713 @param aFill The fill character used to pad the target area.
2715 @panic USER 11 if the resulting length of this descriptor is greater than
2716 its maximum length or aWidth has a negative value other
2717 than KDefaultJustifyWidth.
2721 AppendJustify(aDes.Ptr(),aLength,aWidth,anAlignment,aFill);
2724 EXPORT_C void TDes16::AppendJustify(const TUint16 *aString,TInt aWidth,TAlign anAlignment,TChar aFill)
2726 Appends a zero terminated string onto the end of this descriptor's data and
2729 The zero terminator is not copied.
2731 The target area is considered to be an area of specified width, immediately
2732 following this descriptor's existing data. Source data is copied into, and
2733 aligned within, this target area according to the specified alignment instruction.
2735 If the length of the target area is larger than the length of the source,
2736 then spare space within the target area is padded with the fill character.
2738 @param aString A pointer to a zero terminated string The length of the data
2739 to be copied is the smaller of: the length of the string (excluding the zero
2740 terminator), the width of the target area (only if this is not the explicit
2741 negative value KDefaultJustifyWidth).
2743 @param aWidth The width of the target area. If this has the specific negative
2744 value KDefaultJustifyWidth, then the width is re-set to the length of the
2745 zero terminated string (excluding the zero terminator).
2747 @param anAlignment The alignment of the data within the target area.
2749 @param aFill The fill character used to pad the target area.
2751 @panic USER 11 if the resulting length of this descriptor is greater than
2752 its maximum length or aWidth has a negative value other
2753 than KDefaultJustifyWidth.
2757 __CHECK_ALIGNMENT(aString,ETDes16AppendJustify1);
2758 AppendJustify(aString,STRING_LENGTH_16(aString),aWidth,anAlignment,aFill);
2761 EXPORT_C void TDes16::AppendJustify(const TUint16 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
2763 Appends data onto the end of this descriptor's data and justifies it.
2765 The source of the appended data is a memory location.
2767 The target area is considered to be an area of specified width, immediately
2768 following this descriptor's existing data. Source data is copied into, and
2769 aligned within, this target area according to the specified alignment instruction.
2771 If the length of the target area is larger than the length of the source,
2772 then spare space within the target area is padded with the fill character.
2774 @param aString A pointer to a source memory location.
2776 @param aLength The length of data to be copied. If this is greater than the
2777 width of the target area, then the length of data copied is
2778 limited to the width.
2780 @param aWidth The width of the target area. If this has the specific negative
2781 value KDefaultJustifyWidth, then the width is
2782 re-set to the length of the data source.
2784 @param anAlignment The alignment of the data within the target area.
2786 @param aFill The fill character used to pad the target area.
2788 @panic USER 11 if the resulting length of this descriptor is greater than
2789 its maximum length or aWidth has a negative value other
2790 than KDefaultJustifyWidth.
2792 @panic USER 17 if aLength is negative.
2796 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
2797 __CHECK_ALIGNMENT(aString,ETDes16AppendJustify2);
2798 if (aWidth==KDefaultJustifyWidth)
2802 TInt offset=Length();
2803 AppendFill(aFill,aWidth);
2804 TInt r=aWidth-aLength;
2805 if (anAlignment==ECenter)
2807 else if (anAlignment==ELeft)
2809 memCopy(WPtr()+offset+r,aString,aLength);
2812 EXPORT_C void TDes16::NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
2814 Converts the specified unsigned integer into a fixed width character
2815 representation based on the specified number system and copies the conversion
2816 into this descriptor, replacing any existing data.
2818 The length of this descriptor is set to reflect the new data.
2820 The function generates the exact number of specified characters, either padding
2821 to the left with character zeroes or discarding low order characters as necessary.
2823 When a hexadecimal conversion is specified, hexadecimal characters are in
2826 This function is equivalent to using Format() with parameters which specify:
2828 1. a fixed length target field
2830 2. padding with zero characters, for example "%08x".
2832 When this is the case, always use NumFixedWidth() in preference
2833 to Format() as it is more efficient.
2835 @param aVal The unsigned integer value.
2836 @param aRadix The number system representation for the unsigned integer.
2837 @param aWidth The number of characters: to be used to contain the conversion,
2838 to be copied into this descriptor.
2843 AppendNumFixedWidth(aVal,aRadix,aWidth);
2846 EXPORT_C void TDes16::NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
2848 Converts the specified unsigned integer into a fixed width character
2849 representation based on the specified number system and copies the conversion
2850 into this descriptor, replacing any existing data.
2852 The length of this descriptor is set to reflect the new data.
2854 The function generates the exact number of specified characters, either padding
2855 to the left with character zeroes or discarding low order characters as
2858 When a hexadecimal conversion is specified, hexadecimal characters are in
2861 This function is equivalent to using Format() with parameters which specify:
2863 1. a fixed length target field
2865 2. padding with zero characters, for example "%08x".
2867 When this is the case, always use NumFixedWidthUC() in
2868 preference to Format() as it is more efficient.
2870 @param aVal The unsigned integer value.
2871 @param aRadix The number system representation for the unsigned integer.
2872 @param aWidth The number of characters: to be used to contain the conversion,
2873 to be copied into this descriptor.
2875 @see TDes16::Format()
2880 AppendNumFixedWidthUC(aVal,aRadix,aWidth);
2883 EXPORT_C void TDes16::Num(TInt64 aVal)
2885 Converts the 64-bit signed integer into a decimal character representation
2886 and copies the conversion into this descriptor, replacing any existing data.
2888 The length of this descriptor is set to reflect the new data.
2890 If the integer is negative, the character representation is prefixed by a
2893 @param aVal The 64-bit signed integer value.
2900 EXPORT_C void TDes16::Num(TUint64 aVal, TRadix aRadix)
2902 Converts the specified 64 bit unsigned integer into a character representation
2903 based on the specified number system and copies the conversion into this
2904 descriptor, replacing any existing data.
2906 The length of this descriptor is set to reflect the new data.
2908 When a hexadecimal conversion is specified, hexadecimal characters are in
2911 @param aVal The 64 bit integer value. This is treated as an unsigned
2912 value for all builds.
2913 @param aRadix The number system representation for the 64 bit integer.
2918 AppendNum(aVal,aRadix);
2921 EXPORT_C void TDes16::NumUC(TUint64 aVal, TRadix aRadix)
2923 Converts the specified 64 bit unsigned integer into a character representation
2924 based on the specified number system and copies the conversion into this
2925 descriptor, replacing any existing data.
2927 The length of this descriptor is set to reflect the new data.
2929 When a hexadecimal conversion is specified, hexadecimal characters are in
2932 @param aVal The 64 bit integer value. This is always treated as an unsigned
2933 value for all builds.
2934 @param aRadix The number system representation for the 64 bit integer. If no
2935 explicit value is specified, then EDecimal is the default.
2940 AppendNumUC(aVal,aRadix);
2943 void TDes16::DoPadAppendNum(TInt l, TInt aW, const TUint8* p)
2945 __ASSERT_DEBUG( ((l|(TInt)p)&1)==0, Panic(EDes16PadAppendBadAlign));
2949 Append((const TUint16*)p, l);
2954 TUint16* d = WPtr() + l0;
2955 for (; aW>l; --aW) *d++ = (TUint16)'0';
2959 EXPORT_C void TDes16::AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
2961 Converts the specified unsigned integer into a fixed width character
2962 representation based on the specified number system and appends the conversion
2963 onto the end of this descriptor's data.
2965 The length of this descriptor is incremented to reflect the new content.
2967 The function generates the exact number of specified characters, either padding
2968 to the left with character zeroes or discarding low order characters as
2971 When a hexadecimal conversion is specified, hexadecimal characters are in
2974 @param aVal The unsigned integer value.
2975 @param aRadix The number system representation for the unsigned integer.
2976 @param aWidth The number of characters to be used to contain the conversion,
2977 and to be appended to this descriptor.
2982 buf.Num(aVal,aRadix);
2983 if (buf.Length()>=aWidth)
2984 Append(buf.Left(aWidth));
2987 TInt i=aWidth-buf.Length();
2994 #ifndef __DES16_MACHINE_CODED__
2995 EXPORT_C TPtr16 TDes16::LeftTPtr(TInt aLength) const
2997 Extracts the leftmost part of the data.
2999 The function does not cut or remove any data but constructs a modifiable pointer
3000 descriptor to represent the leftmost part of the data.
3002 @param aLength The length of the data to be extracted. If this value is
3003 greater than the length of the descriptor, the function
3004 extracts the whole of the descriptor.
3006 @return The 16-bit modifiable pointer descriptor representing the leftmost part
3009 @panic USER 10 if aLength is negative.
3013 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
3014 TInt len = Min(aLength,Length());
3015 return(TPtr16((TUint16*)Ptr(),len,len));
3018 EXPORT_C TPtr16 TDes16::RightTPtr(TInt aLength) const
3020 Extracts the rightmost part of the data.
3022 The function does not cut or remove any data but constructs a modifiable pointer
3023 descriptor to represent the rightmost part of the data.
3025 @param aLength The length of data to be extracted. If this value
3026 is greater than the length of the descriptor, the function
3027 extracts the whole of the descriptor.
3029 @return The 16-bit modifiable pointer descriptor representing the rightmost part
3032 @panic USER 10 if aLength is negative.
3036 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
3040 return(TPtr16((TUint16*)Ptr()+len-aLength,aLength,aLength));
3043 EXPORT_C TPtr16 TDes16::MidTPtr(TInt aPos) const
3045 Extracts a portion of the data.
3047 The function does not cut or remove any data but constructs a modifiable pointer
3048 descriptor to represent the defined portion.
3050 The portion is identified by its starting position and by the length of the
3051 remainder of the data starting from the specified position.
3053 @param aPos The starting position of the data to be extracted. This is an
3054 offset value; a zero value refers to the leftmost data position.
3056 @return The 16-bit modifiable pointer descriptor representing the specified
3057 portion of the data.
3059 @panic USER 10 if aPos is negative or aPos is greater than the
3060 length of the descriptor.
3065 __ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
3066 return(TPtr16((TUint16*)Ptr()+aPos,len-aPos,len-aPos));
3069 EXPORT_C TPtr16 TDes16::MidTPtr(TInt aPos,TInt aLength) const
3071 Extracts a portion of the data.
3073 The function does not cut or remove any data but constructs a modifiable pointer
3074 descriptor to represent the defined portion.
3076 The portion is identified by its starting position and by its length.
3078 @param aPos The starting position of the data to be extracted. This is an
3079 offset value; a zero value refers to the leftmost data position.
3080 @param aLength The length of data to be extracted.
3082 @return The 16-bit modifiable pointer descriptor representing the specified
3083 portion of the data.
3085 @panic USER 10 if aPos is negative or aPos plus aLength is greater than the
3086 length of the descriptor.
3090 __ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes16PosOutOfRange));
3091 return(TPtr16((TUint16*)Ptr()+aPos,aLength,aLength));
3095 EXPORT_C void TDes16::AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
3097 Converts the specified unsigned integer into a fixed width character
3098 representation based on the specified number system and appends the conversion
3099 onto the end of this descriptor's data.
3101 The length of this descriptor is incremented to reflect the new content.
3103 The function generates the exact number of specified characters, either
3104 padding to the left with character zeroes or discarding low order characters
3107 When a hexadecimal conversion is specified, hexadecimal characters are in
3110 @param aVal The unsigned integer value.
3111 @param aRadix The number system representation for the unsigned integer.
3112 @param aWidth The number of characters: to be used to contain the conversion,
3113 to be appended to this descriptor.
3118 buf.NumUC(aVal,aRadix);
3119 if (buf.Length()>=aWidth)
3120 Append(buf.Left(aWidth));
3123 TInt i=aWidth-buf.Length();
3130 EXPORT_C void TDes16::AppendNum(TInt64 aVal)
3132 Converts the 64-bit signed integer into a decimal character representation
3133 and appends the conversion onto the end of this descriptor's data.
3135 The length of this descriptor is incremented to reflect the new content.
3137 If the integer is negative, the character representation is prefixed by a
3140 @param aVal The 64-bit signed integer value.
3149 AppendNum(static_cast<TUint64>(aVal), EDecimal);
3152 void TDes16::DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW)
3154 // Convert a TUint64 into the descriptor.
3158 TUint16 buf[APPEND_BUF_SIZE_64];
3159 TUint8* p = (TUint8*)(buf + APPEND_BUF_SIZE_64);
3160 TInt l = __DoConvertNum(aVal, aRadix, aA|256, p);
3161 // coverity[overrun-local]
3162 DoPadAppendNum(l, aW, p);
3165 EXPORT_C void TDes16::AppendNum(TUint64 aVal, TRadix aRadix)
3167 Converts the specified 64 bit integer into a character representation
3168 based on the specified number system and appends the conversion onto the end
3169 of this descriptor's data.
3171 The length of this descriptor is incremented to reflect the new content.
3173 When a hexadecimal conversion is specified, hexadecimal characters are in
3176 @param aVal The 64 bit integer value. This is always treated as an unsigned
3178 @param aRadix The number system representation for the 64 bit integer.
3181 DoAppendNum(aVal, aRadix, 'a', 0);
3184 EXPORT_C void TDes16::AppendNumUC(TUint64 aVal,TRadix aRadix)
3186 Converts the specified 64 bit integer into a character representation
3187 based on the specified number system and appends the conversion onto the end
3188 of this descriptor's data.
3190 The length of this descriptor is incremented to reflect the new content.
3192 When a hexadecimal conversion is specified, hexadecimal characters are in
3195 @param aVal The 64 bit integer value. This is always treated as an unsigned
3197 @param aRadix The number system representation for the 64 bit integer. If no
3198 explicit value is specified, then EDecimal is the default.
3202 DoAppendNum(aVal, aRadix, 'A', 0);
3205 EXPORT_C void TDes16::Format(TRefByValue<const TDesC16> aFmt,...)
3207 Formats and copies text into this descriptor, replacing any existing data.
3209 The length of this descriptor is set to reflect the new data.
3211 The function takes a format string and a variable number of arguments.
3212 The format string contains literal text embedded with directives for converting
3213 the trailing list of arguments into text.
3215 The embedded directives are character sequences prefixed with the '%' character.
3216 The literal text is simply copied into this descriptor unaltered while
3217 the '%' directives are used to convert successive arguments from the
3220 The resulting stream of literal text and converted arguments is copied into
3223 The syntax of the embedded directives follows one of four general patterns.
3225 Note that formatting of single numerical values can be achieved more
3226 conveniently using the Num() and NumUC() member functions of this class.
3228 The full description of the syntax of a format string cannot be included here.
3229 For full details, navigate to the Symbian OS guide, and follow the hierarchy of links:
3234 Using User Library (E32)
3237 How to Use Descriptors
3238 Format string syntax
3241 @param aFmt The descriptor containing the format string.
3242 The TRefByValue class provides a constructor which takes a
3245 @param ... A variable number of arguments to be converted to text as
3246 dictated by the format string.
3248 @panic USER 11 if the resulting length of text in this descriptor exceeds
3249 the descriptor's maximum length.
3250 @panic USER 12 if the format string has incorrect syntax.
3253 @see TDes16::NumUC()
3258 VA_START(list,aFmt);
3259 // coverity[uninit_use_in_call]
3260 FormatList(aFmt,list);
3263 EXPORT_C void TDes16::FormatList(const TDesC16 &aFmt,VA_LIST aList)
3265 Formats and copies text into this descriptor, replacing any existing data.
3267 The length of this descriptor is set to reflect the new data.
3269 The behaviour of this function is the same as Format(). In practice, it is
3270 better and easier to use Format(), passing a variable number of arguments
3271 as required by the format string.
3273 @param aFmt The descriptor containing the format string.
3274 @param aList A pointer to an argument list.
3276 @see TDes16::Format()
3282 AppendFormatList(aFmt,aList);
3285 EXPORT_C void TDes16::AppendFormat(TRefByValue<const TDesC16> aFmt,TDes16Overflow *aOverflowHandler,...)
3287 Formats and appends text onto the end of this descriptor's data.
3289 The length of this descriptor is incremented to reflect the new content.
3291 The function takes a format string and a variable number of arguments.
3292 The format string contains literal text, embedded with directives,
3293 for converting the trailing list of arguments into text.
3295 The embedded directives are character sequences prefixed with the '%' character.
3296 The literal text is simply copied into this descriptor unaltered while
3297 the '%' directives are used to convert successive arguments from the
3298 trailing list. See the description of the Format() function.
3300 Literal text is appended on a character by character basis.
3301 If it results in the length of this descriptor exceeding its maximum length,
3304 1. calls the Overflow() member function of the overflow handler, if an overflow
3306 2 raises a USER 11 panic, if no overflow handler is supplied.
3308 As much literal text as possible will have been copied into this descriptor
3309 and this descriptor will have reached its maximum length.
3311 Text converted from a trailing argument is appended as a complete string.
3312 If an attempt to append this string fails because the resulting length
3313 of this descriptor would exceed its maximum length, then the function:
3315 1. calls the Overflow() member function of the overflow handler, if an overflow
3318 2 raises a USER 11 panic, if no overflow handler is supplied.
3320 None of the generated text is appended and length of this descriptor
3321 may be less than the maximum.
3323 @param aFmt The 16-bit non-modifiable descriptor containing the
3324 format string. The TRefByValue class provides a
3325 constructor which takes a TDesC16 type.
3327 @param aOverflowHandler A pointer to the overflow handler.
3329 @param ... A variable number of arguments to be converted to text
3330 as dictated by the format string.
3332 @panic USER 11 if the length of the descriptor exceeds its maximum length and
3333 no overflow handler has been supplied.
3334 @panic USER 12 if the format string has incorrect syntax.
3336 @see TDes16::Format()
3337 @see TDes16Overflow::Overflow()
3342 VA_START(list, aOverflowHandler);
3343 // coverity[uninit_use_in_call]
3344 AppendFormatList(aFmt,list,aOverflowHandler);
3347 EXPORT_C void TDes16::AppendFormat(TRefByValue<const TDesC16> aFmt,...)
3349 Formats and appends text onto the end of this descriptor's data.
3351 The length of this descriptor is incremented to reflect the new content.
3353 The function takes a format string and a variable number of arguments.
3354 The format string contains literal text, embedded with directives,
3355 for converting the trailing list of arguments into text.
3357 The embedded directives are character sequences prefixed with the '%' character.
3358 The literal text is simply copied into this descriptor unaltered while
3359 the '%' directives are used to convert successive arguments from the
3360 trailing list. See the description of the Format() function.
3362 Literal text is appended on a character by character basis.
3364 Text converted from a trailing argument is appended as a complete string.
3366 @param aFmt The 16-bit non-modifiable descriptor containing the
3367 format string. The TRefByValue class provides a
3368 constructor which takes a TDesC16 type.
3370 @param ... A variable number of arguments to be converted to text
3371 as dictated by the format string.
3373 @panic USER 11 if the resulting length of text in this descriptor exceeds
3374 the descriptor's maximum length.
3375 @panic USER 12 if the format string has incorrect syntax.
3377 @see TDes16::Format()
3382 VA_START(list,aFmt);
3383 AppendFormatList(aFmt,list);
3386 #if !defined(__DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
3387 EXPORT_C TPtrC16::TPtrC16()
3388 : TDesC16(EPtrC,0),iPtr(0)
3390 Constructs an empty 16-bit non-modifiable pointer descriptor.
3392 It represents no data and its length is zero.
3394 The non-modifiable pointer descriptor can, subsequently, be set to represent
3401 EXPORT_C TPtrC16::TPtrC16(const TDesC16 &aDes)
3402 : TDesC16(EPtrC,aDes.Length()),iPtr(aDes.Ptr())
3404 Constructs the 16-bit non-modifiable pointer descriptor from any existing
3407 It is set to point to the same data and is given the same length as the source
3410 @param aDes A reference to a 16-bit non-modifiable descriptor.
3415 #if !defined(__DES16_MACHINE_CODED_HWORD__) | defined(__EABI_CTORS__)
3416 EXPORT_C TPtrC16::TPtrC16(const TUint16 *aString)
3417 : TDesC16(EPtrC,STRING_LENGTH_16(aString)),iPtr(aString)
3419 Constructs the 16-bit non-modifiable pointer descriptor to point to a zero
3420 terminated string, whether in RAM or ROM.
3422 The length of the descriptor is set to the length of the zero terminated string,
3423 excluding the zero terminator.
3425 @param aString A pointer to a zero terminated string.
3428 __CHECK_ALIGNMENT(aString,ETDesC16ConstructCString);
3432 #if !defined(__DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
3433 EXPORT_C TPtrC16::TPtrC16(const TUint16 *aBuf,TInt aLength)
3434 : TDesC16(EPtrC,aLength),iPtr(aBuf)
3436 Constructs the 16-bit non-modifiable pointer descriptor to point to the
3437 specified location in memory, whether in RAM or ROM.
3439 The length of the descriptor is set to the specified length.
3441 @param aBuf A pointer to the location that the descriptor is to represent.
3442 @param aLength The length of the descriptor.This value must be non-negative.
3444 @panic USER 17 if aLength is negative.
3447 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
3448 __CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLength);
3451 EXPORT_C TPtr16::TPtr16(TUint16 *aBuf,TInt aMaxLength)
3452 : TDes16(EPtr,0,aMaxLength),iPtr(aBuf)
3454 Constructs the 16-bit modifiable pointer descriptor to point to the specified
3455 location in memory, whether in RAM or ROM.
3457 The length of the descriptor is set to zero, and its maximum length is set to
3458 the specified value.
3460 @param aBuf A pointer to the location that the descriptor is to represent.
3461 @param aMaxLength The maximum length of the descriptor.
3463 @panic USER 18 if aMaxLength is negative.
3466 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3467 __CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLengthMax);
3470 EXPORT_C TPtr16::TPtr16(TUint16 *aBuf,TInt aLength,TInt aMaxLength)
3471 : TDes16(EPtr,aLength,aMaxLength),iPtr(aBuf)
3473 Constructs the 16-bit modifiable pointer descriptor to point to the specified
3474 location in memory, whether in RAM or ROM.
3476 The length of the descriptor and its maximum length are set to the specified
3479 @param aBuf A pointer to the location that the descriptor is to represent.
3480 @param aLength The length of the descriptor.
3481 @param aMaxLength The maximum length of the descriptor.
3483 @panic USER 8 if aLength is negative, or is greater than the descriptor's
3486 @panic USER 18 if aMaxLength is negative.
3489 __ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3490 __ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes16LengthOutOfRange));
3491 __CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLengthMax);
3494 EXPORT_C TBufBase16::TBufBase16(TInt aMaxLength)
3495 :TDes16(EBuf,0,aMaxLength)
3497 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3500 EXPORT_C TBufBase16::TBufBase16(TInt aLength,TInt aMaxLength)
3501 :TDes16(EBuf,aLength,aMaxLength)
3503 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3504 __ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes16LengthOutOfRange));
3508 #if !defined( __DES16_MACHINE_CODED_HWORD__) | defined(__EABI_CTORS__)
3509 EXPORT_C TBufBase16::TBufBase16(const TUint16* aString,TInt aMaxLength)
3510 :TDes16(EBuf,0,aMaxLength)
3512 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3517 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
3518 EXPORT_C TBufBase16::TBufBase16(const TDesC16& aDes,TInt aMaxLength)
3519 :TDes16(EBuf,0,aMaxLength)
3521 __ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
3526 EXPORT_C void TDesC16::__DbgTestInvariant() const
3528 // Test that the class obeys its invariant.
3544 if (Ptr() != NULL) // TPtr and TPtrC can be null
3545 __CHECK_ALIGNMENT(Ptr(),ETDesC16Invariant);
3549 EXPORT_C void TPtrC16::__DbgTestInvariant() const
3551 // Test that the class obeys its invariant.
3556 TDesC16::__DbgTestInvariant(); // Test base class
3562 EXPORT_C void TDes16::__DbgTestInvariant() const
3564 // Test that the class obeys its invariant.
3569 TDesC16::__DbgTestInvariant(); // Test base class
3570 if (Length()>MaxLength() || !(Type()==EPtr || Type()==EBufCPtr || Type()==EBuf))
3575 EXPORT_C void HBufC16::__DbgTestInvariant() const
3577 // Test that the class obeys its invariant.
3582 TDesC16::__DbgTestInvariant(); // Test base class
3583 if (Length()>(TInt)(STD_CLASS::AllocLen(this)-sizeof(TDesC16)) || Type()!=EBufC)
3588 EXPORT_C void TPtr16::__DbgTestInvariant() const
3590 // Test that the class obeys its invariant.
3595 TDes16::__DbgTestInvariant(); // Test base class
3596 if (!(Type()==EPtr || Type()==EBufCPtr))
3601 /** Collapse all characters from 16 to 8 bits
3603 @return 8-bit pointer descriptor to transformed text
3605 EXPORT_C TPtr8 TDes16::Collapse()
3608 TInt ml = MaxLength();
3609 TText8* d = (TText8*)Ptr();
3611 const TText16* s = (const TText16*)d;
3612 const TText16* sE = s + l;
3614 *d++ = (TText8)*s++;
3615 return TPtr8(d0, l, ml*sizeof(TText));
3618 // Truncate literal string to fit into descriptor
3619 EXPORT_C void TDes16IgnoreOverflow::Overflow(TDes16& /*aDes*/)
3622 #ifndef __KERNEL_MODE__
3625 Default constructor.
3627 Constructs a zero-length 16-bit resizable buffer descriptor.
3629 Note that the object owns no allocated memory.
3631 EXPORT_C RBuf16::RBuf16()
3632 :TDes16(EPtr,0,0),iEPtrType(NULL)
3634 // Zero-length RBuf16 is of type EPtr with NULL pointer.
3643 Constructs a 16-bit resizable buffer descriptor, transferring ownership of the
3644 specified heap descriptor to this object.
3646 @param aHBuf The heap descriptor to be transferred to this object. This pointer
3647 can be NULL, which means that a zero length 16-bit resizable
3648 buffer descriptor is constructed, and the object will not own any
3651 EXPORT_C RBuf16::RBuf16(HBufC16* aHBuf)
3654 //Create EBufCPtr type descriptor that points to aHBuf
3655 new(this) TPtr16(aHBuf->Des());
3657 //Create zero-length RBuf16. It is EPtr type of descriptor that points to NULL.
3665 Protected constructor.
3667 EXPORT_C RBuf16::RBuf16(TInt aType,TInt aLength,TInt aMaxLength)
3668 :TDes16(aType,aLength,aMaxLength)
3676 Transfers ownership of the specified 16-bit resizable buffer descriptor's
3677 buffer to this object.
3679 Note that the function assumes that this descriptor does not already own any
3680 allocated memory. It does not check, nor does it free any pre-existing owned
3681 allocated memory. If this descriptor does already own allocated memory,
3682 RBuf16::Close() should be invoked on this descriptor before this function is
3685 @param aRBuf The source 16-bit resizable buffer. The ownership of this
3686 object's buffer is to be transferred.
3688 @see RBuf16::Close()
3690 EXPORT_C void RBuf16::Assign(const RBuf16& aRBuf)
3692 Mem::Copy(this, &aRBuf, sizeof(*this));
3700 Assigns ownership of the specified allocated memory to this object.
3702 The allocated memory forms the buffer for this descriptor. The current length
3703 of the descriptor is set to zero.
3705 Note that the function assumes that this descriptor does not already own any
3706 allocated memory. It does not check, nor does it free any pre-existing owned
3707 allocated memory. If this descriptor does already own allocated memory,
3708 RBuf16::Close() should be invoked on this descriptor before this function is
3711 @param aHeapCell The allocated memory to be assigned to this object. This
3712 pointer can be NULL, which means that a zero length 16-bit
3713 resizable buffer descriptor is created.
3714 @param aMaxLength The maximum length of the descriptor.
3716 @panic USER 8 If the specified maximum length is greater then the size of
3717 the allocated heap cell, or the specified maximum length
3718 is NOT zero when the pointer to the heap cell is NULL.
3720 @see TDesC16::Length()
3721 @see TDes16::MaxLength()
3722 @see RBuf16::Close()
3724 EXPORT_C void RBuf16::Assign(TUint16 *aHeapCell,TInt aMaxLength)
3726 Assign(aHeapCell,0,aMaxLength);
3733 Assigns ownership of the specified allocated memory to this object.
3735 The allocated memory forms the buffer for this descriptor. The current length
3736 of the descriptor is set to the value of the second parameter.
3738 Note that the function assumes that this descriptor does not already own any
3739 allocated memory. It does not check, nor does it free any pre-existing owned
3740 allocated memory. If this descriptor does already own allocated memory,
3741 RBuf16::Close() should be invoked on this descriptor before this function is
3744 @param aHeapCell The allocated memory to be assigned to this object.
3745 @param aLength The length of the descriptor.
3746 @param aMaxLength The maximum length of the descriptor.
3748 @panic USER 8 If the specified maximum length is greater then the size of
3749 the allocated heap cell, or the specified length is greater then
3750 the specified maximum length, or the specified maximum length
3751 is NOT zero when the pointer to the heap cell is NULL.
3753 @see TDesC16::Length()
3754 @see TDes16::MaxLength()
3755 @see RBuf16::Close()
3757 EXPORT_C void RBuf16::Assign(TUint16 *aHeapCell,TInt aLength,TInt aMaxLength)
3759 __ASSERT_ALWAYS(aLength<=aMaxLength, Panic(ETDes16LengthOutOfRange));
3762 __ASSERT_ALWAYS(User::AllocLen(aHeapCell) >= aMaxLength * (TInt)sizeof(TUint16), Panic(ETDes16LengthOutOfRange));
3763 //Create EPtr type descriptor that points to aHeapCell
3764 new(this) TPtr16(aHeapCell,aLength,aMaxLength);
3768 __ASSERT_ALWAYS(aMaxLength == 0, Panic(ETDes16LengthOutOfRange));
3769 //Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
3779 Transfers ownership of the specified heap descriptor to this object.
3781 Note that the function assumes that this descriptor does not already own any
3782 allocated memory. It does not check, nor does it free any pre-existing owned
3783 allocated memory. If this descriptor does already own allocated memory,
3784 RBuf16::Close() should be invoked on this descriptor before this function is
3787 @param aHBuf The heap descriptor to be transferred to this object.
3788 This pointer can be NULL, which means that a zero length
3789 16-bit resizable buffer descriptor is created.
3791 @see RBuf16::Close()
3793 EXPORT_C void RBuf16::Assign(HBufC16* aHBuf)
3795 new(this) RBuf16(aHBuf);
3802 Swaps the content of two 16-bit resizable buffer descriptors.
3804 @param aRBuf The 16-bit resizable buffer descriptor whose contents are to be
3805 swapped with this one.
3807 EXPORT_C void RBuf16::Swap(RBuf16& aRBuf)
3809 Mem::Swap(this,&aRBuf,sizeof(*this));
3816 Creates a 16-bit resizable buffer descriptor.
3818 The function allocates sufficient memory to contain descriptor data up to
3819 the specified maximum length.
3821 The current length of the descriptor is set to zero. The maximum length of
3822 the descriptor is set to the specified value.
3824 Note that the function assumes that this descriptor does not already own any
3825 allocated memory. It does not check, nor does it free any pre-existing owned
3826 allocated memory. If this descriptor does already own allocated memory,
3827 RBuf16::Close() should be invoked on this descriptor before this function is
3830 @param aMaxLength The maximum length of the descriptor.
3832 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3834 @see TDesC16::Length()
3835 @see TDes16::MaxLength()
3836 @see RBuf16::Close()
3838 EXPORT_C TInt RBuf16::Create(TInt aMaxLength)
3843 TUint16* buf=(TUint16*)User::Alloc(aMaxLength*sizeof(TUint16));
3844 if(!buf) return KErrNoMemory;
3848 iEPtrType = NULL; //Zero-length descriptor.
3851 //Create EPtr type descriptor.
3852 new(this) RBuf16(EPtr,0,aMaxLength);
3861 Creates 16-bit resizable buffer descriptor, and leaves on failure.
3863 The function allocates sufficient memory to contain descriptor data up to
3864 the specified maximum length.
3866 The current length of the descriptor is set to zero. The maximum length of
3867 the descriptor is set to the specified value.
3869 Note that the function assumes that this descriptor does not already own any
3870 allocated memory. It does not check, nor does it free any pre-existing owned
3871 allocated memory. If this descriptor does already own allocated memory,
3872 RBuf16::Close() should be invoked on this descriptor before this function is
3875 @param aMaxLength The maximum length of the descriptor.
3877 @leave KErrNoMemory If there is insufficient memory.
3879 @see TDesC16::Length()
3880 @see TDes16::MaxLength()
3881 @see RBuf16::Close()
3883 EXPORT_C void RBuf16::CreateL(TInt aMaxLength)
3885 User::LeaveIfError(Create(aMaxLength));
3892 Creates a 16-bit resizable buffer descriptor.
3894 The function allocates sufficient memory to contain descriptor data up to
3895 the specified maximum length.
3897 Both the current length and the maximum length of the descriptor are set to
3898 the specified value.
3900 Note that the function assumes that this descriptor does not already own any
3901 allocated memory. It does not check, nor does it free any pre-existing owned
3902 allocated memory. If this descriptor does already own allocated memory,
3903 RBuf16::Close() should be invoked on this descriptor before this function is
3906 @param aMaxLength The length and the maximum length of the descriptor.
3908 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3910 @see RBuf16::Close()
3912 EXPORT_C TInt RBuf16::CreateMax(TInt aMaxLength)
3914 TInt err=Create(aMaxLength);
3924 Creates a 16-bit resizable buffer descriptor, and leaves on failure.
3926 The function allocates sufficient memory to contain descriptor data up to
3927 the specified maximum length.
3929 Both the current length and the maximum length of the descriptor are set to
3930 the specified value.
3932 Note that the function assumes that this descriptor does not already own any
3933 allocated memory. It does not check, nor does it free any pre-existing owned
3934 allocated memory. If this descriptor does already own allocated memory,
3935 RBuf16::Close() should be invoked on this descriptor before this function is
3938 @param aMaxLength The length and the maximum length of the descriptor.
3940 @leave KErrNoMemory If there is insufficient memory.
3942 @see TDesC16::Length()
3943 @see TDes16::MaxLength()
3944 @see RBuf16::Close()
3946 EXPORT_C void RBuf16::CreateMaxL(TInt aMaxLength)
3948 User::LeaveIfError(CreateMax(aMaxLength));
3955 Creates a 16-bit resizable buffer descriptor to contain a copy of the
3956 specified (source) descriptor.
3958 The function allocates sufficient memory so that this descriptor's maximum
3959 length is the same as the length of the source descriptor. Both the current
3960 length and the maximum length of this descriptor are set to
3961 the length of the source descriptor.
3963 The data contained in the source descriptor is copied into this
3966 Note that the function assumes that this descriptor does not
3967 already own any allocated memory. It does not check, nor does it free any
3968 pre-existing owned allocated memory. If this descriptor does already own
3969 allocated memory, RBuf16::Close() should be invoked on this descriptor before
3970 this function is invoked.
3972 @param aDes Source descriptor to be copied into this object.
3974 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
3976 @see TDesC16::Length()
3977 @see TDes16::MaxLength()
3979 @see RBuf16::Close()
3981 EXPORT_C TInt RBuf16::Create(const TDesC16& aDes)
3983 return Create(aDes,aDes.Length());
3991 Creates a 16-bit resizable buffer descriptor to contain a copy of the specified
3992 (source) descriptor, and leaves on failure.
3994 The function allocates sufficient memory so that this descriptor's maximum
3995 length is the same as the length of the source descriptor.Both the current
3996 length and the maximum length of this descriptor are set to the length
3997 of the source descriptor.
3999 The data contained in the source descriptor is copied into this descriptor.
4001 Note that the function assumes that this descriptor does not already own any
4002 allocated memory. It does not check, nor does it free any
4003 pre-existing owned allocated memory. If this descriptor does already own
4004 allocated memory, RBuf16::Close() should be invoked on this descriptor before
4005 this function is invoked.
4007 @param aDes Source descriptor to be copied into this object.
4009 @leave KErrNoMemory If there is insufficient memory.
4011 @see TDesC16::Length()
4012 @see TDes16::MaxLength()
4014 @see RBuf16::Close()
4016 EXPORT_C void RBuf16::CreateL(const TDesC16& aDes)
4018 CreateL(aDes,aDes.Length());
4025 Creates a 16-bit resizable buffer descriptor to contain a copy of the
4026 specified (source) descriptor.
4028 The function allocates sufficient memory so that this descriptor's maximum length
4029 is the same as the value of the aMaxLength parameter.
4031 The data contained in the source descriptor is copied into this descriptor.
4032 The length of data copied is either
4034 - the length of the source descriptor aDes
4038 - the value of the aMaxLength parameter
4040 whichever is the smaller value. The current length of this descriptor is also
4041 set to the smaller value.
4043 Note that the function assumes that this descriptor does not already own any
4044 allocated memory. It does not check, nor does it free any pre-existing owned
4045 allocated memory. If this descriptor does already own allocated memory,
4046 RBuf16::Close() should be invoked on this descriptor before this function is
4049 @param aDes Source descriptor to be copied into this object.
4051 @param aMaxLength The maximum length of this descriptor.
4053 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
4055 @see TDesC16::Length()
4056 @see TDes16::MaxLength()
4058 @see RBuf16::Close()
4060 EXPORT_C TInt RBuf16::Create(const TDesC16& aDes,TInt aMaxLength)
4062 TInt err=Create(aMaxLength);
4064 Copy(aDes.Left(aMaxLength));
4072 Creates a 16-bit resizable buffer descriptor to contain a copy of the specified
4073 (source) descriptor, and leaves on failure.
4075 The function allocates sufficient memory so that this descriptor's maximum
4076 length is the same as the value of the aMaxLength parameter.
4078 The data contained in the source descriptor is copied into this descriptor.
4079 The length of data copied is either
4081 - the length of the source descriptor aDes
4085 - the value of the aMaxLength parameter
4087 whichever is the smaller value. The current length of this descriptor is also
4088 set to the smaller value.
4090 Note that the function assumes that this descriptor does not already own any
4091 allocated memory. It does not check, nor does it free any pre-existing owned
4092 allocated memory. If this descriptor does already own allocated memory,
4093 RBuf16::Close() should be invoked on this descriptor before this function is
4096 @param aDes Source descriptor to be copied into this object.
4098 @param aMaxLength The maximum length of this descriptor.
4100 @leave KErrNoMemory If there is insufficient memory.
4102 @see TDesC16::Length()
4103 @see TDes16::MaxLength()
4105 @see RBuf16::Close()
4107 EXPORT_C void RBuf16::CreateL(const TDesC16& aDes,TInt aMaxLength)
4109 CreateL(aMaxLength);
4110 Copy(aDes.Left(aMaxLength));
4117 Resizes this 16-bit resizable buffer descriptor.
4119 The length and contents of the descriptor are unchanged.
4121 If the buffer descriptor was created from a zero-length heap descriptor
4122 HBufC, this method might leak memory (the heap descriptor is not freed).
4123 It is possible to avoid this by calling the Close() method prior to ReAlloc(),
4124 but this should be done only in this situation (otherwise the buffer contents
4129 if (desc.MaxLength() == 0) desc.Close();
4131 before the call to ReAlloc().
4133 @param aMaxLength The new maximum length of the descriptor. This can be zero,
4134 which results in a descriptor with zero maximum length and no
4137 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
4139 @panic USER 14 If the new maximum length is less then the current descriptor length.
4141 EXPORT_C TInt RBuf16::ReAlloc(TInt aMaxLength)
4143 __ASSERT_ALWAYS(Length()<=aMaxLength, Panic(ETDes16ReAllocTooSmall));
4146 if (!aMaxLength) //Reallocation to zero length
4148 User::Free(iEPtrType); //Free memory
4149 new (this) RBuf16(); //Create zero-length RBuf
4153 if (!iMaxLength) //Reallocation from zero length
4154 return Create(aMaxLength);
4160 TUint16* buf = (TUint16*)User::ReAlloc(iEPtrType,aMaxLength*sizeof(TUint16));
4161 if(!buf) return KErrNoMemory;
4163 iMaxLength = aMaxLength;
4168 HBufC16* hbufc = iEBufCPtrType->ReAlloc(aMaxLength);
4169 if(!hbufc) return KErrNoMemory;
4183 Resizes this 16-bit resizable buffer descriptor, leaving on failure.
4185 The length and contents of the descriptor are unchanged.
4187 If the buffer descriptor was created from a zero-length heap descriptor
4188 HBufC, this method might leak memory (the heap descriptor is not freed).
4189 It is possible to avoid this by calling the Close() method prior to ReAllocL(),
4190 but this should be done only in this situation (otherwise the buffer contents
4195 if (desc.MaxLength() == 0) desc.Close();
4197 before the call to ReAlloc().
4199 @param aMaxLength The new maximum length of the descriptor. This can be zero,
4200 which results in a descriptor with zero maximum length and no
4203 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
4205 @panic USER 14 If the new maximum length is less then the current descriptor length.
4207 EXPORT_C void RBuf16::ReAllocL(TInt aMaxLength)
4209 User::LeaveIfError(ReAlloc(aMaxLength));
4216 Deallocates memory assigned to this object, and re-initializes the object as
4217 a zero-length descriptor.
4219 EXPORT_C void RBuf16::Close()
4221 User::Free(iEPtrType);
4222 //Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
4230 Pushes a cleanup item for this object onto the cleanup stack.
4232 The effect of this is to cause Close() to be called on this 16-bit resizable
4233 buffer descriptor, when CleanupStack::PopAndDestroy() is called at some later time.
4239 x.CleanupClosePushL();
4241 CleanupStack::PopAndDestroy();
4245 @see RBuf16::Close()
4247 EXPORT_C void RBuf16::CleanupClosePushL()
4249 ::CleanupClosePushL(*this);
4256 Tests that the class obeys its invariant.
4258 EXPORT_C void RBuf16::__DbgTestInvariant() const
4261 TDes16::__DbgTestInvariant();
4267 __ASSERT_DEBUG(User::AllocLen(iEPtrType) >= iMaxLength*(TInt)sizeof(TUint16), Panic(EInvariantFalse));
4271 iEBufCPtrType->__DbgTestInvariant();
4272 __ASSERT_DEBUG(iEBufCPtrType->Des().MaxLength() == iMaxLength, Panic(EInvariantFalse));
4273 __ASSERT_DEBUG(iEBufCPtrType->Length() == Length(), Panic(EInvariantFalse));
4281 #endif // __KERNEL_MODE__
4284 #if defined(__DES16_MACHINE_CODED__) || defined(__EABI__)
4285 GLDEF_C void Des16PanicBadDesType()
4287 Panic(ETDes16BadDescriptorType);
4290 GLDEF_C void Des16PanicPosOutOfRange()
4292 Panic(ETDes16PosOutOfRange);
4296 #ifdef __DES16_MACHINE_CODED__
4297 GLDEF_C void Des16PanicLengthNegative()
4299 Panic(ETDes16LengthNegative);
4302 GLDEF_C void Des16PanicMaxLengthNegative()
4304 Panic(ETDes16MaxLengthNegative);
4307 GLDEF_C void Des16PanicLengthOutOfRange()
4309 Panic(ETDes16LengthOutOfRange);
4312 GLDEF_C void Des16PanicDesOverflow()
4314 Panic(ETDes16Overflow);
4317 GLDEF_C void Des16PanicDesIndexOutOfRange()
4319 Panic(ETDes16IndexOutOfRange);