os/kernelhwsrv/kernel/eka/common/des8.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/common/des8.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,3960 @@
     1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\common\des8.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "common.h"
    1.22 +#include <e32des8_private.h>
    1.23 +#ifndef __KERNEL_MODE__
    1.24 +#include <collate.h>
    1.25 +#else
    1.26 +#include <kernel/kern_priv.h>
    1.27 +#endif
    1.28 +#include <unicode.h>
    1.29 +
    1.30 +// Folding/Collation for 8 bit characters
    1.31 +
    1.32 +extern const TUint8 __FoldCollTab8[256];
    1.33 +
    1.34 +const TUint8 __FoldCollTab8[256] =
    1.35 +	{
    1.36 +	0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, // 0x00
    1.37 +	0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
    1.38 +	0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, // 0x10
    1.39 +	0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
    1.40 +	0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, // 0x20
    1.41 +	0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
    1.42 +	0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, // 0x30
    1.43 +	0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
    1.44 +	0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67, // 0x40
    1.45 +	0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
    1.46 +	0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, // 0x50
    1.47 +	0x78,0x79,0x7a,0x5b,0x5c,0x5d,0x5e,0x5f,
    1.48 +	0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67, // 0x60
    1.49 +	0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
    1.50 +	0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77, // 0x70
    1.51 +	0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
    1.52 +	0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, // 0x80
    1.53 +	0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
    1.54 +	0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, // 0x90
    1.55 +	0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
    1.56 +	0x20,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7, // 0xa0
    1.57 +	0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
    1.58 +	0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7, // 0xb0
    1.59 +	0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
    1.60 +	0x61,0x61,0x61,0x61,0x61,0x61,0xe6,0x63, // 0xc0
    1.61 +	0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
    1.62 +	0xf0,0x6e,0x6f,0x6f,0x6f,0x6f,0x6f,0xd7, // 0xd0
    1.63 +	0xf8,0x75,0x75,0x75,0x75,0x79,0xfe,0xdf,
    1.64 +	0x61,0x61,0x61,0x61,0x61,0x61,0xe6,0x63, // 0xe0
    1.65 +	0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
    1.66 +	0xf0,0x6e,0x6f,0x6f,0x6f,0x6f,0x6f,0xf7, // 0xf0
    1.67 +	0xf8,0x75,0x75,0x75,0x75,0x79,0xfe,0x79
    1.68 +	};
    1.69 +
    1.70 +#ifndef __KERNEL_MODE__
    1.71 +inline TUint8* memCopy(TUint8* aPtr, const TUint8* aSrc, TInt aLength)
    1.72 +//
    1.73 +// Copy 8 bit values.
    1.74 +//
    1.75 +	{
    1.76 +
    1.77 +	return Mem::Copy(aPtr, aSrc, aLength);
    1.78 +	}
    1.79 +#endif
    1.80 +
    1.81 +#if (defined(__KERNEL_MODE__) && !defined(__DES8_MACHINE_CODED__)) | defined(__EABI_CTORS__)
    1.82 +inline TInt StringLength(const TUint8* aPtr)
    1.83 +	{
    1.84 +	const TUint8* p = aPtr;
    1.85 +	while (*p)
    1.86 +		++p;
    1.87 +	return p-aPtr;
    1.88 +	}
    1.89 +#endif
    1.90 +
    1.91 +inline TDesC8::TDesC8(TInt aType,TInt aLength)
    1.92 +	:iLength(aLength|(aType<<KShiftDesType8))
    1.93 +	{}
    1.94 +inline TInt TDesC8::Type() const
    1.95 +//
    1.96 +// Return the descriptor type
    1.97 +//
    1.98 +	{
    1.99 +	return(iLength>>KShiftDesType8);
   1.100 +	}
   1.101 +
   1.102 +inline TDes8::TDes8(TInt aType,TInt aLength,TInt aMaxLength)
   1.103 +	: TDesC8(aType,aLength),iMaxLength(aMaxLength)
   1.104 +	{}
   1.105 +
   1.106 +// Class TBufCBase8
   1.107 +inline TBufCBase8::TBufCBase8(TInt aLength)
   1.108 +	:TDesC8(EBufC,aLength)
   1.109 +	{}
   1.110 +
   1.111 +inline TUint8* TBufCBase8::WPtr() const
   1.112 +	{return const_cast<TUint8*>(Ptr());}
   1.113 +
   1.114 +
   1.115 +#ifndef __DES8_MACHINE_CODED__
   1.116 +EXPORT_C const TUint8* TDesC8::Ptr() const
   1.117 +/**
   1.118 +Gets a pointer to the data represented by the descriptor.
   1.119 +
   1.120 +The data cannot be changed through the returned pointer.
   1.121 +
   1.122 +@return A pointer to the data
   1.123 +*/
   1.124 +	{
   1.125 +
   1.126 +	switch (Type())
   1.127 +		{
   1.128 +	case EBufC:
   1.129 +		return(&((SBufC8 *)this)->buf[0]);
   1.130 +	case EPtrC:
   1.131 +		return(((SPtrC8 *)this)->ptr);
   1.132 +	case EPtr:
   1.133 +		return(((SPtr8 *)this)->ptr);
   1.134 +	case EBuf:
   1.135 +		return(&((SBuf8 *)this)->buf[0]);
   1.136 +	case EBufCPtr:
   1.137 +		return(&((SBufCPtr8 *)this)->ptr->buf[0]);
   1.138 +		}
   1.139 +	Panic(ETDes8BadDescriptorType);
   1.140 +	return(NULL);
   1.141 +	}
   1.142 +
   1.143 +EXPORT_C const TUint8 &TDesC8::AtC(TInt anIndex) const
   1.144 +//
   1.145 +// Return a reference to the character in the buffer.
   1.146 +//
   1.147 +	{
   1.148 +
   1.149 +	__ASSERT_ALWAYS(anIndex>=0 && anIndex<Length(),Panic(ETDes8IndexOutOfRange));
   1.150 +	return(Ptr()[anIndex]);
   1.151 +	}
   1.152 +
   1.153 +EXPORT_C TInt TDesC8::Compare(const TDesC8 &aDes) const
   1.154 +/**
   1.155 +Compares this descriptor's data with the specified descriptor's data.
   1.156 +
   1.157 +The comparison proceeds on a byte for byte basis. The result of the comparison 
   1.158 +is based on the difference of the first bytes to disagree.
   1.159 +
   1.160 +Two descriptors are equal if they have the same length and content. Where 
   1.161 +two descriptors have different lengths and the shorter descriptor's data
   1.162 +matches the first part of the longer descriptor's data, the shorter is
   1.163 +considered to be less than the longer.
   1.164 +
   1.165 +@param aDes The 8-bit non-modifable descriptor whose data is to be compared 
   1.166 +            with this descriptor's data.
   1.167 +             
   1.168 +@return Positive, if this descriptor is greater than the specified descriptor. 
   1.169 +        Negative, if this descriptor is less than the specified descriptor.
   1.170 +        Zero, if both descriptors have the same length and the their contents
   1.171 +        are the same.
   1.172 +*/
   1.173 +	{
   1.174 +
   1.175 +	return memcompare(Ptr(), Length(), aDes.Ptr(), aDes.Length());
   1.176 +	}
   1.177 +
   1.178 +#ifndef __KERNEL_MODE__
   1.179 +EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
   1.180 +/**
   1.181 +Compares this descriptor's folded data with the specified descriptor's folded 
   1.182 +data. 
   1.183 +
   1.184 +Note that folding is locale-independent behaviour. It is also important to 
   1.185 +note that there can be no guarantee that folding is in any way culturally 
   1.186 +appropriate, and should not be used for comparing strings in natural language; 
   1.187 +use CompareC() for this.
   1.188 +
   1.189 +@param aDes The 8-bit non modifable descriptor whose data is to be compared 
   1.190 +            with this descriptor's data. 
   1.191 +            
   1.192 +@return Positive, if this descriptor is greater than the specified descriptor. 
   1.193 +        Negative, if this descriptor is less than the specified descriptor.
   1.194 +        Zero, if both descriptors have the same length and the their contents
   1.195 +        are the same.
   1.196 +        
   1.197 +@see TDesC8::Compare()
   1.198 +*/
   1.199 +	{
   1.200 +
   1.201 +	return(Mem::CompareF(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
   1.202 +	}
   1.203 +
   1.204 +EXPORT_C TInt TDesC8::CompareC(const TDesC8 &aDes) const
   1.205 +/**
   1.206 +Compares this descriptor's data with the specified descriptor's data using 
   1.207 +the standard collation method for narrow text appropriate to the current locale.
   1.208 +
   1.209 +@param aDes The 8-bit non modifable descriptor whose data is to be compared 
   1.210 +            with this descriptor's data. 
   1.211 +            
   1.212 +@return Positive, if this descriptor is greater than the specified descriptor. 
   1.213 +        Negative, if this descriptor is less than the specified descriptor.
   1.214 +        Zero, if both descriptors have the same length and the their contents
   1.215 +        are the same.
   1.216 +        
   1.217 +@see TDesC8::Compare()
   1.218 +@deprecated
   1.219 +*/
   1.220 +	{
   1.221 +
   1.222 +	return(Mem::CompareC(Ptr(),Length(),aDes.Ptr(),aDes.Length()));
   1.223 +	}
   1.224 +#endif
   1.225 +#endif
   1.226 +
   1.227 +EXPORT_C TInt TDesC8::Find(const TUint8 *pS,TInt aLenS) const
   1.228 +/**
   1.229 +Searches for the first occurrence of the specified data sequence within this 
   1.230 +descriptor.
   1.231 +
   1.232 +Searching always starts at the beginning of this descriptor's data.
   1.233 +
   1.234 +@param pS    A pointer to a location containing the data sequence to be searched 
   1.235 +             for.
   1.236 +@param aLenS The length of the data sequence to be searched for. This value 
   1.237 +             must not be negative, otherwise the function raises a panic.
   1.238 +             
   1.239 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.240 +        data. KErrNotFound, if the data sequence cannot be found.
   1.241 +       
   1.242 +@panic  USER 29 if aLenS is negative. 
   1.243 +*/
   1.244 +	{
   1.245 +
   1.246 +	if (!aLenS)
   1.247 +		return(0);
   1.248 +	__ASSERT_ALWAYS(aLenS>0,Panic(ETDes8LengthNegative));
   1.249 +	const TUint8 *pB=Ptr();
   1.250 +	TInt aLenB=Length();
   1.251 +	const TUint8 *pC=pB-1;			// using pre-increment addressing
   1.252 +	TInt i=aLenB-aLenS;
   1.253 +	if (i>=0)
   1.254 +		{
   1.255 +		const TUint8* pEndS=pS+aLenS-1;		// using pre-increment addressing
   1.256 +		const TUint8 *pEndB=pB+i;			// using pre-increment addressing
   1.257 +		TUint s=*pS;
   1.258 +		for (;;)
   1.259 +			{
   1.260 +			do
   1.261 +				{
   1.262 +				if (pC==pEndB)
   1.263 +					return KErrNotFound;
   1.264 +				} while (*++pC!=s);
   1.265 +			const TUint8 *p1=pC;
   1.266 +			const TUint8 *p2=pS;
   1.267 +			do
   1.268 +				{
   1.269 +				if (p2==pEndS)
   1.270 +					return (pC-pB);
   1.271 +				} while (*++p1==*++p2);
   1.272 +			}
   1.273 +		}
   1.274 +	return(KErrNotFound);
   1.275 +	}
   1.276 +
   1.277 +EXPORT_C TInt TDesC8::Find(const TDesC8 &aDes) const
   1.278 +/**
   1.279 +Searches for the first occurrence of the specified data sequence within this 
   1.280 +descriptor.
   1.281 +
   1.282 +Searching always starts at the beginning of this descriptor's data.
   1.283 +
   1.284 +@param aDes The 8-bit non modifable descriptor containing the data sequence 
   1.285 +            to be searched for. 
   1.286 +            
   1.287 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.288 +        data. KErrNotFound, if the data sequence cannot be found.
   1.289 +*/
   1.290 +	{
   1.291 +
   1.292 +	return(Find(aDes.Ptr(),aDes.Length()));
   1.293 +	}
   1.294 +
   1.295 +const TUint8* convTable(TMatchType aType)
   1.296 +	{
   1.297 +	switch (aType)
   1.298 +		{
   1.299 +		case EMatchFolded:
   1.300 +		case EMatchCollated: return __FoldCollTab8;
   1.301 +		default: return NULL;
   1.302 +		}
   1.303 +	}
   1.304 +
   1.305 +inline TUint conv(const TUint8* aStr,const TUint8* aConv)
   1.306 +	{
   1.307 +	TUint c=*aStr;
   1.308 +	return aConv ? aConv[c] : c;
   1.309 +	}
   1.310 +
   1.311 +
   1.312 +inline TUint lookup(const TUint8* aStr,const TUint8* aConv)
   1.313 +	{
   1.314 +	return aConv[*aStr];
   1.315 +	}
   1.316 +
   1.317 +TInt DoMatch8(const TDesC8 &aLeftD,const TDesC8 &aRightD,TMatchType aType)
   1.318 +	{
   1.319 +	const TUint8* table=convTable(aType);
   1.320 +	const TUint8* pRight=aRightD.Ptr();
   1.321 +	const TUint8* pM=pRight-1;				// pre-increment addressing
   1.322 +	const TUint8* pP=pM+aRightD.Length();
   1.323 +	const TUint8* pLeft=aLeftD.Ptr()-1;		// pre-increment addressing
   1.324 +	const TUint8* pB=pLeft;	
   1.325 +	const TUint8* pE=pB+aLeftD.Length();
   1.326 +
   1.327 +	// Match any pattern up to the first star
   1.328 +	TUint c;
   1.329 +	for (;;)
   1.330 +		{
   1.331 +		if (pM==pP)		// exhausted the pattern
   1.332 +			return pB==pE ? 0 : KErrNotFound;
   1.333 +		TUint c=conv(++pM,table);
   1.334 +		if (c==KMatchAny)
   1.335 +			break;
   1.336 +		if (pB==pE)			// no more input
   1.337 +			return KErrNotFound;
   1.338 +		if (c!=conv(++pB,table) && c!=KMatchOne)	// match failed
   1.339 +			return KErrNotFound;
   1.340 +		}
   1.341 +	// reached a star
   1.342 +	if (pM==pP)
   1.343 +		return 0;
   1.344 +	TInt r=pM==pRight ? -1 : 0;
   1.345 +	for (;;)
   1.346 +		{
   1.347 +		c=conv(++pM,table);
   1.348 +		if (c==KMatchAny)
   1.349 +			{
   1.350 +star:		if (pM==pP)		// star at end of pattern, always matches
   1.351 +				return Max(r,0);
   1.352 +			if (r<-1)		// skipped some '?', matches at beginning
   1.353 +				r=0;
   1.354 +			continue;
   1.355 +			}
   1.356 +		if (pB==pE)			// no more input
   1.357 +			return KErrNotFound;
   1.358 +		if (c==KMatchOne)
   1.359 +			{				// skip a character in the input
   1.360 +			if (pM==pP)
   1.361 +				return r+((r>=0) ? 0 : (pE-pLeft));
   1.362 +			++pB;
   1.363 +			if (r<0)
   1.364 +				--r;
   1.365 +			continue;
   1.366 +			}
   1.367 +	// Matching a non-wild character
   1.368 +		for (;;)
   1.369 +			{
   1.370 +			if (table)	// pull this test out of the tight loop (10-20% faster)
   1.371 +				{
   1.372 +				while (lookup(++pB,table)!=c)
   1.373 +					{
   1.374 +					if (pB==pE)				// no more input
   1.375 +						return KErrNotFound;
   1.376 +					}
   1.377 +				}
   1.378 +			else
   1.379 +				{
   1.380 +				while (*++pB!=c)
   1.381 +					{
   1.382 +					if (pB==pE)				// no more input
   1.383 +						return KErrNotFound;
   1.384 +					}
   1.385 +				}
   1.386 +			// Try to match up to the next star
   1.387 +			const TUint8* pb=pB;
   1.388 +			const TUint8* pm=pM;
   1.389 +			for (;;)
   1.390 +				{
   1.391 +				if (pm<pP)
   1.392 +					{
   1.393 +					TUint cc=conv(++pm,table);
   1.394 +					if (cc==KMatchAny)
   1.395 +						{	// sub-match successful, back to main loop
   1.396 +						r+=(r>=0 ? 0 : pB-pLeft);
   1.397 +						pB=pb;
   1.398 +						pM=pm;
   1.399 +						goto star;
   1.400 +						}
   1.401 +					if (pb==pE)
   1.402 +						return KErrNotFound;	// no more input
   1.403 +					if (cc!=conv(++pb,table) && cc!=KMatchOne)
   1.404 +						break;	// sub-match failed, try next input character
   1.405 +					}
   1.406 +				else if (pb==pE)	// end of matching pattern
   1.407 +					return r+(r>=0 ? 0 : pB-pLeft);	// end of input, so have a match
   1.408 +				else
   1.409 +					break;		// try next input character
   1.410 +				}
   1.411 +			}
   1.412 +		}
   1.413 +	}
   1.414 +
   1.415 +EXPORT_C TInt TDesC8::Match(const TDesC8 &aDes) const
   1.416 +/**
   1.417 +Searches this descriptor's data for a match with the match pattern supplied 
   1.418 +in the specified descriptor.
   1.419 +
   1.420 +The match pattern can contain the wildcard characters "*" and "?", where "*" 
   1.421 +matches zero or more consecutive occurrences of any character and "?" matches 
   1.422 +a single occurrence of any character.
   1.423 +
   1.424 +Note that there is no 'escape character', which means that it is not possible
   1.425 +to match either the "*" character itself or the "?" character itself using
   1.426 +this function.
   1.427 +
   1.428 +@param aDes An 8-bit non-modifable descriptor containing the match pattern.
   1.429 +
   1.430 +@return If a match is found, the offset within this descriptor's data where 
   1.431 +        the match first occurs. KErrNotFound, if there is no match.
   1.432 +*/
   1.433 +	{
   1.434 +
   1.435 +	return DoMatch8(*this,aDes,EMatchNormal);
   1.436 +	}
   1.437 +
   1.438 +EXPORT_C TInt TDesC8::MatchF(const TDesC8 &aDes) const
   1.439 +/**
   1.440 +Searches this descriptor's folded data for a match with the folded match 
   1.441 +pattern supplied in the specified descriptor.
   1.442 +
   1.443 +The match pattern can contain the wildcard characters "*" and "?", where "*" 
   1.444 +matches zero or more consecutive occurrences of any character and "?" matches 
   1.445 +a single occurrence of any character.
   1.446 +
   1.447 +Note that folding is locale-independent behaviour. It is also important to 
   1.448 +note that there can be no guarantee that folding is in any way culturally 
   1.449 +appropriate, and should not be used for matching strings in natural language; 
   1.450 +use MatchC() for this.
   1.451 +
   1.452 +Note that there is no 'escape character', which means that it is not possible
   1.453 +to match either the "*" character itself or the "?" character itself using
   1.454 +this function.
   1.455 +
   1.456 +@param aDes An 8-bit non-modifable descriptor containing the match pattern. 
   1.457 +
   1.458 +@return If a match is found, the offset within this descriptor's data where 
   1.459 +        the match first occurs. KErrNotFound, if there is no match. 
   1.460 +
   1.461 +@see TDesC8::MatchC()
   1.462 +*/
   1.463 +	{
   1.464 +
   1.465 +	return DoMatch8(*this,aDes,EMatchFolded);
   1.466 +	}
   1.467 +
   1.468 +EXPORT_C TInt TDesC8::MatchC(const TDesC8 &aPattern) const
   1.469 +/**
   1.470 +Searches this descriptor's collated data for a match with the collated match 
   1.471 +pattern supplied in the specified descriptor.
   1.472 +
   1.473 +The function uses the standard collation method for narrow text appropriate to 
   1.474 +the current locale.
   1.475 +	
   1.476 +The match pattern can contain the wildcard characters "*" and "?", where "*" 
   1.477 +matches zero or more consecutive occurrences of any character and "?" matches 
   1.478 +a single occurrence of any character.
   1.479 +
   1.480 +Note that there is no 'escape character', which means that it is not possible
   1.481 +to match either the "*" character itself or the "?" character itself using
   1.482 +this function.
   1.483 +	
   1.484 +@param aPattern An 8-bit non-modifable descriptor containing the match pattern. 
   1.485 +
   1.486 +@return If a match is found, the offset within this descriptor's data where 
   1.487 +        the match first occurs. KErrNotFound, if there is no match.
   1.488 +@deprecated
   1.489 +*/
   1.490 +	{
   1.491 +#ifndef __KERNEL_MODE__
   1.492 +	return MatchF(aPattern);
   1.493 +#else
   1.494 +	return DoMatch8(*this,aPattern,EMatchCollated);
   1.495 +#endif
   1.496 +	}
   1.497 +
   1.498 +#ifndef __KERNEL_MODE__
   1.499 +
   1.500 +EXPORT_C TInt TDesC8::FindF(const TUint8 *pS,TInt aLenS) const
   1.501 +/**
   1.502 +Searches for the first occurrence of the specified folded data sequence within 
   1.503 +this descriptor's folded data.
   1.504 +
   1.505 +Searching always starts at the beginning of this descriptor's data.
   1.506 +
   1.507 +Note that folding is locale-independent behaviour. It is also important to 
   1.508 +note that there can be no guarantee that folding is in any way culturally 
   1.509 +appropriate, and should not be used for finding strings in natural language; 
   1.510 +use FindC() for this.
   1.511 +
   1.512 +@param pS    A pointer to a location containing the data sequence to be
   1.513 +             searched for.
   1.514 +@param aLenS The length of the data sequence to be searched for. This value 
   1.515 +             must not be negative, otherwise the function raises a panic.
   1.516 +             
   1.517 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.518 +        data. KErrNotFound, if the data sequence cannot be found. Zero, if the
   1.519 +        length of the search data sequence is zero.
   1.520 +
   1.521 +@panic USER 29 if aLenS is negative
   1.522 +
   1.523 +@see TDesC8::FindC()
   1.524 +*/
   1.525 +	{
   1.526 +	if (!aLenS)
   1.527 +		return(0);
   1.528 +	const TUint8* table=convTable(EMatchFolded);
   1.529 +	const TUint8 *pB=Ptr();
   1.530 +	TInt aLenB=Length();
   1.531 +	const TUint8 *pC=pB-1;			// using pre-increment addressing
   1.532 +	TInt i=aLenB-aLenS;
   1.533 +	if (i>=0)
   1.534 +		{
   1.535 +		const TUint8* pEndS=pS+aLenS-1;		// using pre-increment addressing
   1.536 +		const TUint8 *pEndB=pB+i;			// using pre-increment addressing
   1.537 +		TUint s=lookup(pS,table);
   1.538 +		for (;;)
   1.539 +			{
   1.540 +			do
   1.541 +				{
   1.542 +				if (pC==pEndB)
   1.543 +					return KErrNotFound;
   1.544 +				} while (lookup(++pC,table)!=s);
   1.545 +			const TUint8 *p1=pC;
   1.546 +			const TUint8 *p2=pS;
   1.547 +			do
   1.548 +				{
   1.549 +				if (p2==pEndS)
   1.550 +					return (pC-pB);
   1.551 +				} while (lookup(++p1,table)==lookup(++p2,table));
   1.552 +			}
   1.553 +		}
   1.554 +	return(KErrNotFound);
   1.555 +	}
   1.556 +
   1.557 +EXPORT_C TInt TDesC8::FindF(const TDesC8 &aDes) const
   1.558 +/**
   1.559 +Searches for the first occurrence of the specified folded data sequence within 
   1.560 +this descriptor's folded data. 
   1.561 +
   1.562 +Searching always starts at the beginning of this descriptor's data.
   1.563 +
   1.564 +Note that folding is locale-independent behaviour. It is also important to 
   1.565 +note that there can be no guarantee that folding is in any way culturally 
   1.566 +appropriate, and should not be used for finding strings in natural language; 
   1.567 +use FindC() for this.
   1.568 +
   1.569 +@param aDes The 8-bit non-modifable descriptor containing the data sequence 
   1.570 +            to be searched for. 
   1.571 +            
   1.572 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.573 +        data. KErrNotFound, if the data sequence cannot be found. Zero, if the 
   1.574 +        length of the search data sequence is zero.
   1.575 +
   1.576 +@see TDesC8::FindC()
   1.577 +*/
   1.578 +	{
   1.579 +
   1.580 +	return(FindF(aDes.Ptr(),aDes.Length()));
   1.581 +	}
   1.582 +
   1.583 +EXPORT_C TInt TDesC8::FindC(const TUint8* aText,TInt aLength) const
   1.584 +/**
   1.585 +Searches for the first occurrence of the specified collated data sequence within 
   1.586 +this descriptor's collated data.
   1.587 +	
   1.588 +Searching always starts at the beginning of this descriptor's data. The function 
   1.589 +uses the standard collation method for narrow text appropriate to the current 
   1.590 +locale.
   1.591 +	
   1.592 +@param aText   A pointer to a location containing the data sequence to be
   1.593 +               searched for.
   1.594 +@param aLength The length of the data sequence to be searched for.
   1.595 +             
   1.596 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.597 +        data. KErrNotFound, if the data sequence cannot be found.
   1.598 +      
   1.599 +@panic USER 29 if aLength is negative.
   1.600 +@deprecated
   1.601 +*/
   1.602 +	{
   1.603 +	return FindF(aText, aLength);
   1.604 +	}
   1.605 +
   1.606 +EXPORT_C TInt TDesC8::FindC(const TDesC8 &aDes) const
   1.607 +/**
   1.608 +Searches for the first occurrence of the specified collated data sequence within 
   1.609 +this descriptor's collated data.
   1.610 +
   1.611 +Searching always starts at the beginning of this descriptor's data. The function 
   1.612 +uses the standard collation method for narrow text appropriate to the current 
   1.613 +locale.
   1.614 +
   1.615 +@param aDes The 8-bit non-modifable descriptor containing the data sequence 
   1.616 +            to be searched for. 
   1.617 +            
   1.618 +@return The offset of the data sequence from the beginning of this descriptor's 
   1.619 +        data. KErrNotFound, if the data sequence cannot be found.
   1.620 +@deprecated
   1.621 +*/
   1.622 +	{
   1.623 +
   1.624 +	return(FindC(aDes.Ptr(),aDes.Length()));
   1.625 +	}
   1.626 +
   1.627 +EXPORT_C TInt TDesC8::LocateF(TChar aChar) const
   1.628 +/**
   1.629 +Searches for the first occurrence of a folded character within this
   1.630 +descriptor's folded data.
   1.631 +
   1.632 +The search starts at the beginning of the data,i.e. at the leftmost position.
   1.633 +
   1.634 +Note that folding is locale-independent behaviour. It is also important to 
   1.635 +note that there can be no guarantee that folding is in any way culturally 
   1.636 +appropriate, and should not be used for searching strings in natural language.
   1.637 +
   1.638 +@param aChar The character to be found.
   1.639 +
   1.640 +@return The offset of the character position from the beginning of the data.
   1.641 +        KErrNotFound, if no matching character can be found.
   1.642 +*/
   1.643 +	{
   1.644 +	TUint c = User::Fold(aChar);
   1.645 +	if(c>=0x100)
   1.646 +		return KErrNotFound;
   1.647 +	const TUint8 *pBuf=Ptr();
   1.648 +	const TUint8 *pB=pBuf-1;
   1.649 +	const TUint8 *pE=pB+Length();
   1.650 +	const TUint8* table=__FoldCollTab8;
   1.651 +	do
   1.652 +		{
   1.653 +		if (pB==pE)
   1.654 +			return KErrNotFound;
   1.655 +		} while (table[*++pB]!=c);
   1.656 +	return pB-pBuf;
   1.657 +	}
   1.658 +#endif	// __KERNEL_MODE__
   1.659 +
   1.660 +#ifndef __DES8_MACHINE_CODED__
   1.661 +EXPORT_C TInt TDesC8::Locate(TChar aChar) const
   1.662 +/**
   1.663 +Searches for the first occurrence of a character within this descriptor's
   1.664 +data.
   1.665 +
   1.666 +The search starts at the beginning of the data, i.e. at the leftmost position.
   1.667 +
   1.668 +@param aChar The character to be found. 
   1.669 +
   1.670 +@return The offset of the character position from the beginning of the data.
   1.671 +        KErrNotFound, if no matching character can be found.
   1.672 +*/
   1.673 +	{
   1.674 +
   1.675 +	const TUint8 *pBuf=Ptr();
   1.676 +	const TUint8 *pB=pBuf-1;
   1.677 +	const TUint8 *pE=pB+Length();
   1.678 +	do
   1.679 +		{
   1.680 +		if (pB==pE)
   1.681 +			return KErrNotFound;
   1.682 +		} while (*++pB!=aChar);
   1.683 +	return pB-pBuf;
   1.684 +	}
   1.685 +#endif
   1.686 +
   1.687 +#ifndef __DES8_MACHINE_CODED__
   1.688 +EXPORT_C TInt TDesC8::LocateReverse(TChar aChar) const
   1.689 +/**
   1.690 +Searches for the first occurrence of a character within this descriptor's data, 
   1.691 +searching from the end of the data.
   1.692 +
   1.693 +The search starts at the rightmost position.
   1.694 +
   1.695 +@param aChar The character to be found.
   1.696 +
   1.697 +@return The offset of the character position from the beginning of the data.
   1.698 +        KErrNotFound, if no matching character can be found.
   1.699 +*/
   1.700 +	{
   1.701 +
   1.702 +	TInt len=Length();
   1.703 +	if (len==0)
   1.704 +		return(KErrNotFound);
   1.705 +	const TUint8 *pB=Ptr();
   1.706 +	const TUint8 *pE=pB+len-1;
   1.707 +	while (pE>=pB)
   1.708 +		{
   1.709 +		if (*pE==aChar)
   1.710 +			break;
   1.711 +		pE--;
   1.712 +		}
   1.713 +	return(pE<pB ? KErrNotFound : pE-pB);
   1.714 +	}
   1.715 +#endif
   1.716 +
   1.717 +#ifndef __KERNEL_MODE__
   1.718 +EXPORT_C TInt TDesC8::LocateReverseF(TChar aChar) const
   1.719 +/**
   1.720 +Searches for the first occurrence of a folded character within this descriptor's 
   1.721 +folded data, searching from the end of the data.
   1.722 +
   1.723 +The search starts at the rightmost position. 
   1.724 +
   1.725 +Note that folding is locale-independent behaviour. It is also important to 
   1.726 +note that there can be no guarantee that folding is in any way culturally 
   1.727 +appropriate, and should not be used for searching strings in natural language.
   1.728 +
   1.729 +@param aChar The character to be found 
   1.730 +
   1.731 +@return The offset of the character position from the beginning of the data.
   1.732 +        KErrNotFound, if no matching character can be found
   1.733 +*/
   1.734 +	{
   1.735 +
   1.736 +	TInt len=Length();
   1.737 +	if (len==0)
   1.738 +		return(KErrNotFound);
   1.739 +	const TUint8 *pB=Ptr();
   1.740 +	const TUint8 *pE=pB+len-1;
   1.741 +	const TUint8* table=__FoldCollTab8;
   1.742 +	TUint c = table[aChar];
   1.743 +	while (pE>=pB)
   1.744 +		{
   1.745 +		if (table[*pE]==c)
   1.746 +			break;
   1.747 +		pE--;
   1.748 +		}
   1.749 +	return(pE<pB ? KErrNotFound : pE-pB);
   1.750 +	}
   1.751 +
   1.752 +EXPORT_C HBufC8 *TDesC8::Alloc() const
   1.753 +/**
   1.754 +Creates a new 8-bit heap descriptor and initialises it with a copy of this 
   1.755 +descriptor's data.
   1.756 +
   1.757 +@return A pointer to the new 8 bit heap descriptor, if creation is successful. 
   1.758 +        NULL, if creation of the descriptor fails.
   1.759 +*/
   1.760 +	{
   1.761 +
   1.762 +	HBufC8 *pH=HBufC8::New(Length());
   1.763 +	if (pH)
   1.764 +		*pH=(*this);
   1.765 +	return(pH);
   1.766 +	}
   1.767 +
   1.768 +EXPORT_C HBufC8 *TDesC8::AllocL() const
   1.769 +/**
   1.770 +Creates a new 8-bit heap descriptor and initialises it with a copy of this 
   1.771 +descriptor's data.
   1.772 +
   1.773 +The function leaves, if creation of the descriptor fails.
   1.774 +
   1.775 +@return A pointer to the 8-bit heap descriptor, if creation is successful.
   1.776 +*/
   1.777 +	{
   1.778 +
   1.779 +	HBufC8 *pH=HBufC8::NewL(Length());
   1.780 +	*pH=(*this);
   1.781 +	return(pH);
   1.782 +	}
   1.783 +
   1.784 +EXPORT_C HBufC8 *TDesC8::AllocLC() const
   1.785 +/**
   1.786 +Creates a new 8-bit heap descriptor, initialises it with a copy of this 
   1.787 +descriptor's data, and puts a pointer to the descriptor onto the cleanup stack.
   1.788 +
   1.789 +The function leaves, if creation of the descriptor fails.
   1.790 +
   1.791 +@return A pointer to the 8 bit heap descriptor, if creation is successful. 
   1.792 +        The pointer is also put onto the cleanup stack.
   1.793 +*/
   1.794 +	{
   1.795 +
   1.796 +	HBufC8 *pH=HBufC8::NewLC(Length());
   1.797 +	*pH=(*this);
   1.798 +	return(pH);
   1.799 +	}
   1.800 +#endif	// __KERNEL_MODE__
   1.801 +
   1.802 +#if !defined(__DES8_MACHINE_CODED__)
   1.803 +
   1.804 +EXPORT_C TPtrC8 TDesC8::Left(TInt aLength) const
   1.805 +/**
   1.806 +Extracts the leftmost part of the data. 
   1.807 +
   1.808 +The function does not cut or remove any data but constructs a non-modifiable 
   1.809 +pointer descriptor to represent the leftmost part of the data.
   1.810 +
   1.811 +@param aLength The length of the data to be extracted. If this value
   1.812 +               is greater than the length of the descriptor, the function
   1.813 +               extracts the whole of the descriptor.
   1.814 +
   1.815 +@return The 8-bit non-modifiable pointer descriptor representing the leftmost 
   1.816 +        part of the data.
   1.817 +
   1.818 +@panic USER 22 if aLength is negative. 
   1.819 +*/
   1.820 +	{
   1.821 +
   1.822 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
   1.823 +	return(TPtrC8(Ptr(),Min(aLength,Length())));
   1.824 +	}
   1.825 +
   1.826 +EXPORT_C TPtrC8 TDesC8::Right(TInt aLength) const
   1.827 +/**
   1.828 +Extracts the rightmost part of the data.
   1.829 +
   1.830 +The function does not cut or remove any data but constructs a non-modifiable 
   1.831 +pointer descriptor to represent the rightmost part of the data.
   1.832 +
   1.833 +@param aLength The length of data to be extracted. If this value
   1.834 +               is greater than the length of the descriptor, the function 
   1.835 +               extracts the whole of the descriptor. 
   1.836 +               
   1.837 +@return The 8 bit non-modifiable pointer descriptor representing the rightmost 
   1.838 +        part of the data.
   1.839 +
   1.840 +@panic USER 22 if aLength is negative. 
   1.841 +*/
   1.842 +	{
   1.843 +
   1.844 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
   1.845 +	TInt len=Length();
   1.846 +	if (aLength>len)
   1.847 +		aLength=len;
   1.848 +    return(TPtrC8(Ptr()+len-aLength,aLength));
   1.849 +	}
   1.850 +
   1.851 +EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos) const
   1.852 +/**
   1.853 +Extracts a portion of the data.
   1.854 +
   1.855 +The function does not cut or remove any data but constructs a non-modifiable 
   1.856 +pointer descriptor to represent the defined portion.
   1.857 +
   1.858 +The portion is identified by its starting position and by the length of the 
   1.859 +remainder of the data starting from the specified position.
   1.860 +
   1.861 +@param aPos The starting position of the data to be extracted. This is an 
   1.862 +            offset value; a zero value refers to the leftmost data position. 
   1.863 +            
   1.864 +@return The 8-bit non-modifiable pointer descriptor representing the specified 
   1.865 +        portion of the data.
   1.866 +        
   1.867 +@panic USER 22  if aPos is negative or aPos is greater than the
   1.868 +                length of the descriptor.       
   1.869 +*/
   1.870 +	{
   1.871 +
   1.872 +	TInt len=Length();
   1.873 +	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
   1.874 +    return(TPtrC8(Ptr()+aPos,len-aPos));
   1.875 +	}
   1.876 +
   1.877 +EXPORT_C TPtrC8 TDesC8::Mid(TInt aPos,TInt aLength) const
   1.878 +/**
   1.879 +Extracts a portion of the data.
   1.880 +
   1.881 +The function does not cut or remove any data but constructs a non-modifiable 
   1.882 +pointer descriptor to represent the defined portion.
   1.883 +
   1.884 +The portion is identified by its starting position and by its length.
   1.885 +
   1.886 +@param aPos    The starting position of the data to be extracted. This is an 
   1.887 +               offset value; a zero value refers to the leftmost data position. 
   1.888 +@param aLength The length of data to be extracted.
   1.889 +
   1.890 +@return The 8 bit non-modifiable pointer descriptor representing the specified 
   1.891 +        portion of the data.
   1.892 +
   1.893 +@panic USER 22  if aPos is negative or aPos plus aLength is greater than the
   1.894 +                length of the descriptor.
   1.895 +*/
   1.896 +	{
   1.897 +
   1.898 +	__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
   1.899 +    return(TPtrC8(Ptr()+aPos,aLength));
   1.900 +	}
   1.901 +
   1.902 +#endif  // !defined(__DES8_MACHINE_CODED__)
   1.903 +
   1.904 +#if !defined( __DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
   1.905 +EXPORT_C TBufCBase8::TBufCBase8()
   1.906 +//
   1.907 +// Constructor
   1.908 +//
   1.909 +	: TDesC8(EBufC,0)
   1.910 +	{}
   1.911 +
   1.912 +EXPORT_C TBufCBase8::TBufCBase8(const TUint8 *aString,TInt aMaxLength)
   1.913 +//
   1.914 +// Constructor
   1.915 +//
   1.916 +	: TDesC8(EBufC,0)
   1.917 +	{
   1.918 +	Copy(aString,aMaxLength);
   1.919 +	}
   1.920 +
   1.921 +EXPORT_C TBufCBase8::TBufCBase8(const TDesC8 &aDes,TInt aMaxLength)
   1.922 +//
   1.923 +// Constructor
   1.924 +//
   1.925 +	: TDesC8(EBufC,0)
   1.926 +	{
   1.927 +	Copy(aDes,aMaxLength);
   1.928 +	}
   1.929 +#endif 
   1.930 +
   1.931 +#ifndef __DES8_MACHINE_CODED__
   1.932 +EXPORT_C void TBufCBase8::Copy(const TUint8 *aString,TInt aMaxLength)
   1.933 +//
   1.934 +// Copy from a string.
   1.935 +//
   1.936 +	{
   1.937 +
   1.938 +	TInt len=STRING_LENGTH(aString);
   1.939 +	__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
   1.940 +	memmove(WPtr(), aString, len);
   1.941 +	DoSetLength(len);
   1.942 +	}
   1.943 +
   1.944 +EXPORT_C void TBufCBase8::Copy(const TDesC8 &aDes,TInt aMaxLength)
   1.945 +//
   1.946 +// Copy from a descriptor.
   1.947 +//
   1.948 +	{
   1.949 +
   1.950 +	TInt len=aDes.Length();
   1.951 +	__ASSERT_ALWAYS(len<=aMaxLength,Panic(ETDes8Overflow));
   1.952 +	memmove(WPtr(), aDes.Ptr(), len);
   1.953 +	DoSetLength(len);
   1.954 +	}
   1.955 +#endif
   1.956 +
   1.957 +#ifndef __KERNEL_MODE__
   1.958 +inline HBufC8::HBufC8(TInt aLength)
   1.959 +	:TBufCBase8(aLength)
   1.960 +	{}
   1.961 +
   1.962 +EXPORT_C HBufC8 *HBufC8::New(TInt aMaxLength)
   1.963 +/**
   1.964 +Creates, and returns a pointer to, a new 8-bit heap descriptor.
   1.965 +
   1.966 +The heap descriptor is empty and its length is zero.
   1.967 +
   1.968 +Data can, subsequently, be assigned into it using the assignment operators.
   1.969 +
   1.970 +@param aMaxLength The requested maximum length of the descriptor. Note that 
   1.971 +                  the resulting heap cell size and, therefore, the resulting
   1.972 +                  maximum length of the descriptor may be larger
   1.973 +                  than requested.
   1.974 +
   1.975 +@return A pointer to the new 8-bit heap descriptor. NULL, if the 8-bit heap 
   1.976 +        descriptor cannot be created.
   1.977 +
   1.978 +@panic USER 30 if aMaxLength is negative.
   1.979 +
   1.980 +@see HBufC8::operator=()
   1.981 +*/
   1.982 +	{
   1.983 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
   1.984 +	return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(0);
   1.985 +	}
   1.986 +
   1.987 +EXPORT_C HBufC8 *HBufC8::NewL(TInt aMaxLength)
   1.988 +/** 
   1.989 +Creates, and returns a pointer to, a new 8-bit heap descriptor, and leaves 
   1.990 +on failure.
   1.991 +
   1.992 +The heap descriptor is empty and its length is zero.
   1.993 +
   1.994 +Data can, subsequently, be assigned into it using the assignment operators.
   1.995 +
   1.996 +@param aMaxLength The requested maximum length of the descriptor. Note that 
   1.997 +                  the resulting heap cell size and, therefore, the resulting
   1.998 +                  maximum length of the descriptor may be larger
   1.999 +                  than requested.
  1.1000 +
  1.1001 +@return A pointer to the new 8 bit heap descriptor. The function leaves, if 
  1.1002 +        the new 8-bit heap descriptor cannot be created.
  1.1003 +
  1.1004 +@panic USER 30 if aMaxLength is negative.
  1.1005 +
  1.1006 +@see HBufC8::operator=()
  1.1007 +*/
  1.1008 +	{
  1.1009 +	return static_cast<HBufC8*>(User::LeaveIfNull(New(aMaxLength)));
  1.1010 +	}
  1.1011 +
  1.1012 +EXPORT_C HBufC8 *HBufC8::NewLC(TInt aMaxLength)
  1.1013 +/**
  1.1014 +Creates, adds a pointer onto the cleanup stack, and returns a pointer to, a 
  1.1015 +new 8 bit heap descriptor; leaves on failure.
  1.1016 +
  1.1017 +The heap descriptor is empty and its length is zero.
  1.1018 +
  1.1019 +Data can, subsequently, be assigned into it using the assignment operators.
  1.1020 +
  1.1021 +@param aMaxLength The requested maximum length of the descriptor. Note that 
  1.1022 +                  the resulting heap cell size and, therefore, the resulting
  1.1023 +                  maximum length of the descriptor may be larger
  1.1024 +                  than requested.
  1.1025 +                  
  1.1026 +@return A pointer to the new 8-bit heap descriptor. The function leaves, if 
  1.1027 +        the new 8-bit heap descriptor cannot be created.
  1.1028 +
  1.1029 +@panic USER 30 if aMaxLength is negative.
  1.1030 +
  1.1031 +@see HBufC8::operator=()
  1.1032 +*/
  1.1033 +	{
  1.1034 +	HBufC8* buf=NewL(aMaxLength);
  1.1035 +	CleanupStack::PushL(buf);
  1.1036 +	return buf;
  1.1037 +	}
  1.1038 +
  1.1039 +EXPORT_C HBufC8 *HBufC8::NewMax(TInt aMaxLength)
  1.1040 +/**
  1.1041 +Creates, and returns a pointer to, a new 8-bit heap descriptor.
  1.1042 +
  1.1043 +No data is assigned into the new descriptor but its length
  1.1044 +is set to aMaxLength.
  1.1045 +
  1.1046 +Data can, subsequently, be assigned into it using the assignment operators.
  1.1047 +
  1.1048 +@param aMaxLength The requested maximum length of the descriptor. Note that 
  1.1049 +                  the resulting heap cell size and, therefore, the resulting
  1.1050 +                  maximum length of the descriptor may be larger
  1.1051 +                  than requested. This also means that the resulting maximum
  1.1052 +                  length of the descriptor may be greater than its length.
  1.1053 +
  1.1054 +@return A pointer to the new 8-bit heap descriptor. NULL, if the new 8-bit 
  1.1055 +        heap descriptor cannot be created.
  1.1056 +
  1.1057 +@panic USER 30 if aMaxLength is negative.
  1.1058 +
  1.1059 +@see HBufC8::operator=()
  1.1060 +*/
  1.1061 +	{
  1.1062 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.1063 +	return new(STD_CLASS::Alloc(_FOFF(HBufC8,iBuf[aMaxLength]))) HBufC8(aMaxLength);
  1.1064 +	}
  1.1065 +
  1.1066 +EXPORT_C HBufC8 *HBufC8::NewMaxL(TInt aMaxLength)
  1.1067 +/**
  1.1068 +Creates, and returns a pointer to, a new 8-bit heap descriptor;
  1.1069 +leaves on failure.
  1.1070 +
  1.1071 +No data is assigned into the new descriptor but its length
  1.1072 +is set to aMaxLength.
  1.1073 +
  1.1074 +Data can, subsequently, be assigned into it using the assignment operators.
  1.1075 +
  1.1076 +@param aMaxLength The requested maximum length of the descriptor. Note that 
  1.1077 +                  the resulting heap cell size and, therefore, the resulting
  1.1078 +                  maximum length of the descriptor may be larger
  1.1079 +                  than requested. This also means that the resulting maximum
  1.1080 +                  length of the descriptor may be greater than its length.
  1.1081 +                  
  1.1082 +@return A pointer to the new 8-bit heap descriptor. The function leaves, if 
  1.1083 +        the new 8-bit heap descriptor cannot be created.
  1.1084 +
  1.1085 +@panic USER 30 if aMaxLength is negative.
  1.1086 +
  1.1087 +@see HBufC8::operator=()
  1.1088 +*/
  1.1089 +	{
  1.1090 +	return static_cast<HBufC8*>(User::LeaveIfNull(NewMax(aMaxLength)));
  1.1091 +	}
  1.1092 +
  1.1093 +EXPORT_C HBufC8 *HBufC8::NewMaxLC(TInt aMaxLength)
  1.1094 +/**
  1.1095 +Creates, adds a pointer onto the cleanup stack and returns a pointer to, a 
  1.1096 +new 8-bit heap descriptor; leaves on failure.
  1.1097 +
  1.1098 +No data is assigned into the new descriptor but its length
  1.1099 +is set to aMaxLength.
  1.1100 +
  1.1101 +Data can, subsequently, be assigned into it using the assignment operators.
  1.1102 +
  1.1103 +@param aMaxLength The requested maximum length of the descriptor. Note that 
  1.1104 +                  the resulting heap cell size and, therefore, the resulting
  1.1105 +                  maximum length of the descriptor may be larger than requested.
  1.1106 +                  This also means that the resulting maximum
  1.1107 +                  length of the descriptor may be greater than its length.
  1.1108 +                  
  1.1109 +@return A pointer to the new 8-bit heap descriptor. This is also put onto the 
  1.1110 +        cleanup stack. The function leaves, if the new 8-bit heap descriptor
  1.1111 +        cannot be created.
  1.1112 +
  1.1113 +@panic USER 30 if aMaxLength is negative.
  1.1114 +
  1.1115 +@see HBufC8::operator=()
  1.1116 +*/
  1.1117 +	{
  1.1118 +	HBufC8* buf=NewMaxL(aMaxLength);
  1.1119 +	CleanupStack::PushL(buf);
  1.1120 +	return buf;
  1.1121 +	}
  1.1122 +
  1.1123 +EXPORT_C HBufC8 &HBufC8::operator=(const TUint8 *aString)
  1.1124 +/**
  1.1125 +Copies data into this 8-bit heap descriptor replacing any existing data.
  1.1126 +
  1.1127 +The length of this descriptor is set to reflect the new data.
  1.1128 +
  1.1129 +Note that the maximum length of this (target) descriptor is the length
  1.1130 +of the descriptor buffer in the allocated host heap cell; this may be greater
  1.1131 +than the maximum length specified when this descriptor was created or
  1.1132 +last re-allocated.
  1.1133 +
  1.1134 +@param aString A pointer to a zero-terminated string. 
  1.1135 +                 
  1.1136 +@return A reference to this 8 bit heap descriptor.
  1.1137 +
  1.1138 +@panic USER 23  if the length of the string, excluding the zero terminator,
  1.1139 +                is greater than the maximum length of this (target) descriptor,
  1.1140 +*/
  1.1141 +	{
  1.1142 +
  1.1143 +	Copy(aString,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
  1.1144 +	return(*this);
  1.1145 +	}
  1.1146 +
  1.1147 +EXPORT_C HBufC8 &HBufC8::operator=(const TDesC8 &aDes)
  1.1148 +/**
  1.1149 +Copies data into this 8-bit heap descriptor replacing any existing data.
  1.1150 +
  1.1151 +The length of this descriptor is set to reflect the new data.
  1.1152 +
  1.1153 +Note that the maximum length of this (target) descriptor is the length
  1.1154 +of the descriptor buffer in the allocated host heap cell; this may be greater
  1.1155 +than the maximum length specified when this descriptor was created or last
  1.1156 +re-allocated.
  1.1157 +
  1.1158 +@param aDes An 8-bit non-modifiable descriptor.
  1.1159 +            
  1.1160 +@return A reference to this 8-bit heap descriptor.
  1.1161 +
  1.1162 +@panic USER 23  if the length of the descriptor aDes is greater than the
  1.1163 +                maximum length of this (target) descriptor
  1.1164 +*/
  1.1165 +	{
  1.1166 +
  1.1167 +	Copy(aDes,(STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
  1.1168 +	return(*this);
  1.1169 +	}
  1.1170 +
  1.1171 +EXPORT_C HBufC8 *HBufC8::ReAlloc(TInt aMaxLength)
  1.1172 +/**
  1.1173 +Expands or contracts the heap descriptor.
  1.1174 +
  1.1175 +This is done by:
  1.1176 +
  1.1177 +1. creating a new heap descriptor.
  1.1178 +
  1.1179 +2. copying the original data into the new descriptor.
  1.1180 +
  1.1181 +3. deleting the original descriptor.
  1.1182 +
  1.1183 +@param aMaxLength The new requested maximum length of the descriptor. 
  1.1184 +                  Note that the resulting heap cell size and, therefore,
  1.1185 +                  the resulting maximum length of the descriptor may be
  1.1186 +                  larger than requested.
  1.1187 +
  1.1188 +@return A pointer to the new expanded or contracted 8 bit heap descriptor -  
  1.1189 +        the original descriptor is deleted. NULL, if the new 8-bit heap descriptor 
  1.1190 +        cannot be created - the original descriptor remains unchanged
  1.1191 +
  1.1192 +@panic USER 26  if aMaxLength is less than the length of the existing data.
  1.1193 +@panic USER 30  if aMaxLength is negative.
  1.1194 +*/
  1.1195 +	{
  1.1196 +
  1.1197 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.1198 +	__ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes8ReAllocTooSmall));
  1.1199 +	return((HBufC8 *)STD_CLASS::ReAlloc(this,(aMaxLength*sizeof(TUint8))+sizeof(TDesC8)));
  1.1200 +	}
  1.1201 +
  1.1202 +EXPORT_C HBufC8 *HBufC8::ReAllocL(TInt aMaxLength)
  1.1203 +/**
  1.1204 +Expands or contracts the descriptor; leaves on failure.
  1.1205 +
  1.1206 +This is done by:
  1.1207 +
  1.1208 +1. creating a new heap descriptor.
  1.1209 +
  1.1210 +2. copying the original data into the new descriptor.
  1.1211 +
  1.1212 +3. deleting the original descriptor.
  1.1213 +
  1.1214 +@param aMaxLength The new requested maximum length of the descriptor. 
  1.1215 +                  Note that the resulting heap cell size and, therefore,
  1.1216 +                  the resulting maximum length of the descriptor may be
  1.1217 +                  larger than requested.
  1.1218 +
  1.1219 +@return A pointer to the new expanded or contracted 8 bit heap descriptor -  
  1.1220 +        the original descriptor is deleted. NULL, if the new 8-bit heap descriptor 
  1.1221 +        cannot be created - the original descriptor remains unchanged
  1.1222 +
  1.1223 +@panic USER 26  if aMaxLength is less than the length of the existing data.
  1.1224 +@panic USER 30  if aMaxLength is negative.
  1.1225 +*/
  1.1226 +	{
  1.1227 +
  1.1228 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.1229 +	__ASSERT_ALWAYS(Length()<=aMaxLength,Panic(ETDes8ReAllocTooSmall));
  1.1230 +	return((HBufC8 *)STD_CLASS::ReAllocL(this,(aMaxLength*sizeof(TUint8))+sizeof(TDesC8)));
  1.1231 +	}
  1.1232 +
  1.1233 +EXPORT_C TPtr8 HBufC8::Des()
  1.1234 +/**
  1.1235 +Creates and returns an 8-bit modifiable pointer descriptor for the data
  1.1236 +represented by this 8-bit heap descriptor.
  1.1237 +
  1.1238 +The content of a heap descriptor normally cannot be altered, other than by 
  1.1239 +complete replacement of the data. Creating a modifiable pointer descriptor 
  1.1240 +provides a way of changing the data.
  1.1241 +
  1.1242 +The modifiable pointer descriptor is set to point to this heap descriptor's 
  1.1243 +data.
  1.1244 +
  1.1245 +The length of the modifiable pointer descriptor is set to the length of this 
  1.1246 +heap descriptor.
  1.1247 +
  1.1248 +The maximum length of the modifiable pointer descriptor is set to the length 
  1.1249 +of the heap descriptor's buffer. Note that the maximum length is the length 
  1.1250 +of the descriptor buffer in the allocated host heap cell; this may be greater 
  1.1251 +than the maximum length requested when this descriptor was originally created 
  1.1252 +or last re-allocated.
  1.1253 +
  1.1254 +When data is modified through this new pointer descriptor, the lengths of 
  1.1255 +both it and this heap descriptor are changed.
  1.1256 +
  1.1257 +Note that it is a common mistake to use Des() to create a TDesC8& reference. 
  1.1258 +While not incorrect, it is simpler and much more efficient to simply dereference 
  1.1259 +the heap descriptor.
  1.1260 +
  1.1261 +@return An 8-bit modifiable pointer descriptor representing the data in this 
  1.1262 +        8-bit heap descriptor.
  1.1263 +*/
  1.1264 +	{
  1.1265 +	return DoDes((STD_CLASS::AllocLen(this)-sizeof(TDesC8))/sizeof(TUint8));
  1.1266 +	}
  1.1267 +#endif	// __KERNEL_MODE__
  1.1268 +
  1.1269 +#ifndef __DES8_MACHINE_CODED__
  1.1270 +EXPORT_C void TDes8::SetLength(TInt aLength)
  1.1271 +/**
  1.1272 +Sets the length of the data represented by the descriptor to the
  1.1273 +specified value.
  1.1274 +
  1.1275 +@param aLength The new length of the descriptor.
  1.1276 +
  1.1277 +@panic USER 23  if alength is negative or is greater than the maximum length of
  1.1278 +                this (target) descriptor.
  1.1279 +*/
  1.1280 +	{
  1.1281 +
  1.1282 +	__ASSERT_ALWAYS(TUint(aLength)<=TUint(MaxLength()),Panic(ETDes8Overflow));
  1.1283 +	DoSetLength(aLength);
  1.1284 +	if (Type()==EBufCPtr)
  1.1285 +		((SBufCPtr8 *)this)->ptr->length=aLength; // Relies on iType==0 for an TBufC
  1.1286 +  	}
  1.1287 +
  1.1288 +EXPORT_C void TDes8::SetMax()
  1.1289 +/**
  1.1290 +Sets the length of the data to the maximum length of the descriptor.
  1.1291 +*/
  1.1292 +	{
  1.1293 +
  1.1294 +	SetLength(iMaxLength);
  1.1295 +	}
  1.1296 +
  1.1297 +EXPORT_C void TDes8::Copy(const TUint8 *aString)
  1.1298 +/**
  1.1299 +Copies data into this descriptor replacing any existing data.
  1.1300 +
  1.1301 +The length of this descriptor is set to reflect the new data.
  1.1302 +
  1.1303 +@param aString A pointer to a zero-terminated string.
  1.1304 +               
  1.1305 +@panic USER 23  if the length of aString, excluding the zero terminator, is
  1.1306 +                greater than the maximum length of this (target) descriptor.
  1.1307 +*/
  1.1308 +	{
  1.1309 +
  1.1310 +	TInt len=STRING_LENGTH(aString);
  1.1311 +	SetLength(len);
  1.1312 +    memmove(WPtr(), aString, len);
  1.1313 +	}
  1.1314 +
  1.1315 +EXPORT_C void TDes8::Copy(const TUint8 *aBuf,TInt aLength)
  1.1316 +/**
  1.1317 +Copies data into this descriptor replacing any existing data.
  1.1318 +
  1.1319 +The length of this descriptor is set to reflect the new data.
  1.1320 +
  1.1321 +@param aBuf    The start address of data to be copied.
  1.1322 +@param aLength The length of data to be copied.
  1.1323 +
  1.1324 +@panic USER 23  if aLength is greater than the maximum length of
  1.1325 +                this (target) descriptor.
  1.1326 +*/
  1.1327 +	{
  1.1328 +
  1.1329 +	SetLength(aLength);
  1.1330 +    memmove(WPtr(), aBuf, aLength);
  1.1331 +	}
  1.1332 +
  1.1333 +EXPORT_C void TDes8::Copy(const TDesC8 &aDes)
  1.1334 +/**
  1.1335 +Copies data into this descriptor replacing any existing data.
  1.1336 +
  1.1337 +The length of this descriptor is set to reflect the new data.
  1.1338 +
  1.1339 +@param aDes An 8-bit non-modifiable descriptor. The length of the data cannot 
  1.1340 +            be greater than the maximum length of the target descriptor.
  1.1341 +
  1.1342 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1343 +                this (target) descriptor.
  1.1344 +*/
  1.1345 +	{
  1.1346 +
  1.1347 +	TInt len=aDes.Length();
  1.1348 +	SetLength(len);
  1.1349 +    memmove(WPtr(), aDes.Ptr(), len);
  1.1350 +	}
  1.1351 +#endif
  1.1352 +
  1.1353 +#ifndef __KERNEL_MODE__
  1.1354 +EXPORT_C void TDes8::Copy(const TDesC16 &aDes)
  1.1355 +/**
  1.1356 +Copies data into this descriptor replacing any existing data.
  1.1357 +
  1.1358 +The length of this descriptor is set to reflect the new data.
  1.1359 +
  1.1360 +@param aDes A 16-bit non-modifiable descriptor. Each double-byte value can 
  1.1361 +            only be copied into the corresponding single byte when the
  1.1362 +            double-byte value is less than decimal 256. A double-byte value of
  1.1363 +            256 or greater cannot be  copied and the corresponding single byte
  1.1364 +            is set to a value of decimal 1.
  1.1365 +            
  1.1366 +@panic USER 23  if the length of the aDes is greater than the maximum length
  1.1367 +                of this (target) descriptor.
  1.1368 +*/
  1.1369 +	{
  1.1370 +
  1.1371 +	TInt len=aDes.Length();
  1.1372 +	SetLength(len);
  1.1373 +	const TUint16 *pS=aDes.Ptr();
  1.1374 +	const TUint16 *pE=pS+len;
  1.1375 +	TUint8 *pT=WPtr();
  1.1376 +	while (pS<pE)
  1.1377 +		{
  1.1378 +		TUint c=(*pS++);
  1.1379 +		if (c>=0x100)
  1.1380 +			c=1;
  1.1381 +		*pT++=(TUint8)c;
  1.1382 +		}
  1.1383 +	}
  1.1384 +#endif
  1.1385 +
  1.1386 +#ifndef __DES8_MACHINE_CODED__
  1.1387 +EXPORT_C void TDes8::Append(TChar aChar)
  1.1388 +/**
  1.1389 +Appends a character onto the end of this descriptor's data.
  1.1390 +
  1.1391 +The length of this descriptor is incremented to reflect the new content.
  1.1392 +
  1.1393 +@param aChar The single character to be appended. The length of the descriptor 
  1.1394 +             is incremented by one. The function assumes that the character
  1.1395 +             is non-Unicode and that it can be represented by a single byte.
  1.1396 +
  1.1397 +@panic USER 23  if the resulting new length of this descriptor is greater than
  1.1398 +                its maximum length.
  1.1399 +*/
  1.1400 +	{
  1.1401 +
  1.1402 +	TInt len=Length();
  1.1403 +	TUint8 *pB=WPtr()+len;
  1.1404 +	SetLength(len+1);
  1.1405 +	*pB++=(TUint8)aChar;
  1.1406 +	}
  1.1407 +
  1.1408 +EXPORT_C void TDes8::Append(const TUint8 *aBuf,TInt aLength)
  1.1409 +/**
  1.1410 +Appends data onto the end of this descriptor's data.
  1.1411 +
  1.1412 +The length of this descriptor is incremented to reflect the new content.
  1.1413 +
  1.1414 +@param aBuf    A pointer to the data to be copied.
  1.1415 +@param aLength The length of the data to be copied.
  1.1416 +
  1.1417 +@panic USER 23  if the resulting new length of this descriptor is greater than
  1.1418 +                its maximum length.
  1.1419 +@panic USER 29  if aLength is negative.
  1.1420 +*/
  1.1421 +	{
  1.1422 +
  1.1423 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
  1.1424 +	TInt len=Length();
  1.1425 +	SetLength(len+aLength);
  1.1426 +    memmove(WPtr()+len, aBuf, aLength);
  1.1427 +	}
  1.1428 +
  1.1429 +EXPORT_C void TDes8::Append(const TDesC8 &aDes)
  1.1430 +/**
  1.1431 +Appends data onto the end of this descriptor's data.
  1.1432 +
  1.1433 +The length of this descriptor is incremented to reflect the new content.
  1.1434 +
  1.1435 +@param aDes An 8-bit non-modifiable descriptor whose data is to be appended.
  1.1436 +
  1.1437 +@panic USER 23  if the resulting new length of this descriptor is greater than
  1.1438 +                its maximum length.
  1.1439 +*/
  1.1440 +	{
  1.1441 +
  1.1442 +	TInt len=Length();
  1.1443 +    TInt n=aDes.Length();
  1.1444 +	SetLength(len+n);
  1.1445 +    memmove(WPtr()+len, aDes.Ptr(), n);
  1.1446 +	}
  1.1447 +#endif
  1.1448 +
  1.1449 +#ifndef __KERNEL_MODE__
  1.1450 +EXPORT_C void TDes8::Append(const TDesC16 &aDes)
  1.1451 +/**
  1.1452 +Appends data onto the end of this descriptor's data.
  1.1453 +
  1.1454 +The length of this descriptor is incremented to reflect the new content.
  1.1455 +
  1.1456 +@param aDes A 16-bit non-modifiable descriptor whose data is to be appended. 
  1.1457 +            Each double-byte value can only be appended as a single byte when
  1.1458 +            the double-byte value is less than decimal 256. A double-byte value
  1.1459 +            of 256 or greater cannot be appended and the corresponding single
  1.1460 +            byte is set to a value of decimal 1.
  1.1461 +
  1.1462 +@panic USER 23  if the resulting new length of this descriptor is greater than
  1.1463 +                its maximum length.
  1.1464 +*/
  1.1465 +	{
  1.1466 +
  1.1467 +	TInt len=Length();
  1.1468 +	TInt n=aDes.Length();
  1.1469 +	const TUint16* pS=aDes.Ptr();
  1.1470 +	const TUint16* pE=pS+n;
  1.1471 +	TUint8 *pT=WPtr()+len;
  1.1472 +	SetLength(len+n);
  1.1473 +	while (pS<pE)
  1.1474 +		{
  1.1475 +		TUint c=(*pS++);
  1.1476 +		if (c>=0x100)
  1.1477 +			c=1;
  1.1478 +		*pT++=(TUint8)c;
  1.1479 +		}
  1.1480 +	}
  1.1481 +#endif
  1.1482 +
  1.1483 +#ifndef __KERNEL_MODE__
  1.1484 +EXPORT_C void TDes8::Swap(TDes8 &aDes)
  1.1485 +/**
  1.1486 +Swaps the data represented by this descriptor with the data represented by 
  1.1487 +the specified descriptor.
  1.1488 +
  1.1489 +The lengths of both descriptors are swapped to reflect the change.
  1.1490 +
  1.1491 +Note that each descriptor must be capable of accommodating the contents of
  1.1492 +the other descriptor.
  1.1493 +
  1.1494 +@param aDes The 8-bit modifiable descriptor whose data is to be swapped with 
  1.1495 +            the data of this descriptor.
  1.1496 +            
  1.1497 +@panic USER 23  if the maximum length of either descriptor is smaller than the 
  1.1498 +                length of the other descriptor.
  1.1499 +*/
  1.1500 +	{
  1.1501 +
  1.1502 +	TInt l=Length();
  1.1503 +	TInt r=aDes.Length();
  1.1504 +	aDes.SetLength(l);
  1.1505 +	SetLength(r);
  1.1506 +	TInt s=Min(l,r);
  1.1507 +	l-=s;
  1.1508 +	r-=s;
  1.1509 +	TUint8 *pL=WPtr();
  1.1510 +	TUint8 *pR=aDes.WPtr();
  1.1511 +	while (s--)
  1.1512 +		{
  1.1513 +		TChar a=(*pL);
  1.1514 +		*pL++=(*pR);
  1.1515 +		*pR++=(TUint8)a;
  1.1516 +		}
  1.1517 +	while (l--)
  1.1518 +		*pR++=(*pL++);
  1.1519 +	while (r--)
  1.1520 +		*pL++=(*pR++);
  1.1521 +	}
  1.1522 +#endif
  1.1523 +
  1.1524 +#ifndef __DES8_MACHINE_CODED__
  1.1525 +EXPORT_C void TDes8::Fill(TChar aChar)
  1.1526 +/**
  1.1527 +Fills the descriptor's data area with the specified character, replacing any 
  1.1528 +existing data.
  1.1529 +
  1.1530 +The descriptor is filled from the beginning up to its current length. The 
  1.1531 +descriptor's length does not change. It is not filled to its maximum length.
  1.1532 +
  1.1533 +@param aChar The fill character. The function assumes that the character is 
  1.1534 +             non-Unicode, and that it can be represented by a single byte.
  1.1535 +*/
  1.1536 +	{
  1.1537 +
  1.1538 +    memset(WPtr(), (TInt)(aChar.operator TUint()), Length());
  1.1539 +	}
  1.1540 +#endif
  1.1541 +
  1.1542 +EXPORT_C void TDes8::Fill(TChar aChar,TInt aLength)
  1.1543 +/**
  1.1544 +Fills the descriptor's data area with the specified character, replacing any 
  1.1545 +existing data.
  1.1546 +
  1.1547 +The descriptor is filled with the specified number of characters.
  1.1548 +and its length is changed to reflect this.
  1.1549 +
  1.1550 +@param aChar   The fill character. The function assumes that the character is 
  1.1551 +               non-Unicode, and that it can be represented by a single byte. 
  1.1552 +@param aLength The new length of the descriptor and the number of fill
  1.1553 +               characters to be copied into it.
  1.1554 +               
  1.1555 +@panic USER 23  if aLength is negative or is greater than the maximum length
  1.1556 +                of this descriptor.
  1.1557 +*/
  1.1558 +	{
  1.1559 +
  1.1560 +	SetLength(aLength);
  1.1561 +    memset(WPtr(), (TInt)(aChar.operator TUint()), aLength);
  1.1562 +	}
  1.1563 +
  1.1564 +#ifndef __KERNEL_MODE__
  1.1565 +EXPORT_C void TDes8::AppendFill(TChar aChar,TInt aLength)
  1.1566 +/**
  1.1567 +Appends and fills this descriptor with the specified character.
  1.1568 +
  1.1569 +The descriptor is appended with the specified number of characters.
  1.1570 +and its length is changed to reflect this.
  1.1571 +
  1.1572 +@param aChar   The fill character. The function assumes that the character
  1.1573 +               is non-Unicode and that it can be represented by a single byte.
  1.1574 +@param aLength The number of fill characters to be appended.
  1.1575 +
  1.1576 +@panic USER 23  if aLength is negative, or the resulting length of this
  1.1577 +                descriptor is greater than its maximum length.
  1.1578 +*/
  1.1579 +	{
  1.1580 +
  1.1581 +	TInt len=Length();
  1.1582 +	SetLength(len+aLength);
  1.1583 +    memset(WPtr()+len, (TInt)(aChar.operator TUint()), aLength);
  1.1584 +	}
  1.1585 +#endif
  1.1586 +
  1.1587 +#ifndef __DES8_MACHINE_CODED__
  1.1588 +#ifndef __KERNEL_MODE__
  1.1589 +EXPORT_C void TDes8::ZeroTerminate()
  1.1590 +/**
  1.1591 +Appends a zero terminator onto the end of this descriptor's data.
  1.1592 +
  1.1593 +The length of the descriptor is not changed. It must, however, be strictly
  1.1594 +less than the descriptor's maximum length. 
  1.1595 +This condition guarantees that there is sufficient space for the
  1.1596 +zero terminator.
  1.1597 +
  1.1598 +@panic USER 23  if the descriptor's length is not strictly less than its
  1.1599 +                maximum length.
  1.1600 +*/
  1.1601 +	{
  1.1602 +
  1.1603 +	TInt len=Length();
  1.1604 +	__ASSERT_ALWAYS(len<MaxLength(),Panic(ETDes8Overflow));
  1.1605 +	WPtr()[len]=0;
  1.1606 +	}
  1.1607 +
  1.1608 +EXPORT_C const TUint8 *TDes8::PtrZ()
  1.1609 +/**
  1.1610 +Appends a zero terminator onto the end of this descriptor's data and returns 
  1.1611 +a pointer to the data.
  1.1612 +
  1.1613 +The length of the descriptor is not changed. It must, however, be strictly
  1.1614 +less than the descriptor's maximum length.
  1.1615 +This condition guarantees that there is sufficient space for the
  1.1616 +zero terminator.
  1.1617 +
  1.1618 +@return A pointer to the descriptor's zero terminated data.
  1.1619 +
  1.1620 +@panic USER 23  if the descriptor's length is not strictly less than its
  1.1621 +                maximum length.
  1.1622 +*/
  1.1623 +	{
  1.1624 +
  1.1625 +	ZeroTerminate();
  1.1626 +	return(Ptr());
  1.1627 +	}
  1.1628 +#endif
  1.1629 +
  1.1630 +EXPORT_C void TDes8::Zero()
  1.1631 +/**
  1.1632 +Sets the length of the data to zero.
  1.1633 +*/
  1.1634 +	{
  1.1635 +
  1.1636 +	SetLength(0);
  1.1637 +	}
  1.1638 +
  1.1639 +EXPORT_C void TDes8::FillZ()
  1.1640 +/**
  1.1641 +Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any 
  1.1642 +existing data.
  1.1643 +
  1.1644 +The descriptor is filled from the beginning up to its current length. The 
  1.1645 +descriptor's length does not change. It is not filled to its maximum length.
  1.1646 +*/
  1.1647 +	{
  1.1648 +
  1.1649 +    memclr(WPtr(), Length());
  1.1650 +	}
  1.1651 +#endif
  1.1652 +
  1.1653 +EXPORT_C void TDes8::FillZ(TInt aLength)
  1.1654 +/**
  1.1655 +Fills the descriptor's data area with binary zeroes, i.e. 0x00, replacing any 
  1.1656 +existing data, and changes its length.
  1.1657 +
  1.1658 +The descriptor is filled with the specified number of binary zeroes.
  1.1659 +The descriptor's length is changed to reflect this.
  1.1660 +
  1.1661 +@param aLength The new length of the descriptor and the number of binary zeroes
  1.1662 +               to be copied into it. 
  1.1663 +               
  1.1664 +@panic USER 23  if aLength is negative, or is greater than the maximum length
  1.1665 +                of this descriptor.
  1.1666 +*/
  1.1667 +	{
  1.1668 +
  1.1669 +	SetLength(aLength);
  1.1670 +    memclr(WPtr(), aLength);
  1.1671 +	}
  1.1672 +
  1.1673 +#ifndef __KERNEL_MODE__
  1.1674 +EXPORT_C void TDes8::Fold()
  1.1675 +/**
  1.1676 +Performs folding on the content of this descriptor.
  1.1677 +
  1.1678 +Note that folding is locale-independent behaviour. It is also important to 
  1.1679 +note that there can be no guarantee that folding is in any way culturally 
  1.1680 +appropriate, and should not be used when dealing with strings in natural
  1.1681 +language.
  1.1682 +*/
  1.1683 +	{
  1.1684 +
  1.1685 +	TUint8 *pB=WPtr();
  1.1686 +	TInt len=Length();
  1.1687 +	const TUint8* table=__FoldCollTab8;
  1.1688 +	while (len--)
  1.1689 +		{
  1.1690 +		*pB=table[*pB];
  1.1691 +		pB++;
  1.1692 +		}
  1.1693 +	}
  1.1694 +
  1.1695 +EXPORT_C void TDes8::Collate()
  1.1696 +/**
  1.1697 +Performs collation on the content of this descriptor.
  1.1698 +@deprecated
  1.1699 +*/
  1.1700 +	{
  1.1701 +
  1.1702 +	TUint8 *pB=WPtr();
  1.1703 +	TInt len=Length();
  1.1704 +	while (len--)
  1.1705 +		{
  1.1706 +		TChar c=User::Collate(*pB);
  1.1707 +		*pB++=(TUint8)c;
  1.1708 +		}
  1.1709 +	}
  1.1710 +
  1.1711 +EXPORT_C void TDes8::LowerCase()
  1.1712 +/**
  1.1713 +Converts the content of this descriptor to lower case.
  1.1714 +
  1.1715 +Conversion is implemented as appropriate to the current locale.
  1.1716 +*/
  1.1717 +	{
  1.1718 +
  1.1719 +	TUint8 *pB=WPtr();
  1.1720 +	TInt len=Length();
  1.1721 +	while (len--)
  1.1722 +		{
  1.1723 +		TCharLC c(*pB);
  1.1724 +		*pB++=(TUint8)c;
  1.1725 +		}
  1.1726 +	}
  1.1727 +
  1.1728 +EXPORT_C void TDes8::UpperCase()
  1.1729 +/**
  1.1730 +Converts the content of this descriptor to upper case.
  1.1731 +
  1.1732 +Conversion is implemented as appropriate to the current locale.
  1.1733 +*/
  1.1734 +	{
  1.1735 +
  1.1736 +	TUint8 *pB=WPtr();
  1.1737 +	TInt len=Length();
  1.1738 +	while (len--)
  1.1739 +		{
  1.1740 +		TCharUC c(*pB);
  1.1741 +		*pB++=(TUint8)c;
  1.1742 +		}
  1.1743 +	}
  1.1744 +
  1.1745 +EXPORT_C void TDes8::Capitalize()
  1.1746 +/**
  1.1747 +Capitalises the content of this descriptor.
  1.1748 +
  1.1749 +Capitalisation is implemented as appropriate to the current locale.
  1.1750 +*/
  1.1751 +	{
  1.1752 +
  1.1753 +	TUint8 *pB=WPtr();
  1.1754 +	TInt len=Length();
  1.1755 +	if (len--)
  1.1756 +		{
  1.1757 +		*pB=(TUint8)User::TitleCase(*pB);
  1.1758 +		++pB;
  1.1759 +		while (len--)
  1.1760 +			{
  1.1761 +			*pB=(TUint8)User::LowerCase(*pB);
  1.1762 +			++pB;
  1.1763 +			}
  1.1764 +		}
  1.1765 +	}
  1.1766 +
  1.1767 +EXPORT_C void TDes8::CopyF(const TDesC8 &aDes)
  1.1768 +/**
  1.1769 +Copies and folds data from the specified descriptor into this descriptor
  1.1770 +replacing any existing data.
  1.1771 +
  1.1772 +The length of this descriptor is set to reflect the new 
  1.1773 +data.
  1.1774 +
  1.1775 +Note that folding is locale-independent behaviour. It is also important to 
  1.1776 +note that there can be no guarantee that folding is in any way culturally 
  1.1777 +appropriate, and should not be used when dealing with strings in natural
  1.1778 +language.
  1.1779 +
  1.1780 +@param aDes An 8-bit non-modifiable descriptor.
  1.1781 +
  1.1782 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1783 +                this target descriptor.
  1.1784 +*/
  1.1785 +	{
  1.1786 +
  1.1787 +	TInt len=aDes.Length();
  1.1788 +	SetLength(len);
  1.1789 +	const TUint8 *pS=aDes.Ptr();
  1.1790 +	TUint8 *pT=WPtr();
  1.1791 +	const TUint8* table=__FoldCollTab8;
  1.1792 +	while (len--)
  1.1793 +		{
  1.1794 +		*pT++=table[*pS++];
  1.1795 +		}
  1.1796 +	}
  1.1797 +
  1.1798 +EXPORT_C void TDes8::CopyC(const TDesC8 &aDes)
  1.1799 +/**
  1.1800 +Copies and collates data from the specified descriptor 
  1.1801 +into this descriptor replacing any existing data.
  1.1802 +
  1.1803 +The length of this descriptor is set to reflect the new data.
  1.1804 +
  1.1805 +@param aDes An 8 bit non-modifiable descriptor.
  1.1806 +
  1.1807 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1808 +                this target descriptor.
  1.1809 +@deprecated
  1.1810 +*/
  1.1811 +	{
  1.1812 +
  1.1813 +	TInt len=aDes.Length();
  1.1814 +	SetLength(len);
  1.1815 +	const TUint8 *pS=aDes.Ptr();
  1.1816 +	TUint8 *pT=WPtr();
  1.1817 +	while (len--)
  1.1818 +		{
  1.1819 +		TChar c=User::Collate(*pS++);
  1.1820 +		*pT++=(TUint8)c;
  1.1821 +		}
  1.1822 +	}
  1.1823 +
  1.1824 +EXPORT_C void TDes8::CopyLC(const TDesC8 &aDes)
  1.1825 +/**
  1.1826 +Copies text from the specified descriptor and converts it to lower case before 
  1.1827 +putting it into this descriptor, replacing any existing data.
  1.1828 +
  1.1829 +The length of this descriptor is set to reflect the new data.
  1.1830 +
  1.1831 +Conversion to lower case is implemented as appropriate to the current locale.
  1.1832 +
  1.1833 +@param aDes An 8-bit non-modifiable descriptor.
  1.1834 +
  1.1835 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1836 +                this target descriptor.
  1.1837 +*/
  1.1838 +	{
  1.1839 +
  1.1840 +	TInt len=aDes.Length();
  1.1841 +	SetLength(len);
  1.1842 +	const TUint8 *pS=aDes.Ptr();
  1.1843 +	TUint8 *pT=WPtr();
  1.1844 +	while (len--)
  1.1845 +		{
  1.1846 +		TCharLC c(*pS++);
  1.1847 +		*pT++=(TUint8)c;
  1.1848 +		}
  1.1849 +	}
  1.1850 +
  1.1851 +EXPORT_C void TDes8::CopyUC(const TDesC8 &aDes)
  1.1852 +/**
  1.1853 +Copies text from the specified descriptor and converts it to upper case before 
  1.1854 +putting it into this descriptor, replacing any existing data.
  1.1855 +
  1.1856 +The length of this descriptor is set to reflect the new data.
  1.1857 +
  1.1858 +Conversion to upper case is implemented as appropriate to the current locale.
  1.1859 +
  1.1860 +@param aDes An 8-bit non-modifiable descriptor.
  1.1861 +
  1.1862 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1863 +                this target descriptor.
  1.1864 +*/
  1.1865 +	{
  1.1866 +
  1.1867 +	TInt len=aDes.Length();
  1.1868 +	SetLength(len);
  1.1869 +	const TUint8 *pS=aDes.Ptr();
  1.1870 +	TUint8 *pT=WPtr();
  1.1871 +	while (len--)
  1.1872 +		{
  1.1873 +		TCharUC c(*pS++);
  1.1874 +		*pT++=(TUint8)c;
  1.1875 +		}
  1.1876 +	}
  1.1877 +
  1.1878 +EXPORT_C void TDes8::CopyCP(const TDesC8 &aDes)
  1.1879 +/**
  1.1880 +Copies text from the specified descriptor and capitalises it before putting 
  1.1881 +it into this descriptor, replacing any existing data.
  1.1882 +
  1.1883 +The length of this descriptor is set to reflect the new data.
  1.1884 +
  1.1885 +Capitalisation is implemented as appropriate to the current locale.
  1.1886 +
  1.1887 +@param aDes An 8-bit non-modifiable descriptor.
  1.1888 +
  1.1889 +@panic USER 23  if the length of aDes is greater than the maximum length of
  1.1890 +                this target descriptor.
  1.1891 +*/
  1.1892 +	{
  1.1893 +
  1.1894 +	TInt len=aDes.Length();
  1.1895 +	SetLength(len);
  1.1896 +	const TUint8 *pS=aDes.Ptr();
  1.1897 +	TUint8 *pT=WPtr();
  1.1898 +	if (len--)
  1.1899 +		{
  1.1900 +		TChar c(*pS++);
  1.1901 +#ifdef _UNICODE
  1.1902 +		c.TitleCase();
  1.1903 +#else
  1.1904 +		c.UpperCase();
  1.1905 +#endif
  1.1906 +		*pT++=(TUint8)c;
  1.1907 +		while (len--)
  1.1908 +			{
  1.1909 +			TCharLC c=(*pS++);
  1.1910 +			*pT++=(TUint8)c;
  1.1911 +			}
  1.1912 +		}
  1.1913 +	}
  1.1914 +
  1.1915 +EXPORT_C void TDes8::Repeat(const TUint8 *aBuf,TInt aLength)
  1.1916 +/**
  1.1917 +Copies data with repetition into this descriptor, from a memory location
  1.1918 +specified by pointer, replacing any existing data.
  1.1919 +
  1.1920 +Copying proceeds until this descriptor is filled up to its current length. 
  1.1921 +If it cannot contain a whole number of copies of the source data, then the 
  1.1922 +last copy is truncated.
  1.1923 +
  1.1924 +@param aBuf    A pointer to data to be repeatedly copied. 
  1.1925 +@param aLength The length of data to be copied.
  1.1926 +
  1.1927 +@panic USER 29  if aLength is negative.
  1.1928 +*/
  1.1929 +	{
  1.1930 +
  1.1931 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
  1.1932 +	TUint8 *pB=WPtr();
  1.1933 +	TInt len=Length();
  1.1934 +	if (len && aLength)
  1.1935 +		{
  1.1936 +		while (len)
  1.1937 +			{
  1.1938 +			TInt i=Min(len,aLength);
  1.1939 +			pB=memCopy(pB,aBuf,i);
  1.1940 +			len-=i;
  1.1941 +			}
  1.1942 +		}
  1.1943 +	}
  1.1944 +
  1.1945 +EXPORT_C void TDes8::Repeat(const TDesC8 &aDes)
  1.1946 +/**
  1.1947 +Copies data with repetition into this descriptor, from another descriptor,
  1.1948 +replacing any existing data.
  1.1949 +
  1.1950 +Copying proceeds until this descriptor is filled up to its current length. 
  1.1951 +If it cannot contain a whole number of copies of the source data, then the 
  1.1952 +last copy is truncated.
  1.1953 +
  1.1954 +@param aDes An 8-bit non-modifiable descriptor whose data is to be repeatedly 
  1.1955 +            copied.
  1.1956 +*/
  1.1957 +	{
  1.1958 +
  1.1959 +	Repeat(aDes.Ptr(),aDes.Length());
  1.1960 +	}
  1.1961 +
  1.1962 +EXPORT_C void TDes8::Trim()
  1.1963 +/**
  1.1964 +Deletes leading and trailing whitespace characters from the descriptor's data.
  1.1965 +
  1.1966 +The length of the descriptor is reduced to reflect the loss of the whitespace characters.
  1.1967 +
  1.1968 +@see TDes8::TrimLeft()
  1.1969 +@see TDes8::TrimRight()
  1.1970 +*/
  1.1971 +	{
  1.1972 +
  1.1973 +	TrimLeft();
  1.1974 +	TrimRight();
  1.1975 +	}
  1.1976 +
  1.1977 +EXPORT_C void TDes8::TrimAll()
  1.1978 +/**
  1.1979 +Deletes leading and trailing whitespace characters from the descriptor's data and 
  1.1980 +replaces each contiguous set of whitespace characters within the data by one whitespace 
  1.1981 +character.
  1.1982 +
  1.1983 +The length of the descriptor is reduced to reflect the loss of the whitespace 
  1.1984 +characters.
  1.1985 +
  1.1986 +@see TDes8::Trim()
  1.1987 +*/
  1.1988 +	{
  1.1989 +
  1.1990 +	TrimLeft();
  1.1991 +	TrimRight();
  1.1992 +	TUint8 *pBuf=(TUint8 *)Ptr();
  1.1993 +	TUint8 *pSrc=pBuf;
  1.1994 +	TUint8 *pDst=pBuf;
  1.1995 +	TInt len=Length();
  1.1996 +	TInt spaces=0;
  1.1997 +	while (len--)
  1.1998 +		{
  1.1999 +		TChar c=*pSrc;
  1.2000 +		if (c.IsSpace())
  1.2001 +			{
  1.2002 +			if (spaces++==0)
  1.2003 +				{
  1.2004 +				if (pDst!=pSrc)
  1.2005 +					*pDst=*pSrc;
  1.2006 +				pDst++;
  1.2007 +				}
  1.2008 +			}
  1.2009 +		else
  1.2010 +			{
  1.2011 +			spaces=0;
  1.2012 +			if (pDst!=pSrc)
  1.2013 +				*pDst=*pSrc;
  1.2014 +			pDst++;
  1.2015 +			}
  1.2016 +		pSrc++;
  1.2017 +		}
  1.2018 +	Delete(pDst-pBuf, pSrc-pDst);
  1.2019 +	}
  1.2020 +
  1.2021 +EXPORT_C void TDes8::TrimLeft()
  1.2022 +/**
  1.2023 +Deletes leading whitespace characters from the descriptor's data.
  1.2024 +
  1.2025 +All whitespace characters up to, but not including the first non-whitespace
  1.2026 +character, are deleted.
  1.2027 +
  1.2028 +The length of the descriptor is reduced to reflect the loss of the
  1.2029 +whitespace characters.
  1.2030 +*/
  1.2031 +	{
  1.2032 +
  1.2033 +	const TUint8 *pBuf=Ptr();
  1.2034 +	const TUint8 *pB=pBuf;
  1.2035 +	TInt len=Length();
  1.2036 +	while (len--)
  1.2037 +		{
  1.2038 +		TChar c=(*pB);
  1.2039 +		if (!c.IsSpace())
  1.2040 +			break;
  1.2041 +		pB++;
  1.2042 +		}
  1.2043 +	Delete(0,pB-pBuf);
  1.2044 +	}
  1.2045 +
  1.2046 +EXPORT_C void TDes8::TrimRight()
  1.2047 +/**
  1.2048 +Deletes trailing whitespace characters from the descriptor's data.
  1.2049 +
  1.2050 +The process starts on the right hand side of the descriptor's data
  1.2051 +and proceeds to the left. 
  1.2052 +
  1.2053 +All whitespace characters up to, but not including the first non-whitespace character, 
  1.2054 +are deleted.
  1.2055 +
  1.2056 +The length of the descriptor is reduced to reflect the loss of the whitespace
  1.2057 +characters.
  1.2058 +*/
  1.2059 +	{
  1.2060 +
  1.2061 +	TInt len=Length();
  1.2062 +	if (len==0)
  1.2063 +		return;
  1.2064 +	const TUint8 *pB=Ptr()+len-1;
  1.2065 +	TInt s=len;
  1.2066 +	while (s)
  1.2067 +		{
  1.2068 +		TChar c=(*pB--);
  1.2069 +		if (!c.IsSpace())
  1.2070 +			break;
  1.2071 +		s--;
  1.2072 +		}
  1.2073 +	Delete(s,len-s);
  1.2074 +	}
  1.2075 +
  1.2076 +EXPORT_C void TDes8::Insert(TInt aPos,const TDesC8 &aDes)
  1.2077 +/**
  1.2078 +Inserts data into this descriptor.
  1.2079 +
  1.2080 +The length of this descriptor is changed to reflect the extra data.
  1.2081 +
  1.2082 +@param aPos The position within the data where insertion is to start. This 
  1.2083 +            is an offset value; a zero value refers to the leftmost data
  1.2084 +            position.
  1.2085 +            
  1.2086 +@param aDes An 8 bit non modifiable descriptor whose data is to be inserted.
  1.2087 +
  1.2088 +@panic USER 22  if aPos is negative or is greater than the length of this
  1.2089 +                descriptor.
  1.2090 +@panic USER 23  if the resulting length of this descriptor is greater than its
  1.2091 +                maximum length.
  1.2092 +*/
  1.2093 +	{
  1.2094 +
  1.2095 +	TInt len=Length();
  1.2096 +	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
  1.2097 +	TInt s=aDes.Length();
  1.2098 +	__ASSERT_ALWAYS((len+s)<=MaxLength(),Panic(ETDes8Overflow));
  1.2099 +	TUint8 *pB=WPtr();
  1.2100 +	memmove(pB+aPos+s,pB+aPos,len-aPos);
  1.2101 +	memmove(pB+aPos,aDes.Ptr(),aDes.Length());
  1.2102 +	SetLength(len+s);
  1.2103 +	}
  1.2104 +
  1.2105 +EXPORT_C void TDes8::Delete(TInt aPos,TInt aLength)
  1.2106 +/**
  1.2107 +Deletes data from this descriptor.
  1.2108 +
  1.2109 +The length of this descriptor is changed to reflect the loss of data.
  1.2110 +
  1.2111 +@param aPos    The position within the data where deletion is to start. This 
  1.2112 +               is an offset value; a zero value refers to the leftmost data
  1.2113 +               position.
  1.2114 +               
  1.2115 +@param aLength The length of data to be deleted. If necessary, the function 
  1.2116 +               adjusts this value to ensure that no data beyond the end of the
  1.2117 +               descriptor data area is deleted.
  1.2118 +
  1.2119 +@panic USER 22  if aPos is negative or is greater than the length of this
  1.2120 +                descriptor.
  1.2121 +*/
  1.2122 +	{
  1.2123 +
  1.2124 +	TInt len=Length();
  1.2125 +	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
  1.2126 +	TInt d=Min(len-aPos,aLength);
  1.2127 +	TUint8 *pB=WPtr();
  1.2128 +	memmove(pB+aPos,pB+aPos+d,len-aPos-d);
  1.2129 +	SetLength(len-d);
  1.2130 +	}
  1.2131 +
  1.2132 +EXPORT_C void TDes8::Replace(TInt aPos,TInt aLength,const TDesC8 &aDes)
  1.2133 +/**
  1.2134 +Replaces data in this descriptor.
  1.2135 +
  1.2136 +The specified length can be different to the length of the replacement data.
  1.2137 +The length of this descriptor changes to reflect the change of data.
  1.2138 +
  1.2139 +@param aPos    The position within the data where replacement is to start.
  1.2140 +               This is an offset value; a zero value refers to the leftmost
  1.2141 +               data position.
  1.2142 +               
  1.2143 +@param aLength The length of data to be replaced.
  1.2144 +
  1.2145 +@param aDes    The source 8-bit non-modifiable descriptor whose data is to
  1.2146 +               replace the target descriptor's data at aPos.
  1.2147 +
  1.2148 +@panic USER 20  if aLength is negative or the sum of aLength and aPos is
  1.2149 +                greater than the length of this descriptor.
  1.2150 +                
  1.2151 +@panic USER 22  if aPos is negative or is greater than the length of this
  1.2152 +                descriptor.
  1.2153 +                
  1.2154 +@panic USER 23  if the resulting length of this descriptor is greater than its
  1.2155 +                maximum length.
  1.2156 +
  1.2157 +@panic USER 28  if the length of the source descriptor aDes is negative or is
  1.2158 +                greater than the maximum length of this target descriptor,
  1.2159 +*/
  1.2160 +	{
  1.2161 +
  1.2162 +	TInt len=Length();
  1.2163 +	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
  1.2164 +	__ASSERT_ALWAYS(aLength>=0 && aPos+aLength<=len,Panic(ETDes8LengthOutOfRange));
  1.2165 +	TInt s=aDes.Length();
  1.2166 +	TInt maxlen=MaxLength();
  1.2167 +	__ASSERT_ALWAYS(s>=0 && s<=maxlen,Panic(ETDes8RemoteLengthOutOfRange));
  1.2168 +	__ASSERT_ALWAYS((len+s-aLength)<=maxlen,Panic(ETDes8Overflow));
  1.2169 +	TUint8 *pB=WPtr();
  1.2170 +	memmove(pB+aPos+s,pB+aPos+aLength,len-aPos-aLength);
  1.2171 +	memmove(pB+aPos,aDes.Ptr(),s);
  1.2172 +	SetLength(len+s-aLength);
  1.2173 +	}
  1.2174 +
  1.2175 +EXPORT_C void TDes8::Justify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
  1.2176 +/**
  1.2177 +Copies data into this descriptor and justifies it, replacing any existing data.
  1.2178 +
  1.2179 +The length of this descriptor is set to reflect the new data.
  1.2180 +
  1.2181 +The target area is considered to be an area of specified width positioned at
  1.2182 +the beginning of this descriptor's data area. Source data is copied into, and
  1.2183 +aligned within this target area according to the specified alignment
  1.2184 +instruction.
  1.2185 +
  1.2186 +If the length of the target area is larger than the length of the source, then
  1.2187 +spare space within the target area is padded with the fill character.
  1.2188 +
  1.2189 +@param aDes        An 8-bit non-modifiable descriptor containing the source data.
  1.2190 +                   The length of the data to be copied is the smaller of:
  1.2191 +                   the length of the source descriptor, and 
  1.2192 +                   the width of the target area (only if this is not the
  1.2193 +                   explicit negative value KDefaultJustifyWidth).
  1.2194 +
  1.2195 +@param aWidth      The width of the target area. If this has the specific
  1.2196 +                   negative value KDefaultJustifyWidth, then the width is
  1.2197 +                   re-set to the length of the data source.
  1.2198 +
  1.2199 +@param anAlignment The alignment of the data within the target area
  1.2200 +
  1.2201 +@param aFill       The fill character used to pad the target area. 
  1.2202 +
  1.2203 +@panic USER 23  if the resulting length of this descriptor is greater than
  1.2204 +                its maximum length or aWidth has a negative value other 
  1.2205 +                than KDefaultJustifyWidth.
  1.2206 +*/
  1.2207 +	{
  1.2208 +
  1.2209 +    Zero();
  1.2210 +    AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
  1.2211 +    }
  1.2212 +
  1.2213 +EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill)
  1.2214 +/**
  1.2215 +Appends data onto the end of this descriptor's data and justifies it.
  1.2216 +	
  1.2217 +The source of the appended data is an existing descriptor.
  1.2218 +	
  1.2219 +The target area is considered to be an area of specified width, immediately 
  1.2220 +following this descriptor's existing data. Source data is copied into, and 
  1.2221 +aligned within this target area according to the specified alignment instruction.
  1.2222 +	
  1.2223 +If the length of the target area is larger than the length of the source, 
  1.2224 +then spare space within the target area is padded with the fill character.
  1.2225 +		
  1.2226 +@param aDes        An 8-bit non-modifiable descriptor containing the source
  1.2227 +                   data. The length of the data to be copied is the smaller of:
  1.2228 +                   the length of the source descriptor, and
  1.2229 +                   the width of the target area (only if this is not the
  1.2230 +                   explicit negative value KDefaultJustifyWidth). 
  1.2231 +	
  1.2232 +@param aWidth      The width of the target area. If this has the specific
  1.2233 +                   negative value KDefaultJustifyWidth, then the width is
  1.2234 +	               re-set to the length of the data source.
  1.2235 +	
  1.2236 +@param anAlignment The alignment of the data within the target area. 
  1.2237 +	
  1.2238 +@param aFill       The fill character used to pad the target area.
  1.2239 +
  1.2240 +@panic USER 23  if the resulting length of this descriptor is greater than
  1.2241 +                its maximum length or aWidth has a negative value other 
  1.2242 +                than KDefaultJustifyWidth.
  1.2243 +*/
  1.2244 +	{
  1.2245 +
  1.2246 +    AppendJustify(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill);
  1.2247 +    } 
  1.2248 +
  1.2249 +EXPORT_C void TDes8::AppendJustify(const TDesC8 &aDes,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
  1.2250 +/**
  1.2251 +Appends data onto the end of this descriptor's data and justifies it.
  1.2252 +	
  1.2253 +The source of the appended data is an existing descriptor.
  1.2254 +	
  1.2255 +The target area is considered to be an area of specified width, immediately 
  1.2256 +following this descriptor's existing data. Source data is copied into, and 
  1.2257 +aligned within this target area according to the specified alignment instruction.
  1.2258 +	
  1.2259 +If the length of the target area is larger than the length of the source, 
  1.2260 +then spare space within the target area is padded with the fill character.
  1.2261 +	
  1.2262 +@param aDes        An 8-bit non-modifiable descriptor containing the source data. 
  1.2263 +
  1.2264 +@param aLength     The length of data to be copied from the source descriptor. 
  1.2265 +                   If this is greater than the width of the target area, then
  1.2266 +                   the length of data copied is limited to the width.
  1.2267 +                   The length of data to be copied must not be 	greater than
  1.2268 +                   the length of the source descriptor. Note that this
  1.2269 +                   condition is not automatically tested. 
  1.2270 +                   
  1.2271 +@param aWidth      The width of the target area. If this has the specific negative 
  1.2272 +                   value KDefaultJustifyWidth, then the width is
  1.2273 +                   re-set to the length of the data source.
  1.2274 +
  1.2275 +@param anAlignment The alignment of the data within the target area. 
  1.2276 +
  1.2277 +@param aFill       The fill character used to pad the target area.
  1.2278 +
  1.2279 +@panic USER 23  if the resulting length of this descriptor is greater than
  1.2280 +                its maximum length or aWidth has a negative value other 
  1.2281 +                than KDefaultJustifyWidth.
  1.2282 +*/
  1.2283 +	{
  1.2284 +
  1.2285 +    AppendJustify(aDes.Ptr(),aLength,aWidth,anAlignment,aFill);
  1.2286 +    } 
  1.2287 +
  1.2288 +EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aWidth,TAlign anAlignment,TChar aFill)
  1.2289 +/**
  1.2290 +Appends a zero terminated string onto the end of this descriptor's data and 
  1.2291 +justifies it.
  1.2292 +
  1.2293 +The zero terminator is not copied.
  1.2294 +
  1.2295 +The target area is considered to be an area of specified width, immediately 
  1.2296 +following this descriptor's existing data. Source data is copied into, and 
  1.2297 +aligned within, this target area according to the specified alignment instruction.
  1.2298 +
  1.2299 +If the length of the target area is larger than the length of the source, 
  1.2300 +then spare space within the target area is padded with the fill character.
  1.2301 +
  1.2302 +@param aString     A pointer to a zero terminated string. The length of the
  1.2303 +                   data to be copied is the smaller of:
  1.2304 +                   the length of the string (excluding the zero terminator),
  1.2305 +                   and the width of the target area (only if this is not the
  1.2306 +                   explicit negative value KDefaultJustifyWidth). 
  1.2307 +
  1.2308 +@param aWidth      The width of the target area. If this has the specific
  1.2309 +                   negative value KDefaultJustifyWidth, then the width
  1.2310 +                   is re-set to the length of the  zero terminated string
  1.2311 +                   (excluding the zero terminator).
  1.2312 +               
  1.2313 +@param anAlignment The alignment of the data within the target area. 
  1.2314 +
  1.2315 +@param aFill       The fill character used to pad the target area.
  1.2316 +
  1.2317 +@panic USER 23  if the resulting length of this descriptor is greater than
  1.2318 +                its maximum length or aWidth has a negative value other 
  1.2319 +                than KDefaultJustifyWidth.
  1.2320 +*/
  1.2321 +	{
  1.2322 +
  1.2323 +    AppendJustify(aString,STRING_LENGTH(aString),aWidth,anAlignment,aFill);
  1.2324 +    } 
  1.2325 +
  1.2326 +EXPORT_C void TDes8::AppendJustify(const TUint8 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)
  1.2327 +/**
  1.2328 +Appends data onto the end of this descriptor's data and justifies it.
  1.2329 +
  1.2330 +The source of the appended data is a memory location.
  1.2331 +
  1.2332 +The target area is considered to be an area of specified width, immediately 
  1.2333 +following this descriptor's existing data. Source data is copied into, and 
  1.2334 +aligned within, this target area according to the specified alignment instruction.
  1.2335 +
  1.2336 +If the length of the target area is larger than the length of the source, 
  1.2337 +then spare space within the target area is padded with the fill character.
  1.2338 +
  1.2339 +@param aString     A pointer to a source memory location. 
  1.2340 +
  1.2341 +@param aLength     The length of data to be copied. If this is greater than the 
  1.2342 +                   width of the target area, then the length of data copied is
  1.2343 +                   limited to the width.
  1.2344 +                    
  1.2345 +@param aWidth      The width of the target area. If this has the specific
  1.2346 +                   negative value KDefaultJustifyWidth, then the width is
  1.2347 +                   re-set to the length of the data source.
  1.2348 +
  1.2349 +@param anAlignment The alignment of the data within the target area. 
  1.2350 +
  1.2351 +@param aFill       The fill character used to pad the target area.
  1.2352 +
  1.2353 +@panic USER 23  if the resulting length of this descriptor is greater than
  1.2354 +                its maximum length or aWidth has a negative value other 
  1.2355 +                than KDefaultJustifyWidth.
  1.2356 +                
  1.2357 +@panic USER 29  if aLength is negative.               
  1.2358 +*/
  1.2359 +	{
  1.2360 +
  1.2361 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
  1.2362 +	if (aWidth==KDefaultJustifyWidth)
  1.2363 +		aWidth=aLength;
  1.2364 +	if (aLength>aWidth)
  1.2365 +		aLength=aWidth;
  1.2366 +	TInt offset=Length();
  1.2367 +	AppendFill(aFill,aWidth);
  1.2368 +	TInt r=aWidth-aLength;
  1.2369 +	if (anAlignment==ECenter)
  1.2370 +		r>>=1;
  1.2371 +	else if (anAlignment==ELeft)
  1.2372 +		r=0;
  1.2373 +	memmove(WPtr()+offset+r,aString,aLength);
  1.2374 +	}
  1.2375 +#endif	// __KERNEL_MODE__
  1.2376 +
  1.2377 +EXPORT_C void TDes8::Num(TInt64 aVal)
  1.2378 +//
  1.2379 +// Convert a TInt64 to the descriptor.
  1.2380 +//
  1.2381 +/**
  1.2382 +Converts the 64-bit signed integer into a decimal character representation
  1.2383 +and copies the conversion into this descriptor, replacing any existing data.
  1.2384 +
  1.2385 +The length of this descriptor is set to reflect the new data.
  1.2386 +
  1.2387 +If the integer is negative, the character representation is prefixed by a 
  1.2388 +minus sign.
  1.2389 +
  1.2390 +@param aVal The 64-bit signed integer value.
  1.2391 +*/
  1.2392 +	{
  1.2393 +	Zero();
  1.2394 +	AppendNum(aVal);
  1.2395 +	}
  1.2396 +
  1.2397 +EXPORT_C void TDes8::Num(TUint64 aVal, TRadix aRadix)
  1.2398 +/**
  1.2399 +Converts the specified 64-bit unsigned integer into a character representation 
  1.2400 +based on the specified number system and copies the conversion into this descriptor, 
  1.2401 +replacing any existing data.
  1.2402 +
  1.2403 +The length of this descriptor is set to reflect the new data.
  1.2404 +
  1.2405 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2406 +lower case.
  1.2407 +
  1.2408 +@param aVal   The 64-bit integer value. This is treated as an unsigned value. 
  1.2409 +@param aRadix The number system representation for the 64-bit integer.
  1.2410 +*/
  1.2411 +	{
  1.2412 +	Zero();
  1.2413 +	AppendNum(aVal, aRadix);
  1.2414 +	}
  1.2415 +
  1.2416 +EXPORT_C void TDes8::NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
  1.2417 +/**
  1.2418 +Converts the specified unsigned integer into a fixed width character
  1.2419 +representation based on the specified number system and copies the conversion
  1.2420 +into this descriptor, replacing any existing data.
  1.2421 +
  1.2422 +The length of this descriptor is set to reflect the new data.
  1.2423 +
  1.2424 +The function generates the exact number of specified characters, either padding 
  1.2425 +to the left with character zeroes or discarding low order characters as necessary.
  1.2426 +
  1.2427 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2428 +lower case.
  1.2429 +
  1.2430 +This function is equivalent to using Format() with parameters which specify:
  1.2431 +
  1.2432 +1. a fixed length target field
  1.2433 +
  1.2434 +2. padding with zero characters, for example "%08x".
  1.2435 +
  1.2436 +When this is the case, always use NumFixedWidth() in preference 
  1.2437 +to Format() as it is more efficient.
  1.2438 +
  1.2439 +@param aVal   The unsigned integer value. 
  1.2440 +@param aRadix The number system representation for the unsigned integer. 
  1.2441 +@param aWidth The number of characters: to be used to contain the conversion, 
  1.2442 +              to be copied into this descriptor.
  1.2443 +              
  1.2444 +@see TDes8::Format()
  1.2445 +*/
  1.2446 +	{
  1.2447 +
  1.2448 +	Zero();
  1.2449 +	AppendNumFixedWidth(aVal,aRadix,aWidth);
  1.2450 +	}
  1.2451 +
  1.2452 +#ifndef __KERNEL_MODE__
  1.2453 +EXPORT_C void TDes8::NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
  1.2454 +/**
  1.2455 +Converts the specified unsigned integer into a fixed width character
  1.2456 +representation based on the specified number system and copies the conversion
  1.2457 +into this descriptor, replacing any existing data.
  1.2458 +
  1.2459 +The length of this descriptor is set to reflect the new data.
  1.2460 +
  1.2461 +The function generates the exact number of specified characters, either padding 
  1.2462 +to the left with character zeroes or discarding low order characters as
  1.2463 +necessary.
  1.2464 +
  1.2465 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2466 +upper case.
  1.2467 +
  1.2468 +This function is equivalent to using Format() with parameters which specify:
  1.2469 +
  1.2470 +1. a fixed length target field
  1.2471 +
  1.2472 +2. padding with zero characters, for example "%08x".
  1.2473 +
  1.2474 +When this is the case, always use NumFixedWidthUC() in 
  1.2475 +preference to Format() as it is more efficient.
  1.2476 +
  1.2477 +@param aVal   The unsigned integer value. 
  1.2478 +@param aRadix The number system representation for the unsigned integer. 
  1.2479 +@param aWidth The number of characters to be used to contain the conversion,
  1.2480 +              and to be copied into this descriptor.
  1.2481 +
  1.2482 +@see TDes8::Format()
  1.2483 +*/
  1.2484 +	{
  1.2485 +
  1.2486 +    Zero();
  1.2487 +    AppendNumFixedWidthUC(aVal,aRadix,aWidth);
  1.2488 +    }
  1.2489 +
  1.2490 +EXPORT_C void TDes8::NumUC(TUint64 aVal, TRadix aRadix)	//NOT __KERNEL_MODE__
  1.2491 +/**
  1.2492 +Converts the specified 64-bit unsigned integer into a character representation 
  1.2493 +based on the specified number system and copies the conversion into this descriptor, 
  1.2494 +replacing any existing data.
  1.2495 +
  1.2496 +The length of this descriptor is set to reflect the new data.
  1.2497 +
  1.2498 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2499 +upper case.
  1.2500 +
  1.2501 +@param aVal   The 64-bit integer value. This is treated as an unsigned value. 
  1.2502 +@param aRadix The number system representation for the 64-bit integer. If no 
  1.2503 +              explicit value is specified, then EDecimal is the default.
  1.2504 +*/
  1.2505 +	{
  1.2506 +	Zero();
  1.2507 +	AppendNumUC(aVal,aRadix);
  1.2508 +	}
  1.2509 +#endif	// __KERNEL_MODE__
  1.2510 +
  1.2511 +EXPORT_C void TDes8::AppendNum(TInt64 aVal)
  1.2512 +/**
  1.2513 +Converts the 64-bit signed integer into a decimal character representation 
  1.2514 +and appends the conversion onto the end of this descriptor's data.
  1.2515 +
  1.2516 +The length of this descriptor is incremented to reflect the new content.
  1.2517 +
  1.2518 +If the integer is negative, the character representation is prefixed by a 
  1.2519 +minus sign.
  1.2520 +
  1.2521 +@param aVal The 64-bit signed integer value.
  1.2522 +*/
  1.2523 +	{
  1.2524 +	if (aVal < 0)
  1.2525 +		{
  1.2526 +		Append('-');
  1.2527 +		aVal = -aVal;
  1.2528 +		}
  1.2529 +
  1.2530 +	AppendNum(aVal, EDecimal);
  1.2531 +	}
  1.2532 +
  1.2533 +#ifndef __DES_MACHINE_CODED__
  1.2534 +GLDEF_C TInt __DoConvertNum(TUint aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
  1.2535 +	{
  1.2536 +	__KERNEL_CHECK_RADIX(aRadix);
  1.2537 +	TUint radix = (TUint)aRadix;
  1.2538 +	TUint8* p = aDest;
  1.2539 +	TBool out16 = (aA>255);
  1.2540 +	aA &= 0xff;
  1.2541 +	do	{
  1.2542 +		TUint q = aVal/radix;
  1.2543 +		TUint c = aVal-q*radix;
  1.2544 +		(c>9) ? c+=(aA-10) : c+='0';
  1.2545 +		aVal = q;
  1.2546 +		if (out16)
  1.2547 +			*--p = 0;
  1.2548 +		*--p = (TUint8)c;
  1.2549 +		} while (aVal);
  1.2550 +	TInt l = aDest - p;
  1.2551 +	aDest = p;
  1.2552 +	return l;
  1.2553 +	}
  1.2554 +
  1.2555 +GLDEF_C TInt __DoConvertNum(TUint64 aVal, TRadix aRadix, TUint aA, TUint8*& aDest)
  1.2556 +	{
  1.2557 +	__KERNEL_CHECK_RADIX(aRadix);
  1.2558 +	TUint radix = (TUint)aRadix;
  1.2559 +	TUint8* p = aDest;
  1.2560 +	TBool out16 = (aA>255);
  1.2561 +	TUint8 a = static_cast<TUint8>(aA);
  1.2562 +	while (aVal >= UI64LIT(0x100000000))
  1.2563 +		{
  1.2564 +		TUint8 c = static_cast<TUint8>(aVal % radix);
  1.2565 +		aVal /= radix;
  1.2566 +		(c > 9) ? c = static_cast<TUint8>(c + a - 10) : c = static_cast<TUint8>(c + '0');
  1.2567 +		if (out16)
  1.2568 +			*--p = 0;
  1.2569 +		*--p = c;
  1.2570 +		}
  1.2571 +	TInt l = aDest - p;
  1.2572 +	aDest = p;
  1.2573 +	return l + __DoConvertNum((TUint)aVal, aRadix, aA, aDest);
  1.2574 +	}
  1.2575 +#endif
  1.2576 +
  1.2577 +void TDes8::DoPadAppendNum(TInt l, TInt aW, const TUint8* p)
  1.2578 +	{
  1.2579 +	if (aW<=0)
  1.2580 +		{
  1.2581 +		Append(p, l);
  1.2582 +		return;
  1.2583 +		}
  1.2584 +	TInt l0 = Length();
  1.2585 +	SetLength(l0 + aW);
  1.2586 +	TUint8* d = WPtr() + l0;
  1.2587 +	for (; aW>l; --aW) *d++ = (TUint8)'0';
  1.2588 +	memcpy(d, p, aW);
  1.2589 +	}
  1.2590 +
  1.2591 +void TDes8::DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW)
  1.2592 +//
  1.2593 +// Convert a TUint64 into the descriptor.
  1.2594 +//
  1.2595 +	{
  1.2596 +	TUint8 buf[APPEND_BUF_SIZE_64];
  1.2597 +	TUint8* p = buf + APPEND_BUF_SIZE_64;
  1.2598 +	TInt l = __DoConvertNum(aVal, aRadix, aA, p);
  1.2599 +	// coverity[overrun-local]
  1.2600 +	DoPadAppendNum(l, aW, p);
  1.2601 +	}
  1.2602 +
  1.2603 +EXPORT_C void TDes8::AppendNum(TUint64 aVal, TRadix aRadix)
  1.2604 +/**
  1.2605 +Converts the specified 64-bit unsigned integer into a character representation 
  1.2606 +based on the specified number system and appends the conversion onto the end 
  1.2607 +of this descriptor's data. The length of this descriptor is incremented to 
  1.2608 +reflect the new content
  1.2609 +
  1.2610 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2611 +lower case.
  1.2612 +
  1.2613 +@param aVal   The 64-bit integer value. This is treated as an unsigned value. 
  1.2614 +@param aRadix The number system representation for the 64-bit integer.
  1.2615 +*/
  1.2616 +	{
  1.2617 +	DoAppendNum(aVal, aRadix, 'a', 0);
  1.2618 +	}
  1.2619 +
  1.2620 +EXPORT_C void TDes8::AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth)
  1.2621 +/**
  1.2622 +Converts the specified unsigned integer into a fixed width character
  1.2623 +representation based on the specified number system and appends the conversion
  1.2624 +onto the end of this descriptor's data.
  1.2625 +
  1.2626 +The length of this descriptor is incremented to reflect the new content.
  1.2627 +
  1.2628 +The function generates the exact number of specified characters, either padding 
  1.2629 +to the left with character zeroes or discarding low order characters as
  1.2630 +necessary.
  1.2631 +
  1.2632 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2633 +lower case.
  1.2634 +
  1.2635 +@param aVal   The unsigned integer value. 
  1.2636 +@param aRadix The number system representation for the unsigned integer. 
  1.2637 +@param aWidth The number of characters to be used to contain the conversion,
  1.2638 +              and to be appended to this descriptor.
  1.2639 +*/
  1.2640 +	{
  1.2641 +	DoAppendNum(aVal, aRadix, 'a', aWidth);
  1.2642 +	}
  1.2643 +
  1.2644 +#if (!defined(__DES8_MACHINE_CODED__) && !defined(__KERNEL_MODE__))
  1.2645 +EXPORT_C TPtr8 TDes8::LeftTPtr(TInt aLength) const
  1.2646 +/**
  1.2647 +Extracts the leftmost part of the data. 
  1.2648 +
  1.2649 +The function does not cut or remove any data but constructs a modifiable 
  1.2650 +pointer descriptor to represent the leftmost part of the data.
  1.2651 +
  1.2652 +@param aLength The length of the data to be extracted. If this value
  1.2653 +               is greater than the length of the descriptor, the function
  1.2654 +               extracts the whole of the descriptor.
  1.2655 +
  1.2656 +@return The 8-bit modifiable pointer descriptor representing the leftmost 
  1.2657 +        part of the data.
  1.2658 +
  1.2659 +@panic USER 22  if aLength is negative. 
  1.2660 +*/
  1.2661 +	{
  1.2662 +
  1.2663 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
  1.2664 +	TInt len=Min(aLength,Length());
  1.2665 +	return(TPtr8((TUint8*)Ptr(),len,len));
  1.2666 +	}
  1.2667 +
  1.2668 +EXPORT_C TPtr8 TDes8::RightTPtr(TInt aLength) const
  1.2669 +/**
  1.2670 +Extracts the rightmost part of the data.
  1.2671 +
  1.2672 +The function does not cut or remove any data but constructs a modifiable 
  1.2673 +pointer descriptor to represent the rightmost part of the data.
  1.2674 +
  1.2675 +@param aLength The length of data to be extracted. If this value
  1.2676 +               is greater than the length of the descriptor, the function 
  1.2677 +               extracts the whole of the descriptor. 
  1.2678 +               
  1.2679 +@return The 8 bit modifiable pointer descriptor representing the rightmost 
  1.2680 +        part of the data.
  1.2681 +
  1.2682 +@panic USER 22  if aLength is negative. 
  1.2683 +*/
  1.2684 +	{
  1.2685 +
  1.2686 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8PosOutOfRange));
  1.2687 +	TInt len=Length();
  1.2688 +	if (aLength>len)
  1.2689 +		aLength=len;
  1.2690 +	return(TPtr8((TUint8*)Ptr()+len-aLength,aLength,aLength));
  1.2691 +	}
  1.2692 +
  1.2693 +EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos) const
  1.2694 +/**
  1.2695 +Extracts a portion of the data.
  1.2696 +
  1.2697 +The function does not cut or remove any data but constructs a modifiable 
  1.2698 +pointer descriptor to represent the defined portion.
  1.2699 +
  1.2700 +The portion is identified by its starting position and by the length of the 
  1.2701 +remainder of the data starting from the specified position.
  1.2702 +
  1.2703 +@param aPos The starting position of the data to be extracted. This is an 
  1.2704 +            offset value; a zero value refers to the leftmost data position. 
  1.2705 +            
  1.2706 +@return The 8-bit modifiable pointer descriptor representing the specified 
  1.2707 +        portion of the data.
  1.2708 +        
  1.2709 +@panic USER 22  if aPos is negative or aPos is greater than the
  1.2710 +                length of the descriptor.       
  1.2711 +*/
  1.2712 +	{
  1.2713 +
  1.2714 +	TInt len=Length();
  1.2715 +	__ASSERT_ALWAYS(aPos>=0 && aPos<=len,Panic(ETDes8PosOutOfRange));
  1.2716 +	return(TPtr8((TUint8*)Ptr()+aPos,len-aPos,len-aPos));
  1.2717 +	}
  1.2718 +
  1.2719 +EXPORT_C TPtr8 TDes8::MidTPtr(TInt aPos,TInt aLength) const
  1.2720 +/**
  1.2721 +Extracts a portion of the data.
  1.2722 +
  1.2723 +The function does not cut or remove any data but constructs a modifiable 
  1.2724 +pointer descriptor to represent the defined portion.
  1.2725 +
  1.2726 +The portion is identified by its starting position and by its length.
  1.2727 +
  1.2728 +@param aPos    The starting position of the data to be extracted. This is an 
  1.2729 +               offset value; a zero value refers to the leftmost data position. 
  1.2730 +@param aLength The length of data to be extracted.
  1.2731 +
  1.2732 +@return The 8 bit modifiable pointer descriptor representing the specified 
  1.2733 +        portion of the data.
  1.2734 +
  1.2735 +@panic USER 22  if aPos is negative or aPos plus aLength is greater than the
  1.2736 +                length of the descriptor.
  1.2737 +*/
  1.2738 +	{
  1.2739 +
  1.2740 +	__ASSERT_ALWAYS(aPos>=0 && (aPos+aLength)<=Length(),Panic(ETDes8PosOutOfRange));
  1.2741 +	return(TPtr8((TUint8*)Ptr()+aPos,aLength,aLength));
  1.2742 +	}
  1.2743 +#endif
  1.2744 +
  1.2745 +#ifndef __KERNEL_MODE__
  1.2746 +EXPORT_C void TDes8::AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth)
  1.2747 +/**
  1.2748 +Converts the specified unsigned integer into a fixed width character
  1.2749 +representation based on the specified number system and appends the conversion
  1.2750 +onto the end of this descriptor's data.
  1.2751 +
  1.2752 +The length of this descriptor is incremented to reflect the new content.
  1.2753 +
  1.2754 +The function generates the exact number of specified characters, either
  1.2755 +padding to the left with character zeroes or discarding low order characters
  1.2756 +as necessary.
  1.2757 +
  1.2758 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2759 +upper case.
  1.2760 +
  1.2761 +@param aVal   The unsigned integer value. 
  1.2762 +@param aRadix The number system representation for the unsigned integer. 
  1.2763 +@param aWidth The number of characters to be used to contain the conversion,
  1.2764 +              and to be appended to this descriptor.
  1.2765 +*/
  1.2766 +	{
  1.2767 +	DoAppendNum(aVal, aRadix, 'A', aWidth);
  1.2768 +	}
  1.2769 +
  1.2770 +EXPORT_C void TDes8::AppendNumUC(TUint64 aVal, TRadix aRadix)
  1.2771 +/** Converts the specified 64-bit unsigned integer into a character
  1.2772 +representation based on the specified number system and appends the conversion
  1.2773 +onto the end of this descriptor's data.
  1.2774 +
  1.2775 +The length of this descriptor is incremented to reflect the new content.
  1.2776 +
  1.2777 +When a hexadecimal conversion is specified, hexadecimal characters are in 
  1.2778 +upper case.
  1.2779 +
  1.2780 +@param aVal   The 64-bit integer value. This is treated as an unsigned value. 
  1.2781 +@param aRadix The number system representation for the 64-bit integer. If no 
  1.2782 +              explicit value is specified, then EDecimal is the default.
  1.2783 +*/
  1.2784 +	{
  1.2785 +	DoAppendNum(aVal, aRadix, 'A', 0);
  1.2786 +	}
  1.2787 +
  1.2788 +EXPORT_C void TDes8::Format(TRefByValue<const TDesC8> aFmt,...)
  1.2789 +/**
  1.2790 +Formats and copies text into this descriptor, replacing any existing data.
  1.2791 +
  1.2792 +The length of this descriptor is set to reflect the new data.
  1.2793 +
  1.2794 +The function takes a format string and a variable number of arguments.
  1.2795 +The format string contains literal text embedded with directives for converting
  1.2796 +the trailing list of arguments into text.
  1.2797 +
  1.2798 +The embedded directives are character sequences prefixed with the '%' character.
  1.2799 +The literal text is simply copied into this descriptor unaltered while
  1.2800 +the '%' directives are used to convert successive arguments from the
  1.2801 +trailing list.
  1.2802 +
  1.2803 +The resulting stream of literal text and converted arguments is copied into
  1.2804 +this descriptor.
  1.2805 +
  1.2806 +The syntax of the embedded directives follows one of four general patterns.
  1.2807 +
  1.2808 +Note that formatting of single numerical values can be achieved more
  1.2809 +conveniently using the Num() and NumUC() member functions of this class.
  1.2810 +
  1.2811 +The full description of the syntax of a format string cannot be	included here.
  1.2812 +For full details, navigate to the Symbian OS guide, and follow the hierarchy of links:
  1.2813 +
  1.2814 +@code
  1.2815 +Symbian OS Guide
  1.2816 +	Base
  1.2817 +		Using  User Library (E32)
  1.2818 +			Buffers and Strings
  1.2819 +				Using Descriptors
  1.2820 +					How to Use Descriptors
  1.2821 +						Format string syntax
  1.2822 +@endcode
  1.2823 +
  1.2824 +@param aFmt The descriptor containing the format string.
  1.2825 +            The TRefByValue class provides a constructor which takes a
  1.2826 +            TDesC8 type.
  1.2827 +
  1.2828 +@param ...  A variable number of arguments to be converted to text as
  1.2829 +            dictated by the format string. 
  1.2830 +
  1.2831 +@panic USER 23  if the  resulting length of text in this descriptor exceeds
  1.2832 +                the descriptor's maximum length.
  1.2833 +@panic USER 24  if the format string has incorrect syntax.
  1.2834 +
  1.2835 +@see TDes8::Num()
  1.2836 +@see TDes8::NumUC()
  1.2837 +*/
  1.2838 +	{
  1.2839 +
  1.2840 +    VA_LIST list;
  1.2841 +    VA_START(list,aFmt);
  1.2842 +	// coverity[uninit_use_in_call]
  1.2843 +    FormatList(aFmt,list);
  1.2844 +    }
  1.2845 +
  1.2846 +EXPORT_C void TDes8::FormatList(const TDesC8 &aFmt,VA_LIST aList)
  1.2847 +/**
  1.2848 +Formats and copies text into this descriptor, replacing any existing data.
  1.2849 +
  1.2850 +The length of this descriptor is set to reflect the new data.
  1.2851 +
  1.2852 +The behaviour of this function is the same as Format(). In practice, it is 
  1.2853 +better and easier to use Format(), passing a variable number of arguments 
  1.2854 +as required by the format string.
  1.2855 +
  1.2856 +@param aFmt  The descriptor containing the format string.
  1.2857 +@param aList A pointer to an argument list.
  1.2858 +
  1.2859 +@see TDes8::Format()
  1.2860 +@see VA_LIST
  1.2861 +*/
  1.2862 +	{
  1.2863 +
  1.2864 +	Zero();
  1.2865 +	AppendFormatList(aFmt,aList);
  1.2866 +	}
  1.2867 +
  1.2868 +EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,TDes8Overflow *aOverflowHandler,...)
  1.2869 +/**
  1.2870 +Formats and appends text onto the end of this descriptor's data.
  1.2871 +
  1.2872 +The length of this descriptor is incremented to reflect the new content.
  1.2873 +
  1.2874 +The function takes a format string and a variable number of arguments.
  1.2875 +The format string contains literal text, embedded with directives,
  1.2876 +for converting the trailing list of arguments into text.
  1.2877 +
  1.2878 +The embedded directives are character sequences prefixed with the '%' character.
  1.2879 +The literal text is simply copied into this descriptor unaltered while
  1.2880 +the '%' directives are used to convert successive arguments from the
  1.2881 +trailing list. See the description of the Format() function.
  1.2882 +
  1.2883 +Literal text is appended on a character by character basis.
  1.2884 +If it results in the length of this descriptor exceeding its maximum length,
  1.2885 +then the function:
  1.2886 +
  1.2887 +1. calls the Overflow() member function of the overflow handler, if an overflow
  1.2888 +   handler is supplied
  1.2889 +2  raises a USER 23 panic, if no overflow handler is supplied.
  1.2890 +
  1.2891 +As much literal text as possible will have been copied into this descriptor
  1.2892 +and this descriptor will have reached its maximum length.
  1.2893 +
  1.2894 +Text converted from a trailing argument is appended as a complete string.
  1.2895 +If an attempt to append this string fails because the resulting length
  1.2896 +of this descriptor would exceed its maximum length, then the function:
  1.2897 +
  1.2898 +1. calls the Overflow() member function of the overflow handler, if an overflow
  1.2899 +   handler is supplied
  1.2900 +   
  1.2901 +2  raises a USER 23 panic, if no overflow handler is supplied.
  1.2902 +  
  1.2903 +None of the generated text is appended and length of this descriptor
  1.2904 +may be less than the maximum.
  1.2905 +
  1.2906 +@param aFmt             The 8-bit non-modifiable descriptor containing the
  1.2907 +                        format string. The TRefByValue class provides a
  1.2908 +                        constructor which takes a TDesC8 type. 
  1.2909 +
  1.2910 +@param aOverflowHandler A pointer to the overflow handler. 
  1.2911 +
  1.2912 +@param ...              A variable number of arguments to be converted to text
  1.2913 +                        as dictated by the format string. 
  1.2914 +
  1.2915 +@panic USER 23  if the length of the descriptor exceeds its maximum length and
  1.2916 +                no overflow handler has been supplied.
  1.2917 +@panic USER 24  if the format string has incorrect syntax.
  1.2918 +
  1.2919 +@see TDes8::Format()
  1.2920 +@see TDes8Overflow::Overflow()
  1.2921 +*/
  1.2922 +	{
  1.2923 +
  1.2924 +	VA_LIST list;
  1.2925 +	VA_START(list, aOverflowHandler);
  1.2926 +	// coverity[uninit_use_in_call]
  1.2927 +	AppendFormatList(aFmt,list,aOverflowHandler);
  1.2928 +	}
  1.2929 +
  1.2930 +EXPORT_C void TDes8::AppendFormat(TRefByValue<const TDesC8> aFmt,...)
  1.2931 +/**
  1.2932 +Formats and appends text onto the end of this descriptor's data.
  1.2933 +
  1.2934 +The length of this descriptor is incremented to reflect the new content.
  1.2935 +
  1.2936 +The function takes a format string and a variable number of arguments.
  1.2937 +The format string contains literal text, embedded with directives,
  1.2938 +for converting the trailing list of arguments into text.
  1.2939 +
  1.2940 +The embedded directives are character sequences prefixed with the '%' character.
  1.2941 +The literal text is simply copied into this descriptor unaltered while
  1.2942 +the '%' directives are used to convert successive arguments from the
  1.2943 +trailing list. See the description of the Format() function.
  1.2944 +
  1.2945 +Literal text is appended on a character by character basis.
  1.2946 +
  1.2947 +Text converted from a trailing argument is appended as a complete string.
  1.2948 +
  1.2949 +@param aFmt The 8-bit non-modifiable descriptor containing the
  1.2950 +            format string. The TRefByValue class provides a
  1.2951 +            constructor which takes a TDesC8 type. 
  1.2952 +
  1.2953 +@param ...  A variable number of arguments to be converted to text
  1.2954 +            as dictated by the format string. 
  1.2955 +
  1.2956 +
  1.2957 +@panic USER 23  if the  resulting length of text in this descriptor exceeds
  1.2958 +                the descriptor's maximum length.
  1.2959 +@panic USER 24  if the format string has incorrect syntax.
  1.2960 +
  1.2961 +@see TDes8::Format()
  1.2962 +*/
  1.2963 +	{
  1.2964 +
  1.2965 +    VA_LIST list;
  1.2966 +    VA_START(list,aFmt);
  1.2967 +    AppendFormatList(aFmt,list);
  1.2968 +    }
  1.2969 +#endif	// __KERNEL_MODE__
  1.2970 +
  1.2971 +#if !defined(__DES8_MACHINE_CODED__) | defined(__EABI_CTORS__)
  1.2972 +EXPORT_C TPtrC8::TPtrC8()
  1.2973 +	: TDesC8(EPtrC,0),iPtr(0)
  1.2974 +/**
  1.2975 +Default constructor.
  1.2976 +
  1.2977 +Constructs an empty 8-bit non-modifiable pointer descriptor.
  1.2978 +
  1.2979 +It represents no data and its length is zero.
  1.2980 +
  1.2981 +The non-modifiable pointer descriptor can, subsequently, be set to represent 
  1.2982 +data.
  1.2983 +
  1.2984 +@see TPtrC8::Set()
  1.2985 +*/
  1.2986 +	{}
  1.2987 +
  1.2988 +EXPORT_C TPtrC8::TPtrC8(const TDesC8 &aDes)
  1.2989 +	: TDesC8(EPtrC,aDes.Length()),iPtr(aDes.Ptr())
  1.2990 +/**
  1.2991 +Constructs the 8-bit non-modifiable pointer descriptor from any existing
  1.2992 +descriptor.
  1.2993 +
  1.2994 +It is set to point to the same data and is given the same length as the source 
  1.2995 +descriptor.
  1.2996 +
  1.2997 +@param aDes A reference to an 8bit non-modifiable descriptor.
  1.2998 +*/
  1.2999 +	{}
  1.3000 +
  1.3001 +EXPORT_C TPtrC8::TPtrC8(const TUint8 *aString)
  1.3002 +	: TDesC8(EPtrC,STRING_LENGTH(aString)),iPtr(aString)
  1.3003 +/**
  1.3004 +Constructs the 8-bit non-modifiable pointer descriptor to point to a zero
  1.3005 +terminated string, whether in RAM or ROM.
  1.3006 +
  1.3007 +The length of the descriptor is set to the length of the zero terminated
  1.3008 +string, excluding the zero terminator.
  1.3009 +
  1.3010 +@param aString A pointer to a zero terminated string.
  1.3011 +*/
  1.3012 +	{}
  1.3013 +
  1.3014 +EXPORT_C TPtrC8::TPtrC8(const TUint8 *aBuf,TInt aLength)
  1.3015 +	: TDesC8(EPtrC,aLength),iPtr(aBuf)
  1.3016 +/**
  1.3017 +Constructs the 8-bit non-modifiable pointer descriptor to point to the
  1.3018 +specified location in memory, whether in RAM or ROM.
  1.3019 +
  1.3020 +The length of the descriptor is set to the specified length.
  1.3021 +
  1.3022 +@param aBuf    A pointer to the location that the descriptor is to represent.
  1.3023 +@param aLength The length of the descriptor. This value must be non-negative.
  1.3024 +
  1.3025 +@panic USER 29  if aLength is negative.
  1.3026 +*/
  1.3027 +	{
  1.3028 +	__ASSERT_ALWAYS(aLength>=0,Panic(ETDes8LengthNegative));
  1.3029 +	}
  1.3030 +
  1.3031 +EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aMaxLength)
  1.3032 +	: TDes8(EPtr,0,aMaxLength),iPtr(aBuf)
  1.3033 +/**
  1.3034 +Constructs the 8-bit modifiable pointer descriptor to point to the specified 
  1.3035 +location in memory, whether in RAM or ROM.
  1.3036 +
  1.3037 +The length of the descriptor is set to zero and its maximum length is set
  1.3038 +to the specified value.
  1.3039 +
  1.3040 +@param aBuf       A pointer to the location that the descriptor is to
  1.3041 +                  represent.
  1.3042 +                  
  1.3043 +@param aMaxLength The maximum length of the descriptor.
  1.3044 +
  1.3045 +@panic USER 30  if aMaxLength is negative.
  1.3046 +*/
  1.3047 +	{
  1.3048 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3049 +	}
  1.3050 +
  1.3051 +EXPORT_C TPtr8::TPtr8(TUint8 *aBuf,TInt aLength,TInt aMaxLength)
  1.3052 +	: TDes8(EPtr,aLength,aMaxLength),iPtr(aBuf)
  1.3053 +/**
  1.3054 +Constructs the 8-bit modifiable pointer descriptor to point to the specified 
  1.3055 +location in memory, whether in RAM or ROM.
  1.3056 +
  1.3057 +The length of the descriptor and its maximum length are set to the specified
  1.3058 +values.
  1.3059 +
  1.3060 +@param aBuf       A pointer to the location that the descriptor is
  1.3061 +                  to represent.
  1.3062 +@param aLength    The length of the descriptor.
  1.3063 +@param aMaxLength The maximum length of the descriptor.
  1.3064 +
  1.3065 +@panic USER 20  if aLength is negative, or is greater than the descriptor's 
  1.3066 +                maximum length,
  1.3067 +@panic USER 30  if aMaxLength is negative.
  1.3068 +*/
  1.3069 +	{
  1.3070 +	__ASSERT_ALWAYS(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3071 +	__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
  1.3072 +	}
  1.3073 +
  1.3074 +EXPORT_C TPtr8::TPtr8(TBufCBase8 &aLcb,TInt aMaxLength)
  1.3075 +	: TDes8(EBufCPtr,aLcb.Length(),aMaxLength),iPtr((TUint8*)&aLcb)
  1.3076 +	{
  1.3077 +	__ASSERT_DEBUG(aLcb.Length()<=aMaxLength,Panic(ETDes8LengthOutOfRange));
  1.3078 +	}
  1.3079 +
  1.3080 +EXPORT_C TBufBase8::TBufBase8(TInt aMaxLength)
  1.3081 +	:TDes8(EBuf,0,aMaxLength)
  1.3082 +	{
  1.3083 +	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3084 +	}
  1.3085 +
  1.3086 +EXPORT_C TBufBase8::TBufBase8(TInt aLength,TInt aMaxLength)
  1.3087 +	:TDes8(EBuf,aLength,aMaxLength)
  1.3088 +	{
  1.3089 +	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3090 +	__ASSERT_ALWAYS(TUint(aLength)<=TUint(aMaxLength),Panic(ETDes8LengthOutOfRange));
  1.3091 +	}
  1.3092 +
  1.3093 +EXPORT_C TBufBase8::TBufBase8(const TUint8* aString,TInt aMaxLength)
  1.3094 +	:TDes8(EBuf,0,aMaxLength)
  1.3095 +	{
  1.3096 +	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3097 +	Copy(aString);
  1.3098 +	}
  1.3099 +
  1.3100 +EXPORT_C TBufBase8::TBufBase8(const TDesC8& aDes,TInt aMaxLength)
  1.3101 +	:TDes8(EBuf,0,aMaxLength)
  1.3102 +	{
  1.3103 +	__ASSERT_DEBUG(aMaxLength>=0,Panic(ETDes8MaxLengthNegative));
  1.3104 +	Copy(aDes);
  1.3105 +	}
  1.3106 +
  1.3107 +#endif
  1.3108 +
  1.3109 +// Truncate literal string to fit into descriptor
  1.3110 +EXPORT_C void TDes8IgnoreOverflow::Overflow(TDes8& /*aDes*/)
  1.3111 +	{}
  1.3112 +
  1.3113 +#ifndef __KERNEL_MODE__
  1.3114 +EXPORT_C void TDesC8::__DbgTestInvariant() const
  1.3115 +//
  1.3116 +// Test that the class obeys its invariant.
  1.3117 +//
  1.3118 +    {
  1.3119 +
  1.3120 +#if defined(_DEBUG)
  1.3121 +	switch (Type())
  1.3122 +		{
  1.3123 +	case EBufC:
  1.3124 +	case EPtrC:
  1.3125 +	case EPtr:
  1.3126 +	case EBuf:
  1.3127 +	case EBufCPtr:
  1.3128 +		break;
  1.3129 +	default:
  1.3130 +		User::Invariant();
  1.3131 +		}
  1.3132 +#endif
  1.3133 +    }
  1.3134 +
  1.3135 +EXPORT_C void TPtrC8::__DbgTestInvariant() const
  1.3136 +//
  1.3137 +// Test that the class obeys its invariant.
  1.3138 +//
  1.3139 +    {
  1.3140 +
  1.3141 +#if defined(_DEBUG)
  1.3142 +	TDesC8::__DbgTestInvariant(); // Test base class
  1.3143 +	if (Type()!=EPtrC)
  1.3144 +		User::Invariant();
  1.3145 +#endif
  1.3146 +	}
  1.3147 +
  1.3148 +EXPORT_C void TDes8::__DbgTestInvariant() const
  1.3149 +//
  1.3150 +// Test that the class obeys its invariant.
  1.3151 +//
  1.3152 +    {
  1.3153 +
  1.3154 +#if defined(_DEBUG)
  1.3155 +	TDesC8::__DbgTestInvariant(); // Test base class
  1.3156 +	if (Length()>MaxLength() || !(Type()==EPtr || Type()==EBufCPtr || Type()==EBuf))
  1.3157 +		User::Invariant();
  1.3158 +#endif
  1.3159 +	}
  1.3160 +
  1.3161 +EXPORT_C void HBufC8::__DbgTestInvariant() const
  1.3162 +//
  1.3163 +// Test that the class obeys its invariant.
  1.3164 +//
  1.3165 +    {
  1.3166 +
  1.3167 +#if defined(_DEBUG)
  1.3168 +	TDesC8::__DbgTestInvariant(); // Test base class
  1.3169 +	if (Length()>(TInt)(User::AllocLen(this)-sizeof(TDesC8)) || Type()!=EBufC)
  1.3170 +		User::Invariant();
  1.3171 +#endif
  1.3172 +	}
  1.3173 +
  1.3174 +EXPORT_C void TPtr8::__DbgTestInvariant() const
  1.3175 +//
  1.3176 +// Test that the class obeys its invariant.
  1.3177 +//
  1.3178 +    {
  1.3179 +
  1.3180 +#if defined(_DEBUG)
  1.3181 +	TDes8::__DbgTestInvariant(); // Test base class
  1.3182 +	if (!(Type()==EPtr || Type()==EBufCPtr))
  1.3183 +		User::Invariant();
  1.3184 +#endif
  1.3185 +	}
  1.3186 +
  1.3187 +/** Expand all characters from 8 to 16 bits
  1.3188 +
  1.3189 +@return 16-bit pointer descriptor to transformed text
  1.3190 +
  1.3191 +The length of descriptor increased by 2 (length *= 2).
  1.3192 +
  1.3193 +@panic USER 187 if either the descriptor length or the maximum length is odd
  1.3194 +or data pointer is not aligned by 2-bytes boundary
  1.3195 +*/
  1.3196 +EXPORT_C TPtr16 TDes8::Expand()
  1.3197 +	{
  1.3198 +	TInt l = Length();
  1.3199 +	TInt ml = MaxLength();
  1.3200 +	const TText8* s0 = Ptr();
  1.3201 +	const TText8* s = s0 + l;
  1.3202 +	__ASSERT_ALWAYS( !((ml|(TInt)s0)&1), Panic(EDes8ExpandOdd) );
  1.3203 +	SetLength(l<<1);
  1.3204 +	TText16* d = ((TText16*)s0) + l;
  1.3205 +	while (s > s0)
  1.3206 +		*--d = *--s;
  1.3207 +	return TPtr16(d, l, ml>>1);
  1.3208 +	}
  1.3209 +
  1.3210 +
  1.3211 +/** Collapse all characters from 16 to 8 bits
  1.3212 +
  1.3213 +The length of descriptor truncated by 2 (length /= 2).
  1.3214 +
  1.3215 +@panic USER 188  if either the descriptor length or the maximum length is odd
  1.3216 +or data pointer is not aligned by 2-bytes boundary.
  1.3217 +*/
  1.3218 +
  1.3219 +EXPORT_C void TDes8::Collapse()
  1.3220 +	{
  1.3221 +	TInt l = Length();
  1.3222 +	TInt ml = MaxLength();
  1.3223 +	TText8* d = (TText8*)Ptr();
  1.3224 +	__ASSERT_ALWAYS( !((l|ml|(TInt)d)&1), Panic(EDes8CollapseOdd) );
  1.3225 +	const TText16* s = (const TText16*)d;
  1.3226 +	const TText16* sE = s + (l>>1);
  1.3227 +	while (s < sE)
  1.3228 +		*d++ = (TText8)*s++;
  1.3229 +	SetLength(l>>1);
  1.3230 +	}
  1.3231 +#else // __KERNEL_MODE__
  1.3232 +
  1.3233 +EXPORT_C TInt TDesC8::CompareF(const TDesC8 &aDes) const
  1.3234 +/**
  1.3235 +Compares this descriptor's folded data with the specified descriptor's folded 
  1.3236 +data. 
  1.3237 +
  1.3238 +Note that folding is locale-independent behaviour. It is also important to 
  1.3239 +note that there can be no guarantee that folding is in any way culturally 
  1.3240 +appropriate, and should not be used for comparing strings in natural language; 
  1.3241 +use CompareC() for this.
  1.3242 +
  1.3243 +@param aDes The 8-bit non modifable descriptor whose data is to be compared 
  1.3244 +            with this descriptor's data. 
  1.3245 +            
  1.3246 +@return Positive, if this descriptor is greater than the specified descriptor. 
  1.3247 +        Negative, if this descriptor is less than the specified descriptor.
  1.3248 +        Zero, if both descriptors have the same length and the their contents
  1.3249 +        are the same.
  1.3250 +        
  1.3251 +@see TDesC8::Compare()
  1.3252 +*/
  1.3253 +	{
  1.3254 +
  1.3255 +	TInt ll = Length();
  1.3256 +	TInt rl = aDes.Length();
  1.3257 +	TInt r = memicmp(Ptr(), aDes.Ptr(), Min(ll, rl));
  1.3258 +	if (r == 0)
  1.3259 +		r = ll - rl;
  1.3260 +	return r;
  1.3261 +	}
  1.3262 +
  1.3263 +#endif	// __KERNEL_MODE__
  1.3264 +
  1.3265 +#ifndef __KERNEL_MODE__
  1.3266 +
  1.3267 +/**
  1.3268 +Default constructor.
  1.3269 +
  1.3270 +Constructs a zero-length 8-bit resizable buffer descriptor.
  1.3271 +
  1.3272 +Note that the object owns no allocated memory.
  1.3273 +*/
  1.3274 +EXPORT_C RBuf8::RBuf8()
  1.3275 +	:TDes8(EPtr,0,0),iEPtrType(NULL)
  1.3276 +	{
  1.3277 +	// Zero-length RBuf8 is of type EPtr with NULL pointer.
  1.3278 +	}
  1.3279 +
  1.3280 +
  1.3281 +
  1.3282 +
  1.3283 +/**
  1.3284 +Constructor.
  1.3285 +			
  1.3286 +Constructs an 8-bit resizable buffer descriptor, transferring ownership of the
  1.3287 +specified heap descriptor to this object.
  1.3288 +
  1.3289 +@param aHBuf The heap descriptor to be transferred to this object. This pointer
  1.3290 +             can be NULL, which means that a zero length 8-bit resizable
  1.3291 +             buffer	descriptor is constructed, and the object will not own any
  1.3292 +             allocated memory.
  1.3293 +*/
  1.3294 +EXPORT_C RBuf8::RBuf8(HBufC8* aHBuf)
  1.3295 +	{
  1.3296 +	if(aHBuf)
  1.3297 +		//Create EBufCPtr type descriptor that points to aHBuf
  1.3298 +		new(this) TPtr8(aHBuf->Des());
  1.3299 +	else
  1.3300 +		//Create zero-length RBuf8. It is EPtr type of descriptor that points to NULL.
  1.3301 +		new(this) RBuf8();
  1.3302 +	}
  1.3303 +
  1.3304 +
  1.3305 +
  1.3306 +
  1.3307 +/**
  1.3308 +Protected constructor.
  1.3309 +*/
  1.3310 +EXPORT_C RBuf8::RBuf8(TInt aType,TInt aLength,TInt aMaxLength)
  1.3311 +	:TDes8(aType,aLength,aMaxLength)
  1.3312 +	{
  1.3313 +	}
  1.3314 +
  1.3315 +
  1.3316 +
  1.3317 +
  1.3318 +/**
  1.3319 +Transfers ownership of the specified 8-bit resizable buffer descriptor's 
  1.3320 +buffer to this object.
  1.3321 +
  1.3322 +Note that the function assumes that this descriptor does not already own any
  1.3323 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3324 +allocated memory.  If this descriptor does already own allocated memory,
  1.3325 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3326 +invoked.
  1.3327 +
  1.3328 +@param aRBuf The source 8-bit resizable buffer. The ownership of this
  1.3329 +             object's buffer is to be transferred.
  1.3330 +
  1.3331 +@see RBuf8::Close()
  1.3332 +*/
  1.3333 +EXPORT_C void RBuf8::Assign(const RBuf8& aRBuf)
  1.3334 +	{
  1.3335 +	Mem::Copy(this, &aRBuf, sizeof(RBuf8)); 
  1.3336 +	__TEST_INVARIANT;
  1.3337 +	}
  1.3338 +
  1.3339 +
  1.3340 +
  1.3341 +
  1.3342 +/**
  1.3343 +Assigns ownership of the specified allocated memory to this object.
  1.3344 +
  1.3345 +The allocated memory forms the buffer for this descriptor. The current length
  1.3346 +of the descriptor is set to zero.
  1.3347 +
  1.3348 +Note that the function assumes that this descriptor does not already own any
  1.3349 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3350 +allocated memory.  If this descriptor does already own allocated memory,
  1.3351 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3352 +invoked.
  1.3353 +
  1.3354 +@param aHeapCell  The allocated memory to be assigned to this object. This
  1.3355 +                  pointer can be NULL, which means that a zero length 8-bit
  1.3356 +                  resizable buffer descriptor is created.
  1.3357 +@param aMaxLength The maximum length of the descriptor.
  1.3358 +
  1.3359 +@panic USER 20 If the specified maximum length is greater then the size of
  1.3360 +               the allocated heap cell, or the specified maximum length
  1.3361 +               is NOT zero when the pointer to the heap cell is NULL.
  1.3362 +              
  1.3363 +@see TDesC8::Length()
  1.3364 +@see TDes8::MaxLength()
  1.3365 +@see RBuf8::Close()
  1.3366 +*/
  1.3367 +EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aMaxLength)
  1.3368 +	{
  1.3369 +	Assign(aHeapCell,0,aMaxLength);
  1.3370 +	}
  1.3371 +
  1.3372 +
  1.3373 +
  1.3374 +
  1.3375 +/**
  1.3376 +Assigns ownership of the specified allocated memory to this object.
  1.3377 +
  1.3378 +The allocated memory forms the buffer for this descriptor. The current length
  1.3379 +of the descriptor is set to the value of the second parameter.
  1.3380 +
  1.3381 +Note that the function assumes that this descriptor does not already own any
  1.3382 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3383 +allocated memory.  If this descriptor does already own allocated memory,
  1.3384 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3385 +invoked.
  1.3386 +
  1.3387 +@param aHeapCell  The allocated memory to be assigned to this object.
  1.3388 +@param aLength	  The length of the descriptor.
  1.3389 +@param aMaxLength The maximum length of the descriptor.
  1.3390 +
  1.3391 +@panic USER 20 If the specified maximum length is greater then the size of
  1.3392 +               the allocated heap cell, or the specified length is greater then
  1.3393 +               the specified maximum length, or the specified maximum length
  1.3394 +               is NOT zero when the pointer to the heap cell is NULL.
  1.3395 +
  1.3396 +@see TDesC8::Length()
  1.3397 +@see TDes8::MaxLength()
  1.3398 +@see RBuf8::Close()
  1.3399 +*/
  1.3400 +EXPORT_C void RBuf8::Assign(TUint8 *aHeapCell,TInt aLength,TInt aMaxLength)
  1.3401 +	{
  1.3402 +	__ASSERT_ALWAYS(aLength<=aMaxLength, Panic(ETDes8LengthOutOfRange));
  1.3403 +	if(aHeapCell)
  1.3404 +		{
  1.3405 +		__ASSERT_ALWAYS(User::AllocLen(aHeapCell) >= aMaxLength * (TInt)sizeof(TUint8), Panic(ETDes8LengthOutOfRange));
  1.3406 +		//Create EPtr type descriptor that points to aHeapCell
  1.3407 +		new(this) TPtr8(aHeapCell,aLength,aMaxLength); 
  1.3408 +		}
  1.3409 +	else
  1.3410 +		{
  1.3411 +		__ASSERT_ALWAYS(aMaxLength == 0, Panic(ETDes8LengthOutOfRange));
  1.3412 +		//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
  1.3413 +		new(this) RBuf8();
  1.3414 +		}
  1.3415 +	__TEST_INVARIANT;
  1.3416 +	}
  1.3417 +
  1.3418 +
  1.3419 +
  1.3420 +
  1.3421 +/**
  1.3422 +Transfers ownership of the specified heap descriptor to this object.
  1.3423 +
  1.3424 +Note that the function assumes that this descriptor does not already own any
  1.3425 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3426 +allocated memory.  If this descriptor does already own allocated memory,
  1.3427 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3428 +invoked.
  1.3429 +
  1.3430 +@param aHBuf  The heap descriptor to be transferred to this object.
  1.3431 +              This pointer can be NULL, which means that a zero length
  1.3432 +              8-bit resizable buffer descriptor is created.
  1.3433 +@see RBuf8::Close()
  1.3434 +*/
  1.3435 +EXPORT_C void RBuf8::Assign(HBufC8* aHBuf)
  1.3436 +	{
  1.3437 +	new(this) RBuf8(aHBuf);
  1.3438 +	}
  1.3439 +
  1.3440 +
  1.3441 +
  1.3442 +
  1.3443 +/**
  1.3444 +Swaps the content of two 8-bit resizable buffer descriptors.
  1.3445 +
  1.3446 +@param aRBuf The 8-bit resizable buffer descriptor whose contents are to be
  1.3447 +             swapped with this one.
  1.3448 +*/
  1.3449 +EXPORT_C void RBuf8::Swap(RBuf8& aRBuf)
  1.3450 +	{
  1.3451 +	Mem::Swap(this,&aRBuf,sizeof(*this));
  1.3452 +	}
  1.3453 +
  1.3454 +
  1.3455 +
  1.3456 +
  1.3457 +/**
  1.3458 +Creates an 8-bit resizable buffer descriptor.
  1.3459 +
  1.3460 +The function allocates sufficient memory to contain descriptor data up to
  1.3461 +the specified maximum length.
  1.3462 +
  1.3463 +The current length of the descriptor is set to zero. The maximum length of
  1.3464 +the descriptor is set to the specified value.
  1.3465 +
  1.3466 +Note that the function assumes that this descriptor does not already own any
  1.3467 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3468 +allocated memory.  If this descriptor does already own allocated memory,
  1.3469 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3470 +invoked.
  1.3471 +
  1.3472 +@param aMaxLength  The maximum length of the descriptor.
  1.3473 +
  1.3474 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient	memory.
  1.3475 +
  1.3476 +@see TDesC8::Length()
  1.3477 +@see TDes8::MaxLength()
  1.3478 +@see RBuf8::Close()
  1.3479 +*/
  1.3480 +EXPORT_C TInt RBuf8::Create(TInt aMaxLength)
  1.3481 +	{
  1.3482 +	if (aMaxLength)
  1.3483 +		{
  1.3484 +		//Allocate memory
  1.3485 +		TUint8* buf=(TUint8*)User::Alloc(aMaxLength*sizeof(TUint8));
  1.3486 +		if(!buf) return KErrNoMemory;
  1.3487 +		iEPtrType = buf;
  1.3488 +		}
  1.3489 +	else
  1.3490 +		iEPtrType = NULL; //Zero-length descriptor.
  1.3491 +
  1.3492 +
  1.3493 +	//Create EPtr type descriptor.
  1.3494 +	new(this) RBuf8(EPtr,0,aMaxLength);
  1.3495 +	__TEST_INVARIANT;
  1.3496 +	return KErrNone;
  1.3497 +	}
  1.3498 +
  1.3499 +
  1.3500 +
  1.3501 +
  1.3502 +/**
  1.3503 +Creates an 8-bit resizable buffer descriptor, and leaves on failure.
  1.3504 +
  1.3505 +The function allocates sufficient memory to contain descriptor data up to
  1.3506 +the specified maximum length.
  1.3507 +
  1.3508 +The current length of the descriptor is set to zero. The maximum length of
  1.3509 +the descriptor is set to the specified value.
  1.3510 +
  1.3511 +Note that the function assumes that this descriptor does not already own any
  1.3512 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3513 +allocated memory.  If this descriptor does already own allocated memory,
  1.3514 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3515 +invoked.
  1.3516 +
  1.3517 +@param aMaxLength The length and the maximum length of the descriptor.
  1.3518 +
  1.3519 +@leave KErrNoMemory If there is insufficient memory.
  1.3520 +
  1.3521 +@see TDesC8::Length()
  1.3522 +@see TDes8::MaxLength()
  1.3523 +@see RBuf8::Close()
  1.3524 +*/
  1.3525 +EXPORT_C void RBuf8::CreateL(TInt aMaxLength)
  1.3526 +	{
  1.3527 +	User::LeaveIfError(Create(aMaxLength));
  1.3528 +	}
  1.3529 +
  1.3530 +
  1.3531 +
  1.3532 +
  1.3533 +/**
  1.3534 +Creates an 8-bit resizable buffer descriptor.
  1.3535 +
  1.3536 +The function allocates sufficient memory to contain descriptor data up to
  1.3537 +the specified maximum length.
  1.3538 +
  1.3539 +Both the current length and the maximum length of the descriptor are set to
  1.3540 +the specified value.
  1.3541 +
  1.3542 +Note that the function assumes that this descriptor does not already own any
  1.3543 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3544 +allocated memory.  If this descriptor does already own allocated memory,
  1.3545 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3546 +invoked.
  1.3547 +
  1.3548 +@param aMaxLength  The length and the maximum length of the descriptor.
  1.3549 +
  1.3550 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
  1.3551 +
  1.3552 +@see RBuf8::Close()
  1.3553 +*/
  1.3554 +EXPORT_C TInt RBuf8::CreateMax(TInt aMaxLength)
  1.3555 +	{
  1.3556 +	TInt err=Create(aMaxLength); 
  1.3557 +	if(err==KErrNone)
  1.3558 +		SetMax(); 
  1.3559 +	return err;
  1.3560 +	}
  1.3561 +
  1.3562 +
  1.3563 +
  1.3564 +
  1.3565 +/**
  1.3566 +Creates an 8-bit resizable buffer descriptor, and leaves on failure.
  1.3567 +
  1.3568 +The function allocates sufficient memory to contain descriptor data up to
  1.3569 +the specified maximum length.
  1.3570 +
  1.3571 +Both the current length and the maximum length of the descriptor are set to
  1.3572 +the specified value. 
  1.3573 +
  1.3574 +Note that the function assumes that this descriptor does not already own any
  1.3575 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3576 +allocated memory.  If this descriptor does already own allocated memory,
  1.3577 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3578 +invoked.
  1.3579 +
  1.3580 +@param aMaxLength The length and the maximum length of the descriptor.
  1.3581 +
  1.3582 +@leave KErrNoMemory If there is insufficient memory.
  1.3583 +
  1.3584 +@see TDesC8::Length()
  1.3585 +@see TDes8::MaxLength()
  1.3586 +@see RBuf8::Close()
  1.3587 +*/
  1.3588 +EXPORT_C void RBuf8::CreateMaxL(TInt aMaxLength)
  1.3589 +	{
  1.3590 +	User::LeaveIfError(CreateMax(aMaxLength));
  1.3591 +	}
  1.3592 +
  1.3593 +
  1.3594 +
  1.3595 +
  1.3596 +/**
  1.3597 +Creates a 8-bit resizable buffer descriptor to contain a copy of the
  1.3598 +specified (source) descriptor.
  1.3599 +
  1.3600 +The function allocates sufficient memory so that this descriptor's maximum
  1.3601 +length is the same as the length of the source descriptor. Both the current
  1.3602 +length and the maximum length of this descriptor are set to
  1.3603 +the length of the source descriptor.
  1.3604 +				
  1.3605 +The data contained in the source descriptor is copied into this
  1.3606 +descriptor.
  1.3607 +
  1.3608 +Note that the function assumes that this descriptor does not
  1.3609 +already own any allocated memory. It does not check, nor does it free any
  1.3610 +pre-existing owned allocated memory.  If this descriptor does already own 
  1.3611 +allocated memory, RBuf8::Close() should be invoked on this descriptor before 
  1.3612 +this function is invoked.
  1.3613 +
  1.3614 +@param aDes Source descriptor to be copied into this object.
  1.3615 +
  1.3616 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
  1.3617 +
  1.3618 +@see TDesC8::Length()
  1.3619 +@see TDes8::MaxLength()
  1.3620 +@see TDes8::Copy()
  1.3621 +@see RBuf8::Close()
  1.3622 +*/
  1.3623 +EXPORT_C TInt RBuf8::Create(const TDesC8& aDes)
  1.3624 +	{
  1.3625 +	return Create(aDes,aDes.Length());
  1.3626 +	}
  1.3627 +
  1.3628 +
  1.3629 +
  1.3630 +
  1.3631 +/**
  1.3632 +Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
  1.3633 +(source) descriptor, and leaves on failure.
  1.3634 + 
  1.3635 +The function allocates sufficient memory so that this descriptor's maximum
  1.3636 +length is the same as the length of the source descriptor.Both the current
  1.3637 +length and the maximum length of this descriptor are set to the length
  1.3638 +of the source descriptor.
  1.3639 +
  1.3640 +The data contained in the source descriptor is copied into this descriptor.
  1.3641 +
  1.3642 +Note that the function assumes that this descriptor does not already own any
  1.3643 +allocated memory. It does not check, nor does it free any
  1.3644 +pre-existing owned allocated memory.  If this descriptor does already own 
  1.3645 +allocated memory, RBuf8::Close() should be invoked on this descriptor before 
  1.3646 +this function is invoked.
  1.3647 +
  1.3648 +@param aDes Source descriptor to be copied into this object.
  1.3649 +
  1.3650 +@leave KErrNoMemory If there is insufficient memory.
  1.3651 +
  1.3652 +@see TDesC8::Length()
  1.3653 +@see TDes8::MaxLength()
  1.3654 +@see TDes8::Copy()
  1.3655 +@see RBuf8::Close()
  1.3656 +*/
  1.3657 +EXPORT_C void RBuf8::CreateL(const TDesC8& aDes)
  1.3658 +	{
  1.3659 +	CreateL(aDes,aDes.Length());
  1.3660 +	}
  1.3661 +
  1.3662 +
  1.3663 +
  1.3664 +
  1.3665 +/**
  1.3666 +Creates an 8-bit resizable buffer descriptor to contain a copy of the
  1.3667 +specified (source) descriptor. 
  1.3668 +
  1.3669 +The function allocates sufficient memory so that this descriptor's maximum length
  1.3670 +is the same as the value of the aMaxLength parameter.
  1.3671 +
  1.3672 +The data contained in the source descriptor is copied into this descriptor.
  1.3673 +The length of data copied is either
  1.3674 +
  1.3675 +- the length of the source descriptor aDes
  1.3676 +
  1.3677 +or
  1.3678 +
  1.3679 +- the value of the aMaxLength parameter
  1.3680 +
  1.3681 +whichever is the smaller value. The current length of this descriptor is also
  1.3682 +set to the smaller value.
  1.3683 +
  1.3684 +Note that the function assumes that this descriptor does not already own any
  1.3685 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3686 +allocated memory.  If this descriptor does already own allocated memory,
  1.3687 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3688 +invoked.
  1.3689 +
  1.3690 +@param aDes Source descriptor to be copied into this object.
  1.3691 +            
  1.3692 +@param aMaxLength The maximum length of this descriptor.
  1.3693 +
  1.3694 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
  1.3695 +
  1.3696 +@see TDesC8::Length()
  1.3697 +@see TDes8::MaxLength()
  1.3698 +@see TDes8::Copy()
  1.3699 +@see RBuf8::Close()
  1.3700 +*/
  1.3701 +EXPORT_C TInt RBuf8::Create(const TDesC8& aDes,TInt aMaxLength)
  1.3702 +	{
  1.3703 +	TInt err=Create(aMaxLength);
  1.3704 +	if(err==KErrNone)
  1.3705 +		Copy(aDes.Left(aMaxLength));
  1.3706 +	return err;
  1.3707 +	}
  1.3708 +
  1.3709 +
  1.3710 +
  1.3711 +
  1.3712 +/**
  1.3713 +Creates an 8-bit resizable buffer descriptor to contain a copy of the specified
  1.3714 +(source) descriptor, and leaves on failure.
  1.3715 +
  1.3716 +The function allocates sufficient memory so that this descriptor's maximum
  1.3717 +length is the same as the value of the aMaxLength parameter.
  1.3718 +
  1.3719 +The data contained in the source descriptor is copied into this descriptor.
  1.3720 +The length of data copied is either
  1.3721 +
  1.3722 +- the length of the source descriptor aDes
  1.3723 +
  1.3724 +or
  1.3725 +
  1.3726 +- the value of the aMaxLength parameter
  1.3727 +
  1.3728 +whichever is the smaller value. The current length of this descriptor is also
  1.3729 +set to the smaller value.
  1.3730 +
  1.3731 +Note that the function assumes that this descriptor does not already own any
  1.3732 +allocated memory. It does not check, nor does it free any pre-existing owned
  1.3733 +allocated memory.  If this descriptor does already own allocated memory,
  1.3734 +RBuf8::Close() should be invoked on this descriptor before this function is
  1.3735 +invoked.
  1.3736 +
  1.3737 +@param aDes Source descriptor to be copied into this object.
  1.3738 +            
  1.3739 +@param aMaxLength The maximum length of this descriptor.
  1.3740 +
  1.3741 +@leave KErrNoMemory If there is insufficient memory.
  1.3742 +
  1.3743 +@see TDesC8::Length()
  1.3744 +@see TDes8::MaxLength()
  1.3745 +@see TDes8::Copy()
  1.3746 +@see RBuf8::Close()
  1.3747 +*/
  1.3748 +EXPORT_C void RBuf8::CreateL(const TDesC8& aDes,TInt aMaxLength)
  1.3749 +	{
  1.3750 +	CreateL(aMaxLength);
  1.3751 +	Copy(aDes.Left(aMaxLength));
  1.3752 +	}
  1.3753 +
  1.3754 +
  1.3755 +
  1.3756 +
  1.3757 +/**
  1.3758 +Resizes this 8-bit resizable buffer descriptor.
  1.3759 +
  1.3760 +The length and contents of the descriptor are unchanged.
  1.3761 +
  1.3762 +If the buffer descriptor was created from a zero-length heap descriptor
  1.3763 +HBufC, this method might leak memory (the heap descriptor is not freed).
  1.3764 +It is possible to avoid this by calling the Close() method prior to ReAlloc(),
  1.3765 +but this should be done only in this situation (otherwise the buffer contents
  1.3766 +will be lost).
  1.3767 +
  1.3768 +For example, add
  1.3769 +@code
  1.3770 +    if (desc.MaxLength() == 0) desc.Close();
  1.3771 +@endcode
  1.3772 +before the call to ReAlloc().
  1.3773 +
  1.3774 +@param aMaxLength The new maximum length of the descriptor. This can be zero,
  1.3775 +                  which results in a descriptor with zero maximum length and no
  1.3776 +                  allocated memory.
  1.3777 +                  
  1.3778 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
  1.3779 +
  1.3780 +@panic USER 26 If the new maximum length is less then the current descriptor length.
  1.3781 +*/
  1.3782 +EXPORT_C TInt RBuf8::ReAlloc(TInt aMaxLength)
  1.3783 +	{
  1.3784 +	__ASSERT_ALWAYS(Length()<=aMaxLength, Panic(ETDes8ReAllocTooSmall));
  1.3785 +	__TEST_INVARIANT;
  1.3786 +
  1.3787 +	if (!aMaxLength)				//Reallocation to zero length
  1.3788 +		{
  1.3789 +		User::Free(iEPtrType);	//Free memory 
  1.3790 +		new (this) RBuf8();			//Create zero-length RBuf
  1.3791 +		return KErrNone;
  1.3792 +		}
  1.3793 +
  1.3794 +	if (!iMaxLength)				//Reallocation from zero length
  1.3795 +		return Create(aMaxLength);
  1.3796 +
  1.3797 +	switch(Type())
  1.3798 +		{
  1.3799 +		case EPtr:
  1.3800 +			{
  1.3801 +			TUint8* buf = (TUint8*)User::ReAlloc(iEPtrType,aMaxLength*sizeof(TUint8));
  1.3802 +			if(!buf) return KErrNoMemory;
  1.3803 +			iEPtrType = buf;
  1.3804 +			iMaxLength = aMaxLength;
  1.3805 +			break;
  1.3806 +			}
  1.3807 +		case EBufCPtr:
  1.3808 +			{
  1.3809 +			HBufC8* hbufc = iEBufCPtrType->ReAlloc(aMaxLength);
  1.3810 +			if(!hbufc) return KErrNoMemory;
  1.3811 +			Assign(hbufc);
  1.3812 +			break;
  1.3813 +			}
  1.3814 +		}
  1.3815 +
  1.3816 +	__TEST_INVARIANT;
  1.3817 +	return KErrNone;
  1.3818 +	}
  1.3819 +
  1.3820 +
  1.3821 +
  1.3822 +
  1.3823 +/**
  1.3824 +Resizes this 8-bit resizable buffer descriptor, leaving on failure.
  1.3825 +
  1.3826 +The length and contents of the descriptor are unchanged.
  1.3827 +
  1.3828 +If the buffer descriptor was created from a zero-length heap descriptor
  1.3829 +HBufC, this method might leak memory (the heap descriptor is not freed).
  1.3830 +It is possible to avoid this by calling the Close() method prior to ReAllocL(),
  1.3831 +but this should be done only in this situation (otherwise the buffer contents
  1.3832 +will be lost).
  1.3833 +
  1.3834 +For example, add
  1.3835 +@code
  1.3836 +    if (desc.MaxLength() == 0) desc.Close();
  1.3837 +@endcode
  1.3838 +before the call to ReAlloc().
  1.3839 +
  1.3840 +@param aMaxLength The new maximum length of the descriptor. This can be zero,
  1.3841 +                  which results in a descriptor with zero maximum length and no
  1.3842 +                  allocated memory.
  1.3843 +                  
  1.3844 +@return KErrNone, if successful; KErrNoMemory, if there is insufficient memory.
  1.3845 +
  1.3846 +@panic USER 26 If the new maximum length is less then the current descriptor length.
  1.3847 +*/
  1.3848 +EXPORT_C void RBuf8::ReAllocL(TInt aMaxLength)
  1.3849 +	{
  1.3850 +	User::LeaveIfError(ReAlloc(aMaxLength));
  1.3851 +	}
  1.3852 +
  1.3853 +
  1.3854 +
  1.3855 +
  1.3856 +/**
  1.3857 +Deallocates memory assigned to this object, and re-initializes the object as
  1.3858 +a zero-length descriptor.
  1.3859 +*/
  1.3860 +EXPORT_C void RBuf8::Close() 
  1.3861 +	{
  1.3862 +	User::Free(iEPtrType); 
  1.3863 +	//Create zero-length RBuf. It is EPtr type of descriptor that points to NULL.
  1.3864 +	new(this) RBuf8();
  1.3865 +	}
  1.3866 +
  1.3867 +
  1.3868 +
  1.3869 +
  1.3870 +/**
  1.3871 +Pushes a cleanup item for this object onto the cleanup stack.
  1.3872 +
  1.3873 +The effect of this is to cause Close() to be called on this 8-bit resizable
  1.3874 +buffer descriptor, when CleanupStack::PopAndDestroy() is called at some later time.
  1.3875 +
  1.3876 +@code
  1.3877 +...
  1.3878 +RBuf8 x;
  1.3879 +....
  1.3880 +x.CleanupClosePushL();
  1.3881 +...
  1.3882 +CleanupStack::PopAndDestroy();
  1.3883 +...
  1.3884 +@endcode
  1.3885 +
  1.3886 +@see RBuf8::Close()
  1.3887 +*/
  1.3888 +EXPORT_C void RBuf8::CleanupClosePushL()
  1.3889 +	{
  1.3890 +	::CleanupClosePushL(*this);
  1.3891 +	}
  1.3892 +
  1.3893 +
  1.3894 +
  1.3895 +
  1.3896 +/**
  1.3897 +Tests that the class obeys its invariant.
  1.3898 +*/
  1.3899 +EXPORT_C void RBuf8::__DbgTestInvariant() const
  1.3900 +	{
  1.3901 +#ifdef _DEBUG
  1.3902 +	TDes8::__DbgTestInvariant();
  1.3903 +	switch(Type())
  1.3904 +		{
  1.3905 +	case EPtr:
  1.3906 +		if (iEPtrType)
  1.3907 +			{
  1.3908 +			__ASSERT_DEBUG(User::AllocLen(iEPtrType) >= iMaxLength*(TInt)sizeof(TUint8), Panic(EInvariantFalse));
  1.3909 +			}
  1.3910 +		break;
  1.3911 +	case EBufCPtr:
  1.3912 +		iEBufCPtrType->__DbgTestInvariant(); 
  1.3913 +		__ASSERT_DEBUG(iEBufCPtrType->Des().MaxLength() == iMaxLength, Panic(EInvariantFalse));
  1.3914 +		__ASSERT_DEBUG(iEBufCPtrType->Length() == Length(), Panic(EInvariantFalse));
  1.3915 +		break;
  1.3916 +	default:
  1.3917 +		User::Invariant();
  1.3918 +		}
  1.3919 +#endif // _DEBUG
  1.3920 +	}
  1.3921 +
  1.3922 +#endif	// __KERNEL_MODE__
  1.3923 +
  1.3924 +
  1.3925 +#if defined(__DES8_MACHINE_CODED__) || defined(__EABI__)
  1.3926 +GLDEF_C void Des8PanicBadDesType()
  1.3927 +	{
  1.3928 +	Panic(ETDes8BadDescriptorType);
  1.3929 +	}
  1.3930 +
  1.3931 +GLDEF_C void Des8PanicPosOutOfRange()
  1.3932 +	{
  1.3933 +	Panic(ETDes8PosOutOfRange);
  1.3934 +	}
  1.3935 +#endif
  1.3936 +
  1.3937 +#ifdef __DES8_MACHINE_CODED__
  1.3938 +GLDEF_C void Des8PanicLengthNegative()
  1.3939 +	{
  1.3940 +	Panic(ETDes8LengthNegative);
  1.3941 +	}
  1.3942 +
  1.3943 +GLDEF_C void Des8PanicMaxLengthNegative()
  1.3944 +	{
  1.3945 +	Panic(ETDes8MaxLengthNegative);
  1.3946 +	}
  1.3947 +
  1.3948 +GLDEF_C void Des8PanicLengthOutOfRange()
  1.3949 +	{
  1.3950 +	Panic(ETDes8LengthOutOfRange);
  1.3951 +	}
  1.3952 +
  1.3953 +GLDEF_C void Des8PanicDesOverflow()
  1.3954 +	{
  1.3955 +	Panic(ETDes8Overflow);
  1.3956 +	}
  1.3957 +
  1.3958 +GLDEF_C void Des8PanicDesIndexOutOfRange()
  1.3959 +	{
  1.3960 +	Panic(ETDes8IndexOutOfRange);
  1.3961 +	}
  1.3962 +#endif
  1.3963 +