|
1 // Copyright (c) 2001-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 // This file contains the API definition for the classes TDelimitedParserBase8 |
|
15 // and CDelimitedData8. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file DelimitedParser8.h |
|
21 @publishedAll |
|
22 @released |
|
23 */ |
|
24 |
|
25 #ifndef __DELIMITEDPARSER8_H__ |
|
26 #define __DELIMITEDPARSER8_H__ |
|
27 |
|
28 // System includes |
|
29 // |
|
30 #include <e32base.h> |
|
31 #include <delimitedparsercommon.h> |
|
32 |
|
33 |
|
34 /** |
|
35 Comments : Provides non-modifying functionality for parsing data delimited by |
|
36 a single character. The data is delimited into segments. Uses 8-bit descriptors. |
|
37 |
|
38 The object contains a descriptor with the data which can be parsed from left |
|
39 to right, or right to left. It is non-owning. The current segment can be extracted, |
|
40 which then parses the string for the next segment. |
|
41 |
|
42 This is a base class and an object of this type cannot be instantiated. It should |
|
43 be derived. The derived class should ensure that the data iDataDes is set before |
|
44 calling one of the protected parsing functions. The derived class should also ensure |
|
45 that the delimiting character has been set. |
|
46 |
|
47 If the data iDataDes has not been parsed, then calling any functionality that |
|
48 requires the data to have been parsed will result in a panic |
|
49 KDelimitedParserErrNotParsed. The data can only be parsed by calling one of the |
|
50 protected parsing functions from the derived class. |
|
51 |
|
52 If the delimiting character iDelimiter has not been set, then calling the protected |
|
53 parsing functions and some of the other public functionality that requires the |
|
54 delimiter to be set will result in a panic KDelimitingParserErrNoDelimiter. |
|
55 @publishedAll |
|
56 @released |
|
57 @since 6.0 |
|
58 */ |
|
59 class TDelimitedParserBase8 |
|
60 { |
|
61 public: // Methods |
|
62 |
|
63 IMPORT_C void Reset() const; |
|
64 |
|
65 IMPORT_C TInt GetNext(TPtrC8& aSegment) const; |
|
66 |
|
67 IMPORT_C TInt Inc() const; |
|
68 |
|
69 IMPORT_C TInt Dec() const; |
|
70 |
|
71 IMPORT_C TInt Peek(TPtrC8& aSegment) const; |
|
72 |
|
73 IMPORT_C TBool Eos() const; |
|
74 |
|
75 IMPORT_C TBool FrontDelimiter() const; |
|
76 |
|
77 IMPORT_C TBool BackDelimiter() const; |
|
78 |
|
79 IMPORT_C const TDesC8& Des() const; |
|
80 |
|
81 IMPORT_C TInt Remainder(TPtrC8& aRemainder) const; |
|
82 |
|
83 protected: // Methods |
|
84 |
|
85 IMPORT_C TDelimitedParserBase8(); |
|
86 |
|
87 IMPORT_C void Parse(const TDesC8& aData); |
|
88 |
|
89 IMPORT_C void ParseReverse(const TDesC8& aData); |
|
90 |
|
91 IMPORT_C void SetDelimiter(TChar aDelimiter); |
|
92 |
|
93 private: // Methods |
|
94 |
|
95 void DoParse(const TDesC8& aData); |
|
96 |
|
97 TInt FindNextSegment(TInt aStartPos) const; |
|
98 |
|
99 TInt FindPrevSegment(TInt aStartPos) const; |
|
100 |
|
101 private: // Attributes |
|
102 |
|
103 /** Descriptor with the string |
|
104 */ |
|
105 TPtrC8 iDataDes; |
|
106 |
|
107 /** Descriptor with the current segment. |
|
108 */ |
|
109 mutable TPtrC8 iCurrentSegment; |
|
110 |
|
111 /** Position of next segment. |
|
112 */ |
|
113 mutable TInt iNextSegmentPos; |
|
114 |
|
115 /** Direction of parsing. |
|
116 */ |
|
117 TDelimitedDataParseMode iMode; |
|
118 |
|
119 /** Delimiting character |
|
120 */ |
|
121 TInt iDelimiter; |
|
122 |
|
123 /** |
|
124 A friend class. |
|
125 @see CDelimitedDataBase8 |
|
126 @since 6.0 |
|
127 */ |
|
128 friend class CDelimitedDataBase8; |
|
129 |
|
130 }; |
|
131 |
|
132 /** |
|
133 Dependencies : CBase, TDelimitedParserBase8 |
|
134 Comments : Provides functionality for creating and editing a delimited data object. |
|
135 Uses 8-bit descriptors |
|
136 |
|
137 The object contains a descriptor buffer with the data. Functionality is provided |
|
138 to allow segments to be added or removed from the data. There is access to the |
|
139 internal delimited data parser to provide parsing functionality to be excercised |
|
140 on the created data. |
|
141 |
|
142 This a base class that cannot be instantiated. It should be derived. The derived |
|
143 class must set the delimited data parser, which is an object derived from |
|
144 TDelimitedParserBase. This helper class must set the delimiting object |
|
145 |
|
146 If the delimiting character has not been set, then calling any of the functionality |
|
147 will cause a panic KDelimitedParserErrNoDelimiter. |
|
148 @publishedAll |
|
149 @released |
|
150 @since 6.0 |
|
151 */ |
|
152 class CDelimitedDataBase8 : public CBase |
|
153 { |
|
154 public: // Methods |
|
155 |
|
156 IMPORT_C ~CDelimitedDataBase8(); |
|
157 |
|
158 IMPORT_C void InsertCurrentL(const TDesC8& aSegment); |
|
159 |
|
160 IMPORT_C void RemoveCurrentL(); |
|
161 |
|
162 IMPORT_C void PushBackL(const TDesC8& aSegment); |
|
163 |
|
164 IMPORT_C void PopBackL(); |
|
165 |
|
166 IMPORT_C void PushFrontL(const TDesC8& aSegment); |
|
167 |
|
168 IMPORT_C void PopFrontL(); |
|
169 |
|
170 IMPORT_C void TrimFrontDelimiterL(); |
|
171 |
|
172 IMPORT_C void AddFrontDelimiterL(); |
|
173 |
|
174 IMPORT_C void TrimBackDelimiterL(); |
|
175 |
|
176 IMPORT_C void AddBackDelimiterL(); |
|
177 |
|
178 IMPORT_C void Parse(); |
|
179 |
|
180 IMPORT_C void ParseReverse(); |
|
181 |
|
182 IMPORT_C const TDelimitedParserBase8& Parser() const; |
|
183 |
|
184 protected: // Methods |
|
185 |
|
186 IMPORT_C CDelimitedDataBase8(); |
|
187 |
|
188 IMPORT_C void ConstructL(const TDesC8& aData); |
|
189 |
|
190 IMPORT_C void SetDelimiter(TChar aDelimiter); |
|
191 |
|
192 private: // Methods |
|
193 |
|
194 |
|
195 void SetDataL(const TDesC8& aData); |
|
196 |
|
197 void SetData(HBufC8* aDataBuf); |
|
198 |
|
199 void DoInsertL(const TDesC8& aSegment); |
|
200 |
|
201 void DoRemoveL(); |
|
202 |
|
203 private: // Attributes |
|
204 |
|
205 /** Descriptor buffer. |
|
206 */ |
|
207 HBufC8* iDataBuf; |
|
208 |
|
209 /** Parser object |
|
210 */ |
|
211 TDelimitedParserBase8 iParser; |
|
212 |
|
213 }; |
|
214 |
|
215 #endif // __DELIMITEDPARSER8_H__ |