First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <delimitedpath8.h>
17 #include <delimitedpath16.h>
18 #include <escapeutils.h>
22 // Implemetation of CDelimitedPath8
27 Static factory constructor. Uses two phase construction and leaves
28 nothing on the CleanupStack.
30 @param aPath A descriptor with the initial path.
31 @return A pointer to the newly created object.
33 EXPORT_C CDelimitedPath8* CDelimitedPath8::NewL(const TDesC8& aPath)
35 CDelimitedPath8* self = NewLC(aPath);
36 CleanupStack::Pop(self);
41 Static factory constructor. Uses two phase construction and leaves a pointer
42 to created object on the CleanupStack.
44 @param aPath A descriptor with the initial path.
45 @return A pointer to the newly created object.
47 EXPORT_C CDelimitedPath8* CDelimitedPath8::NewLC(const TDesC8& aPath)
49 CDelimitedPath8* self = new (ELeave) CDelimitedPath8;
50 CleanupStack::PushL(self);
51 self->ConstructL(aPath);
58 EXPORT_C CDelimitedPath8::~CDelimitedPath8()
63 Escape encodes the segment then inserts the escaped version in a position before
64 the current parsed segment. The new segment should only contain a single path segment,
65 as any path delimiters in the segment will be converted to an escape triple.
66 The parser is left in a state where its current segment is the same one as before the insertion.
68 @pre The path must have been initially parsed.
69 @param aSegment A descriptor with the unescaped path segment.
70 @post The path will have been extended to include the new segment.
71 The current segment will remain as the one before the insertion.
73 EXPORT_C void CDelimitedPath8::InsertAndEscapeCurrentL(const TDesC8& aSegment)
75 // Create escaped version of the segment
76 HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
77 CleanupStack::PushL(escaped);
80 InsertCurrentL(*escaped);
83 CleanupStack::PopAndDestroy(escaped);
87 Escape encodes the segment then inserts the escaped version at the back of the path.
88 The new segment should only contain a single path segment, as any path delimiters in
89 the segment will be converted to an escape triple. The parser is left in a state
90 where its current segment is the same one as before the insertion.
92 @pre The delimiter must have been set.
93 @param aSegment A descriptor with the unescaped path segment.
94 @post The path will have been extended to include the new segment
96 EXPORT_C void CDelimitedPath8::PushAndEscapeBackL(const TDesC8& aSegment)
98 // Create escaped version of the segment
99 HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
100 CleanupStack::PushL(escaped);
102 // Insert the segment
106 CleanupStack::PopAndDestroy(escaped);
110 Escape encodes the segment then inserts the escaped version at the front of the path.
111 The new segment should only contain a single path segment, as any path delimiters in
112 the segment will be converted to an escape triple. The parser is left in a state where
113 its current segment is the same one as before the insertion.
115 @pre The delimiter must have been set.
116 @param aSegment A descriptor with the unescaped path segment.
117 @post The path will have been extended to include the new segment
119 EXPORT_C void CDelimitedPath8::PushAndEscapeFrontL(const TDesC8& aSegment)
121 // Create escaped version of the segment
122 HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
123 CleanupStack::PushL(escaped);
125 // Insert the segment
126 PushFrontL(*escaped);
129 CleanupStack::PopAndDestroy(escaped);
135 CDelimitedPath8::CDelimitedPath8()
136 : CDelimitedDataBase8()
141 Second phase of two-phase construction method. Does any allocations required to fully construct
144 @param aPath A descriptor with the initial string.
145 @pre First phase of construction is complete.
146 @post The object is fully constructed.
148 void CDelimitedPath8::ConstructL(const TDesC8& aPath)
150 // Call base class ConstructL()
151 CDelimitedDataBase8::ConstructL(aPath);
153 // Set the delimiter to '/'
154 SetDelimiter(TChar('/'));
159 // Implemetation of CDelimitedPath16
164 Static factory constructor. Uses two phase construction and leaves nothing on
168 @param aPath A descriptor with the initial path.
169 @return A pointer to created object.
170 @post Nothing left on the CleanupStack.
172 EXPORT_C CDelimitedPath16* CDelimitedPath16::NewL(const TDesC16& aPath)
174 CDelimitedPath16* self = NewLC(aPath);
175 CleanupStack::Pop(self);
180 Static factory constructor. Uses two phase construction and leaves a pointer to
181 created object on the CleanupStack.
184 @param aPath A descriptor with the initial path.
185 @return A pointer to created object.
186 @post Pointer to created object left of CleanupStack.
188 EXPORT_C CDelimitedPath16* CDelimitedPath16::NewLC(const TDesC16& aPath)
190 CDelimitedPath16* self = new (ELeave) CDelimitedPath16;
191 CleanupStack::PushL(self);
192 self->ConstructL(aPath);
201 EXPORT_C CDelimitedPath16::~CDelimitedPath16()
206 Escape encodes the segment then inserts the escaped version in a position before the
207 current parsed segment. The new segment should only contain a single path segment, as
208 any path delimiters in the segment will be converted to an escape triple. The parser
209 is left in a state where its current segment is the same one as before the insertion.
212 @param aSegment A descriptor with the unescaped path segment.
213 @pre The path must have been initially parsed.
214 @post The path will have been extended to include the new segment. The
215 current segment will remain as the one before the insertion.
217 EXPORT_C void CDelimitedPath16::InsertAndEscapeCurrentL(const TDesC16& aSegment)
219 // Need to convert to utf8 first
220 HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
221 CleanupStack::PushL(utf8);
223 // Create escaped version of component
224 HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
225 CleanupStack::PushL(escaped);
227 // Convert back to 16-bits
228 HBufC16* converted = HBufC16::NewLC(escaped->Length());
229 converted->Des().Copy(*escaped);
231 // Insert the segment
232 InsertCurrentL(*converted);
235 CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
239 Escape encodes the segment then inserts the escaped version at the back of the path.
240 The new segment should only contain a single path segment, as any path delimiters in
241 the segment will be converted to an escape triple. The parser is left in a state where
242 its current segment is the same one as before the insertion.
244 @warning A re-parse is required to ensure that the parser is valid.
246 @param aSegment A descriptor with the unescaped path segment.
247 @pre The delimiter must have been set.
248 @post The path will have been extended to include the new segment.
250 EXPORT_C void CDelimitedPath16::PushAndEscapeBackL(const TDesC16& aSegment)
252 // Need to convert to utf8 first
253 HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
254 CleanupStack::PushL(utf8);
256 // Create escaped version of component
257 HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
258 CleanupStack::PushL(escaped);
260 // Convert back to 16-bits
261 HBufC16* converted = HBufC16::NewLC(escaped->Length());
262 converted->Des().Copy(*escaped);
264 // Insert the segment
265 PushBackL(*converted);
268 CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
272 Escape encodes the segment then inserts the escaped version at the front of the path.
273 The new segment should only contain a single path segment, as any path delimiters in
274 the segment will be converted to an escape triple. The parser is left in a state where
275 its current segment is the same one as before the insertion.
277 @warning A re-parse is required to ensure that the parser is valid.
279 @param aSegment A descriptor with the unescaped path segment.
280 @pre The delimiter must have been set.
281 @post The path will have been extended to include the new segment.
283 EXPORT_C void CDelimitedPath16::PushAndEscapeFrontL(const TDesC16& aSegment)
285 // Need to convert to utf8 first
286 HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
287 CleanupStack::PushL(utf8);
289 // Create escaped version of component
290 HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
291 CleanupStack::PushL(escaped);
293 // Convert back to 16-bits
294 HBufC16* converted = HBufC16::NewLC(escaped->Length());
295 converted->Des().Copy(*escaped);
297 // Insert the segment
298 PushFrontL(*converted);
301 CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
305 Constructor. First phase of two-phase construction method. Does non-allocating construction.
309 CDelimitedPath16::CDelimitedPath16()
310 : CDelimitedDataBase16()
315 Second phase of two-phase construction method. Does any allocations required to fully construct
319 @param aPath A descriptor with the initial path.
320 @pre First phase of construction is complete.
321 @post The object is fully constructed.
323 void CDelimitedPath16::ConstructL(const TDesC16& aPath)
325 // Call base class ConstructL()
326 CDelimitedDataBase16::ConstructL(aPath);
328 // Set the delimiter to '/'
329 SetDelimiter(TChar('/'));