kernel/eka/common/des16.cpp
changeset 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\common\des16.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "common.h"
       
    19 #include <e32des16_private.h>
       
    20 #include <collate.h>
       
    21 #ifdef _UNICODE
       
    22 #include <unicode.h>
       
    23 #include "collateimp.h"
       
    24 #endif
       
    25 #include "CompareImp.h"
       
    26 
       
    27 
       
    28 #define __CHECK_ALIGNMENT(p,c) __ASSERT_DEBUG(!(TUint(p)&1),Des16Panic(c))
       
    29 
       
    30 enum TDes16Panic
       
    31 	{
       
    32 	ETDesC16ConstructCString=0,
       
    33 	ETDesC16ConstructBufLength=1,
       
    34 	ETDesC16ConstructBufLengthMax=2,
       
    35 	ETDesC16FindPtrLen=3,
       
    36 	ETDesC16FindFPtrLen=4,
       
    37 	ETDesC16FindCPtrLen=5,
       
    38 	ETBufCBase16CopyStringMax=6,
       
    39 	EHBufC16AssignCString=7,
       
    40 	ETDes16AssignCString=8,
       
    41 	ETDes16CopyCString=9,
       
    42 	ETDes16CopyBufLength=10,
       
    43 	ETDes16AppendBufLength=11,
       
    44 	ETDes16RepeatBufLength=12,
       
    45 	ETDes16AppendJustify1=13,
       
    46 	ETDes16AppendJustify2=14,
       
    47 	ETPtrC16SetBufLength=15,
       
    48 	ETPtr16SetBufLengthMax=16,
       
    49 	ETDesC16Invariant=17,
       
    50 	ETDesC16Ptr=18
       
    51 	};
       
    52 
       
    53 #ifdef _DEBUG
       
    54 _LIT(KLitDes16Align,"Des16Align");
       
    55 void Des16Panic(TDes16Panic aPanic)
       
    56 	{
       
    57 	PANIC_CURRENT_THREAD(KLitDes16Align,aPanic);
       
    58 	}
       
    59 #endif
       
    60 
       
    61 inline TUint16* memCopy(TUint16* aPtr, const TUint16* aSrc, TInt aLength)
       
    62 	{
       
    63 	return (TUint16 *)Mem::Copy(aPtr,aSrc,aLength<<1);
       
    64 	}
       
    65 
       
    66 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
       
    67 inline TInt StringLength(const TUint16* aPtr)
       
    68 	{
       
    69 	const TUint16* p = aPtr;
       
    70 	while (*p)
       
    71 		++p;
       
    72 	return p-aPtr;
       
    73 	}
       
    74 #endif
       
    75 
       
    76 inline TDesC16::TDesC16(TInt aType,TInt aLength)
       
    77 	:iLength(aLength|(aType<<KShiftDesType16))
       
    78 	{}
       
    79 inline TInt TDesC16::Type() const
       
    80 //
       
    81 // Return the descriptor type
       
    82 //
       
    83 	{
       
    84 	return(iLength>>KShiftDesType16);
       
    85 	}
       
    86 
       
    87 inline TDes16::TDes16(TInt aType,TInt aLength,TInt aMaxLength)
       
    88 	: TDesC16(aType,aLength),iMaxLength(aMaxLength)
       
    89 	{}
       
    90 
       
    91 // Class TBufCBase16
       
    92 inline TBufCBase16::TBufCBase16(TInt aLength)
       
    93 	:TDesC16(EBufC,aLength)
       
    94 	{}
       
    95 inline TUint16* TBufCBase16::WPtr() const
       
    96 	{return const_cast<TUint16*>(Ptr());}
       
    97 
       
    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)
       
   101 	{
       
   102 	__ASSERT_DEBUG(aLcb.Length()<=aMaxLength,Panic(ETDes16LengthOutOfRange));
       
   103 	}
       
   104 #endif
       
   105 
       
   106 #if !defined( __DES16_MACHINE_CODED__)
       
   107 /**
       
   108 Gets a pointer to the data represented by the descriptor.
       
   109 
       
   110 The data cannot be changed through the returned pointer.
       
   111 
       
   112 @return A pointer to the data
       
   113 */
       
   114 EXPORT_C const TUint16 *TDesC16::Ptr() const
       
   115 	{
       
   116 
       
   117 	const TUint16* p=NULL;
       
   118 	switch (Type())
       
   119 		{
       
   120 	case EBufC:
       
   121 		p=(&((SBufC16 *)this)->buf[0]); break;
       
   122 	case EPtrC:
       
   123 		p=(((SPtrC16 *)this)->ptr); break;
       
   124 	case EPtr:
       
   125 		p=(((SPtr16 *)this)->ptr); break;
       
   126 	case EBuf:
       
   127 		p=(&((SBuf16 *)this)->buf[0]); break;
       
   128 	case EBufCPtr:
       
   129 		p=(&((SBufCPtr16 *)this)->ptr->buf[0]); break;
       
   130 	default:
       
   131 		Panic(ETDes16BadDescriptorType);
       
   132 		}
       
   133 	__CHECK_ALIGNMENT(p,ETDesC16Ptr);
       
   134 	return p;
       
   135 	}
       
   136 
       
   137 EXPORT_C const TUint16 &TDesC16::AtC(TInt anIndex) const
       
   138 //
       
   139 // Return a reference to the character in the buffer.
       
   140 //
       
   141 	{
       
   142 
       
   143 	__ASSERT_ALWAYS(anIndex>=0 && anIndex<Length(),Panic(ETDes16IndexOutOfRange));
       
   144 	return(Ptr()[anIndex]);
       
   145 	}
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 /**
       
   151 Compares this descriptor's data with the specified descriptor's data.
       
   152 
       
   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.
       
   156 
       
   157 Two descriptors are equal if they have the same length and content. Where 
       
   158 two descriptors have different lengths and the shorter descriptor's data 
       
   159 matches the first part of the longer descriptor's data, the shorter is
       
   160 considered to be less than the longer.
       
   161 
       
   162 @param aDes The 16-bit non-modifable descriptor whose data is to be compared 
       
   163             with this descriptor's data. 
       
   164             
       
   165 @return Positive. if this descriptor is greater than the specified descriptor.
       
   166         Negative. if this descriptor is less than the specified descriptor.
       
   167         Zero, if both descriptors have the same length and the their contents
       
   168         are the same.
       
   169 */
       
   170 EXPORT_C TInt TDesC16::Compare(const TDesC16 &aDes) const
       
   171 	{
       
   172 	return MEM_COMPARE_16(Ptr(),Length(),aDes.Ptr(),aDes.Length());
       
   173 	}
       
   174 
       
   175 
       
   176 
       
   177 
       
   178 /**
       
   179 Compares this descriptor's folded data with the specified descriptor's folded 
       
   180 data.
       
   181 
       
   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.
       
   186 
       
   187 @param aDes The 16-bit non-modifable descriptor whose data is to be compared 
       
   188             with this descriptor's data. 
       
   189             
       
   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
       
   193         are the same.
       
   194         
       
   195 @see TDesC16::Compare()
       
   196 */
       
   197 EXPORT_C TInt TDesC16::CompareF(const TDesC16 &aDes) const
       
   198 	{
       
   199 
       
   200 	return(Mem::CompareF(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
       
   201 	}
       
   202 
       
   203 
       
   204 
       
   205 
       
   206 /**
       
   207 Compares this descriptor's data with the specified descriptor's data using 
       
   208 the standard collation method appropriate to the current locale.
       
   209 
       
   210 @param aDes The 16-bit non-modifable descriptor whose data is to be compared 
       
   211             with this descriptor's data. 
       
   212             
       
   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.
       
   216         
       
   217 @see TDesC16::Compare()
       
   218 */
       
   219 EXPORT_C TInt TDesC16::CompareC(const TDesC16 &aDes) const
       
   220 	{
       
   221 
       
   222 	return(Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
       
   223 	}
       
   224 #endif
       
   225 
       
   226 
       
   227 
       
   228 
       
   229 #ifdef _UNICODE
       
   230 /**
       
   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.
       
   233 
       
   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.
       
   237 
       
   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.
       
   241 
       
   242 Strings may match even if the lengths of their respective descriptors are 
       
   243 different.
       
   244 
       
   245 @param aDes             The 16-bit non-modifable descriptor whose data is to
       
   246                         be compared with this descriptor's data.
       
   247                           
       
   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.
       
   252                  
       
   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.
       
   258                         
       
   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.
       
   262         
       
   263 @see Mem::CollationMethodByIndex()
       
   264 @see Mem::CollationMethodById()
       
   265 @see TDesC16::Compare()
       
   266 */
       
   267 EXPORT_C TInt TDesC16::CompareC(const TDesC16& aDes, TInt aMaxLevel, const TCollationMethod* aCollationMethod) const
       
   268 	{
       
   269 	return Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length(),aMaxLevel,aCollationMethod);
       
   270 	}
       
   271 
       
   272 /**
       
   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
       
   277 */
       
   278 EXPORT_C HBufC16* TDesC16::GetNormalizedDecomposedFormL() const
       
   279 	{
       
   280 	//pre create a buffer with of size Length
       
   281 	TInt strLength=Length();
       
   282 	HBufC16* outBuf=HBufC16::NewL(strLength);
       
   283 
       
   284 	TUTF32Iterator input(Ptr(),Ptr()+strLength);
       
   285 	TCanonicalDecompositionIterator output;
       
   286 	output.Set(input);
       
   287 
       
   288 	TInt currentAllocateCount=0;
       
   289 	TUint16* outPtr = (TUint16* )outBuf->Des().Ptr();
       
   290 	TInt preAllocateCount= outBuf->Des().MaxLength();
       
   291 
       
   292 	for (;!output.AtEnd();output.Next(),currentAllocateCount++)
       
   293 		{
       
   294 		if (currentAllocateCount>=preAllocateCount)
       
   295 			{
       
   296 			const TInt KMaxGrowSize=16;
       
   297 			HBufC16* newOutBuf = outBuf->ReAlloc(preAllocateCount+KMaxGrowSize);
       
   298 			if(!newOutBuf)
       
   299 				{
       
   300 				delete outBuf;
       
   301 				User::Leave(KErrNoMemory);
       
   302 				}
       
   303 			outBuf = newOutBuf;
       
   304 			outPtr = (TUint16* )outBuf->Des().Ptr();
       
   305 			preAllocateCount = outBuf->Des().MaxLength();
       
   306 			}
       
   307 		outPtr[currentAllocateCount] = (TUint16)(TUint)(output.Current());
       
   308 		}
       
   309 	// update the length of the buffer...
       
   310 	outBuf->Des().SetLength(currentAllocateCount);
       
   311 
       
   312 	//compress the unused slot
       
   313 	if (currentAllocateCount<preAllocateCount)
       
   314 		outBuf = outBuf->ReAlloc(currentAllocateCount); // can't fail to shrink memory
       
   315 	return outBuf;
       
   316 	}
       
   317 
       
   318 /**
       
   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
       
   323 */	
       
   324 EXPORT_C HBufC16* TDesC16::GetFoldedDecomposedFormL() const
       
   325 	{
       
   326 	//pre create a buffer with of size Length
       
   327 	TInt strLength=Length();
       
   328 	HBufC16* outBuf=HBufC16::NewL(strLength);
       
   329 
       
   330 	TUTF32Iterator input(Ptr(),Ptr()+strLength);
       
   331 	TFoldedCanonicalIterator output (input);
       
   332 
       
   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++)
       
   338 		{
       
   339 		if (currentAllocateCount>=preAllocateCount)
       
   340 			{
       
   341 			const TInt KMaxGrowSize=16;
       
   342 			HBufC16* newOutBuf = outBuf->ReAlloc(preAllocateCount+KMaxGrowSize);
       
   343 			if(!newOutBuf)
       
   344 				{
       
   345 				delete outBuf;
       
   346 				User::Leave(KErrNoMemory);
       
   347 				}
       
   348 			outBuf = newOutBuf;
       
   349 			outPtr = (TUint16* )outBuf->Des().Ptr();
       
   350 			preAllocateCount = outBuf->Des().MaxLength();
       
   351 			}
       
   352 		outPtr[currentAllocateCount] = (TUint16)(TUint)(output.Current());
       
   353 		}
       
   354 	// update the length of the buffer...
       
   355 	outBuf->Des().SetLength(currentAllocateCount);
       
   356 
       
   357 	//compress the unused slot
       
   358 	if (currentAllocateCount<preAllocateCount)
       
   359 		outBuf = outBuf->ReAlloc(currentAllocateCount); // can't fail to shrink memory
       
   360 	return outBuf;
       
   361 	}
       
   362 
       
   363 //some utils function
       
   364 static void ResetAndDestroyArray(TAny* aPtr)
       
   365 	{
       
   366 	(STATIC_CAST(RPointerArray<HBufC8>*,aPtr))->ResetAndDestroy();
       
   367 	}
       
   368 
       
   369 /**
       
   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		
       
   384 */	
       
   385 EXPORT_C HBufC8* TDesC16::GetCollationKeysL(TInt aMaxLevel,const TCollationMethod* aCollationMethod) const
       
   386 	{
       
   387 	// Clamp the maximum level of the comparison.
       
   388 	if(aMaxLevel < 0)
       
   389 		aMaxLevel = 0;
       
   390 	if(aMaxLevel > 3)
       
   391 		aMaxLevel = 3;
       
   392 	
       
   393 	RPointerArray<HBufC8> levelBuffer;
       
   394  	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArray, &levelBuffer));
       
   395   	TInt strLength=Length();
       
   396  	TInt outputBufferSize=0;
       
   397  	
       
   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++)
       
   402 		{
       
   403 		TInt levelKeySize=TCollationKey::MaxSizePerKey(i);
       
   404 		HBufC8* buffer=HBufC8::NewLC(strLength*levelKeySize);
       
   405 		levelBuffer.AppendL(buffer);
       
   406 		CleanupStack::Pop();
       
   407 		outputBufferSize+=levelKeySize;
       
   408 		}
       
   409 	TCollationMethod clm;
       
   410 	
       
   411 	//if collationMethod is NULL, use the default one
       
   412 	if (aCollationMethod==NULL)
       
   413 		{
       
   414 		clm=*(GetLocaleCharSet()->iCollationDataSet->iMethod);
       
   415 		}
       
   416 	else
       
   417 		{
       
   418 		clm = *aCollationMethod;			
       
   419 		}
       
   420 	//if the main table is empty use the standard table
       
   421 	if (clm.iMainTable==NULL)
       
   422 		clm.iMainTable=StandardCollationMethod();	
       
   423 	
       
   424 	TCollationValueIterator tvi(clm);	
       
   425   	TUTF32Iterator input(Ptr(),Ptr()+strLength);	
       
   426  	tvi.SetSourceIt(input);
       
   427 
       
   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++)
       
   434 		{
       
   435 		for (TInt i=0;i<=aMaxLevel;i++)
       
   436 			{
       
   437 			if (currentKeyCount==preAllocateCount)
       
   438 				levelBuffer[i]=levelBuffer[i]->ReAllocL((currentKeyCount+KMaxBufferGrowSize)*TCollationKey::MaxSizePerKey(i));
       
   439 			
       
   440 			collateKey.AppendToDescriptor(levelBuffer[i]->Des(),i);
       
   441 			}
       
   442 		if (currentKeyCount==preAllocateCount)
       
   443 			preAllocateCount+=KMaxBufferGrowSize;
       
   444 		}
       
   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++)
       
   450 		{
       
   451 		outputResultPtr.Append(*levelBuffer[count]);
       
   452 		if (count!=aMaxLevel)
       
   453 			{
       
   454 			if (count==0)
       
   455 				outputResultPtr.Append(0);
       
   456 			outputResultPtr.Append(0);
       
   457 			}
       
   458 		}
       
   459 	CleanupStack::PopAndDestroy();
       
   460 	return outputResult;	
       
   461 	}	
       
   462 
       
   463 #endif
       
   464 
       
   465 /**
       
   466 Searches for the first occurrence of the specified data sequence within this
       
   467 descriptor.
       
   468 
       
   469 Searching always starts at the beginning of this descriptor's data.
       
   470 
       
   471 @param pS    A pointer to a location containing the data sequence to be searched 
       
   472              for.
       
   473              
       
   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.
       
   476              
       
   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.
       
   479        
       
   480 @panic  USER 17 if aLenS is negative. 
       
   481 */
       
   482 EXPORT_C TInt TDesC16::Find(const TUint16 *pS,TInt aLenS) const
       
   483 	{
       
   484 
       
   485 	if (!aLenS)
       
   486 		return(0);
       
   487 	__ASSERT_ALWAYS(aLenS>0,Panic(ETDes16LengthNegative));
       
   488 	__CHECK_ALIGNMENT(pS,ETDesC16FindPtrLen);
       
   489 	const TUint16 *pB=Ptr();
       
   490 	TInt aLenB=Length();
       
   491 	const TUint16 *pC=pB-1;			// using pre-increment addressing
       
   492 	TInt i=aLenB-aLenS;
       
   493 	if (i>=0)
       
   494 		{
       
   495 		const TUint16* pEndS=pS+aLenS-1;		// using pre-increment addressing
       
   496 		const TUint16 *pEndB=pB+i;			// using pre-increment addressing
       
   497 		TUint s=*pS;
       
   498 		for (;;)
       
   499 			{
       
   500 			do
       
   501 				{
       
   502 				if (pC==pEndB)
       
   503 					return KErrNotFound;
       
   504 				} while (*++pC!=s);
       
   505 			const TUint16 *p1=pC;
       
   506 			const TUint16 *p2=pS;
       
   507 			do
       
   508 				{
       
   509 				if (p2==pEndS)
       
   510 					return (pC-pB);
       
   511 				} while (*++p1==*++p2);
       
   512 			}
       
   513 		}
       
   514 	return(KErrNotFound);
       
   515 	}
       
   516 
       
   517 
       
   518 
       
   519 
       
   520 /**
       
   521 Searches for the first occurrence of the specified data sequence within this 
       
   522 descriptor.
       
   523 
       
   524 Searching always starts at the beginning of this descriptor's 
       
   525 data.
       
   526 
       
   527 @param aDes The 16-bit non-modifiable descriptor containing the data sequence 
       
   528             to be searched for. 
       
   529             
       
   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.
       
   532 */
       
   533 EXPORT_C TInt TDesC16::Find(const TDesC16 &aDes) const
       
   534 	{
       
   535 
       
   536 	return(Find(aDes.Ptr(),aDes.Length()));
       
   537 	}
       
   538 
       
   539 
       
   540 
       
   541 
       
   542 /**
       
   543 Searches for the first occurrence of the specified folded data sequence within
       
   544 this descriptor's folded data.
       
   545 
       
   546 Searching always starts at the beginning of this descriptor's data.
       
   547 
       
   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.
       
   552 
       
   553 @param pS    A pointer to a location containing the data sequence to be
       
   554              searched for.
       
   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.
       
   557              
       
   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.
       
   561 
       
   562 @panic USER 17 if aLenS is negative
       
   563 
       
   564 @see TDesC16::FindC()
       
   565 */
       
   566 EXPORT_C TInt TDesC16::FindF(const TUint16 *pS,TInt aLenS) const
       
   567 	{
       
   568 	__CHECK_ALIGNMENT(pS,ETDesC16FindFPtrLen);
       
   569 	TUTF32Iterator candidateStrIt(Ptr(), Ptr() + Length());
       
   570 	TUTF32Iterator searchTermIt(pS, pS + aLenS);
       
   571 	return ::FindFolded(candidateStrIt, searchTermIt);
       
   572 	}
       
   573 
       
   574 
       
   575 
       
   576 
       
   577 /**
       
   578 Searches for the first occurrence of the specified folded data sequence within 
       
   579 this descriptor's folded data.
       
   580 
       
   581 Searching always starts at the beginning of this descriptor's data.
       
   582 
       
   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.
       
   587 
       
   588 @param aDes The 16-bit non-modifable descriptor containing the data sequence 
       
   589             to be searched for. 
       
   590             
       
   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.
       
   594         
       
   595 @see TDesC16::FindC()
       
   596 */
       
   597 EXPORT_C TInt TDesC16::FindF(const TDesC16 &aDes) const
       
   598 	{
       
   599 	TUTF32Iterator candidateStrIt(Ptr(), Ptr() + Length());
       
   600 	TUTF32Iterator searchTermIt(aDes.Ptr(), aDes.Ptr() + aDes.Length());
       
   601 	return ::FindFolded(candidateStrIt, searchTermIt);
       
   602 	}
       
   603 
       
   604 
       
   605 
       
   606 
       
   607 /**
       
   608 Searches for the first occurrence of the specified collated data sequence within
       
   609 this descriptor's collated data.
       
   610 
       
   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.
       
   613 
       
   614 @param aText   A pointer to a location containing the data sequence to be
       
   615                searched for.             
       
   616 @param aLength The length of the data sequence to be searched for.
       
   617 
       
   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. 
       
   620 
       
   621 @panic USER 17 if aLength is negative.
       
   622 */
       
   623 EXPORT_C TInt TDesC16::FindC(const TUint16 *aText,TInt aLength) const
       
   624 	{
       
   625 	__CHECK_ALIGNMENT(aText,ETDesC16FindCPtrLen);
       
   626 
       
   627 	TCollate c(GetLocaleCharSet(),TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
       
   628 	return c.Find(Ptr(),Length(),aText,aLength,1);
       
   629 	}
       
   630 
       
   631 
       
   632 
       
   633 
       
   634 /**
       
   635 Searches for the first occurrence of the specified collated data sequence
       
   636 within this descriptor's collated data to the specified maximum collation
       
   637 level.
       
   638 
       
   639 @param aText            A pointer to a location containing the data sequence to
       
   640                         be searched for.             
       
   641                         
       
   642 @param aLength          The length of the data sequence to be searched for.
       
   643                           
       
   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.
       
   648                        
       
   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. 
       
   651 */
       
   652 EXPORT_C TInt TDesC16::FindC(const TUint16 *aText,TInt aLength, TInt aMaxLevel) const
       
   653 
       
   654 	{
       
   655 	__CHECK_ALIGNMENT(aText,ETDesC16FindCPtrLen);
       
   656 
       
   657 	TCollate c(GetLocaleCharSet(),TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
       
   658 	return c.Find(Ptr(),Length(),aText,aLength,aMaxLevel);
       
   659 	}
       
   660 
       
   661 
       
   662 
       
   663 
       
   664 /**
       
   665 Searches for the first occurrence of the specified collated data sequence 
       
   666 within this descriptor's collated data.
       
   667 
       
   668 Searching always starts at the beginning of this descriptor's data. The
       
   669 function uses the standard collation method appropriate to the current
       
   670 locale.
       
   671 
       
   672 @param aDes The 16-bit non-modifable descriptor containing the data sequence 
       
   673             to be searched for. 
       
   674             
       
   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.
       
   677 */
       
   678 EXPORT_C TInt TDesC16::FindC(const TDesC16 &aDes) const
       
   679 	{
       
   680 
       
   681 	return(FindC(aDes.Ptr(),aDes.Length()));
       
   682 	}
       
   683 
       
   684 /**
       
   685 Searches for the first occurrence of the specified collated data sequence 
       
   686 within this descriptor's collated data.
       
   687 
       
   688 Searching always starts at the beginning of this descriptor's data. The
       
   689 function uses the standard collation method appropriate to the current
       
   690 locale.
       
   691 
       
   692 @param aDes             The 16-bit non-modifable descriptor containing the data sequence 
       
   693                         to be searched for.
       
   694 
       
   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. 
       
   697 
       
   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.
       
   703 
       
   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.
       
   708                           
       
   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.
       
   711 */
       
   712 EXPORT_C TInt TDesC16::FindC(const TDesC16 &aDes, TInt &aLengthFound, const TCollationMethod &aMethod, TInt aMaxLevel) const
       
   713 	{
       
   714 	TCollate c(aMethod);
       
   715 	return c.Find(Ptr(),Length(),aDes.Ptr(),aDes.Length(),aLengthFound,aMaxLevel); 
       
   716 	}
       
   717 
       
   718 
       
   719 #ifdef _UNICODE
       
   720 LOCAL_C const TText* convTable(TMatchType aType)
       
   721 	{
       
   722 	switch (aType)
       
   723 		{
       
   724 		case EMatchFolded:											  // at present, folding is...
       
   725 		case EMatchCollated: return (const TText *)(TChar::EFoldStandard); // ...the same as collation: use all folding methods
       
   726 		default: return 0;
       
   727 		}
       
   728 	}
       
   729 #else
       
   730 LOCAL_C const TText* convTable(TMatchType aType)
       
   731 	{
       
   732 	switch (aType)
       
   733 		{
       
   734 		case EMatchFolded: return Locl::FoldTable();
       
   735 		case EMatchCollated: return Locl::CollTable();
       
   736 		default: return NULL;
       
   737 		}
       
   738 	}
       
   739 #endif
       
   740 
       
   741 inline TUint conv(const TUint16* aStr,const TText *aConv, const TUnicodeDataSet* aCharDataSet)
       
   742 //
       
   743 // If aConv is not NULL then convert the character.
       
   744 //
       
   745 	{
       
   746 
       
   747 #ifdef _UNICODE
       
   748 	if (aConv)
       
   749 		return TUnicode(*aStr).Fold((TInt)aConv, aCharDataSet);
       
   750 	else
       
   751 		return *aStr;
       
   752 #else
       
   753 	TUint c=*aStr;
       
   754 	return aConv && c<0x100 ? aConv[c] : c;
       
   755 #endif
       
   756 	}
       
   757 
       
   758 inline TUint lookup(const TUint16* aStr,const TText *aConv)
       
   759 	{
       
   760 #ifdef _UNICODE
       
   761 	return TUnicode(*aStr).Fold((TInt)aConv,GetLocaleCharSet()->iCharDataSet);
       
   762 #else
       
   763 	TUint c=*aStr;
       
   764 	return c<0x100 ? aConv[c] : c;
       
   765 #endif
       
   766 	}
       
   767 
       
   768 TInt DoMatch16(const TDesC16 &aLeftD,const TDesC16 &aRightD,TMatchType aType)
       
   769 	{
       
   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();
       
   777 
       
   778 
       
   779 	const TUnicodeDataSet* charDataSet = GetLocaleCharSet()->iCharDataSet;
       
   780 
       
   781 	// Match any pattern up to the first star
       
   782 	TUint c;
       
   783 	for (;;)
       
   784 		{
       
   785 		if (pM==pP)		// exhausted the pattern
       
   786 			return pB==pE ? 0 : KErrNotFound;
       
   787 		TUint c=conv(++pM,table, charDataSet);
       
   788 		if (c==KMatchAny)
       
   789 			break;
       
   790 		if (pB==pE)			// no more input
       
   791 			return KErrNotFound;
       
   792 		if (c!=conv(++pB,table, charDataSet) && c!=KMatchOne)	// match failed
       
   793 			return KErrNotFound;
       
   794 		}
       
   795 	// reached a star
       
   796 	if (pM==pP)
       
   797 		return 0;
       
   798 	TInt r=pM==pRight ? -1 : 0;
       
   799 	for (;;)
       
   800 		{
       
   801 		c=conv(++pM,table, charDataSet);
       
   802 		if (c==KMatchAny)
       
   803 			{
       
   804 star:		if (pM==pP)		// star at end of pattern, always matches
       
   805 				return Max(r,0);
       
   806 			if (r<-1)		// skipped some '?', matches at beginning
       
   807 				r=0;
       
   808 			continue;
       
   809 			}
       
   810 		if (pB==pE)			// no more input
       
   811 			return KErrNotFound;
       
   812 		if (c==KMatchOne)
       
   813 			{				// skip a character in the input
       
   814 			if (pM==pP)
       
   815 				return r+((r>=0) ? 0 : (pE-pLeft));
       
   816 			++pB;
       
   817 			if (r<0)
       
   818 				--r;
       
   819 			continue;
       
   820 			}
       
   821 	// Matching a non-wild character
       
   822 		for (;;)
       
   823 			{
       
   824 			if (table)
       
   825 				{
       
   826 				while (lookup(++pB,table)!=c)
       
   827 					{
       
   828 					if (pB==pE)				// no more input
       
   829 						return KErrNotFound;
       
   830 					}
       
   831 				}
       
   832 			else
       
   833 				{
       
   834 				while (*++pB!=c)
       
   835 					{
       
   836 					if (pB==pE)				// no more input
       
   837 						return KErrNotFound;
       
   838 					}
       
   839 				}
       
   840 			// Try to match up to the next star
       
   841 			const TUint16* pb=pB;
       
   842 			const TUint16* pm=pM;
       
   843 			for (;;)
       
   844 				{
       
   845 				if (pm<pP)
       
   846 					{
       
   847 					TUint cc=conv(++pm,table, charDataSet);
       
   848 					if (cc==KMatchAny)
       
   849 						{	// sub-match successful, back to main loop
       
   850 						r+=(r>=0 ? 0 : pB-pLeft);
       
   851 						pB=pb;
       
   852 						pM=pm;
       
   853 						goto star;
       
   854 						}
       
   855 					if (pb==pE)
       
   856 						return KErrNotFound;	// no more input
       
   857 					if (cc!=conv(++pb,table, charDataSet) && cc!=KMatchOne)
       
   858 						break;	// sub-match failed, try next input character
       
   859 					}
       
   860 				else if (pb==pE)	// end of matching pattern
       
   861 					return r+(r>=0 ? 0 : pB-pLeft);	// end of input, so have a match
       
   862 				else
       
   863 					break;		// try next input character
       
   864 				}
       
   865 			}
       
   866 		}
       
   867 	}
       
   868 
       
   869 
       
   870 
       
   871 EXPORT_C TDesC16::TPrefix TDesC16::HasPrefixC(const TDesC16& aPossiblePrefix,
       
   872 	TInt aLevel, const TCollationMethod* aCollationMethod) const
       
   873 /**
       
   874 Compares aPossiblePrefix against the start of the descriptor, using a
       
   875 collated comparison.
       
   876 
       
   877 @param aLevel The maximum level at which to perform the collation.
       
   878 
       
   879               0: Only check character identities.
       
   880        
       
   881               1: Check accents as well.
       
   882        
       
   883               2: Check case as well.
       
   884           
       
   885               3: Check Unicode values.
       
   886        
       
   887               Currently only level 0 is supported.
       
   888        
       
   889 @param aCollationMethod The collation method to be used for the matching.
       
   890 
       
   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.
       
   900 */	
       
   901 	{
       
   902 	const TText16* lp = aPossiblePrefix.Ptr();
       
   903 	const TText16* rp = Ptr();
       
   904 	TInt ll = aPossiblePrefix.Length();
       
   905 	TInt rl = Length();
       
   906 	TInt r;
       
   907 	if (!aCollationMethod)
       
   908 		{
       
   909 		TCollate c(GetLocaleCharSet());
       
   910 		r = c.Compare(rp, rl, lp, ll, aLevel);
       
   911 		}
       
   912 	else
       
   913 		{
       
   914 		TCollate c(*aCollationMethod);
       
   915 		r = c.Compare(rp, rl, lp, ll, aLevel);
       
   916 		}
       
   917 	return r == 1 || r == 0? EIsPrefix : EIsNotPrefix;
       
   918 	}
       
   919 
       
   920 EXPORT_C TInt TDesC16::Match(const TDesC16 &aDes) const
       
   921 /**
       
   922 Searches this descriptor's data for a match with the match pattern supplied 
       
   923 in the specified descriptor.
       
   924 
       
   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.
       
   928 
       
   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
       
   931 this function.
       
   932 
       
   933 @param aDes A 16-bit non-modifable descriptor containing the match pattern. 
       
   934 
       
   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.
       
   937 */
       
   938 	{
       
   939 
       
   940 	return DoMatch16(*this,aDes,EMatchNormal);
       
   941 
       
   942 	}
       
   943 
       
   944 EXPORT_C TInt TDesC16::MatchF(const TDesC16 &aDes) const
       
   945 /**
       
   946 Searches this descriptor's folded data for a match with the folded match pattern 
       
   947 supplied in the specified descriptor.
       
   948 
       
   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.
       
   952 
       
   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.
       
   957 
       
   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
       
   960 this function.
       
   961 
       
   962 @param aDes A 16-bit non-modifable descriptor containing the match pattern. 
       
   963 
       
   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.
       
   966         
       
   967 @see TDesC16::MatchC()
       
   968 */
       
   969 	{
       
   970 	const TText16* csp = Ptr();
       
   971 	const TText16* stp = aDes.Ptr();
       
   972 	return LocateMatchStringFolded(csp, csp + Length(), stp, stp + aDes.Length());
       
   973 	}
       
   974 
       
   975 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern) const
       
   976 /**
       
   977 Searches this descriptor's collated data for a match with the collated match 
       
   978 pattern supplied in the specified descriptor.
       
   979 
       
   980 The function uses the standard collation method appropriate to
       
   981 the current locale.
       
   982 	
       
   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.
       
   986 
       
   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
       
   989 this function.
       
   990 	
       
   991 @param aPattern A 16-bit non-modifable descriptor containing the match pattern.
       
   992 
       
   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.
       
   995 */
       
   996 	{
       
   997 	TCollationMethod m=*Mem::GetDefaultMatchingTable();
       
   998 	m.iFlags |= (TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
       
   999 	TCollate c(m);
       
  1000 	return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), 0, '?', '*');
       
  1001 	}
       
  1002 
       
  1003 /**
       
  1004 Searches this descriptor's collated data for a match with the collated match 
       
  1005 pattern supplied in the specified descriptor.
       
  1006 
       
  1007 The function uses the standard collation method appropriate to
       
  1008 the current locale.
       
  1009 	
       
  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.
       
  1013 
       
  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.
       
  1028 
       
  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.
       
  1031 */
       
  1032 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern, TInt aWildChar, TInt aWildSequenceChar, 
       
  1033 							  TInt aEscapeChar, TInt aMaxLevel, const TCollationMethod* aCollationMethod) const
       
  1034 	{
       
  1035 	TCollationMethod m(aCollationMethod ? *aCollationMethod : *Mem::GetDefaultMatchingTable());
       
  1036 	m.iFlags |= (TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase);
       
  1037 	TCollate c(m);
       
  1038 	return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), aMaxLevel, aWildChar, aWildSequenceChar, aEscapeChar);
       
  1039 	}
       
  1040 
       
  1041 
       
  1042 /**
       
  1043 Searches this descriptor's collated data for a match with the collated match 
       
  1044 pattern supplied in the specified descriptor.
       
  1045 
       
  1046 The function uses the standard collation method appropriate to
       
  1047 the current locale.
       
  1048 	
       
  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.
       
  1052 
       
  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.
       
  1072 */
       
  1073 EXPORT_C TInt TDesC16::MatchC(const TDesC16 &aPattern, const TCollationMethod* aCollationMethod,
       
  1074 							  TInt aMaxLevel, TInt aWildChar, TInt aWildSequenceChar, TInt aEscapeChar) const
       
  1075 	{
       
  1076 	TCollate c(*aCollationMethod);
       
  1077 	return c.Match(Ptr(), Length(), aPattern.Ptr(), aPattern.Length(), aMaxLevel, aWildChar, aWildSequenceChar, aEscapeChar);
       
  1078 	}
       
  1079 
       
  1080 
       
  1081 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1082 EXPORT_C TInt TDesC16::Locate(TChar aChar) const
       
  1083 /**
       
  1084 Searches for the first occurrence of a character within this descriptor's 
       
  1085 data.
       
  1086 
       
  1087 The search starts at the beginning of the data, i.e. at the leftmost 
       
  1088 position.
       
  1089 
       
  1090 @param aChar The character to be found. 
       
  1091 
       
  1092 @return The offset of the character position from the beginning of the data.
       
  1093         KErrNotFound, if no matching character can be found.
       
  1094 */
       
  1095 	{
       
  1096 
       
  1097 	const TUint16 *pBuf=Ptr();
       
  1098 	const TUint16 *pB=pBuf-1;
       
  1099 	const TUint16 *pE=pB+Length();
       
  1100 	do
       
  1101 		{
       
  1102 		if (pB==pE)
       
  1103 			return KErrNotFound;
       
  1104 		} while (TUint(*++pB)!=aChar);
       
  1105 	return pB-pBuf;
       
  1106 	}
       
  1107 #endif
       
  1108 
       
  1109 LOCAL_C TInt DoLocateF16(const TDesC16& aDes,TUint aChar)
       
  1110 //
       
  1111 // Locate character aChar in the descriptor folded.
       
  1112 //
       
  1113 	{
       
  1114 #ifdef _UNICODE
       
  1115 	const TText* table = convTable(EMatchFolded);
       
  1116 	TUint16 aChar16 = (TUint16)aChar;
       
  1117 	aChar = lookup(&aChar16,table);
       
  1118 #else
       
  1119 	const TText* table=Locl::FoldTable;
       
  1120 	if (aChar<0x100)
       
  1121 		aChar=table[aChar];
       
  1122 #endif
       
  1123 	const TUint16 *pBuf=aDes.Ptr();
       
  1124 	const TUint16 *pB=pBuf-1;
       
  1125 	const TUint16 *pE=pB+aDes.Length();
       
  1126 	do
       
  1127 		{
       
  1128 		if (pB==pE)
       
  1129 			return KErrNotFound;
       
  1130 		} while (lookup(++pB,table)!=aChar);
       
  1131 	return pB-pBuf;
       
  1132 	}
       
  1133 
       
  1134 EXPORT_C TInt TDesC16::LocateF(TChar aChar) const
       
  1135 /**
       
  1136 Searches for the first occurrence of a folded character within this
       
  1137 descriptor's folded data.
       
  1138 
       
  1139 The search starts at the beginning of the data, i.e. at the leftmost 
       
  1140 position.
       
  1141 
       
  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.
       
  1145 
       
  1146 @param aChar The character to be found.
       
  1147 
       
  1148 @return The offset of the character position from the beginning of the data.
       
  1149         KErrNotFound, if no matching character can be found.
       
  1150 */
       
  1151 	{
       
  1152 
       
  1153 	return DoLocateF16(*this,aChar);
       
  1154 
       
  1155 	}
       
  1156 
       
  1157 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1158 EXPORT_C TInt TDesC16::LocateReverse(TChar aChar) const
       
  1159 /**
       
  1160 Searches for the first occurrence of a character within this descriptor's 
       
  1161 data, searching from the end of the data.
       
  1162 
       
  1163 The search starts at the rightmost position.
       
  1164 
       
  1165 @param aChar The character to be found.
       
  1166 
       
  1167 @return The offset of the character position from the beginning of the data.
       
  1168         KErrNotFound, if no matching character can be found.
       
  1169 */
       
  1170 	{
       
  1171 
       
  1172 	TInt len=Length();
       
  1173 	if (len==0)
       
  1174 		return(KErrNotFound);
       
  1175 	const TUint16 *pB=Ptr();
       
  1176 	const TUint16 *pE=pB+len-1;
       
  1177 	while (pE>=pB)
       
  1178 		{
       
  1179 		if (TUint(*pE)==aChar)
       
  1180 			break;
       
  1181 		pE--;
       
  1182 		}
       
  1183 	return(pE<pB ? KErrNotFound : pE-pB);
       
  1184 	}
       
  1185 #endif
       
  1186 
       
  1187 EXPORT_C TInt TDesC16::LocateReverseF(TChar aChar) const
       
  1188 /**
       
  1189 Searches for the first occurrence of a folded character within this descriptor's 
       
  1190 folded data, searching from the end of the data.
       
  1191 
       
  1192 The search starts at the rightmost position.
       
  1193 
       
  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.
       
  1197 
       
  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.
       
  1201 */
       
  1202 	{
       
  1203 
       
  1204 	TInt len=Length();
       
  1205 	if (len==0)
       
  1206 		return(KErrNotFound);
       
  1207 	const TUint16 *pB=Ptr();
       
  1208 	const TUint16 *pE=pB+len-1;
       
  1209 	aChar.Fold();
       
  1210 	while (pE>=pB)
       
  1211 		{
       
  1212 		TCharF c(*pE);
       
  1213 		if (c==aChar)
       
  1214 			break;
       
  1215 		pE--;
       
  1216 		}
       
  1217 	return(pE<pB ? KErrNotFound : pE-pB);
       
  1218 	}
       
  1219 
       
  1220 EXPORT_C HBufC16 *TDesC16::Alloc() const
       
  1221 /**
       
  1222 Creates a new 16-bit heap descriptor and initialises it with a copy of this 
       
  1223 descriptor's data.
       
  1224 
       
  1225 @return A pointer to the new 16-bit heap descriptor, if creation is successful. 
       
  1226         NULL, if creation of the descriptor fails.
       
  1227 */
       
  1228 	{
       
  1229 
       
  1230 	HBufC16 *pH=HBufC16::New(Length());
       
  1231 	if (pH)
       
  1232 		*pH=(*this);
       
  1233 	return(pH);
       
  1234 	}
       
  1235 
       
  1236 EXPORT_C HBufC16 *TDesC16::AllocL() const
       
  1237 /**
       
  1238 Creates a new 16-bit heap descriptor and initialises it with a copy of this 
       
  1239 descriptor's data.
       
  1240 
       
  1241 The function leaves, if creation of the descriptor fails.
       
  1242 
       
  1243 @return A pointer to the 16-bit heap descriptor, if creation is successful.
       
  1244 */
       
  1245 	{
       
  1246 
       
  1247 	HBufC16 *pH=HBufC16::NewL(Length());
       
  1248 	*pH=(*this);
       
  1249 	return(pH);
       
  1250 	}
       
  1251 
       
  1252 EXPORT_C HBufC16 *TDesC16::AllocLC() const
       
  1253 /**
       
  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.
       
  1256 
       
  1257 The function leaves, if creation of the descriptor fails.
       
  1258 
       
  1259 @return A pointer to the 16-bit heap descriptor, if creation is successful. 
       
  1260         The pointer is also put onto the cleanup stack.
       
  1261 */
       
  1262 	{
       
  1263 
       
  1264 	HBufC16 *pH=HBufC16::NewLC(Length());
       
  1265 	*pH=(*this);
       
  1266 	return(pH);
       
  1267 	}
       
  1268 
       
  1269 #if !defined(__DES16_MACHINE_CODED__)
       
  1270 
       
  1271 EXPORT_C TPtrC16 TDesC16::Left(TInt aLength) const
       
  1272 /**
       
  1273 Extracts the leftmost part of the data. 
       
  1274 
       
  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.
       
  1277 
       
  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.
       
  1281                
       
  1282 @return The 16-bit non-modifiable pointer descriptor representing the leftmost 
       
  1283         part of the data.
       
  1284 
       
  1285 @panic USER 10 if aLength is negative. 
       
  1286 */
       
  1287 	{
       
  1288 
       
  1289 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
       
  1290 	return(TPtrC16(Ptr(),Min(aLength,Length())));
       
  1291 	}
       
  1292 
       
  1293 EXPORT_C TPtrC16 TDesC16::Right(TInt aLength) const
       
  1294 /**
       
  1295 Extracts the rightmost part of the data.
       
  1296 
       
  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.
       
  1299 
       
  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. 
       
  1303                
       
  1304 @return The 16-bit non-modifiable pointer descriptor representing the rightmost 
       
  1305         part of the data.
       
  1306 
       
  1307 @panic USER 10 if aLength is negative.
       
  1308 */
       
  1309 	{
       
  1310 
       
  1311 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
       
  1312 	TInt len=Length();
       
  1313 	if (aLength>len)
       
  1314 		aLength=len;
       
  1315     return(TPtrC16(Ptr()+len-aLength,aLength));
       
  1316 	}
       
  1317 
       
  1318 EXPORT_C TPtrC16 TDesC16::Mid(TInt aPos) const
       
  1319 /**
       
  1320 Extracts a portion of the data.
       
  1321 
       
  1322 The function does not cut or remove any data but constructs a non-modifiable 
       
  1323 pointer descriptor to represent the defined portion.
       
  1324 
       
  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.
       
  1327 
       
  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.
       
  1330              
       
  1331 @return The 16-bit non-modifiable pointer descriptor representing the specified 
       
  1332         portion of the data.
       
  1333 
       
  1334 @panic USER 10  if aPos is negative or aPos is greater than the
       
  1335                 length of the descriptor.
       
  1336 */
       
  1337 	{
       
  1338 
       
  1339 	TInt len=Length();
       
  1340 	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
       
  1341     return(TPtrC16(Ptr()+aPos,len-aPos));
       
  1342 	}
       
  1343 
       
  1344 EXPORT_C TPtrC16 TDesC16::Mid(TInt aPos,TInt aLength) const
       
  1345 /**
       
  1346 Extracts a portion of the data.
       
  1347 
       
  1348 The function does not cut or remove any data but constructs a non-modifiable 
       
  1349 pointer descriptor to represent the defined portion.
       
  1350 
       
  1351 The portion is identified by its starting position and by its length.
       
  1352 
       
  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.
       
  1356 
       
  1357 @return The 16-bit non-modifiable pointer descriptor representing the specified 
       
  1358         portion of the data.
       
  1359         
       
  1360 @panic USER 10  if aPos is negative or aPos plus aLength is greater than the
       
  1361                 length of the descriptor.
       
  1362 */
       
  1363 	{
       
  1364 
       
  1365 	__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes16PosOutOfRange));
       
  1366     return(TPtrC16(Ptr()+aPos,aLength));
       
  1367 	}
       
  1368 
       
  1369 #endif  // !defined(__DES16_MACHINE_CODED__)
       
  1370 
       
  1371 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
       
  1372 EXPORT_C TBufCBase16::TBufCBase16()
       
  1373 //
       
  1374 // Constructor
       
  1375 //
       
  1376 	: TDesC16(EBufC,0)
       
  1377 	{}
       
  1378 #endif
       
  1379 
       
  1380 #if !defined( __DES16_MACHINE_CODED_HWORD__) | defined(__EABI_CTORS__)
       
  1381 EXPORT_C TBufCBase16::TBufCBase16(const TUint16 *aString,TInt aMaxLength)
       
  1382 //
       
  1383 // Constructor
       
  1384 //
       
  1385 	: TDesC16(EBufC,0)
       
  1386 	{
       
  1387 	Copy(aString,aMaxLength);
       
  1388 	}
       
  1389 #endif
       
  1390 
       
  1391 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
       
  1392 EXPORT_C TBufCBase16::TBufCBase16(const TDesC16 &aDes,TInt aMaxLength)
       
  1393 //
       
  1394 // Constructor
       
  1395 //
       
  1396 	: TDesC16(EBufC,0)
       
  1397 	{
       
  1398 	Copy(aDes,aMaxLength);
       
  1399 	}
       
  1400 #endif
       
  1401 
       
  1402 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1403 EXPORT_C void TBufCBase16::Copy(const TUint16 *aString,TInt aMaxLength)
       
  1404 //
       
  1405 // Copy from a string.
       
  1406 //
       
  1407 	{
       
  1408 
       
  1409 	__CHECK_ALIGNMENT(aString,ETBufCBase16CopyStringMax);
       
  1410 	TInt len=STRING_LENGTH_16(aString);
       
  1411 	__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes16Overflow));
       
  1412 	memCopy(WPtr(),aString,len);
       
  1413 	DoSetLength(len);
       
  1414 	}
       
  1415 #endif
       
  1416 
       
  1417 #ifndef __DES16_MACHINE_CODED__
       
  1418 EXPORT_C void TBufCBase16::Copy(const TDesC16 &aDes,TInt aMaxLength)
       
  1419 //
       
  1420 // Copy from a descriptor.
       
  1421 //
       
  1422 	{
       
  1423 
       
  1424 	TInt len=aDes.Length();
       
  1425 	__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes16Overflow));
       
  1426 	memCopy(WPtr(),aDes.Ptr(),len);
       
  1427 	DoSetLength(len);
       
  1428 	}
       
  1429 #endif
       
  1430 
       
  1431 inline HBufC16::HBufC16(TInt aLength)
       
  1432 	:TBufCBase16(aLength)
       
  1433 	{}
       
  1434 
       
  1435 EXPORT_C HBufC16 *HBufC16::New(TInt aMaxLength)
       
  1436 /**
       
  1437 Creates, and returns a pointer to, a new 16-bit heap descriptor.
       
  1438 
       
  1439 The heap descriptor is empty and its length is zero.
       
  1440 
       
  1441 Data can, subsequently, be assigned into it using the assignment operators.
       
  1442 
       
  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
       
  1446                   requested.
       
  1447 
       
  1448 @return A pointer to the new 16-bit heap descriptor. NULL, if the 16-bit heap 
       
  1449         descriptor cannot be created.
       
  1450         
       
  1451 @panic USER 18 if aMaxLength is negative.
       
  1452 
       
  1453 @see HBufC16::operator=()
       
  1454 */
       
  1455 	{
       
  1456 	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  1457 	return new(STD_CLASS::Alloc(_FOFF(HBufC16,iBuf[aMaxLength]))) HBufC16(0);
       
  1458 	}
       
  1459 
       
  1460 EXPORT_C HBufC16 *HBufC16::NewL(TInt aMaxLength)
       
  1461 /**
       
  1462 Creates, and returns a pointer to, a new 16-bit heap descriptor, and leaves 
       
  1463 on failure.
       
  1464 
       
  1465 The heap descriptor is empty and its length is zero.
       
  1466 
       
  1467 Data can, subsequently, be assigned into it using the assignment operators.
       
  1468 
       
  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
       
  1472                   than requested.
       
  1473                   
       
  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.
       
  1476         
       
  1477 
       
  1478 @panic USER 18 if aMaxLength is negative.
       
  1479 
       
  1480 @see HBufC16::operator=()
       
  1481 */
       
  1482 	{
       
  1483 	return static_cast<HBufC16*>(User::LeaveIfNull(New(aMaxLength)));
       
  1484 	}
       
  1485 
       
  1486 EXPORT_C HBufC16 *HBufC16::NewLC(TInt aMaxLength)
       
  1487 /**
       
  1488 Creates, adds a pointer onto the cleanup stack and returns a pointer to, a 
       
  1489 new 16-bit heap descriptor; leaves on failure.
       
  1490 
       
  1491 The heap descriptor is empty and its length is zero.
       
  1492 
       
  1493 Data can, subsequently, be assigned into it using the assignment operators.
       
  1494 
       
  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
       
  1498                   than requested.
       
  1499                   
       
  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.
       
  1502         
       
  1503 @panic USER 18 if aMaxLength is negative.
       
  1504 
       
  1505 @see HBufC16::operator=()
       
  1506 */
       
  1507 	{
       
  1508 	HBufC16* buf=NewL(aMaxLength);
       
  1509 	CleanupStack::PushL(buf);
       
  1510 	return buf;
       
  1511 	}
       
  1512 
       
  1513 EXPORT_C HBufC16 *HBufC16::NewMax(TInt aMaxLength)
       
  1514 /**
       
  1515 Creates, and returns a pointer to, a new 16-bit heap descriptor.
       
  1516 
       
  1517 No data is assigned into the new descriptor but its length
       
  1518 is set to aMaxLength.
       
  1519 
       
  1520 Data can, subsequently, be assigned into it using the assignment operators.
       
  1521 
       
  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.
       
  1529 
       
  1530 @panic USER 18 if aMaxLength is negative.
       
  1531 
       
  1532 @see HBufC16::operator=()
       
  1533 */
       
  1534 	{
       
  1535 	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  1536 	return new(STD_CLASS::Alloc(_FOFF(HBufC16,iBuf[aMaxLength]))) HBufC16(aMaxLength);
       
  1537 	}
       
  1538 
       
  1539 EXPORT_C HBufC16 *HBufC16::NewMaxL(TInt aMaxLength)
       
  1540 /**
       
  1541 Creates, and returns a pointer to, a new 16-bit heap descriptor;
       
  1542 leaves on failure.
       
  1543 
       
  1544 No data is assigned into the new descriptor but its length is set
       
  1545 to aMaxLength.
       
  1546 
       
  1547 Data can, subsequently, be assigned into it using the assignment operators.
       
  1548 
       
  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.
       
  1554                   
       
  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.
       
  1557 
       
  1558 @panic USER 18 if aMaxLength is negative.
       
  1559 
       
  1560 @see HBufC16::operator=()
       
  1561 */
       
  1562 	{
       
  1563 	return static_cast<HBufC16*>(User::LeaveIfNull(NewMax(aMaxLength)));
       
  1564 	}
       
  1565 
       
  1566 EXPORT_C HBufC16 *HBufC16::NewMaxLC(TInt aMaxLength)
       
  1567 /**
       
  1568 Creates, adds a pointer onto the cleanup stack and returns a pointer to, a 
       
  1569 new 16-bit heap descriptor; leaves on failure.
       
  1570 
       
  1571 No data is assigned into the new descriptor but its length
       
  1572 is set to aMaxLength.
       
  1573 
       
  1574 Data can, subsequently, be assigned into it using the assignment operators.
       
  1575 
       
  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.
       
  1579 
       
  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 
       
  1582         cannot be created.
       
  1583 
       
  1584 @panic USER 18 if aMaxLength is negative.
       
  1585 
       
  1586 @see HBufC16::operator=()
       
  1587 */
       
  1588 	{
       
  1589 	HBufC16* buf=NewMaxL(aMaxLength);
       
  1590 	CleanupStack::PushL(buf);
       
  1591 	return buf;
       
  1592 	}
       
  1593 
       
  1594 EXPORT_C HBufC16 &HBufC16::operator=(const TUint16 *aString)
       
  1595 /**
       
  1596 Copies data into this 16-bit heap descriptor replacing any existing data.
       
  1597 
       
  1598 The length of this descriptor is set to reflect the new data.
       
  1599 
       
  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
       
  1603 last re-allocated.
       
  1604 
       
  1605 @param aString A pointer to a zero-terminated string.
       
  1606 
       
  1607 @return A reference to this 16-bit heap descriptor.
       
  1608 
       
  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.
       
  1611 */
       
  1612 	{
       
  1613 
       
  1614 	__CHECK_ALIGNMENT(aString,EHBufC16AssignCString);
       
  1615 	Copy(aString,(STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
       
  1616 	return(*this);
       
  1617 	}
       
  1618 
       
  1619 EXPORT_C HBufC16 &HBufC16::operator=(const TDesC16 &aDes)
       
  1620 /**
       
  1621 Copies data into this 16-bit heap descriptor replacing any existing data.
       
  1622 
       
  1623 The length of this descriptor is set to reflect the new data.
       
  1624 
       
  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
       
  1628 last re-allocated.
       
  1629 
       
  1630 @param aDes A 16-bit non-modifiable descriptor.
       
  1631 
       
  1632 @return A reference to this 16-bit heap descriptor.
       
  1633 
       
  1634 @panic USER 11  if the length of the descriptor aDes is greater than the
       
  1635                 maximum length of this (target) descriptor
       
  1636 */
       
  1637 	{
       
  1638 
       
  1639 	Copy(aDes,(STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
       
  1640 	return(*this);
       
  1641 	}
       
  1642 
       
  1643 EXPORT_C HBufC16 *HBufC16::ReAlloc(TInt aMaxLength)
       
  1644 /**
       
  1645 Expands or contracts this 16-bit heap descriptor.
       
  1646 
       
  1647 This is done by:
       
  1648 
       
  1649 1. creating a new heap descriptor.
       
  1650 
       
  1651 2. copying the original data into the new descriptor.
       
  1652 
       
  1653 3. deleting the original descriptor.
       
  1654 
       
  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.
       
  1659                   
       
  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.
       
  1663 
       
  1664 @panic USER 14 if aMaxLength is less than the length of the existing data.
       
  1665 @panic USER 18 if aMaxLength is negative.
       
  1666 */
       
  1667 	{
       
  1668 
       
  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)));
       
  1672 	}
       
  1673 
       
  1674 EXPORT_C HBufC16 *HBufC16::ReAllocL(TInt aMaxLength)
       
  1675 /**
       
  1676 Expands or contracts this 16-bit heap descriptor; leaves on failure.
       
  1677 
       
  1678 This is done by:
       
  1679 
       
  1680 1. creating a new heap descriptor.
       
  1681 
       
  1682 2. copying the original data into the new descriptor.
       
  1683 
       
  1684 3. deleting the original descriptor.
       
  1685 
       
  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.
       
  1690                   
       
  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
       
  1694         remains unchanged.
       
  1695 
       
  1696 @panic USER 14 if aMaxLength is less than the length of the existing data.
       
  1697 @panic USER 18 if aMaxLength is negative.
       
  1698 */
       
  1699 	{
       
  1700 
       
  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)));
       
  1704 	}
       
  1705 
       
  1706 EXPORT_C TPtr16 HBufC16::Des()
       
  1707 /**
       
  1708 Creates and returns a 16-bit modifiable pointer descriptor for the data
       
  1709 represented by this 16-bit heap descriptor.
       
  1710 
       
  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.
       
  1714 
       
  1715 The modifiable pointer descriptor is set to point to this heap descriptor's 
       
  1716 data.
       
  1717 
       
  1718 The length of the modifiable pointer descriptor is set to the length of this 
       
  1719 heap descriptor.
       
  1720 
       
  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.
       
  1726 
       
  1727 When data is modified through this new pointer descriptor, the lengths of 
       
  1728 both it and this heap descriptor are changed.
       
  1729 
       
  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.
       
  1733 
       
  1734 @return A 16-bit modifiable pointer descriptor representing the data in this 
       
  1735         16-bit heap descriptor.
       
  1736 */
       
  1737 	{
       
  1738 
       
  1739 	return DoDes((STD_CLASS::AllocLen(this)-sizeof(TDesC16))/sizeof(TUint16));
       
  1740 	}
       
  1741 
       
  1742 #ifndef __DES16_MACHINE_CODED__
       
  1743 EXPORT_C void TDes16::SetLength(TInt aLength)
       
  1744 /**
       
  1745 Sets the length of the data represented by the descriptor to the
       
  1746 specified value.
       
  1747 
       
  1748 @param aLength The new length of the descriptor.
       
  1749 
       
  1750 @panic USER 11  if aLength is negative or is greater than the maximum length of
       
  1751                 this (target) descriptor.
       
  1752 */
       
  1753 	{
       
  1754 
       
  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
       
  1759   	}
       
  1760 
       
  1761 EXPORT_C void TDes16::SetMax()
       
  1762 /**
       
  1763 Sets the length of the data to the maximum length of the descriptor.
       
  1764 */
       
  1765 	{
       
  1766 
       
  1767 	SetLength(iMaxLength);
       
  1768 	}
       
  1769 #endif
       
  1770 
       
  1771 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1772 EXPORT_C void TDes16::Copy(const TUint16 *aString)
       
  1773 /**
       
  1774 Copies data into this descriptor replacing any existing data.
       
  1775 
       
  1776 The length of this descriptor is set to reflect the new data.
       
  1777 
       
  1778 @param aString A pointer to a zero-terminated string.
       
  1779 
       
  1780 @panic USER 11  if the length of aString, excluding the zero terminator, is
       
  1781                 greater than the maximum length of this (target) descriptor.
       
  1782 */
       
  1783 	{
       
  1784 
       
  1785 	__CHECK_ALIGNMENT(aString,ETDes16CopyCString);
       
  1786 	TInt len=STRING_LENGTH_16(aString);
       
  1787 	SetLength(len);
       
  1788     memCopy(WPtr(),aString,len);
       
  1789 	}
       
  1790 #endif
       
  1791 
       
  1792 #ifndef __DES16_MACHINE_CODED__
       
  1793 EXPORT_C void TDes16::Copy(const TUint16 *aBuf,TInt aLength)
       
  1794 /**
       
  1795 Copies data into this descriptor replacing any existing data.
       
  1796 
       
  1797 The length of this descriptor is set to reflect the new data.
       
  1798 
       
  1799 @param aBuf    The start address of data to be copied. 
       
  1800 @param aLength The length of data to be copied.
       
  1801 
       
  1802 @panic USER 11  if aLength is negative or is greater than maximum length
       
  1803                 of this (target) descriptor.
       
  1804 */
       
  1805 	{
       
  1806 
       
  1807 	__CHECK_ALIGNMENT(aBuf,ETDes16CopyBufLength);
       
  1808 	SetLength(aLength);
       
  1809     memCopy(WPtr(),aBuf,aLength);
       
  1810 	}
       
  1811 
       
  1812 EXPORT_C void TDes16::Copy(const TDesC16 &aDes)
       
  1813 /**
       
  1814 Copies data into this descriptor replacing any existing data.
       
  1815 
       
  1816 The length of this descriptor is set to reflect the new data.
       
  1817 
       
  1818 @param aDes A 16-bit non modifiable descriptor.
       
  1819 
       
  1820 @panic USER 11  if the length of aDes is greater than the maximum length
       
  1821                 of this (target) descriptor.
       
  1822 */
       
  1823 	{
       
  1824 
       
  1825 	TInt len=aDes.Length();
       
  1826 	SetLength(len);
       
  1827     memCopy(WPtr(),aDes.Ptr(),len);
       
  1828 	}
       
  1829 #endif
       
  1830 
       
  1831 EXPORT_C void TDes16::Copy(const TDesC8 &aDes)
       
  1832 /**
       
  1833 Copies data into this descriptor replacing any existing data.
       
  1834 
       
  1835 The length of this descriptor is set to reflect the new data.
       
  1836 
       
  1837 @param aDes An 8 bit non modifiable descriptor. 
       
  1838 
       
  1839 @panic USER 11  if the length of aDes is greater than the maximum
       
  1840                 length of this (target) descriptor.
       
  1841 */
       
  1842 	{
       
  1843 
       
  1844 	TInt len=aDes.Length();
       
  1845 	SetLength(len);
       
  1846 	const TUint8 *pS=aDes.Ptr();
       
  1847 	const TUint8 *pE=pS+len;
       
  1848 	TUint16 *pT=WPtr();
       
  1849 	while (pS<pE)
       
  1850 		*pT++=(*pS++);
       
  1851 	}
       
  1852 
       
  1853 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1854 EXPORT_C void TDes16::Append(TChar aChar)
       
  1855 /**
       
  1856 Appends data onto the end of this descriptor's data.
       
  1857 
       
  1858 The length of this descriptor is incremented to reflect the new content.
       
  1859 
       
  1860 @param aChar A single character to be appended. The length of the descriptor 
       
  1861              is incremented by one.
       
  1862              
       
  1863 @panic USER 11  if the resulting new length of this descriptor is greater than
       
  1864                 its maximum length.
       
  1865 */
       
  1866 	{
       
  1867 
       
  1868 	TInt len=Length();
       
  1869 	TUint16 *pB=WPtr()+len;
       
  1870 	SetLength(len+1);
       
  1871 	*pB++=(TUint16)aChar;
       
  1872 	}
       
  1873 #endif
       
  1874 
       
  1875 #ifndef __DES16_MACHINE_CODED__
       
  1876 EXPORT_C void TDes16::Append(const TUint16 *aBuf,TInt aLength)
       
  1877 /**
       
  1878 Appends data onto the end of this descriptor's data.
       
  1879 
       
  1880 The length of this descriptor is incremented to reflect the new content.
       
  1881 
       
  1882 @param aBuf    A pointer to the data to be copied.
       
  1883 @param aLength The length of data to be copied.
       
  1884 
       
  1885 @panic USER 11  if the resulting new length of this descriptor is greater than
       
  1886                 its maximum length.
       
  1887 @panic USER 17  if aLength is negative.
       
  1888 */
       
  1889 	{
       
  1890 
       
  1891 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
       
  1892 	__CHECK_ALIGNMENT(aBuf,ETDes16AppendBufLength);
       
  1893 	TInt len=Length();
       
  1894 	SetLength(len+aLength);
       
  1895     memCopy(WPtr()+len,aBuf,aLength);
       
  1896 	}
       
  1897 
       
  1898 EXPORT_C void TDes16::Append(const TDesC16 &aDes)
       
  1899 /**
       
  1900 Appends data onto the end of this descriptor's data.
       
  1901 
       
  1902 The length of this descriptor is incremented to reflect the new content.
       
  1903 
       
  1904 @param aDes A 16-bit non modifiable descriptor whose data is to be appended.
       
  1905 
       
  1906 @panic USER 11  if the resulting new length of this descriptor is greater than
       
  1907                 its maximum length.
       
  1908 */
       
  1909 	{
       
  1910 
       
  1911 	TInt len=Length();
       
  1912     TInt n=aDes.Length();
       
  1913 	SetLength(len+n);
       
  1914     memCopy(WPtr()+len,aDes.Ptr(),n);
       
  1915 	}
       
  1916 #endif
       
  1917 
       
  1918 EXPORT_C void TDes16::Swap(TDes16 &aDes)
       
  1919 /**
       
  1920 Swaps the data represented by this descriptor with the data represented by 
       
  1921 the specified descriptor.
       
  1922 
       
  1923 The lengths of both descriptors are also swapped to reflect the change.
       
  1924 
       
  1925 Note that each descriptor must be capable of accommodating the contents of
       
  1926 the other descriptor.
       
  1927 
       
  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.
       
  1931 
       
  1932 @param aDes The 16-bit modifiable descriptor whose data is to be swapped with 
       
  1933             the data of this descriptor.
       
  1934             
       
  1935 @panic USER 11  if the maximum length of either descriptor is smaller than the 
       
  1936                 length of the other descriptor.
       
  1937 */
       
  1938 	{
       
  1939 
       
  1940 	TInt l=Length();
       
  1941 	TInt r=aDes.Length();
       
  1942 	aDes.SetLength(l);
       
  1943 	SetLength(r);
       
  1944 	TInt s=Min(l,r);
       
  1945 	l-=s;
       
  1946 	r-=s;
       
  1947 	TUint16 *pL=WPtr();
       
  1948 	TUint16 *pR=aDes.WPtr();
       
  1949 	while (s--)
       
  1950 		{
       
  1951 		TChar a=(*pL);
       
  1952 		*pL++=(*pR);
       
  1953 		*pR++=(TUint16)a;
       
  1954 		}
       
  1955 	while (l--)
       
  1956 		*pR++=(*pL++);
       
  1957 	while (r--)
       
  1958 		*pL++=(*pR++);
       
  1959 	}
       
  1960 
       
  1961 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  1962 EXPORT_C void TDes16::Fill(TChar aChar)
       
  1963 /**
       
  1964 Fills the descriptor's data area with the specified character, replacing any 
       
  1965 existing data.
       
  1966 
       
  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.
       
  1969 
       
  1970 @param aChar The fill character.
       
  1971 */
       
  1972 	{
       
  1973 
       
  1974 	TUint16 *pB=WPtr();
       
  1975 	TUint16 *pE=pB+Length();
       
  1976 	while (pB<pE)
       
  1977 		*pB++=(TUint16)aChar;
       
  1978 	}
       
  1979 #endif
       
  1980 
       
  1981 EXPORT_C void TDes16::Fill(TChar aChar,TInt aLength)
       
  1982 /** 
       
  1983 Fills the descriptor's data area with the specified character, replacing any 
       
  1984 existing data.
       
  1985 
       
  1986 The descriptor is filled with the specified number of characters,
       
  1987 and its length is changed to reflect this.
       
  1988 
       
  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. 
       
  1992                
       
  1993 @panic USER 11  if aLength is negative or is greater than the maximum length
       
  1994                 of this descriptor.
       
  1995 */
       
  1996 	{
       
  1997 
       
  1998 	SetLength(aLength);
       
  1999 	Fill(aChar);
       
  2000 	}
       
  2001 
       
  2002 EXPORT_C void TDes16::AppendFill(TChar aChar,TInt aLength)
       
  2003 /**
       
  2004 Appends and fills this descriptor with the specified character.
       
  2005 
       
  2006 The descriptor is appended with the specified number of characters.
       
  2007 and its length is changed to reflect this.
       
  2008 
       
  2009 @param aChar   The fill character. 
       
  2010 @param aLength The number of fill characters to be appended.
       
  2011 
       
  2012 @panic USER 11  if aLength is negative, or the resulting length of this
       
  2013                 descriptor is greater than its maximum length.
       
  2014 */
       
  2015 	{
       
  2016 
       
  2017 	TInt len=Length();
       
  2018 	TUint16 *pB=WPtr()+len;
       
  2019 	SetLength(len+aLength);
       
  2020 	TUint16 *pE=pB+aLength;
       
  2021 	while (pB<pE)
       
  2022 		*pB++=(TUint16)aChar;
       
  2023 	}
       
  2024 
       
  2025 #ifndef __DES16_MACHINE_CODED_HWORD__
       
  2026 EXPORT_C void TDes16::ZeroTerminate()
       
  2027 /**
       
  2028 Appends a zero terminator onto the end of this descriptor's data.
       
  2029 
       
  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.
       
  2033 
       
  2034 @panic USER 11  if the descriptor's length is not strictly less than its
       
  2035                 maximum length.
       
  2036 */
       
  2037 	{
       
  2038 
       
  2039 	TInt len=Length();
       
  2040 	__ASSERT_ALWAYS(len<MaxLength(),Panic(ETDes16Overflow));
       
  2041 	WPtr()[len]=0;
       
  2042 	}
       
  2043 
       
  2044 EXPORT_C const TUint16 *TDes16::PtrZ()
       
  2045 /**
       
  2046 Appends a zero terminator onto the end of this descriptor's data and returns 
       
  2047 a pointer to the data.
       
  2048 
       
  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
       
  2052 zero terminator.
       
  2053 
       
  2054 @return A pointer to the descriptor's zero terminated data.
       
  2055 
       
  2056 @panic USER 11  if the descriptor's length is not strictly less than its
       
  2057                 maximum length.
       
  2058 */
       
  2059 	{
       
  2060 
       
  2061 	ZeroTerminate();
       
  2062 	return(Ptr());
       
  2063 	}
       
  2064 #endif
       
  2065 
       
  2066 #ifndef __DES16_MACHINE_CODED__
       
  2067 EXPORT_C void TDes16::Zero()
       
  2068 /**
       
  2069 Sets the length of the data to zero.
       
  2070 */
       
  2071 	{
       
  2072 
       
  2073 	SetLength(0);
       
  2074 	}
       
  2075 #endif
       
  2076 
       
  2077 #ifndef __DES16_MACHINE_CODED__
       
  2078 EXPORT_C void TDes16::FillZ()
       
  2079 /**
       
  2080 Fills the descriptor's data area with binary zeroes, i.e.0x0000, replacing any 
       
  2081 existing data.
       
  2082 
       
  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.
       
  2085 */
       
  2086 	{
       
  2087 
       
  2088     memclr(WPtr(),Length()*2);
       
  2089 	}
       
  2090 #endif
       
  2091 
       
  2092 EXPORT_C void TDes16::FillZ(TInt aLength)
       
  2093 /**
       
  2094 Fills the descriptor's data area with binary zeroes, i.e. 0x0000, replacing any 
       
  2095 existing data, and changes its length.
       
  2096 
       
  2097 The descriptor is filled with the specified number of binary zeroes.
       
  2098 The descriptor's length is changed to reflect this.
       
  2099 
       
  2100 @param aLength The new length of the descriptor and the number of binary zeroes
       
  2101                to be copied into it. 
       
  2102                
       
  2103 @panic USER 11  if aLength is negative, or is greater than the maximum length
       
  2104                 of this descriptor.
       
  2105 */
       
  2106 	{
       
  2107 
       
  2108 	SetLength(aLength);
       
  2109     FillZ();
       
  2110 	}
       
  2111 
       
  2112 EXPORT_C void TDes16::Fold()
       
  2113 /**
       
  2114 Performs folding on the content of this descriptor.
       
  2115 
       
  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
       
  2119 language.
       
  2120 */
       
  2121 	{
       
  2122 
       
  2123 	TUint16 *pB=WPtr();
       
  2124 	TInt len=Length();
       
  2125 	while (len--)
       
  2126 		{
       
  2127 		TCharF c(*pB);
       
  2128 		*pB++=(TUint16)c;
       
  2129 		}
       
  2130 	}
       
  2131 
       
  2132 EXPORT_C void TDes16::Collate()
       
  2133 /**
       
  2134 Performs collation on the content of this descriptor.
       
  2135 */
       
  2136 	{
       
  2137 
       
  2138 	TUint16 *pB=WPtr();
       
  2139 	TInt len=Length();
       
  2140 	while (len--)
       
  2141 		{
       
  2142 		TChar c=User::Collate(*pB);
       
  2143 		*pB++=(TUint16)c;
       
  2144 		}
       
  2145 	}
       
  2146 
       
  2147 EXPORT_C void TDes16::LowerCase()
       
  2148 /**
       
  2149 Converts the content of this descriptor to lower case.
       
  2150 
       
  2151 Conversion is implemented as appropriate to the current locale.
       
  2152 */
       
  2153 	{
       
  2154 
       
  2155 	TUint16 *pB=WPtr();
       
  2156 	TInt len=Length();
       
  2157 	while (len--)
       
  2158 		{
       
  2159 		TCharLC c(*pB);
       
  2160 		*pB++=(TUint16)c;
       
  2161 		}
       
  2162 	}
       
  2163 
       
  2164 EXPORT_C void TDes16::UpperCase()
       
  2165 /**
       
  2166 Converts the content of this descriptor to upper case.
       
  2167 
       
  2168 Conversion is implemented as appropriate to the current locale.
       
  2169 */
       
  2170 	{
       
  2171 
       
  2172 	TUint16 *pB=WPtr();
       
  2173 	TInt len=Length();
       
  2174 	while (len--)
       
  2175 		{
       
  2176 		TCharUC c(*pB);
       
  2177 		*pB++=(TUint16)c;
       
  2178 		}
       
  2179 	}
       
  2180 
       
  2181 EXPORT_C void TDes16::Capitalize()
       
  2182 /**
       
  2183 Capitalises the content of this descriptor.
       
  2184 
       
  2185 Capitalisation is implemented as appropriate to the current locale.
       
  2186 */
       
  2187 	{
       
  2188 
       
  2189 	TUint16 *pB=WPtr();
       
  2190 	TInt len=Length();
       
  2191 	if (len--)
       
  2192 		{
       
  2193 		*pB=(TUint16)User::TitleCase(*pB);
       
  2194 		++pB;
       
  2195 		while (len--)
       
  2196 			{
       
  2197 			*pB=(TUint16)User::LowerCase(*pB);
       
  2198 			++pB;
       
  2199 			}
       
  2200 		}
       
  2201 	}
       
  2202 
       
  2203 EXPORT_C void TDes16::CopyF(const TDesC16 &aDes)
       
  2204 /**
       
  2205 Copies and folds data from the specified descriptor into this descriptor replacing 
       
  2206 any existing data.
       
  2207 
       
  2208 The length of this descriptor is set to reflect the new 
       
  2209 data.
       
  2210 
       
  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
       
  2214 language.
       
  2215 
       
  2216 @param aDes A 16-bit non-modifiable descriptor.
       
  2217 
       
  2218 @panic USER 11  if the length of aDes is greater than the maximum length of
       
  2219                 this target descriptor.
       
  2220 */
       
  2221 	{
       
  2222 
       
  2223 	TInt len=aDes.Length();
       
  2224 	SetLength(len);
       
  2225 	const TUint16 *pS=aDes.Ptr();
       
  2226 	TUint16 *pT=WPtr();
       
  2227 	while (len--)
       
  2228 		{
       
  2229 		TCharF c(*pS++);
       
  2230 		*pT++=(TUint16)c;
       
  2231 		}
       
  2232 	}
       
  2233 
       
  2234 EXPORT_C void TDes16::CopyC(const TDesC16 &aDes)
       
  2235 /**
       
  2236 Copies and collates data from the specified descriptor
       
  2237 into this descriptor replacing any existing data.
       
  2238 
       
  2239 The length of this descriptor is set to reflect the new data.
       
  2240 
       
  2241 @param aDes A 16-bit non-modifiable descriptor.
       
  2242 
       
  2243 @panic USER 11  if the length of aDes is greater than the maximum length of
       
  2244                 this target descriptor.
       
  2245 */
       
  2246 	{
       
  2247 
       
  2248 	TInt len=aDes.Length();
       
  2249 	SetLength(len);
       
  2250 	const TUint16 *pS=aDes.Ptr();
       
  2251 	TUint16 *pT=WPtr();
       
  2252 	while (len--)
       
  2253 		{
       
  2254 		TChar c=User::Collate(*pS++);
       
  2255 		*pT++=(TUint16)c;
       
  2256 		}
       
  2257 	}
       
  2258 
       
  2259 EXPORT_C void TDes16::CopyLC(const TDesC16 &aDes)
       
  2260 /**
       
  2261 Copies text from the specified descriptor and converts it to lower case before 
       
  2262 putting it into this descriptor, replacing any existing data.
       
  2263 
       
  2264 The length of this descriptor is set to reflect the new data.
       
  2265 
       
  2266 Conversion to lower case is implemented as appropriate to the current locale.
       
  2267 
       
  2268 @param aDes A 16-bit non modifiable descriptor.
       
  2269 
       
  2270 @panic USER 11  if the length of aDes is greater than the maximum length of
       
  2271                 this target descriptor.
       
  2272 */
       
  2273 	{
       
  2274 
       
  2275 	TInt len=aDes.Length();
       
  2276 	SetLength(len);
       
  2277 	const TUint16 *pS=aDes.Ptr();
       
  2278 	TUint16 *pT=WPtr();
       
  2279 	while (len--)
       
  2280 		{
       
  2281 		TCharLC c(*pS++);
       
  2282 		*pT++=(TUint16)c;
       
  2283 		}
       
  2284 	}
       
  2285 
       
  2286 EXPORT_C void TDes16::CopyUC(const TDesC16 &aDes)
       
  2287 /**
       
  2288 Copies text from the specified descriptor and converts it to upper case before 
       
  2289 putting it into this descriptor, replacing any existing data.
       
  2290 
       
  2291 The length of this descriptor is set to reflect the new data.
       
  2292 
       
  2293 Conversion to upper case is implemented as appropriate to the current locale.
       
  2294 
       
  2295 @param aDes A 16-bit non modifiable descriptor.
       
  2296 
       
  2297 @panic USER 11  if the length of aDes is greater than the maximum length of
       
  2298                 this target descriptor.
       
  2299 */
       
  2300 	{
       
  2301 
       
  2302 	TInt len=aDes.Length();
       
  2303 	SetLength(len);
       
  2304 	const TUint16 *pS=aDes.Ptr();
       
  2305 	TUint16 *pT=WPtr();
       
  2306 	while (len--)
       
  2307 		{
       
  2308 		TCharUC c(*pS++);
       
  2309 		*pT++=(TUint16)c;
       
  2310 		}
       
  2311 	}
       
  2312 
       
  2313 EXPORT_C void TDes16::CopyCP(const TDesC16 &aDes)
       
  2314 /**
       
  2315 Copies text from the specified descriptor and capitalises it before putting 
       
  2316 it into this descriptor, replacing any existing data.
       
  2317 
       
  2318 The length of this descriptor is set to reflect the new data.
       
  2319 
       
  2320 Capitalisation is implemented as appropriate to the current locale.
       
  2321 
       
  2322 @param aDes A 16-bit non-modifiable descriptor.
       
  2323 
       
  2324 @panic USER 11  if the length of aDes is greater than the maximum length of
       
  2325                 this target descriptor.
       
  2326 */
       
  2327 	{
       
  2328 
       
  2329 	TInt len=aDes.Length();
       
  2330 	SetLength(len);
       
  2331 	const TUint16 *pS=aDes.Ptr();
       
  2332 	TUint16 *pT=WPtr();
       
  2333 	if (len--)
       
  2334 		{
       
  2335 		TChar c(*pS++);
       
  2336 #ifdef _UNICODE
       
  2337 		c.TitleCase();
       
  2338 #else
       
  2339 		c.UpperCase();
       
  2340 #endif
       
  2341 		*pT++=(TUint16)c;
       
  2342 		while (len--)
       
  2343 			{
       
  2344 			TCharLC c=(*pS++);
       
  2345 			*pT++=(TUint16)c;
       
  2346 			}
       
  2347 		}
       
  2348 	}
       
  2349 
       
  2350 EXPORT_C void TDes16::Repeat(const TUint16 *aBuf,TInt aLength)
       
  2351 /**
       
  2352 Copies data with repetition into this descriptor, from a memory location
       
  2353 specified by pointer, replacing any existing data.
       
  2354 
       
  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.
       
  2358 
       
  2359 @param aBuf    A pointer to data to be repeatedly copied. 
       
  2360 @param aLength The length of data to be copied. 
       
  2361 
       
  2362 @panic USER 17  if aLength is negative.
       
  2363 */
       
  2364 	{
       
  2365 
       
  2366 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
       
  2367 	__CHECK_ALIGNMENT(aBuf,ETDes16RepeatBufLength);
       
  2368 	TUint16 *pB=WPtr();
       
  2369 	TInt len=Length();
       
  2370 	if (len && aLength)
       
  2371 		{
       
  2372 		while (len)
       
  2373 			{
       
  2374 			TInt i=Min(len,aLength);
       
  2375 			pB=memCopy(pB,aBuf,i);
       
  2376 			len-=i;
       
  2377 			}
       
  2378 		}
       
  2379 	}
       
  2380 
       
  2381 EXPORT_C void TDes16::Repeat(const TDesC16 &aDes)
       
  2382 /**
       
  2383 Copies data with repetition into this descriptor, from another descriptor,
       
  2384 replacing any existing data.
       
  2385 
       
  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.
       
  2389 
       
  2390 @param aDes A 16-bit non modifiable descriptor whose data is to be repeatedly 
       
  2391             copied.
       
  2392 */
       
  2393 	{
       
  2394 
       
  2395 	Repeat(aDes.Ptr(),aDes.Length());
       
  2396 	}
       
  2397 
       
  2398 EXPORT_C void TDes16::Trim()
       
  2399 /**
       
  2400 Deletes leading and trailing whitespace characters from the descriptor's data.
       
  2401 
       
  2402 The length of the descriptor is reduced to reflect the loss of the whitespace characters.
       
  2403 
       
  2404 @see TDes16::TrimLeft()
       
  2405 @see TDes16::TrimRight()
       
  2406 */
       
  2407 	{
       
  2408 
       
  2409 	TrimLeft();
       
  2410 	TrimRight();
       
  2411 	}
       
  2412 
       
  2413 EXPORT_C void TDes16::TrimAll()
       
  2414 /**
       
  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.
       
  2418 
       
  2419 The length of the descriptor is reduced to reflect the loss of the whitespace
       
  2420 characters.
       
  2421 
       
  2422 @see TDes16::Trim()
       
  2423 */
       
  2424 	{
       
  2425 
       
  2426 	TrimLeft();
       
  2427 	TrimRight();
       
  2428 	TUint16 *pBuf=(TUint16 *)Ptr();
       
  2429 	TUint16 *pSrc=pBuf;
       
  2430 	TUint16 *pDst=pBuf;
       
  2431 	TInt len=Length();
       
  2432 	TInt spaces=0;
       
  2433 	while (len--)
       
  2434 		{
       
  2435 		TChar c=*pSrc;
       
  2436 		if (c.IsSpace())
       
  2437 			{
       
  2438 			if (spaces++==0)
       
  2439 				{
       
  2440 				if (pDst!=pSrc)
       
  2441 					*pDst=*pSrc;
       
  2442 				pDst++;
       
  2443 				}
       
  2444 			}
       
  2445 		else
       
  2446 			{
       
  2447 			spaces=0;
       
  2448 			if (pDst!=pSrc)
       
  2449 				*pDst=*pSrc;
       
  2450 			pDst++;
       
  2451 			}
       
  2452 		pSrc++;
       
  2453 		}
       
  2454 	Delete(pDst-pBuf, pSrc-pDst);
       
  2455 	}
       
  2456 
       
  2457 EXPORT_C void TDes16::TrimLeft()
       
  2458 /**
       
  2459 Deletes leading whitespace characters from the descriptor's data.
       
  2460 
       
  2461 All whitespace characters up to, but not including the first
       
  2462 non-whitespace character, are deleted.
       
  2463 
       
  2464 The length of the descriptor is reduced to reflect the loss
       
  2465 of the whitespace characters.
       
  2466 */
       
  2467 	{
       
  2468 
       
  2469 	const TUint16 *pBuf=Ptr();
       
  2470 	const TUint16 *pB=pBuf;
       
  2471 	TInt len=Length();
       
  2472 	while (len--)
       
  2473 		{
       
  2474 		TChar c=(*pB);
       
  2475 		if (!c.IsSpace())
       
  2476 			break;
       
  2477 		pB++;
       
  2478 		}
       
  2479 	Delete(0,pB-pBuf);
       
  2480 	}
       
  2481 
       
  2482 EXPORT_C void TDes16::TrimRight()
       
  2483 /**
       
  2484 Deletes trailing whitespace characters from the descriptor's data.
       
  2485 
       
  2486 The process starts on the right hand side of the descriptor's data
       
  2487 and proceeds to the left. 
       
  2488 
       
  2489 All whitespace characters up to, but not including the first non-whitespace character, 
       
  2490 are deleted.
       
  2491 
       
  2492 The length of the descriptor is reduced to reflect the loss of the whitespace
       
  2493 characters.
       
  2494 */
       
  2495 	{
       
  2496 
       
  2497 	TInt len=Length();
       
  2498 	if (len==0)
       
  2499 		return;
       
  2500 	const TUint16 *pB=Ptr()+len-1;
       
  2501 	TInt s=len;
       
  2502 	while (s)
       
  2503 		{
       
  2504 		TChar c=(*pB--);
       
  2505 		if (!c.IsSpace())
       
  2506 			break;
       
  2507 		s--;
       
  2508 		}
       
  2509 	Delete(s,len-s);
       
  2510 	}
       
  2511 
       
  2512 EXPORT_C void TDes16::Insert(TInt aPos,const TDesC16 &aDes)
       
  2513 /**
       
  2514 Inserts data into this descriptor.
       
  2515 
       
  2516 The length of this descriptor is changed to reflect the extra data.
       
  2517 
       
  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
       
  2520             position.
       
  2521             
       
  2522 @param aDes A 16-bit non modifiable descriptor whose data is to be inserted.
       
  2523 
       
  2524 @panic USER 10  if aPos is negative or is greater than the length of this
       
  2525                 descriptor.
       
  2526 @panic USER 11  if the resulting length of this descriptor is greater than its
       
  2527                 maximum length.
       
  2528 */
       
  2529 	{
       
  2530 
       
  2531 	TInt len=Length();
       
  2532 	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
       
  2533 	TInt s=aDes.Length();
       
  2534 	__ASSERT_ALWAYS((len+s)<=MaxLength(),Panic(ETDes16Overflow));
       
  2535 	TUint16 *pB=WPtr();
       
  2536 	memCopy(pB+aPos+s,pB+aPos,len-aPos);
       
  2537 	memCopy(pB+aPos,aDes.Ptr(),aDes.Length());
       
  2538 	SetLength(len+s);
       
  2539 	}
       
  2540 
       
  2541 EXPORT_C void TDes16::Delete(TInt aPos,TInt aLength)
       
  2542 /**
       
  2543 Deletes data from this descriptor.
       
  2544 
       
  2545 The length of this descriptor is changed to reflect the loss of data.
       
  2546 
       
  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
       
  2549                position. 
       
  2550             
       
  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.
       
  2554 
       
  2555 @panic USER 10  if aPos is negative or is greater than the length of this
       
  2556                 descriptor.
       
  2557 */
       
  2558 	{
       
  2559 
       
  2560 	TInt len=Length();
       
  2561 	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
       
  2562 	TInt d=Min(len-aPos,aLength);
       
  2563 	TUint16 *pB=WPtr();
       
  2564 	memCopy(pB+aPos,pB+aPos+d,len-aPos-d);
       
  2565 	SetLength(len-d);
       
  2566 	}
       
  2567 
       
  2568 EXPORT_C void TDes16::Replace(TInt aPos,TInt aLength,const TDesC16 &aDes)
       
  2569 /**
       
  2570 Replaces data in this descriptor.
       
  2571 
       
  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.
       
  2574 
       
  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
       
  2577                data position. 
       
  2578             
       
  2579 @param aLength The length of data to be replaced.
       
  2580 
       
  2581 @param aDes    The source 16-bit non modifiable descriptor whose data is to
       
  2582                replace the target descriptor's data at aPos.
       
  2583 
       
  2584 @panic USER  8  if aLength is negative or the sum of aLength and aPos is
       
  2585                 greater than the length of this descriptor.
       
  2586                
       
  2587 @panic USER 10  if aPos is negative or is greater than the length of this
       
  2588                 descriptor.
       
  2589                 
       
  2590 @panic USER 11  if the resulting length of this descriptor is greater than its
       
  2591                 maximum length.
       
  2592                 
       
  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,                
       
  2595 */
       
  2596 	{
       
  2597 
       
  2598 	TInt len=Length();
       
  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));
       
  2605 	TUint16 *pB=WPtr();
       
  2606 	memCopy(pB+aPos+s,pB+aPos+aLength,len-aPos-aLength);
       
  2607 	memCopy(pB+aPos,aDes.Ptr(),s);
       
  2608 	SetLength(len+s-aLength);
       
  2609 	}
       
  2610 
       
  2611 EXPORT_C void TDes16::Justify(const TDesC16 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
       
  2612 /**
       
  2613 Copies data into this descriptor and justifies it, replacing any existing data.
       
  2614 
       
  2615 The length of this descriptor is set to reflect the new data.
       
  2616 
       
  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
       
  2620 instruction.
       
  2621 
       
  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.
       
  2624 
       
  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).
       
  2630 
       
  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.
       
  2634 
       
  2635 @param anAlignment The alignment of the data within the target area
       
  2636 
       
  2637 @param aFill       The fill character used to pad the target area. 
       
  2638 
       
  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.
       
  2642 */
       
  2643 	{
       
  2644 
       
  2645     Zero();
       
  2646     AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
       
  2647     }
       
  2648 
       
  2649 EXPORT_C void TDes16::AppendJustify(const TDesC16 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
       
  2650 /**
       
  2651 Appends data onto the end of this descriptor's data and justifies it.
       
  2652 	
       
  2653 The source of the appended data is an existing descriptor.
       
  2654 	
       
  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.
       
  2658 	
       
  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.
       
  2661 		
       
  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). 
       
  2667 	
       
  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.
       
  2671 	
       
  2672 @param anAlignment The alignment of the data within the target area. 
       
  2673 	
       
  2674 @param aFill       The fill character used to pad the target area.
       
  2675 
       
  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.
       
  2679 */
       
  2680 	{
       
  2681 
       
  2682     AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
       
  2683     } 
       
  2684 
       
  2685 EXPORT_C void TDes16::AppendJustify(const TDesC16 &aDes,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
       
  2686 /**
       
  2687 Appends data onto the end of this descriptor's data and justifies it.
       
  2688 	
       
  2689 The source of the appended data is an existing descriptor.
       
  2690 	
       
  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.
       
  2694 	
       
  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.
       
  2697 	
       
  2698 @param aDes        An 8-bit non-modifiable descriptor containing the source data. 
       
  2699 
       
  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. 
       
  2706                    
       
  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.
       
  2710 
       
  2711 @param anAlignment The alignment of the data within the target area. 
       
  2712 
       
  2713 @param aFill       The fill character used to pad the target area.
       
  2714 
       
  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.
       
  2718 */
       
  2719 	{
       
  2720 
       
  2721     AppendJustify(aDes.Ptr(),aLength,aWidth,anAlignment,aFill);
       
  2722     } 
       
  2723 
       
  2724 EXPORT_C void TDes16::AppendJustify(const TUint16 *aString,TInt aWidth,TAlign anAlignment,TChar aFill)
       
  2725 /**
       
  2726 Appends a zero terminated string onto the end of this descriptor's data and 
       
  2727 justifies it.
       
  2728 
       
  2729 The zero terminator is not copied.
       
  2730 
       
  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.
       
  2734 
       
  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.
       
  2737 
       
  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). 
       
  2742                     
       
  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).
       
  2746                     
       
  2747 @param anAlignment The alignment of the data within the target area. 
       
  2748 
       
  2749 @param aFill       The fill character used to pad the target area.
       
  2750 
       
  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.
       
  2754 */
       
  2755 	{
       
  2756 
       
  2757  	__CHECK_ALIGNMENT(aString,ETDes16AppendJustify1);
       
  2758 	AppendJustify(aString,STRING_LENGTH_16(aString),aWidth,anAlignment,aFill);
       
  2759     } 
       
  2760 
       
  2761 EXPORT_C void TDes16::AppendJustify(const TUint16 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
       
  2762 /**
       
  2763 Appends data onto the end of this descriptor's data and justifies it.
       
  2764 
       
  2765 The source of the appended data is a memory location.
       
  2766 
       
  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.
       
  2770 
       
  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.
       
  2773 
       
  2774 @param aString     A pointer to a source memory location. 
       
  2775 
       
  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.
       
  2779                
       
  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. 
       
  2783                
       
  2784 @param anAlignment The alignment of the data within the target area. 
       
  2785 
       
  2786 @param aFill       The fill character used to pad the target area.
       
  2787 
       
  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.
       
  2791                 
       
  2792 @panic USER 17  if aLength is negative.  
       
  2793 */
       
  2794 	{
       
  2795 
       
  2796 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
       
  2797 	__CHECK_ALIGNMENT(aString,ETDes16AppendJustify2);
       
  2798 	if (aWidth==KDefaultJustifyWidth)
       
  2799 		aWidth=aLength;
       
  2800 	if (aLength>aWidth)
       
  2801 		aLength=aWidth;
       
  2802 	TInt offset=Length();
       
  2803 	AppendFill(aFill,aWidth);
       
  2804 	TInt r=aWidth-aLength;
       
  2805 	if (anAlignment==ECenter)
       
  2806 		r>>=1;
       
  2807 	else if (anAlignment==ELeft)
       
  2808 		r=0;
       
  2809 	memCopy(WPtr()+offset+r,aString,aLength);
       
  2810 	}
       
  2811 
       
  2812 EXPORT_C void TDes16::NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
       
  2813 /**
       
  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.
       
  2817 
       
  2818 The length of this descriptor is set to reflect the new data.
       
  2819 
       
  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.
       
  2822 
       
  2823 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  2824 lower case.
       
  2825 
       
  2826 This function is equivalent to using Format() with parameters which specify:
       
  2827 
       
  2828 1. a fixed length target field
       
  2829 
       
  2830 2. padding with zero characters, for example "%08x".
       
  2831 
       
  2832 When this is the case, always use NumFixedWidth() in preference 
       
  2833 to Format() as it is more efficient.
       
  2834 
       
  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.
       
  2839 */
       
  2840 	{
       
  2841 
       
  2842 	Zero();
       
  2843 	AppendNumFixedWidth(aVal,aRadix,aWidth);
       
  2844 	}
       
  2845 
       
  2846 EXPORT_C void TDes16::NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
       
  2847 /** 
       
  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.
       
  2851 
       
  2852 The length of this descriptor is set to reflect the new data.
       
  2853 
       
  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
       
  2856 necessary.
       
  2857 
       
  2858 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  2859 upper case.
       
  2860 
       
  2861 This function is equivalent to using Format() with parameters which specify:
       
  2862 
       
  2863 1. a fixed length target field
       
  2864 
       
  2865 2. padding with zero characters, for example "%08x".
       
  2866 
       
  2867 When this is the case, always use NumFixedWidthUC() in 
       
  2868 preference to Format() as it is more efficient.
       
  2869 
       
  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.
       
  2874               
       
  2875 @see TDes16::Format()
       
  2876 */
       
  2877 	{
       
  2878 
       
  2879     Zero();
       
  2880     AppendNumFixedWidthUC(aVal,aRadix,aWidth);
       
  2881     }
       
  2882 
       
  2883 EXPORT_C void TDes16::Num(TInt64 aVal)
       
  2884 /**
       
  2885 Converts the 64-bit signed integer into a decimal character representation 
       
  2886 and copies the conversion into this descriptor, replacing any existing data. 
       
  2887 
       
  2888 The length of this descriptor is set to reflect the new data.
       
  2889 
       
  2890 If the integer is negative, the character representation is prefixed by a 
       
  2891 minus sign.
       
  2892 
       
  2893 @param aVal The 64-bit signed integer value.
       
  2894 */
       
  2895 	{
       
  2896 	Zero();
       
  2897 	AppendNum(aVal);
       
  2898 	}
       
  2899 
       
  2900 EXPORT_C void TDes16::Num(TUint64 aVal, TRadix aRadix)
       
  2901 /**
       
  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.
       
  2905 
       
  2906 The length of this descriptor is set to reflect the new data.
       
  2907 	
       
  2908 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  2909 lower case.
       
  2910 	
       
  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.
       
  2914 */
       
  2915 	{
       
  2916 
       
  2917 	Zero();
       
  2918 	AppendNum(aVal,aRadix);
       
  2919 	}
       
  2920 
       
  2921 EXPORT_C void TDes16::NumUC(TUint64 aVal, TRadix aRadix)
       
  2922 /**
       
  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.
       
  2926 
       
  2927 The length of this descriptor is set to reflect the new data.
       
  2928 
       
  2929 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  2930 upper case.
       
  2931 
       
  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.
       
  2936 */
       
  2937 	{
       
  2938 
       
  2939 	Zero();
       
  2940 	AppendNumUC(aVal,aRadix);
       
  2941 	}
       
  2942 
       
  2943 void TDes16::DoPadAppendNum(TInt l, TInt aW, const TUint8* p)
       
  2944 	{
       
  2945 	__ASSERT_DEBUG( ((l|(TInt)p)&1)==0, Panic(EDes16PadAppendBadAlign));
       
  2946 	l>>=1;
       
  2947 	if (aW<=0)
       
  2948 		{
       
  2949 		Append((const TUint16*)p, l);
       
  2950 		return;
       
  2951 		}
       
  2952 	TInt l0 = Length();
       
  2953 	SetLength(l0 + aW);
       
  2954 	TUint16* d = WPtr() + l0;
       
  2955 	for (; aW>l; --aW) *d++ = (TUint16)'0';
       
  2956 	memcpy(d, p, aW*2);
       
  2957 	}
       
  2958 
       
  2959 EXPORT_C void TDes16::AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
       
  2960 /**
       
  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.
       
  2964 
       
  2965 The length of this descriptor is incremented to reflect the new content.
       
  2966 
       
  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
       
  2969 necessary.
       
  2970 
       
  2971 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  2972 lower case.
       
  2973 
       
  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.
       
  2978 */
       
  2979 	{
       
  2980 
       
  2981 	TBuf16<32> buf;
       
  2982 	buf.Num(aVal,aRadix);
       
  2983 	if (buf.Length()>=aWidth)
       
  2984 		Append(buf.Left(aWidth));
       
  2985 	else
       
  2986 		{
       
  2987 		TInt i=aWidth-buf.Length();
       
  2988 		while(i--)
       
  2989 			Append(TChar('0'));
       
  2990 		Append(buf);
       
  2991 		}
       
  2992 	}
       
  2993 
       
  2994 #ifndef __DES16_MACHINE_CODED__
       
  2995 EXPORT_C TPtr16 TDes16::LeftTPtr(TInt aLength) const
       
  2996 /**
       
  2997 Extracts the leftmost part of the data. 
       
  2998 
       
  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.
       
  3001 
       
  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.
       
  3005                
       
  3006 @return The 16-bit modifiable pointer descriptor representing the leftmost part
       
  3007 		of the data.
       
  3008 
       
  3009 @panic USER 10  if aLength is negative. 
       
  3010 */
       
  3011 	{
       
  3012 
       
  3013 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
       
  3014 	TInt len = Min(aLength,Length());
       
  3015 	return(TPtr16((TUint16*)Ptr(),len,len));
       
  3016 	}
       
  3017 
       
  3018 EXPORT_C TPtr16 TDes16::RightTPtr(TInt aLength) const
       
  3019 /**
       
  3020 Extracts the rightmost part of the data.
       
  3021 
       
  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.
       
  3024 
       
  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. 
       
  3028                
       
  3029 @return The 16-bit modifiable pointer descriptor representing the rightmost part
       
  3030 		of the data.
       
  3031 
       
  3032 @panic USER 10  if aLength is negative.
       
  3033 */
       
  3034 	{
       
  3035 
       
  3036 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16PosOutOfRange));
       
  3037 	TInt len=Length();
       
  3038 	if (aLength>len)
       
  3039 		aLength=len;
       
  3040 	return(TPtr16((TUint16*)Ptr()+len-aLength,aLength,aLength));
       
  3041 	}
       
  3042 
       
  3043 EXPORT_C TPtr16 TDes16::MidTPtr(TInt aPos) const
       
  3044 /**
       
  3045 Extracts a portion of the data.
       
  3046 
       
  3047 The function does not cut or remove any data but constructs a modifiable pointer
       
  3048 descriptor to represent the defined portion.
       
  3049 
       
  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.
       
  3052 
       
  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.
       
  3055              
       
  3056 @return The 16-bit modifiable pointer descriptor representing the specified 
       
  3057         portion of the data.
       
  3058 
       
  3059 @panic USER 10  if aPos is negative or aPos is greater than the
       
  3060                 length of the descriptor.
       
  3061 */
       
  3062 	{
       
  3063 
       
  3064 	TInt len=Length();
       
  3065 	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes16PosOutOfRange));
       
  3066 	return(TPtr16((TUint16*)Ptr()+aPos,len-aPos,len-aPos));
       
  3067 	}
       
  3068 
       
  3069 EXPORT_C TPtr16 TDes16::MidTPtr(TInt aPos,TInt aLength) const
       
  3070 /**
       
  3071 Extracts a portion of the data.
       
  3072 
       
  3073 The function does not cut or remove any data but constructs a modifiable pointer
       
  3074 descriptor to represent the defined portion.
       
  3075 
       
  3076 The portion is identified by its starting position and by its length.
       
  3077 
       
  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.
       
  3081 
       
  3082 @return The 16-bit modifiable pointer descriptor representing the specified
       
  3083 		portion of the data.
       
  3084         
       
  3085 @panic USER 10  if aPos is negative or aPos plus aLength is greater than the
       
  3086                 length of the descriptor.
       
  3087 */
       
  3088 	{
       
  3089 
       
  3090 	__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes16PosOutOfRange));
       
  3091 	return(TPtr16((TUint16*)Ptr()+aPos,aLength,aLength));
       
  3092 	}
       
  3093 #endif
       
  3094 
       
  3095 EXPORT_C void TDes16::AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
       
  3096 /**
       
  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.
       
  3100 
       
  3101 The length of this descriptor is incremented to reflect the new content.
       
  3102 
       
  3103 The function generates the exact number of specified characters, either
       
  3104 padding to the left with character zeroes or discarding low order characters
       
  3105 as necessary.
       
  3106 
       
  3107 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  3108 upper case.
       
  3109 
       
  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.
       
  3114 */
       
  3115 	{
       
  3116 
       
  3117 	TBuf16<32> buf;
       
  3118 	buf.NumUC(aVal,aRadix);
       
  3119 	if (buf.Length()>=aWidth)
       
  3120 		Append(buf.Left(aWidth));
       
  3121 	else
       
  3122 		{
       
  3123 		TInt i=aWidth-buf.Length();
       
  3124 		while(i--)
       
  3125 			Append(TChar('0'));
       
  3126 		Append(buf);
       
  3127 		}
       
  3128 	}
       
  3129 
       
  3130 EXPORT_C void TDes16::AppendNum(TInt64 aVal)
       
  3131 /**
       
  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.
       
  3134 
       
  3135 The length of this descriptor is incremented to reflect the new content.
       
  3136 
       
  3137 If the integer is negative, the character representation is prefixed by a 
       
  3138 minus sign.
       
  3139 
       
  3140 @param aVal The 64-bit signed integer value.
       
  3141 */
       
  3142 	{
       
  3143 
       
  3144 	if (aVal<0)
       
  3145 		{
       
  3146 		Append('-');
       
  3147 		aVal=-aVal;
       
  3148 		}
       
  3149 	AppendNum(static_cast<TUint64>(aVal), EDecimal);
       
  3150 	}
       
  3151 
       
  3152 void TDes16::DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW)
       
  3153 //
       
  3154 // Convert a TUint64 into the descriptor.
       
  3155 //
       
  3156 	{
       
  3157 
       
  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);
       
  3163 	}
       
  3164 
       
  3165 EXPORT_C void TDes16::AppendNum(TUint64 aVal, TRadix aRadix)
       
  3166 /**
       
  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.
       
  3170 
       
  3171 The length of this descriptor is incremented to reflect the new content.
       
  3172 	
       
  3173 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  3174 lower case.
       
  3175 	
       
  3176 @param aVal   The 64 bit integer value. This is always treated as an unsigned
       
  3177               value. 
       
  3178 @param aRadix The number system representation for the 64 bit integer.
       
  3179 */
       
  3180 	{
       
  3181 	DoAppendNum(aVal, aRadix, 'a', 0);
       
  3182 	}
       
  3183 
       
  3184 EXPORT_C void TDes16::AppendNumUC(TUint64 aVal,TRadix aRadix)
       
  3185 /**
       
  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.
       
  3189 
       
  3190 The length of this descriptor is incremented to reflect the new content.
       
  3191 	
       
  3192 When a hexadecimal conversion is specified, hexadecimal characters are in 
       
  3193 upper case.
       
  3194 	
       
  3195 @param aVal   The 64 bit integer value. This is always treated as an unsigned
       
  3196               value. 
       
  3197 @param aRadix The number system representation for the 64 bit integer. If no 
       
  3198               explicit value is specified, then EDecimal is the default.
       
  3199 */
       
  3200 
       
  3201 	{
       
  3202 	DoAppendNum(aVal, aRadix, 'A', 0);
       
  3203 	}
       
  3204 
       
  3205 EXPORT_C void TDes16::Format(TRefByValue<const TDesC16> aFmt,...)
       
  3206 /**
       
  3207 Formats and copies text into this descriptor, replacing any existing data.
       
  3208 
       
  3209 The length of this descriptor is set to reflect the new data.
       
  3210 
       
  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.
       
  3214 
       
  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
       
  3218 trailing list.
       
  3219 
       
  3220 The resulting stream of literal text and converted arguments is copied into
       
  3221 this descriptor.
       
  3222 
       
  3223 The syntax of the embedded directives follows one of four general patterns.
       
  3224 
       
  3225 Note that formatting of single numerical values can be achieved more
       
  3226 conveniently using the Num() and NumUC() member functions of this class.
       
  3227 
       
  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:
       
  3230 
       
  3231 @code
       
  3232 Symbian OS Guide
       
  3233 	Base
       
  3234 		Using  User Library (E32)
       
  3235 			Buffers and Strings
       
  3236 				Using Descriptors
       
  3237 					How to Use Descriptors
       
  3238 						Format string syntax
       
  3239 @endcode
       
  3240 
       
  3241 @param aFmt The descriptor containing the format string.
       
  3242             The TRefByValue class provides a constructor which takes a
       
  3243             TDesC8 type.
       
  3244 
       
  3245 @param ...  A variable number of arguments to be converted to text as
       
  3246             dictated by the format string. 
       
  3247 
       
  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.
       
  3251 
       
  3252 @see TDes16::Num()
       
  3253 @see TDes16::NumUC()
       
  3254 */
       
  3255 	{
       
  3256 
       
  3257     VA_LIST list;
       
  3258     VA_START(list,aFmt);
       
  3259 	// coverity[uninit_use_in_call]
       
  3260     FormatList(aFmt,list);
       
  3261     }
       
  3262 
       
  3263 EXPORT_C void TDes16::FormatList(const TDesC16 &aFmt,VA_LIST aList)
       
  3264 /**
       
  3265 Formats and copies text into this descriptor, replacing any existing data.
       
  3266 
       
  3267 The length of this descriptor is set to reflect the new data.
       
  3268 
       
  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.
       
  3272 
       
  3273 @param aFmt  The descriptor containing the format string.
       
  3274 @param aList A pointer to an argument list.
       
  3275 
       
  3276 @see TDes16::Format()
       
  3277 @see VA_LIST
       
  3278 */
       
  3279 	{
       
  3280 
       
  3281 	Zero();
       
  3282 	AppendFormatList(aFmt,aList);
       
  3283 	}
       
  3284 
       
  3285 EXPORT_C void TDes16::AppendFormat(TRefByValue<const TDesC16> aFmt,TDes16Overflow *aOverflowHandler,...)
       
  3286 /**
       
  3287 Formats and appends text onto the end of this descriptor's data.
       
  3288 
       
  3289 The length of this descriptor is incremented to reflect the new content.
       
  3290 
       
  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.
       
  3294 
       
  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.
       
  3299 
       
  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,
       
  3302 then the function:
       
  3303 
       
  3304 1. calls the Overflow() member function of the overflow handler, if an overflow
       
  3305    handler is supplied
       
  3306 2  raises a USER 11 panic, if no overflow handler is supplied.
       
  3307 
       
  3308 As much literal text as possible will have been copied into this descriptor
       
  3309 and this descriptor will have reached its maximum length.
       
  3310 
       
  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:
       
  3314 
       
  3315 1. calls the Overflow() member function of the overflow handler, if an overflow
       
  3316    handler is supplied
       
  3317    
       
  3318 2  raises a USER 11 panic, if no overflow handler is supplied.
       
  3319   
       
  3320 None of the generated text is appended and length of this descriptor
       
  3321 may be less than the maximum.
       
  3322 
       
  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. 
       
  3326 
       
  3327 @param aOverflowHandler A pointer to the overflow handler. 
       
  3328 
       
  3329 @param ...              A variable number of arguments to be converted to text
       
  3330                         as dictated by the format string. 
       
  3331 
       
  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.
       
  3335 
       
  3336 @see TDes16::Format()
       
  3337 @see TDes16Overflow::Overflow()
       
  3338 */
       
  3339 	{
       
  3340 
       
  3341 	VA_LIST list;
       
  3342 	VA_START(list, aOverflowHandler);
       
  3343 	// coverity[uninit_use_in_call]
       
  3344 	AppendFormatList(aFmt,list,aOverflowHandler);
       
  3345 	}
       
  3346 
       
  3347 EXPORT_C void TDes16::AppendFormat(TRefByValue<const TDesC16> aFmt,...)
       
  3348 /**
       
  3349 Formats and appends text onto the end of this descriptor's data.
       
  3350 
       
  3351 The length of this descriptor is incremented to reflect the new content.
       
  3352 
       
  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.
       
  3356 
       
  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.
       
  3361 
       
  3362 Literal text is appended on a character by character basis.
       
  3363 
       
  3364 Text converted from a trailing argument is appended as a complete string.
       
  3365 
       
  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. 
       
  3369 
       
  3370 @param ...  A variable number of arguments to be converted to text
       
  3371             as dictated by the format string. 
       
  3372 
       
  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.
       
  3376 
       
  3377 @see TDes16::Format()
       
  3378 */
       
  3379 	{
       
  3380 
       
  3381     VA_LIST list;
       
  3382     VA_START(list,aFmt);
       
  3383     AppendFormatList(aFmt,list);
       
  3384     }
       
  3385 
       
  3386 #if !defined(__DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
       
  3387 EXPORT_C TPtrC16::TPtrC16()
       
  3388 	: TDesC16(EPtrC,0),iPtr(0)
       
  3389 /**
       
  3390 Constructs an empty 16-bit non-modifiable pointer descriptor.
       
  3391 
       
  3392 It represents no data and its length is zero.
       
  3393 
       
  3394 The non-modifiable pointer descriptor can, subsequently, be set to represent 
       
  3395 data.
       
  3396 
       
  3397 @see TPtrC16::Set()
       
  3398 */
       
  3399 	{}
       
  3400 
       
  3401 EXPORT_C TPtrC16::TPtrC16(const TDesC16 &aDes)
       
  3402 	: TDesC16(EPtrC,aDes.Length()),iPtr(aDes.Ptr())
       
  3403 /** 
       
  3404 Constructs the 16-bit non-modifiable pointer descriptor from any existing
       
  3405 descriptor.
       
  3406 
       
  3407 It is set to point to the same data and is given the same length as the source
       
  3408 descriptor.
       
  3409 
       
  3410 @param aDes A reference to a 16-bit non-modifiable descriptor.
       
  3411 */
       
  3412 	{}
       
  3413 #endif
       
  3414 
       
  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)
       
  3418 /**
       
  3419 Constructs the 16-bit non-modifiable pointer descriptor to point to a zero 
       
  3420 terminated string, whether in RAM or ROM.
       
  3421 
       
  3422 The length of the descriptor is set to the length of the zero terminated string, 
       
  3423 excluding the zero terminator.
       
  3424 
       
  3425 @param aString A pointer to a zero terminated string.
       
  3426 */
       
  3427 	{
       
  3428 	__CHECK_ALIGNMENT(aString,ETDesC16ConstructCString);
       
  3429 	}
       
  3430 #endif
       
  3431 
       
  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)
       
  3435 /**
       
  3436 Constructs the 16-bit non-modifiable pointer descriptor to point to the 
       
  3437 specified location in memory, whether in RAM or ROM.
       
  3438 
       
  3439 The length of the descriptor is set to the specified length.
       
  3440 
       
  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.
       
  3443 
       
  3444 @panic USER 17  if aLength is negative.
       
  3445 */
       
  3446 	{
       
  3447 	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative));
       
  3448 	__CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLength);
       
  3449 	}
       
  3450 
       
  3451 EXPORT_C TPtr16::TPtr16(TUint16 *aBuf,TInt aMaxLength)
       
  3452 	: TDes16(EPtr,0,aMaxLength),iPtr(aBuf)
       
  3453 /**
       
  3454 Constructs the 16-bit modifiable pointer descriptor to point to the specified 
       
  3455 location in memory, whether in RAM or ROM.
       
  3456 
       
  3457 The length of the descriptor is set to zero, and its maximum length is set to
       
  3458 the specified value.
       
  3459 
       
  3460 @param aBuf       A pointer to the location that the descriptor is to represent.
       
  3461 @param aMaxLength The maximum length of the descriptor.
       
  3462 
       
  3463 @panic USER 18  if aMaxLength is negative.
       
  3464 */
       
  3465 	{
       
  3466 	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3467 	__CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLengthMax);
       
  3468 	}
       
  3469 
       
  3470 EXPORT_C TPtr16::TPtr16(TUint16 *aBuf,TInt aLength,TInt aMaxLength)
       
  3471 	: TDes16(EPtr,aLength,aMaxLength),iPtr(aBuf)
       
  3472 /**
       
  3473 Constructs the 16-bit modifiable pointer descriptor to point to the specified 
       
  3474 location in memory, whether in RAM or ROM.
       
  3475 
       
  3476 The length of the descriptor and its maximum length are set to the specified
       
  3477 values.
       
  3478 
       
  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.
       
  3482 
       
  3483 @panic USER 8   if aLength is negative, or is greater than the descriptor's 
       
  3484                 maximum length,
       
  3485                 
       
  3486 @panic USER 18  if aMaxLength is negative.
       
  3487 */
       
  3488 	{
       
  3489 	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3490 	__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes16LengthOutOfRange));
       
  3491 	__CHECK_ALIGNMENT(aBuf,ETDesC16ConstructBufLengthMax);
       
  3492 	}
       
  3493 
       
  3494 EXPORT_C TBufBase16::TBufBase16(TInt aMaxLength)
       
  3495 	:TDes16(EBuf,0,aMaxLength)
       
  3496 	{
       
  3497 	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3498 	}
       
  3499 
       
  3500 EXPORT_C TBufBase16::TBufBase16(TInt aLength,TInt aMaxLength)
       
  3501 	:TDes16(EBuf,aLength,aMaxLength)
       
  3502 	{
       
  3503 	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3504 	__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes16LengthOutOfRange));
       
  3505 	}
       
  3506 #endif
       
  3507 
       
  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)
       
  3511 	{
       
  3512 	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3513 	Copy(aString);
       
  3514 	}
       
  3515 #endif
       
  3516 
       
  3517 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__)
       
  3518 EXPORT_C TBufBase16::TBufBase16(const TDesC16& aDes,TInt aMaxLength)
       
  3519 	:TDes16(EBuf,0,aMaxLength)
       
  3520 	{
       
  3521 	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes16MaxLengthNegative));
       
  3522 	Copy(aDes);
       
  3523 	}
       
  3524 #endif
       
  3525 
       
  3526 EXPORT_C void TDesC16::__DbgTestInvariant() const
       
  3527 //
       
  3528 // Test that the class obeys its invariant.
       
  3529 //
       
  3530     {
       
  3531 
       
  3532 #if defined(_DEBUG)
       
  3533 	switch (Type())
       
  3534 		{
       
  3535 	case EBufC:
       
  3536 	case EPtrC:
       
  3537 	case EPtr:
       
  3538 	case EBuf:
       
  3539 	case EBufCPtr:
       
  3540 		break;
       
  3541 	default:
       
  3542 		User::Invariant();
       
  3543 		}
       
  3544 	if (Ptr() != NULL) // TPtr and TPtrC can be null
       
  3545  		__CHECK_ALIGNMENT(Ptr(),ETDesC16Invariant);
       
  3546 #endif
       
  3547     }
       
  3548 
       
  3549 EXPORT_C void TPtrC16::__DbgTestInvariant() const
       
  3550 //
       
  3551 // Test that the class obeys its invariant.
       
  3552 //
       
  3553     {
       
  3554 
       
  3555 #if defined(_DEBUG)
       
  3556 	TDesC16::__DbgTestInvariant(); // Test base class
       
  3557 	if (Type()!=EPtrC)
       
  3558 		User::Invariant();
       
  3559 #endif
       
  3560 	}
       
  3561 
       
  3562 EXPORT_C void TDes16::__DbgTestInvariant() const
       
  3563 //
       
  3564 // Test that the class obeys its invariant.
       
  3565 //
       
  3566     {
       
  3567 
       
  3568 #if defined(_DEBUG)
       
  3569 	TDesC16::__DbgTestInvariant(); // Test base class
       
  3570 	if (Length()>MaxLength() || !(Type()==EPtr || Type()==EBufCPtr || Type()==EBuf))
       
  3571 		User::Invariant();
       
  3572 #endif
       
  3573 	}
       
  3574 
       
  3575 EXPORT_C void HBufC16::__DbgTestInvariant() const
       
  3576 //
       
  3577 // Test that the class obeys its invariant.
       
  3578 //
       
  3579     {
       
  3580 
       
  3581 #if defined(_DEBUG)
       
  3582 	TDesC16::__DbgTestInvariant(); // Test base class
       
  3583 	if (Length()>(TInt)(STD_CLASS::AllocLen(this)-sizeof(TDesC16)) || Type()!=EBufC)
       
  3584 		User::Invariant();
       
  3585 #endif
       
  3586 	}
       
  3587 
       
  3588 EXPORT_C void TPtr16::__DbgTestInvariant() const
       
  3589 //
       
  3590 // Test that the class obeys its invariant.
       
  3591 //
       
  3592     {
       
  3593 
       
  3594 #if defined(_DEBUG)
       
  3595 	TDes16::__DbgTestInvariant(); // Test base class
       
  3596 	if (!(Type()==EPtr || Type()==EBufCPtr))
       
  3597 		User::Invariant();
       
  3598 #endif
       
  3599 	}
       
  3600 
       
  3601 /** Collapse all characters from 16 to 8 bits
       
  3602 
       
  3603 @return 8-bit pointer descriptor to transformed text
       
  3604 */
       
  3605 EXPORT_C TPtr8 TDes16::Collapse()
       
  3606 	{
       
  3607 	TInt l = Length();
       
  3608 	TInt ml = MaxLength();
       
  3609 	TText8* d = (TText8*)Ptr();
       
  3610 	TText8* d0 = d;
       
  3611 	const TText16* s = (const TText16*)d;
       
  3612 	const TText16* sE = s + l;
       
  3613 	while (s < sE)
       
  3614 		*d++ = (TText8)*s++;
       
  3615 	return TPtr8(d0, l, ml*sizeof(TText));
       
  3616 	}
       
  3617 
       
  3618 // Truncate literal string to fit into descriptor
       
  3619 EXPORT_C void TDes16IgnoreOverflow::Overflow(TDes16& /*aDes*/)
       
  3620 	{}
       
  3621 
       
  3622 #ifndef __KERNEL_MODE__
       
  3623 
       
  3624 /**
       
  3625 Default constructor.
       
  3626 
       
  3627 Constructs a zero-length 16-bit resizable buffer descriptor.
       
  3628 
       
  3629 Note that the object owns no allocated memory.
       
  3630 */
       
  3631 EXPORT_C RBuf16::RBuf16()
       
  3632 	:TDes16(EPtr,0,0),iEPtrType(NULL)
       
  3633 	{
       
  3634 	// Zero-length RBuf16 is of type EPtr with NULL pointer.
       
  3635 	}
       
  3636 
       
  3637 
       
  3638 
       
  3639 
       
  3640 /**
       
  3641 Constructor.
       
  3642 			
       
  3643 Constructs a 16-bit resizable buffer descriptor, transferring ownership of the
       
  3644 specified heap descriptor to this object.
       
  3645 
       
  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
       
  3649              allocated memory.
       
  3650 */
       
  3651 EXPORT_C RBuf16::RBuf16(HBufC16* aHBuf)
       
  3652 	{
       
  3653 	if(aHBuf)
       
  3654 		//Create EBufCPtr type descriptor that points to aHBuf
       
  3655 		new(this) TPtr16(aHBuf->Des());
       
  3656 	else
       
  3657 		//Create zero-length RBuf16. It is EPtr type of descriptor that points to NULL.
       
  3658 		new(this) RBuf16();
       
  3659 	}
       
  3660 
       
  3661 
       
  3662 
       
  3663 
       
  3664 /**
       
  3665 Protected constructor.
       
  3666 */
       
  3667 EXPORT_C RBuf16::RBuf16(TInt aType,TInt aLength,TInt aMaxLength)
       
  3668 	:TDes16(aType,aLength,aMaxLength)
       
  3669 	{
       
  3670 	}
       
  3671 
       
  3672 
       
  3673 
       
  3674 
       
  3675 /**
       
  3676 Transfers ownership of the specified 16-bit resizable buffer descriptor's 
       
  3677 buffer to this object.
       
  3678 
       
  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
       
  3683 invoked.
       
  3684 
       
  3685 @param aRBuf The source 16-bit resizable buffer. The ownership of this
       
  3686              object's buffer is to be transferred.
       
  3687 
       
  3688 @see RBuf16::Close()
       
  3689 */
       
  3690 EXPORT_C void RBuf16::Assign(const RBuf16& aRBuf)
       
  3691 	{
       
  3692 	Mem::Copy(this, &aRBuf, sizeof(*this)); 
       
  3693 	__TEST_INVARIANT;
       
  3694 	}
       
  3695 
       
  3696 
       
  3697 
       
  3698 
       
  3699 /**
       
  3700 Assigns ownership of the specified allocated memory to this object.
       
  3701 
       
  3702 The allocated memory forms the buffer for this descriptor. The current length
       
  3703 of the descriptor is set to zero.
       
  3704 
       
  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
       
  3709 invoked.
       
  3710 
       
  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.
       
  3715 
       
  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.
       
  3719               
       
  3720 @see TDesC16::Length()
       
  3721 @see TDes16::MaxLength()
       
  3722 @see RBuf16::Close()
       
  3723 */
       
  3724 EXPORT_C void RBuf16::Assign(TUint16 *aHeapCell,TInt aMaxLength)
       
  3725 	{
       
  3726 	Assign(aHeapCell,0,aMaxLength);
       
  3727 	}
       
  3728 
       
  3729 
       
  3730 
       
  3731 
       
  3732 /**
       
  3733 Assigns ownership of the specified allocated memory to this object.
       
  3734 
       
  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.
       
  3737 
       
  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
       
  3742 invoked.
       
  3743 
       
  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.
       
  3747 
       
  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.
       
  3752 
       
  3753 @see TDesC16::Length()
       
  3754 @see TDes16::MaxLength()
       
  3755 @see RBuf16::Close()
       
  3756 */
       
  3757 EXPORT_C void RBuf16::Assign(TUint16 *aHeapCell,TInt aLength,TInt aMaxLength)
       
  3758 	{
       
  3759 	__ASSERT_ALWAYS(aLength<=aMaxLength, Panic(ETDes16LengthOutOfRange));
       
  3760 	if(aHeapCell)
       
  3761 		{
       
  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); 
       
  3765 		}
       
  3766 	else
       
  3767 		{
       
  3768 		__ASSERT_ALWAYS(aMaxLength == 0, Panic(ETDes16LengthOutOfRange));
       
  3769 		//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
       
  3770 		new(this) RBuf16();
       
  3771 		}
       
  3772 	__TEST_INVARIANT;
       
  3773 	}
       
  3774 
       
  3775 
       
  3776 
       
  3777 
       
  3778 /**
       
  3779 Transfers ownership of the specified heap descriptor to this object.
       
  3780 
       
  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
       
  3785 invoked.
       
  3786 
       
  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.
       
  3790 
       
  3791 @see RBuf16::Close()
       
  3792 */
       
  3793 EXPORT_C void RBuf16::Assign(HBufC16* aHBuf)
       
  3794 	{
       
  3795 	new(this) RBuf16(aHBuf);
       
  3796 	}
       
  3797 
       
  3798 
       
  3799 
       
  3800 
       
  3801 /**
       
  3802 Swaps the content of two 16-bit resizable buffer descriptors.
       
  3803 
       
  3804 @param aRBuf The 16-bit resizable buffer descriptor whose contents are to be
       
  3805              swapped with this one.
       
  3806 */
       
  3807 EXPORT_C void RBuf16::Swap(RBuf16& aRBuf)
       
  3808 	{
       
  3809 	Mem::Swap(this,&aRBuf,sizeof(*this));
       
  3810 	}
       
  3811 
       
  3812 
       
  3813 
       
  3814 
       
  3815 /**
       
  3816 Creates a 16-bit resizable buffer descriptor.
       
  3817 
       
  3818 The function allocates sufficient memory to contain descriptor data up to
       
  3819 the specified maximum length.
       
  3820 
       
  3821 The current length of the descriptor is set to zero. The maximum length of
       
  3822 the descriptor is set to the specified value.
       
  3823 
       
  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
       
  3828 invoked.
       
  3829 
       
  3830 @param aMaxLength  The maximum length of the descriptor.
       
  3831 
       
  3832 @return KErrNone, if successful; KErrNoMemory, if there is insufficient	memory.
       
  3833 
       
  3834 @see TDesC16::Length()
       
  3835 @see TDes16::MaxLength()
       
  3836 @see RBuf16::Close()
       
  3837 */
       
  3838 EXPORT_C TInt RBuf16::Create(TInt aMaxLength)
       
  3839 	{
       
  3840 	if (aMaxLength)
       
  3841 		{
       
  3842 		//Allocate memory
       
  3843 		TUint16* buf=(TUint16*)User::Alloc(aMaxLength*sizeof(TUint16));
       
  3844 		if(!buf) return KErrNoMemory;
       
  3845 		iEPtrType = buf;
       
  3846 		}
       
  3847 	else
       
  3848 		iEPtrType = NULL; //Zero-length descriptor.
       
  3849 
       
  3850 
       
  3851 	//Create EPtr type descriptor.
       
  3852 	new(this) RBuf16(EPtr,0,aMaxLength);
       
  3853 	__TEST_INVARIANT;
       
  3854 	return KErrNone;
       
  3855 	}
       
  3856 
       
  3857 
       
  3858 
       
  3859 
       
  3860 /**
       
  3861 Creates 16-bit resizable buffer descriptor, and leaves on failure.
       
  3862 
       
  3863 The function allocates sufficient memory to contain descriptor data up to
       
  3864 the specified maximum length.
       
  3865 
       
  3866 The current length of the descriptor is set to zero. The maximum length of
       
  3867 the descriptor is set to the specified value.
       
  3868 
       
  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
       
  3873 invoked.
       
  3874 
       
  3875 @param aMaxLength The maximum length of the descriptor.
       
  3876 
       
  3877 @leave KErrNoMemory If there is insufficient memory.
       
  3878 
       
  3879 @see TDesC16::Length()
       
  3880 @see TDes16::MaxLength()
       
  3881 @see RBuf16::Close()
       
  3882 */
       
  3883 EXPORT_C void RBuf16::CreateL(TInt aMaxLength)
       
  3884 	{
       
  3885 	User::LeaveIfError(Create(aMaxLength));
       
  3886 	}
       
  3887 
       
  3888 
       
  3889 
       
  3890 
       
  3891 /**
       
  3892 Creates a 16-bit resizable buffer descriptor.
       
  3893 
       
  3894 The function allocates sufficient memory to contain descriptor data up to
       
  3895 the specified maximum length.
       
  3896 
       
  3897 Both the current length and the maximum length of the descriptor are set to
       
  3898 the specified value.
       
  3899 
       
  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
       
  3904 invoked.
       
  3905 
       
  3906 @param aMaxLength  The length and the maximum length of the descriptor.
       
  3907 
       
  3908 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
       
  3909 
       
  3910 @see RBuf16::Close()
       
  3911 */
       
  3912 EXPORT_C TInt RBuf16::CreateMax(TInt aMaxLength)
       
  3913 	{
       
  3914 	TInt err=Create(aMaxLength); 
       
  3915 	if(err==KErrNone)
       
  3916 		SetMax(); 
       
  3917 	return err;
       
  3918 	}
       
  3919 
       
  3920 
       
  3921 
       
  3922 
       
  3923 /**
       
  3924 Creates a 16-bit resizable buffer descriptor, and leaves on failure.
       
  3925 
       
  3926 The function allocates sufficient memory to contain descriptor data up to
       
  3927 the specified maximum length.
       
  3928 
       
  3929 Both the current length and the maximum length of the descriptor are set to
       
  3930 the specified value. 
       
  3931 
       
  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
       
  3936 invoked.
       
  3937 
       
  3938 @param aMaxLength The length and the maximum length of the descriptor.
       
  3939 
       
  3940 @leave KErrNoMemory If there is insufficient memory.
       
  3941 
       
  3942 @see TDesC16::Length()
       
  3943 @see TDes16::MaxLength()
       
  3944 @see RBuf16::Close()
       
  3945 */
       
  3946 EXPORT_C void RBuf16::CreateMaxL(TInt aMaxLength)
       
  3947 	{
       
  3948 	User::LeaveIfError(CreateMax(aMaxLength));
       
  3949 	}
       
  3950 
       
  3951 
       
  3952 
       
  3953 
       
  3954 /**
       
  3955 Creates a 16-bit resizable buffer descriptor to contain a copy of the
       
  3956 specified (source) descriptor.
       
  3957 
       
  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.
       
  3962 				
       
  3963 The data contained in the source descriptor is copied into this
       
  3964 descriptor.
       
  3965 
       
  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.
       
  3971 
       
  3972 @param aDes Source descriptor to be copied into this object.
       
  3973 
       
  3974 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
       
  3975 
       
  3976 @see TDesC16::Length()
       
  3977 @see TDes16::MaxLength()
       
  3978 @see TDes16::Copy()
       
  3979 @see RBuf16::Close()
       
  3980 */
       
  3981 EXPORT_C TInt RBuf16::Create(const TDesC16& aDes)
       
  3982 	{
       
  3983 	return Create(aDes,aDes.Length());
       
  3984 	}
       
  3985 
       
  3986 
       
  3987 
       
  3988 
       
  3989 
       
  3990 /**
       
  3991 Creates a 16-bit resizable buffer descriptor to contain a copy of the specified
       
  3992 (source) descriptor, and leaves on failure.
       
  3993  
       
  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.
       
  3998 
       
  3999 The data contained in the source descriptor is copied into this descriptor.
       
  4000 
       
  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.
       
  4006 
       
  4007 @param aDes Source descriptor to be copied into this object.
       
  4008 
       
  4009 @leave KErrNoMemory If there is insufficient memory.
       
  4010 
       
  4011 @see TDesC16::Length()
       
  4012 @see TDes16::MaxLength()
       
  4013 @see TDes16::Copy()
       
  4014 @see RBuf16::Close()
       
  4015 */
       
  4016 EXPORT_C void RBuf16::CreateL(const TDesC16& aDes)
       
  4017 	{
       
  4018 	CreateL(aDes,aDes.Length());
       
  4019 	}
       
  4020 
       
  4021 
       
  4022 
       
  4023 
       
  4024 /**
       
  4025 Creates a 16-bit resizable buffer descriptor to contain a copy of the
       
  4026 specified (source) descriptor. 
       
  4027 
       
  4028 The function allocates sufficient memory so that this descriptor's maximum length
       
  4029 is the same as the value of the aMaxLength parameter.
       
  4030 
       
  4031 The data contained in the source descriptor is copied into this descriptor.
       
  4032 The length of data copied is either
       
  4033 
       
  4034 - the length of the source descriptor aDes
       
  4035 
       
  4036 or
       
  4037 
       
  4038 - the value of the aMaxLength parameter
       
  4039 
       
  4040 whichever is the smaller value. The current length of this descriptor is also
       
  4041 set to the smaller value.
       
  4042 
       
  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
       
  4047 invoked.
       
  4048 
       
  4049 @param aDes Source descriptor to be copied into this object.
       
  4050             
       
  4051 @param aMaxLength The maximum length of this descriptor.
       
  4052 
       
  4053 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
       
  4054 
       
  4055 @see TDesC16::Length()
       
  4056 @see TDes16::MaxLength()
       
  4057 @see TDes16::Copy()
       
  4058 @see RBuf16::Close()
       
  4059 */
       
  4060 EXPORT_C TInt RBuf16::Create(const TDesC16& aDes,TInt aMaxLength)
       
  4061 	{
       
  4062 	TInt err=Create(aMaxLength);
       
  4063 	if(err==KErrNone) 
       
  4064 		Copy(aDes.Left(aMaxLength));
       
  4065 	return err;
       
  4066 	}
       
  4067 
       
  4068 
       
  4069 
       
  4070 
       
  4071 /**
       
  4072 Creates a 16-bit resizable buffer descriptor to contain a copy of the specified
       
  4073 (source) descriptor, and leaves on failure.
       
  4074 
       
  4075 The function allocates sufficient memory so that this descriptor's maximum
       
  4076 length is the same as the value of the aMaxLength parameter.
       
  4077 
       
  4078 The data contained in the source descriptor is copied into this descriptor.
       
  4079 The length of data copied is either
       
  4080 
       
  4081 - the length of the source descriptor aDes
       
  4082 
       
  4083 or
       
  4084 
       
  4085 - the value of the aMaxLength parameter
       
  4086 
       
  4087 whichever is the smaller value. The current length of this descriptor is also
       
  4088 set to the smaller value.
       
  4089 
       
  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
       
  4094 invoked.
       
  4095 
       
  4096 @param aDes Source descriptor to be copied into this object.
       
  4097             
       
  4098 @param aMaxLength The maximum length of this descriptor.
       
  4099 
       
  4100 @leave KErrNoMemory If there is insufficient memory.
       
  4101 
       
  4102 @see TDesC16::Length()
       
  4103 @see TDes16::MaxLength()
       
  4104 @see TDes16::Copy()
       
  4105 @see RBuf16::Close()
       
  4106 */
       
  4107 EXPORT_C void RBuf16::CreateL(const TDesC16& aDes,TInt aMaxLength)
       
  4108 	{
       
  4109 	CreateL(aMaxLength);
       
  4110 	Copy(aDes.Left(aMaxLength));
       
  4111 	}
       
  4112 
       
  4113 
       
  4114 
       
  4115 
       
  4116 /**
       
  4117 Resizes this 16-bit resizable buffer descriptor.
       
  4118 
       
  4119 The length and contents of the descriptor are unchanged.
       
  4120 
       
  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
       
  4125 will be lost).
       
  4126 
       
  4127 For example, add
       
  4128 @code
       
  4129     if (desc.MaxLength() == 0) desc.Close();
       
  4130 @endcode
       
  4131 before the call to ReAlloc().
       
  4132     
       
  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
       
  4135                   allocated memory.
       
  4136                   
       
  4137 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
       
  4138 
       
  4139 @panic USER 14 If the new maximum length is less then the current descriptor length.
       
  4140 */
       
  4141 EXPORT_C TInt RBuf16::ReAlloc(TInt aMaxLength)
       
  4142 	{
       
  4143 	__ASSERT_ALWAYS(Length()<=aMaxLength, Panic(ETDes16ReAllocTooSmall));
       
  4144 	__TEST_INVARIANT;
       
  4145 
       
  4146 	if (!aMaxLength)				//Reallocation to zero length
       
  4147 		{
       
  4148 		User::Free(iEPtrType);	//Free memory 
       
  4149 		new (this) RBuf16();		//Create zero-length RBuf
       
  4150 		return KErrNone;
       
  4151 		}
       
  4152 
       
  4153 	if (!iMaxLength)				//Reallocation from zero length
       
  4154 		return Create(aMaxLength); 
       
  4155 
       
  4156 	switch(Type())
       
  4157 		{
       
  4158 		case EPtr:
       
  4159 			{
       
  4160 			TUint16* buf = (TUint16*)User::ReAlloc(iEPtrType,aMaxLength*sizeof(TUint16));
       
  4161 			if(!buf) return KErrNoMemory;
       
  4162 			iEPtrType = buf;
       
  4163 			iMaxLength = aMaxLength;
       
  4164 			break;
       
  4165 			}
       
  4166 		case EBufCPtr:
       
  4167 			{
       
  4168 			HBufC16* hbufc = iEBufCPtrType->ReAlloc(aMaxLength);
       
  4169 			if(!hbufc) return KErrNoMemory;
       
  4170 			Assign(hbufc);
       
  4171 			break;
       
  4172 			}
       
  4173 		}
       
  4174 
       
  4175 	__TEST_INVARIANT;
       
  4176 	return KErrNone;
       
  4177 	}
       
  4178 
       
  4179 
       
  4180 
       
  4181 
       
  4182 /**
       
  4183 Resizes this 16-bit resizable buffer descriptor, leaving on failure.
       
  4184 
       
  4185 The length and contents of the descriptor are unchanged.
       
  4186 
       
  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
       
  4191 will be lost).
       
  4192 
       
  4193 For example, add
       
  4194 @code
       
  4195     if (desc.MaxLength() == 0) desc.Close();
       
  4196 @endcode
       
  4197 before the call to ReAlloc().
       
  4198 
       
  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
       
  4201                   allocated memory.
       
  4202                   
       
  4203 @return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
       
  4204 
       
  4205 @panic USER 14 If the new maximum length is less then the current descriptor length.
       
  4206 */
       
  4207 EXPORT_C void RBuf16::ReAllocL(TInt aMaxLength)
       
  4208 	{
       
  4209 	User::LeaveIfError(ReAlloc(aMaxLength));
       
  4210 	}
       
  4211 
       
  4212 
       
  4213 
       
  4214 
       
  4215 /**
       
  4216 Deallocates memory assigned to this object, and re-initializes the object as
       
  4217 a zero-length descriptor.
       
  4218 */
       
  4219 EXPORT_C void RBuf16::Close() 
       
  4220 	{
       
  4221 	User::Free(iEPtrType); 
       
  4222 	//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
       
  4223 	new(this) RBuf16();
       
  4224 	}
       
  4225 
       
  4226 
       
  4227 
       
  4228 
       
  4229 /**
       
  4230 Pushes a cleanup item for this object onto the cleanup stack.
       
  4231 
       
  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.
       
  4234 
       
  4235 @code
       
  4236 ...
       
  4237 RBuf16 x;
       
  4238 ....
       
  4239 x.CleanupClosePushL();
       
  4240 ...
       
  4241 CleanupStack::PopAndDestroy();
       
  4242 ...
       
  4243 @endcode
       
  4244 
       
  4245 @see RBuf16::Close()
       
  4246 */
       
  4247 EXPORT_C void RBuf16::CleanupClosePushL()
       
  4248 	{
       
  4249 	::CleanupClosePushL(*this);
       
  4250 	}
       
  4251 
       
  4252 
       
  4253 
       
  4254 
       
  4255 /**
       
  4256 Tests that the class obeys its invariant.
       
  4257 */
       
  4258 EXPORT_C void RBuf16::__DbgTestInvariant() const
       
  4259 	{
       
  4260 #ifdef _DEBUG
       
  4261 	TDes16::__DbgTestInvariant();
       
  4262 	switch(Type())
       
  4263 		{
       
  4264 	case EPtr:
       
  4265 		if (iEPtrType)
       
  4266 			{
       
  4267 			__ASSERT_DEBUG(User::AllocLen(iEPtrType) >= iMaxLength*(TInt)sizeof(TUint16), Panic(EInvariantFalse));
       
  4268 			}
       
  4269 		break;
       
  4270 	case EBufCPtr:
       
  4271 		iEBufCPtrType->__DbgTestInvariant(); 
       
  4272 		__ASSERT_DEBUG(iEBufCPtrType->Des().MaxLength() == iMaxLength, Panic(EInvariantFalse));
       
  4273 		__ASSERT_DEBUG(iEBufCPtrType->Length() == Length(), Panic(EInvariantFalse));
       
  4274 		break;
       
  4275 	default:
       
  4276 		User::Invariant();
       
  4277 		}
       
  4278 #endif // _DEBUG
       
  4279 	}
       
  4280 
       
  4281 #endif	// __KERNEL_MODE__
       
  4282 
       
  4283 
       
  4284 #if defined(__DES16_MACHINE_CODED__) || defined(__EABI__)
       
  4285 GLDEF_C void Des16PanicBadDesType()
       
  4286 	{
       
  4287 	Panic(ETDes16BadDescriptorType);
       
  4288 	}
       
  4289 
       
  4290 GLDEF_C void Des16PanicPosOutOfRange()
       
  4291 	{
       
  4292 	Panic(ETDes16PosOutOfRange);
       
  4293 	}
       
  4294 #endif
       
  4295 
       
  4296 #ifdef __DES16_MACHINE_CODED__
       
  4297 GLDEF_C void Des16PanicLengthNegative()
       
  4298 	{
       
  4299 	Panic(ETDes16LengthNegative);
       
  4300 	}
       
  4301 
       
  4302 GLDEF_C void Des16PanicMaxLengthNegative()
       
  4303 	{
       
  4304 	Panic(ETDes16MaxLengthNegative);
       
  4305 	}
       
  4306 
       
  4307 GLDEF_C void Des16PanicLengthOutOfRange()
       
  4308 	{
       
  4309 	Panic(ETDes16LengthOutOfRange);
       
  4310 	}
       
  4311 
       
  4312 GLDEF_C void Des16PanicDesOverflow()
       
  4313 	{
       
  4314 	Panic(ETDes16Overflow);
       
  4315 	}
       
  4316 
       
  4317 GLDEF_C void Des16PanicDesIndexOutOfRange()
       
  4318 	{
       
  4319 	Panic(ETDes16IndexOutOfRange);
       
  4320 	}
       
  4321 #endif
       
  4322