|         |      1 // Copyright (c) 2000-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 "Eclipse Public License v1.0" | 
|         |      5 // which accompanies this distribution, and is available | 
|         |      6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". | 
|         |      7 // | 
|         |      8 // Initial Contributors: | 
|         |      9 // Nokia Corporation - initial contribution. | 
|         |     10 // | 
|         |     11 // Contributors: | 
|         |     12 // | 
|         |     13 // Description: | 
|         |     14 // A string class implementation which allows quick addition of partial strings | 
|         |     15 // (no copying) by using an internal array of fragmented strings. | 
|         |     16 // The class allows comprehensive character based matching functionality  | 
|         |     17 // along with infinite depth marking. | 
|         |     18 //  | 
|         |     19 // | 
|         |     20  | 
|         |     21 #ifndef __CFRAGMENTEDSTRING_H__ | 
|         |     22 #define __CFRAGMENTEDSTRING_H__ | 
|         |     23  | 
|         |     24 // includes | 
|         |     25 #include <e32base.h> | 
|         |     26 #include <cstack.h> | 
|         |     27  | 
|         |     28  | 
|         |     29 // | 
|         |     30 // CFragmentedString | 
|         |     31  | 
|         |     32 //##ModelId=3B666BC6034A | 
|         |     33  | 
|         |     34  | 
|         |     35  | 
|         |     36 class CFragmentedString : protected CArrayPtrFlat<HBufC> | 
|         |     37 /**   | 
|         |     38 Utility that allows a single string to be built from an array of consecutive sub-strings. | 
|         |     39  | 
|         |     40 The sub-strings can be inserted by reference or copied. | 
|         |     41  | 
|         |     42 The object maintains information that points to a current position within the string. A typical  | 
|         |     43 use is to test the contents of the string using one of the Match...() functions, and then use  | 
|         |     44 ConsumeMatched() to advance past the matched area. | 
|         |     45  | 
|         |     46 The class also supports inserting an unlimited number of marks in the string, and performing  | 
|         |     47 operations relative to the head (i.e. last inserted) mark.  | 
|         |     48     @publishedAll | 
|         |     49     @deprecated | 
|         |     50 */ | 
|         |     51 	{ | 
|         |     52 protected: | 
|         |     53 	class TStringMark | 
|         |     54 	/** A mark at a string position. */ | 
|         |     55 		{ | 
|         |     56 	public: | 
|         |     57 		/** Constructor. | 
|         |     58  | 
|         |     59 		@param aIndex Array index of the marked sub-string | 
|         |     60 		@param aCharacter Character position within the sub-string for the mark | 
|         |     61 		*/ | 
|         |     62 		TStringMark(TInt aIndex, TInt aCharacter) | 
|         |     63 		: iMarkIndex(aIndex), iMarkCharacter(aCharacter) | 
|         |     64 		{ | 
|         |     65 		} | 
|         |     66  | 
|         |     67 	public: | 
|         |     68 		/** Array index of the marked sub-string. */ | 
|         |     69 		TInt iMarkIndex; | 
|         |     70 		/** Character position within the sub-string for the mark. */ | 
|         |     71 		TInt iMarkCharacter; | 
|         |     72 		}; | 
|         |     73 	/** A stack of string position marks. */ | 
|         |     74 	typedef CStack<TStringMark, ETrue> CMarkStack; | 
|         |     75  | 
|         |     76 public: | 
|         |     77 	/** Defines possible results of a string matching operation for this class. */ | 
|         |     78 	enum TStringMatch  | 
|         |     79 		{  | 
|         |     80 		/** There was no match. */ | 
|         |     81 		ENoMatch,  | 
|         |     82 		/** There was a complete match. */ | 
|         |     83 		EMatch, | 
|         |     84 		/** String contained insufficient data to perform the match operation. | 
|         |     85  | 
|         |     86 		This can mean that the start of the target string was matched, but the string  | 
|         |     87 		being searched ended before a complete match was found. */ | 
|         |     88 		EInsufficientData | 
|         |     89 		}; | 
|         |     90  | 
|         |     91 public: | 
|         |     92 	IMPORT_C CFragmentedString(); | 
|         |     93 	//##ModelId=3B666BC700AD | 
|         |     94 	IMPORT_C ~CFragmentedString(); | 
|         |     95  | 
|         |     96 	//##ModelId=3B666BC70099 | 
|         |     97 	IMPORT_C void AddStringL(HBufC* aString); // this version is more efficient | 
|         |     98 	//##ModelId=3B666BC700A3 | 
|         |     99 	IMPORT_C void AddStringL(const TDesC& aString); | 
|         |    100 	 | 
|         |    101 	//##ModelId=3B666BC70090 | 
|         |    102 	IMPORT_C TInt Length() const; | 
|         |    103 	//##ModelId=3B666BC70071 | 
|         |    104 	IMPORT_C HBufC* StringL() const; | 
|         |    105 	//##ModelId=3B666BC70068 | 
|         |    106 	IMPORT_C HBufC* ContentL() const; | 
|         |    107 	//##ModelId=3B666BC70067 | 
|         |    108 	IMPORT_C void Reset(); | 
|         |    109  | 
|         |    110 	//##ModelId=3B666BC7005D | 
|         |    111 	IMPORT_C TStringMatch Match(const TDesC& aString); | 
|         |    112 	//##ModelId=3B666BC70049 | 
|         |    113 	IMPORT_C TStringMatch MatchRange(const TUint aLower, const TUint aUpper); | 
|         |    114 	//##ModelId=3B666BC7003F | 
|         |    115 	IMPORT_C TStringMatch MatchSelect(const TDesC& aSelection); | 
|         |    116 	//##ModelId=3B666BC70037 | 
|         |    117 	IMPORT_C TStringMatch MatchNotSelect(const TDesC& aSelection); | 
|         |    118 	//##ModelId=3B666BC70036 | 
|         |    119 	IMPORT_C void ConsumeMatched(); | 
|         |    120  | 
|         |    121 	//##ModelId=3B666BC70035 | 
|         |    122 	IMPORT_C HBufC* MarkedL(); | 
|         |    123 	//##ModelId=3B666BC7002B | 
|         |    124 	IMPORT_C HBufC* MarkedWithInitialTextL(const TDesC& aInitialText); | 
|         |    125 	//##ModelId=3B666BC70022 | 
|         |    126 	IMPORT_C void Mark(); // Mark can leave | 
|         |    127 	//##ModelId=3B666BC70021 | 
|         |    128 	IMPORT_C void DeleteMark(); | 
|         |    129 	//##ModelId=3B666BC70018 | 
|         |    130 	IMPORT_C void ResetToMark(); | 
|         |    131  | 
|         |    132 	//##ModelId=3B666BC7000E | 
|         |    133 	IMPORT_C void ReplaceMarkedL(HBufC* aString); | 
|         |    134 	//##ModelId=3B666BC70005 | 
|         |    135 	IMPORT_C void ReplaceMarkedAndSkipL(HBufC* aString); | 
|         |    136 	//##ModelId=3B666BC70003 | 
|         |    137 	IMPORT_C void InsertStringL(HBufC* aString); | 
|         |    138  | 
|         |    139 protected: | 
|         |    140 	//##ModelId=3B666BC603E1 | 
|         |    141 	IMPORT_C void DeleteToMark(const TStringMark& aStringMark); | 
|         |    142 	//##ModelId=3B666BC603C4 | 
|         |    143 	IMPORT_C void InsertStringToL(HBufC* aString, TInt aStringIndex, TInt aLengthIntoString); | 
|         |    144 	//##ModelId=3B666BC70072 | 
|         |    145 	HBufC* StringL(TInt aStartIndex, TInt aStartCharacter, TInt aEndIndex, TInt aEndCharacter, const TDesC* aInitialText=NULL) const; | 
|         |    146 	//##ModelId=3B666BC603C3 | 
|         |    147 	void StartMatch(); | 
|         |    148 	//##ModelId=3B666BC603B8 | 
|         |    149 	CFragmentedString::TStringMatch DoMatchSelect(const TDesC& aSelection, TBool aInSelection); | 
|         |    150 	//##ModelId=3B666BC603AE | 
|         |    151 	TBool FindNextMatchChar(TUint& aChar); | 
|         |    152  | 
|         |    153 protected: | 
|         |    154 	//##ModelId=3B666BC603A4 | 
|         |    155 	/** Result of the last match operation. */ | 
|         |    156 	TStringMatch iMatched; | 
|         |    157  | 
|         |    158 	/** Array index of the sub-string found in the last match operation. */ | 
|         |    159 	//##ModelId=3B666BC6039A | 
|         |    160 	TInt iMatchedToIndex; | 
|         |    161 	/** Current character position within the iMatchedToIndex sub-string found in the last match operation. */ | 
|         |    162 	//##ModelId=3B666BC60390 | 
|         |    163 	TInt iMatchedToCharacter; | 
|         |    164 	/** Array index of the current sub-string. */ | 
|         |    165 	//##ModelId=3B666BC60386 | 
|         |    166 	TInt iCurrentIndex; | 
|         |    167 	/** Current character position within the current sub-string. */ | 
|         |    168 	//##ModelId=3B666BC6037C | 
|         |    169 	TInt iCurrentCharacter; | 
|         |    170 	/** Stack of marks in the string. | 
|         |    171  | 
|         |    172 	Mark() pushes a mark on the stack; DeleteMark() pops one off. | 
|         |    173 	*/ | 
|         |    174 	//##ModelId=3B666BC60372 | 
|         |    175 	CMarkStack iMarkStack; | 
|         |    176 	}; | 
|         |    177  | 
|         |    178 #endif // __CFRAGMENTEDSTRING_H__ |