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