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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
21 #ifndef __CFRAGMENTEDSTRING_H__
22 #define __CFRAGMENTEDSTRING_H__
32 //##ModelId=3B666BC6034A
36 class CFragmentedString : protected CArrayPtrFlat<HBufC>
38 Utility that allows a single string to be built from an array of consecutive sub-strings.
40 The sub-strings can be inserted by reference or copied.
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.
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.
54 /** A mark at a string position. */
59 @param aIndex Array index of the marked sub-string
60 @param aCharacter Character position within the sub-string for the mark
62 TStringMark(TInt aIndex, TInt aCharacter)
63 : iMarkIndex(aIndex), iMarkCharacter(aCharacter)
68 /** Array index of the marked sub-string. */
70 /** Character position within the sub-string for the mark. */
73 /** A stack of string position marks. */
74 typedef CStack<TStringMark, ETrue> CMarkStack;
77 /** Defines possible results of a string matching operation for this class. */
80 /** There was no match. */
82 /** There was a complete match. */
84 /** String contained insufficient data to perform the match operation.
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. */
92 IMPORT_C CFragmentedString();
93 //##ModelId=3B666BC700AD
94 IMPORT_C ~CFragmentedString();
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);
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();
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();
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();
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);
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
148 //##ModelId=3B666BC603B8
149 CFragmentedString::TStringMatch DoMatchSelect(const TDesC& aSelection, TBool aInSelection);
150 //##ModelId=3B666BC603AE
151 TBool FindNextMatchChar(TUint& aChar);
154 //##ModelId=3B666BC603A4
155 /** Result of the last match operation. */
156 TStringMatch iMatched;
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
167 /** Current character position within the current sub-string. */
168 //##ModelId=3B666BC6037C
169 TInt iCurrentCharacter;
170 /** Stack of marks in the string.
172 Mark() pushes a mark on the stack; DeleteMark() pops one off.
174 //##ModelId=3B666BC60372
175 CMarkStack iMarkStack;
178 #endif // __CFRAGMENTEDSTRING_H__