os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedPath.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <delimitedpath8.h>
    17 #include <delimitedpath16.h>
    18 #include <escapeutils.h>
    19 
    20 //
    21 //
    22 // Implemetation of CDelimitedPath8
    23 //
    24 //
    25 
    26 /**
    27 	Static factory constructor. Uses two phase construction and leaves 
    28 	nothing on the CleanupStack. 
    29 	
    30 	@param			aPath	A descriptor with the initial path.
    31 	@return			A pointer to the newly created object. 
    32  */
    33 EXPORT_C CDelimitedPath8* CDelimitedPath8::NewL(const TDesC8& aPath)
    34 	{
    35 	CDelimitedPath8* self = NewLC(aPath);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 /**
    41 	Static factory constructor. Uses two phase construction and leaves a pointer 
    42 	to created object on the CleanupStack. 
    43 
    44 	@param			aPath	A descriptor with the initial path.
    45 	@return			A pointer to the newly created object.
    46  */
    47 EXPORT_C CDelimitedPath8* CDelimitedPath8::NewLC(const TDesC8& aPath)
    48 	{
    49 	CDelimitedPath8* self = new (ELeave) CDelimitedPath8;
    50 	CleanupStack::PushL(self);
    51 	self->ConstructL(aPath);
    52 	return self;
    53 	}
    54 
    55 /**
    56 	Destructor. 
    57 */
    58 EXPORT_C CDelimitedPath8::~CDelimitedPath8()
    59 	{
    60 	}
    61 
    62 /**
    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.
    67 
    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.
    72  */
    73 EXPORT_C void CDelimitedPath8::InsertAndEscapeCurrentL(const TDesC8& aSegment)
    74 	{
    75 	// Create escaped version of the segment
    76 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
    77 	CleanupStack::PushL(escaped);
    78 
    79 	// Insert the segment
    80 	InsertCurrentL(*escaped);
    81 
    82 	// Cleanup
    83 	CleanupStack::PopAndDestroy(escaped);
    84 	}
    85 
    86 /**
    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. 
    91 
    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
    95  */
    96 EXPORT_C void CDelimitedPath8::PushAndEscapeBackL(const TDesC8& aSegment)
    97 	{
    98 	// Create escaped version of the segment
    99 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
   100 	CleanupStack::PushL(escaped);
   101 
   102 	// Insert the segment
   103 	PushBackL(*escaped);
   104 
   105 	// Cleanup
   106 	CleanupStack::PopAndDestroy(escaped);
   107 	}
   108 
   109 /**
   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. 
   114 
   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
   118  */
   119 EXPORT_C void CDelimitedPath8::PushAndEscapeFrontL(const TDesC8& aSegment)
   120 	{
   121 	// Create escaped version of the segment
   122 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
   123 	CleanupStack::PushL(escaped);
   124 
   125 	// Insert the segment
   126 	PushFrontL(*escaped);
   127 
   128 	// Cleanup
   129 	CleanupStack::PopAndDestroy(escaped);
   130 	}
   131 
   132 /**
   133 	Constructor.
   134 */
   135 CDelimitedPath8::CDelimitedPath8()
   136 : CDelimitedDataBase8()
   137 	{
   138 	}
   139 
   140 /**
   141 	Second phase of two-phase construction method. Does any allocations required to fully construct 
   142 	the object.
   143 
   144 	@param			aPath	A descriptor with the initial string.
   145 	@pre 			First phase of construction is complete.
   146 	@post			The object is fully constructed.
   147 */
   148 void CDelimitedPath8::ConstructL(const TDesC8& aPath)
   149 	{
   150 	// Call base class ConstructL()
   151 	CDelimitedDataBase8::ConstructL(aPath);
   152 
   153 	// Set the delimiter to '/'
   154 	SetDelimiter(TChar('/'));
   155 	}
   156 
   157 //
   158 //
   159 // Implemetation of CDelimitedPath16
   160 //
   161 //
   162 
   163 /**
   164 	Static factory constructor. Uses two phase construction and leaves nothing on 
   165 	the CleanupStack.
   166 						
   167 	@since			6.0
   168 	@param			aPath	A descriptor with the initial path.
   169 	@return			A pointer to created object.
   170 	@post			Nothing left on the CleanupStack.
   171  */
   172 EXPORT_C CDelimitedPath16* CDelimitedPath16::NewL(const TDesC16& aPath)
   173 	{
   174 	CDelimitedPath16* self = NewLC(aPath);
   175 	CleanupStack::Pop(self);
   176 	return self;
   177 	}
   178 
   179 /**
   180 	Static factory constructor. Uses two phase construction and leaves a pointer to 
   181 	created object on the CleanupStack.
   182 						
   183 	@since			6.0
   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.
   187 */
   188 EXPORT_C CDelimitedPath16* CDelimitedPath16::NewLC(const TDesC16& aPath)
   189 	{
   190 	CDelimitedPath16* self = new (ELeave) CDelimitedPath16;
   191 	CleanupStack::PushL(self);
   192 	self->ConstructL(aPath);
   193 	return self;
   194 	}
   195 
   196 /**
   197 	Destructor.
   198 	
   199 	@since			6.0
   200 */
   201 EXPORT_C CDelimitedPath16::~CDelimitedPath16()
   202 	{
   203 	}
   204 
   205 /**
   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.
   210 						
   211 	@since			6.0
   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.
   216 */
   217 EXPORT_C void CDelimitedPath16::InsertAndEscapeCurrentL(const TDesC16& aSegment)
   218 	{
   219 	// Need to convert to utf8 first
   220 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   221 	CleanupStack::PushL(utf8);
   222 
   223 	// Create escaped version of component
   224 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   225 	CleanupStack::PushL(escaped);
   226 
   227 	// Convert back to 16-bits
   228 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   229 	converted->Des().Copy(*escaped);
   230 
   231 	// Insert the segment
   232 	InsertCurrentL(*converted);
   233 
   234 	// Cleanup
   235 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   236 	}
   237 
   238 /**
   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.
   243 						
   244 	@warning		A re-parse is required to ensure that the parser is valid.
   245 	@since			6.0
   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.
   249 */
   250 EXPORT_C void CDelimitedPath16::PushAndEscapeBackL(const TDesC16& aSegment)
   251 	{
   252 	// Need to convert to utf8 first
   253 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   254 	CleanupStack::PushL(utf8);
   255 
   256 	// Create escaped version of component
   257 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   258 	CleanupStack::PushL(escaped);
   259 
   260 	// Convert back to 16-bits
   261 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   262 	converted->Des().Copy(*escaped);
   263 
   264 	// Insert the segment
   265 	PushBackL(*converted);
   266 
   267 	// Cleanup
   268 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   269 	}
   270 
   271 /**
   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.
   276 						
   277 	@warning		A re-parse is required to ensure that the parser is valid.
   278 	@since			6.0
   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.
   282 */
   283 EXPORT_C void CDelimitedPath16::PushAndEscapeFrontL(const TDesC16& aSegment)
   284 	{
   285 	// Need to convert to utf8 first
   286 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   287 	CleanupStack::PushL(utf8);
   288 
   289 	// Create escaped version of component
   290 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   291 	CleanupStack::PushL(escaped);
   292 
   293 	// Convert back to 16-bits
   294 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   295 	converted->Des().Copy(*escaped);
   296 
   297 	// Insert the segment
   298 	PushFrontL(*converted);
   299 
   300 	// Cleanup
   301 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   302 	}
   303 
   304 /**
   305 	Constructor. First phase of two-phase construction method. Does non-allocating construction.
   306 						
   307 	@since			6.0
   308 */
   309 CDelimitedPath16::CDelimitedPath16()
   310 : CDelimitedDataBase16()
   311 	{
   312 	}
   313 
   314 /**
   315 	Second phase of two-phase construction method. Does any allocations required to fully construct 
   316 	the object.
   317 						
   318 	@since			6.0
   319 	@param			aPath	A descriptor with the initial path.
   320 	@pre 			First phase of construction is complete.
   321 	@post			The object is fully constructed.
   322 */
   323 void CDelimitedPath16::ConstructL(const TDesC16& aPath)
   324 	{
   325 	// Call base class ConstructL()
   326 	CDelimitedDataBase16::ConstructL(aPath);
   327 
   328 	// Set the delimiter to '/'
   329 	SetDelimiter(TChar('/'));
   330 	}