|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Declaration of class TCodParser. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef COD_PARSER_H |
|
22 #define COD_PARSER_H |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <e32base.h> |
|
27 |
|
28 // FORWARD DECLARATION |
|
29 |
|
30 class CCodData; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 |
|
35 /** |
|
36 * COD Parser. |
|
37 */ |
|
38 NONSHARABLE_CLASS( TCodParser ) |
|
39 { |
|
40 |
|
41 public: // constructor |
|
42 |
|
43 /** |
|
44 * Constructor. |
|
45 */ |
|
46 inline TCodParser(); |
|
47 |
|
48 public: // new methods |
|
49 |
|
50 /** |
|
51 * Parse the buffer into aData. Existing data in aData is lost. |
|
52 * Leaves on failure; leave code can be KErrCodInvalidDescriptor as well |
|
53 * as general errors. The resulting data is not checked semantically |
|
54 * (i.e. mandatory attributes may be missing). |
|
55 * @param aBuf COD content buffer to be parsed. |
|
56 * @param aData COD will be parsed into this. |
|
57 */ |
|
58 void ParseL( const TDesC& aBuf, CCodData& aData ); |
|
59 |
|
60 private: // types |
|
61 |
|
62 enum TCodAttr ///< COD Attributes. |
|
63 { |
|
64 ECodName, ///< COD-Name. |
|
65 ECodVendor, ///< COD-Vendor. |
|
66 ECodDescription, ///< COD-Description. |
|
67 ECodUrl, ///< COD-URL. |
|
68 ECodSize, ///< COD-Size. |
|
69 ECodType, ///< COD-Type. |
|
70 ECodInstallNotify, ///< COD-Install-Notify. |
|
71 ECodNextUrl, ///< COD-Netx-URL. |
|
72 ECodNextUrlAtError, ///< COD-Next-URLatError. |
|
73 ECodInfoUrl, ///< COD-Info-URL. |
|
74 ECodPrice, ///< COD-Price. |
|
75 ECodIcon, ///< COD-Icon. |
|
76 ECodUnknownAttr ///< Future COD attributes. |
|
77 }; |
|
78 |
|
79 private: // parsing |
|
80 |
|
81 /** |
|
82 * Parse one line. |
|
83 * @return ETrue if more lines to go, EFalse if done. |
|
84 */ |
|
85 TBool AttrLineL(); |
|
86 |
|
87 /** |
|
88 * Parse an attribute name. Empty token sets error. |
|
89 * @return Attribute name type. |
|
90 */ |
|
91 TCodAttr AttrName(); |
|
92 |
|
93 /** |
|
94 * Parse an attribute value. |
|
95 * @return pointer to the value. |
|
96 */ |
|
97 TPtrC AttrValue(); |
|
98 |
|
99 /** |
|
100 * Skip (optional) white space. |
|
101 */ |
|
102 void SkipWhiteSpace(); |
|
103 |
|
104 /** |
|
105 * Skip past the end of current line (ignoring anything). |
|
106 */ |
|
107 void NextLine(); |
|
108 |
|
109 /** |
|
110 * Parse *WS until ?CR LF. Set error if something else found. |
|
111 * (Advance to LF, leaving the LF as lookahead char). |
|
112 */ |
|
113 void EndOfLine(); |
|
114 |
|
115 /** |
|
116 * Parse *WS : *WS. Set error if no colon found. |
|
117 * @return ETrue if colon found. |
|
118 */ |
|
119 TBool Colon(); |
|
120 |
|
121 /** |
|
122 * Check if current character is value char. |
|
123 * @return ETrue if current character is value char. |
|
124 */ |
|
125 TBool IsValueChar() const; |
|
126 |
|
127 /** |
|
128 * Check if current character is control char. |
|
129 * @return ETrue if current character is control char. |
|
130 */ |
|
131 TBool IsControl() const; |
|
132 |
|
133 /** |
|
134 * Check if current character is white space. |
|
135 * @return ETrue if current character is white space. |
|
136 */ |
|
137 TBool IsWhiteSpace() const; |
|
138 |
|
139 /** |
|
140 * Check if current character is separator. |
|
141 * @return ETrue if current character is separator. |
|
142 */ |
|
143 TBool IsSeparator() const; |
|
144 |
|
145 /** |
|
146 * Check if current character is CR LF or LF. |
|
147 * @return ETrue if current character is CR LF or LF. |
|
148 */ |
|
149 TBool IsEndOfLine() const; |
|
150 |
|
151 /** |
|
152 * Set error code if not already set. |
|
153 * @param aError Error. |
|
154 */ |
|
155 inline void Error( TInt aError ); |
|
156 |
|
157 private: // data |
|
158 |
|
159 const TDesC* iBuf; ///< Data buffer. Not owned. |
|
160 CCodData* iData; ///< COD Data. Not owned. |
|
161 const TText* iCurP; ///< Current character position. |
|
162 const TText* iEndP; ///< End pointer (past the buffer); |
|
163 TInt iError; ///< Error code. |
|
164 |
|
165 }; |
|
166 |
|
167 #include "CodParser.inl" |
|
168 |
|
169 #endif /* def COD_PARSER_H */ |