1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\e32des16.h
18 #ifndef __E32DES16_H__
19 #define __E32DES16_H__
24 const TUint KMaskDesLength16=0xfffffff;
30 struct TCollationMethod;
39 Abstract base class for 16-bit descriptors.
41 The class encapsulates the data member containing the length of data
42 represented by a 16-bit descriptor. It also provides member functions through
43 which the data can be accessed, but not modified.
45 Data represented by this class is treated as a contiguous set of 16-bit (i.e.
46 double byte) values or data items.
48 This class cannot be instantiated as it is intended to form part of a class
49 hierarchy; it provides a well defined part of descriptor behaviour. It can,
50 however, be passed as an argument type for functions which want access to
51 descriptor data but do not need to modify that data.
59 A value returned by a call to HasPrefixC().
61 @see TDesC16::HasPrefixC
65 Indicates that a supplied prefix can be extended to
66 be equivalent to the text at the start of a descriptor.
70 Indicates that a supplied prefix does not seem to be a
71 prefix, but it is possible that it could be extended to
72 become equivalent to text at the start of this descriptor.
76 Indicates that a supplied prefix cannot be extended to be
77 equivalent to the text at the start of a descriptor.
82 inline TBool operator<(const TDesC16 &aDes) const;
83 inline TBool operator<=(const TDesC16 &aDes) const;
84 inline TBool operator>(const TDesC16 &aDes) const;
85 inline TBool operator>=(const TDesC16 &aDes) const;
86 inline TBool operator==(const TDesC16 &aDes) const;
87 inline TBool operator!=(const TDesC16 &aDes) const;
88 inline const TUint16 &operator[](TInt anIndex) const;
89 inline TInt Length() const;
90 inline TInt Size() const;
91 IMPORT_C const TUint16 *Ptr() const;
92 IMPORT_C TInt Compare(const TDesC16 &aDes) const;
93 IMPORT_C TInt CompareF(const TDesC16 &aDes) const;
94 IMPORT_C TInt CompareC(const TDesC16 &aDes) const;
95 IMPORT_C TInt CompareC(const TDesC16& aDes,TInt aMaxLevel,const TCollationMethod* aCollationMethod) const;
99 IMPORT_C HBufC16* GetNormalizedDecomposedFormL() const;
103 IMPORT_C HBufC16* GetFoldedDecomposedFormL() const;
107 IMPORT_C HBufC8* GetCollationKeysL(TInt aMaxLevel,const TCollationMethod* aCollationMethod) const;
108 IMPORT_C TInt Match(const TDesC16 &aDes) const;
109 IMPORT_C TInt MatchF(const TDesC16 &aDes) const;
110 IMPORT_C TInt MatchC(const TDesC16 &aDes) const;
111 IMPORT_C TInt MatchC(const TDesC16 &aPattern, TInt aWildChar, TInt aWildSequenceChar,
112 TInt aEscapeChar, TInt aMaxLevel = 3, const TCollationMethod* aCollationMethod = NULL) const;
113 IMPORT_C TInt MatchC(const TDesC16 &aPattern, const TCollationMethod* aCollationMethod,
114 TInt aMaxLevel = 3, TInt aWildChar = '?', TInt aWildSequenceChar = '*', TInt aEscapeChar = 0) const;
115 IMPORT_C TInt Locate(TChar aChar) const;
116 IMPORT_C TInt LocateReverse(TChar aChar) const;
117 IMPORT_C TInt Find(const TDesC16 &aDes) const;
118 IMPORT_C TInt Find(const TUint16 *aBuf,TInt aLen) const;
119 IMPORT_C TPrefix HasPrefixC(const TDesC16& aPossiblePrefix, TInt aLevel, const TCollationMethod* aCollationMethod) const;
120 IMPORT_C TPtrC16 Left(TInt aLength) const;
121 IMPORT_C TPtrC16 Right(TInt aLength) const;
122 IMPORT_C TPtrC16 Mid(TInt aPos) const;
123 IMPORT_C TPtrC16 Mid(TInt aPos,TInt aLength) const;
124 IMPORT_C TInt LocateF(TChar aChar) const;
125 IMPORT_C TInt LocateReverseF(TChar aChar) const;
126 IMPORT_C TInt FindF(const TDesC16 &aDes) const;
127 IMPORT_C TInt FindF(const TUint16 *aBuf,TInt aLen) const;
128 IMPORT_C TInt FindC(const TDesC16 &aDes) const;
129 IMPORT_C TInt FindC(const TUint16 *aBuf,TInt aLen) const;
130 IMPORT_C TInt FindC(const TUint16 *aText,TInt aLength, TInt aMaxLevel) const;
131 IMPORT_C TInt FindC(const TDesC16 &aDes,TInt &aLengthFound, const TCollationMethod &aMethod,TInt aMaxLevel) const;
132 IMPORT_C HBufC16 *Alloc() const;
133 IMPORT_C HBufC16 *AllocL() const;
134 IMPORT_C HBufC16 *AllocLC() const;
137 inline TDesC16(TInt aType,TInt aLength);
138 // delay this for a while
139 #ifdef SYMBIAN_FIX_TDESC_CONSTRUCTORS
140 inline TDesC16( const TDesC16& aOther) : iLength(aOther.iLength) {}
142 // inline ~TDesC16() {} Commented out for the moment since it breaks code
143 inline TInt Type() const;
144 inline void DoSetLength(TInt aLength);
145 IMPORT_C const TUint16 &AtC(TInt anIndex) const;
151 class TPtrC16 : public TDesC16
156 16-bit non-modifiable pointer descriptor.
158 This is a descriptor class intended for instantiation and encapsulates a
159 pointer to the 16-bit data that it represents. The data can live in ROM or RAM
160 and this location is separate from the descriptor object itself.
162 The data is intended to be accessed, but not changed, through this descriptor.
163 The base class provides the functions through which data is accessed.
175 IMPORT_C TPtrC16(const TDesC16 &aDes);
176 IMPORT_C TPtrC16(const TUint16 *aString);
177 IMPORT_C TPtrC16(const TUint16 *aBuf,TInt aLength);
178 inline void Set(const TUint16 *aBuf,TInt aLength);
179 inline void Set(const TDesC16 &aDes);
180 inline void Set(const TPtrC16 &aPtr);
182 TPtrC16& operator=(const TPtrC16 &aDes);
194 An interface that defines an overflow handler for a 16-bit descriptor.
196 The interface encapsulates a function that is called when an attempt to append
197 formatted text fails because the descriptor is already at its maximum length.
199 A derived class must provide an implementation for the Overflow() member function.
201 @see TDes16::AppendFormat
206 Handles the overflow.
208 This function is called when the TDes16::AppendFormat()
209 variant that takes an overflow handler argument, fails.
211 @param aDes The 16-bit modifiable descriptor whose overflow results in the
212 call to this overflow handler.
214 virtual void Overflow(TDes16 &aDes)=0;
217 class TDes16IgnoreOverflow : public TDes16Overflow
222 A derived class which provides an implementation for the Overflow() member function
223 where truncation is required.
225 @see TDes16::AppendFormat
230 Handles the overflow.
232 This function is called when the TDes16::AppendFormat()
233 variant that takes an overflow handler argument, fails.
235 @param aDes The 16-bit modifiable descriptor whose overflow results in the
236 call to this overflow handler.
238 IMPORT_C virtual void Overflow(TDes16 &aDes);
242 class TDes16 : public TDesC16
247 Abstract base class for 16-bit modifiable descriptors.
249 The class encapsulates the data member containing the maximum length of data
250 represented by a 16-bit descriptor. It also provides member functions through
251 which the data can be modified.
253 The class adds to the behaviour provided by TDesC16.
255 This class cannot be instantiated as it is intended to form part of a class
256 hierarchy; it provides a well defined part of descriptor behaviour. It can,
257 however, be passed as an argument type for functions which need to both modify
258 and access descriptor data.
266 inline TDes16& operator=(const TUint16 *aString);
267 inline TDes16& operator=(const TDesC16 &aDes);
268 inline TDes16& operator=(const TDes16 &aDes);
269 inline TInt MaxLength() const;
270 inline TInt MaxSize() const;
271 inline const TUint16 &operator[](TInt anIndex) const;
272 inline TUint16 &operator[](TInt anIndex);
273 inline TDes16 &operator+=(const TDesC16 &aDes);
274 IMPORT_C void Zero();
275 IMPORT_C void SetLength(TInt aLength);
276 IMPORT_C void SetMax();
277 IMPORT_C void Copy(const TDesC8 &aDes);
278 IMPORT_C void Copy(const TDesC16 &aDes);
279 IMPORT_C void Copy(const TUint16 *aBuf,TInt aLength);
280 IMPORT_C void Copy(const TUint16 *aString);
281 IMPORT_C void Append(TChar aChar);
282 IMPORT_C void Append(const TDesC16 &aDes);
283 IMPORT_C void Append(const TUint16 *aBuf,TInt aLength);
284 IMPORT_C void Fill(TChar aChar);
285 IMPORT_C void Fill(TChar aChar,TInt aLength);
286 IMPORT_C void FillZ();
287 IMPORT_C void FillZ(TInt aLength);
288 IMPORT_C void NumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth);
289 IMPORT_C void AppendNumFixedWidth(TUint aVal,TRadix aRadix,TInt aWidth);
290 IMPORT_C TPtr16 LeftTPtr(TInt aLength) const;
291 IMPORT_C TPtr16 RightTPtr(TInt aLength) const;
292 IMPORT_C TPtr16 MidTPtr(TInt aPos) const;
293 IMPORT_C TPtr16 MidTPtr(TInt aPos,TInt aLength) const;
294 IMPORT_C const TUint16 *PtrZ();
295 IMPORT_C void CopyF(const TDesC16 &aDes);
296 IMPORT_C void CopyC(const TDesC16 &aDes);
297 IMPORT_C void CopyLC(const TDesC16 &aDes);
298 IMPORT_C void CopyUC(const TDesC16 &aDes);
299 IMPORT_C void CopyCP(const TDesC16 &aDes);
300 IMPORT_C void AppendFill(TChar aChar,TInt aLength);
301 IMPORT_C void ZeroTerminate();
302 IMPORT_C void Swap(TDes16 &aDes);
303 IMPORT_C void Fold();
304 IMPORT_C void Collate();
305 IMPORT_C void LowerCase();
306 IMPORT_C void UpperCase();
307 IMPORT_C void Capitalize();
308 IMPORT_C void Repeat(const TDesC16 &aDes);
309 IMPORT_C void Repeat(const TUint16 *aBuf,TInt aLength);
310 IMPORT_C void Trim();
311 IMPORT_C void TrimAll();
312 IMPORT_C void TrimLeft();
313 IMPORT_C void TrimRight();
314 IMPORT_C void Insert(TInt aPos,const TDesC16 &aDes);
315 IMPORT_C void Delete(TInt aPos,TInt aLength);
316 IMPORT_C void Replace(TInt aPos,TInt aLength,const TDesC16 &aDes);
317 IMPORT_C void Justify(const TDesC16 &aDes,TInt aWidth,TAlign anAlignment,TChar aFill);
318 IMPORT_C void NumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth);
319 IMPORT_C void NumUC(TUint64 aVal, TRadix aRadix=EDecimal);
320 IMPORT_C TInt Num(TReal aVal,const TRealFormat &aFormat) __SOFTFP;
321 IMPORT_C void Num(TInt64 aVal);
322 IMPORT_C void Num(TUint64 aVal, TRadix aRadix);
323 IMPORT_C void Format(TRefByValue<const TDesC16> aFmt,...);
324 IMPORT_C void FormatList(const TDesC16 &aFmt,VA_LIST aList);
325 IMPORT_C void AppendJustify(const TDesC16 &Des,TInt aWidth,TAlign anAlignment,TChar aFill);
326 IMPORT_C void AppendJustify(const TDesC16 &Des,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill);
327 IMPORT_C void AppendJustify(const TUint16 *aString,TInt aWidth,TAlign anAlignment,TChar aFill);
328 IMPORT_C void AppendJustify(const TUint16 *aString,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill);
329 IMPORT_C void AppendNumFixedWidthUC(TUint aVal,TRadix aRadix,TInt aWidth);
330 IMPORT_C void AppendNumUC(TUint64 aVal, TRadix aRadix=EDecimal);
331 IMPORT_C TInt AppendNum(TReal aVal,const TRealFormat &aFormat) __SOFTFP;
332 IMPORT_C void AppendNum(TInt64 aVal);
333 IMPORT_C void AppendNum(TUint64 aVal, TRadix aRadix);
334 IMPORT_C void AppendFormat(TRefByValue<const TDesC16> aFmt,TDes16Overflow *aOverflowHandler,...);
335 IMPORT_C void AppendFormat(TRefByValue<const TDesC16> aFmt,...);
336 IMPORT_C void AppendFormatList(const TDesC16 &aFmt,VA_LIST aList,TDes16Overflow *aOverflowHandler=NULL);
337 IMPORT_C TPtr8 Collapse();
340 inline TDes16(TInt aType,TInt aLength,TInt aMaxLength);
341 // delay this for a while
342 #ifdef SYMBIAN_FIX_TDESC_CONSTRUCTORS
343 inline TDes16(const TDes16& aOther) : TDesC16(aOther), iMaxLength(aOther.iMaxLength) {}
345 inline TUint16 *WPtr() const;
346 void DoAppendNum(TUint64 aVal, TRadix aRadix, TUint aA, TInt aW);
347 void DoPadAppendNum(TInt aLength, TInt aW, const TUint8* aBuf);
353 class TPtr16 : public TDes16
358 16-bit modifiable pointer descriptor
360 This is a descriptor class intended for instantiation and encapsulates a
361 pointer to the 16-bit data that it represents. The data can live in ROM or
362 RAM and this location is separate from the descriptor object itself.
364 The data is intended to be accessed and modified through this descriptor.
365 The base classes provide the functions through which the data can be
378 IMPORT_C TPtr16(TUint16 *aBuf,TInt aMaxLength);
379 IMPORT_C TPtr16(TUint16 *aBuf,TInt aLength,TInt aMaxLength);
380 inline TPtr16& operator=(const TUint16 *aString);
381 inline TPtr16& operator=(const TDesC16& aDes);
382 inline TPtr16& operator=(const TPtr16& aDes);
383 inline void Set(TUint16 *aBuf,TInt aLength,TInt aMaxLength);
384 inline void Set(const TPtr16 &aPtr);
386 IMPORT_C TPtr16(TBufCBase16 &aLcb,TInt aMaxLength);
390 friend class TBufCBase16;
394 class TBufCBase16 : public TDesC16
400 IMPORT_C TBufCBase16();
401 inline TBufCBase16(TInt aLength);
402 IMPORT_C TBufCBase16(const TUint16 *aString,TInt aMaxLength);
403 IMPORT_C TBufCBase16(const TDesC16 &aDes,TInt aMaxLength);
404 IMPORT_C void Copy(const TUint16 *aString,TInt aMaxLength);
405 IMPORT_C void Copy(const TDesC16 &aDes,TInt aMaxLength);
406 inline TPtr16 DoDes(TInt aMaxLength);
407 inline TUint16 *WPtr() const;
411 class HBufC16 : public TBufCBase16
416 16-bit heap descriptor.
418 This is a descriptor class which provides a buffer of fixed length, allocated
419 on the heap, for containing and accessing data.
421 The class is intended for instantiation.
423 Heap descriptors have the important property that they can be made larger
424 or smaller, changing the size of the descriptor buffer. This is achieved by
425 reallocating the descriptor. Unlike the behaviour of dynamic buffers, reallocation
426 is not done automatically.
428 Data is intended to be accessed, but not modified; however, it can be completely
429 replaced using the assignment operators of this class. The base class (TDesC16) provides
430 the functions through which the data is accessed.
432 The descriptor is hosted by a heap cell, and the 16-bit data that the descriptor
433 represents is part of the descriptor object itself. The size of the cell depends
434 on the requested maximum length of the descriptor buffer when the descriptor
435 is created or re-allocated.
437 It is important to note that the size of the allocated cell, and, therefore,
438 the resulting maximum length of the descriptor, may be larger than requested
439 due to the way memory is allocated in Symbian OS. The amount by which this
440 may be rounded up depends on the platform and build type.
448 IMPORT_C static HBufC16 *New(TInt aMaxLength);
449 IMPORT_C static HBufC16 *NewL(TInt aMaxLength);
450 IMPORT_C static HBufC16 *NewLC(TInt aMaxLength);
451 IMPORT_C static HBufC16 *NewMax(TInt aMaxLength);
452 IMPORT_C static HBufC16 *NewMaxL(TInt aMaxLength);
453 IMPORT_C static HBufC16 *NewMaxLC(TInt aMaxLength);
454 IMPORT_C static HBufC16 *NewL(RReadStream &aStream,TInt aMaxLength);
455 IMPORT_C static HBufC16 *NewLC(RReadStream &aStream,TInt aMaxLength);
456 IMPORT_C HBufC16& operator=(const TUint16 *aString);
457 IMPORT_C HBufC16& operator=(const TDesC16 &aDes);
458 inline HBufC16& operator=(const HBufC16 &aLcb);
459 IMPORT_C HBufC16 *ReAlloc(TInt aMaxLength);
460 IMPORT_C HBufC16 *ReAllocL(TInt aMaxLength);
461 IMPORT_C TPtr16 Des();
463 inline HBufC16(TInt aLength);
472 #define __Size16 (sizeof(TInt)/sizeof(TInt16))
476 #define __Align16(s) ((((s)+__Size16-1)/__Size16)*__Size16)
479 class TBufC16 : public TBufCBase16
484 16-bit non-modifiable buffer descriptor.
486 This is a descriptor class which provides a buffer of fixed length for
487 containing and accessing TUint16 data.
489 The class intended for instantiation. The 16-bit data that the descriptor
490 represents is part of the descriptor object itself.
492 The class is templated, based on an integer value which defines the size of
493 the descriptor's data area.
495 The data is intended to be accessed, but not modified; however, it can be
496 completely replaced using the assignment operators of this class. The base
497 class provides the functions through which the data is accessed.
507 inline TBufC16(const TUint16 *aString);
508 inline TBufC16(const TDesC16 &aDes);
509 inline TBufC16<S> &operator=(const TUint16 *aString);
510 inline TBufC16<S> &operator=(const TDesC16 &aDes);
513 TUint16 iBuf[__Align16(S)];
516 class TBufBase16 : public TDes16
522 IMPORT_C TBufBase16(TInt aMaxLength);
523 IMPORT_C TBufBase16(TInt aLength,TInt aMaxLength);
524 IMPORT_C TBufBase16(const TUint16* aString,TInt aMaxLength);
525 IMPORT_C TBufBase16(const TDesC16& aDes,TInt aMaxLength);
529 class TBuf16 : public TBufBase16
534 A descriptor class which provides a buffer of fixed length for
535 containing, accessing and manipulating TUint16 data.
537 The class is intended for instantiation. The 16-bit data that the descriptor
538 represents is part of the descriptor object itself.
540 The class is templated, based on an integer value which determines the size
541 of the data area which is created as part of the buffer descriptor object;
542 this is also the maximum length of the descriptor.
544 The data is intended to be both accessed and modified. The base classes provide
545 the functions through which the data is accessed.
555 inline explicit TBuf16(TInt aLength);
556 inline TBuf16(const TUint16* aString);
557 inline TBuf16(const TDesC16& aDes);
558 inline TBuf16<S>& operator=(const TUint16* aString);
559 inline TBuf16<S>& operator=(const TDesC16& aDes);
560 inline TBuf16<S>& operator=(const TBuf16<S>& aDes);
562 TUint16 iBuf[__Align16(S)];
566 #ifndef __KERNEL_MODE__
568 class RBuf16 : public TDes16
573 16 bit resizable buffer descriptor.
575 The class provides a buffer that contains, accesses and manipulates
576 TUint16 data. The buffer itself is on the heap, and is managed by the class.
578 Internally, RBuf16 behaves in one of two ways:
580 - as a TPtr16 descriptor type, where the buffer just contains data
581 - as a pointer to a heap descriptor, an HBufC16* type, where the buffer
582 contains both descriptor information and the data.
584 Note that the handling of the distinction is hidden from view.
586 An RBuf16 object can allocate its own buffer. Alternatively, it can take
587 ownership of a pre-existing section of allocated memory, or it can take
588 ownership of a pre-existing heap descriptor. It can also reallocate the buffer
589 to resize it. Regardless of the way in which the buffer has been allocated,
590 the RBuf16 object is responsible for freeing memory when the object itself is closed.
592 The class is intended for instantiation.
594 The class is derived from TDes16, which means that data can be both accessed
595 and modified. The base classes provide the functions through which the data is
596 accessed. In addition, an RBuf16 object can be passed to any function that is
597 prototyped to take a TDes16 or a TDesC16 type.
608 IMPORT_C explicit RBuf16(HBufC16* aHBuf);
609 inline RBuf16& operator=(const TUint16* aString);
610 inline RBuf16& operator=(const TDesC16& aDes);
611 inline RBuf16& operator=(const RBuf16& aDes);
612 IMPORT_C void Assign(const RBuf16& aRBuf);
613 IMPORT_C void Assign(TUint16 *aHeapCell,TInt aMaxLength);
614 IMPORT_C void Assign(TUint16 *aHeapCell,TInt aLength,TInt aMaxLength);
615 IMPORT_C void Assign(HBufC16* aHBuf);
616 IMPORT_C void Swap(RBuf16& aRBuf);
617 IMPORT_C TInt Create(TInt aMaxLength);
618 IMPORT_C void CreateL(TInt aMaxLength);
619 IMPORT_C TInt CreateMax(TInt aMaxLength);
620 IMPORT_C void CreateMaxL(TInt aMaxLength);
621 inline void CreateL(RReadStream &aStream,TInt aMaxLength);
622 IMPORT_C TInt Create(const TDesC16& aDes);
623 IMPORT_C void CreateL(const TDesC16& aDes);
624 IMPORT_C TInt Create(const TDesC16& aDes,TInt aMaxLength);
625 IMPORT_C void CreateL(const TDesC16& aDes,TInt aMaxLength);
626 IMPORT_C TInt ReAlloc(TInt aMaxLength);
627 IMPORT_C void ReAllocL(TInt aMaxLength);
628 IMPORT_C void Close();
629 IMPORT_C void CleanupClosePushL();
632 IMPORT_C RBuf16(TInt aType,TInt aLength,TInt aMaxLength);
633 RBuf16(const RBuf16&); // Outlaw copy construction
636 TUint16* iEPtrType; //Pointer to data used when RBuf is of EPtr type
637 HBufC16* iEBufCPtrType; //Pointer to data used when RBuf is of EBufCPtr type
642 #endif //__KERNEL_MODE__
649 Value reference used in operator TLitC16::__TRefDesC16()
653 typedef TRefByValue<const TDesC16> __TRefDesC16;
664 Encapsulates literal text.
666 This is always constructed using an _LIT16 macro.
668 This class is build independent; i.e. an explicit 16-bit build variant
669 is generated for both a non-Unicode build and a Unicode build.
671 The class has no explicit constructors.
677 inline const TDesC16* operator&() const;
678 inline operator const TDesC16&() const;
679 inline const TDesC16& operator()() const;
680 inline operator const __TRefDesC16() const;
682 #if defined(__GCC32__)
686 typedef wchar_t __TText;
687 #elif defined(__VC32__)
691 typedef TUint16 __TText;
692 #elif defined(__CW32__)
696 typedef TUint16 __TText;
697 #elif !defined(__TText_defined)
698 #error no typedef for __TText
709 __TText iBuf[__Align16(S)];
712 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
713 #include <e32des16_private.h>