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