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