os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedPathSegment.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedPathSegment.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,357 @@
     1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <delimitedpathsegment8.h>
    1.20 +#include <delimitedpathsegment16.h>
    1.21 +#include <escapeutils.h>
    1.22 +
    1.23 +//
    1.24 +//
    1.25 +// Implemetation of CDelimitedPathSegment8
    1.26 +//
    1.27 +//
    1.28 +
    1.29 +/**
    1.30 +	Static factory constructor. Uses two phase construction and leaves nothing on 
    1.31 +	the CleanupStack.
    1.32 +	
    1.33 +	@since			6.0
    1.34 +	@param			aPathSegment	A descriptor with the initial path segment.
    1.35 +	@return			A pointer to created object.
    1.36 +	@post			Nothing left on the CleanupStack.
    1.37 +*/
    1.38 +EXPORT_C CDelimitedPathSegment8* CDelimitedPathSegment8::NewL(const TDesC8& aPathSegment)
    1.39 +	{
    1.40 +	CDelimitedPathSegment8* self = NewLC(aPathSegment);
    1.41 +	CleanupStack::Pop(self);
    1.42 +	return self;
    1.43 +	}
    1.44 +
    1.45 +/**
    1.46 +	Static factory constructor. Uses two phase construction and leaves a pointer to 
    1.47 +	created object on the CleanupStack.
    1.48 +	
    1.49 +	@since			6.0
    1.50 +	@param			aPathSegment	A descriptor with the initial path segment.
    1.51 +	@return			A pointer to created object.
    1.52 +	@post			Pointer to created object left of CleanupStack.
    1.53 +*/
    1.54 +EXPORT_C CDelimitedPathSegment8* CDelimitedPathSegment8::NewLC(const TDesC8& aPathSegment)
    1.55 +	{
    1.56 +	CDelimitedPathSegment8* self = new (ELeave) CDelimitedPathSegment8;
    1.57 +	CleanupStack::PushL(self);
    1.58 +	self->ConstructL(aPathSegment);
    1.59 +	return self;
    1.60 +	}
    1.61 +
    1.62 +/**
    1.63 +	Destructor.
    1.64 +	
    1.65 +	@since			6.0
    1.66 +*/
    1.67 +EXPORT_C CDelimitedPathSegment8::~CDelimitedPathSegment8()
    1.68 +	{
    1.69 +	}
    1.70 +
    1.71 +/**
    1.72 +
    1.73 +	Escape encodes the parameter then inserts the escaped version in a position before the 
    1.74 +	current parsed parameter. The new parameter should only contain a single path segment 
    1.75 +	parameter, as any parameter delimiters in the parameter will be converted to an escape 
    1.76 +	triple. The parser is left in a state where its current parameter is the same one as before 
    1.77 +	the insertion.
    1.78 +						
    1.79 +	@since			6.0
    1.80 +	@param			aParam	A descriptor with the unescaped path segment parameter
    1.81 +	@pre 			The path segment must have been initially parsed.
    1.82 +	@post			The path segment will have been extended to include the new 
    1.83 +	parameter. The current segment will remain as the one before the insertion.
    1.84 +*/
    1.85 +EXPORT_C void CDelimitedPathSegment8::InsertAndEscapeCurrentL(const TDesC8& aParam)
    1.86 +	{
    1.87 +	// Create escaped version of the parameter
    1.88 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
    1.89 +	CleanupStack::PushL(escaped);
    1.90 +
    1.91 +	// Insert the segment
    1.92 +	InsertCurrentL(*escaped);
    1.93 +
    1.94 +	// Cleanup
    1.95 +	CleanupStack::PopAndDestroy(escaped);
    1.96 +	}
    1.97 +
    1.98 +/**
    1.99 +	Escape encodes the parameter then inserts the escaped version at the front of the 
   1.100 +	path segment. The new parameter should only contain a single path segment parameter, 
   1.101 +	as any parameter delimiters in the parameter will be converted to an escape triple. 
   1.102 +	The parser is left in a state where its current parameter is the same one as before 
   1.103 +	the insertion.
   1.104 +						
   1.105 +	@warning		A re-parse is required to ensure that the parser is valid.
   1.106 +	@since			6.0
   1.107 +	@param			aParam	A descriptor with the unescaped path segment parameter
   1.108 +	@pre 			The path segment must have been initially parsed.
   1.109 +	@post			The path segment will have been extended to include the new 
   1.110 +	parameter. The current segment will remain as the one before the insertion.
   1.111 +*/
   1.112 +EXPORT_C void CDelimitedPathSegment8::PushAndEscapeBackL(const TDesC8& aParam)
   1.113 +	{
   1.114 +	// Create escaped version of the parameter
   1.115 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
   1.116 +	CleanupStack::PushL(escaped);
   1.117 +
   1.118 +	// Insert the segment
   1.119 +	PushBackL(*escaped);
   1.120 +
   1.121 +	// Cleanup
   1.122 +	CleanupStack::PopAndDestroy(escaped);
   1.123 +	}
   1.124 +
   1.125 +/**
   1.126 +	Escape encodes the parameter then inserts the escaped version at the back of the 
   1.127 +	path segment. The new parameter should only contain a single path segment parameter, 
   1.128 +	as any parameter delimiters in the parameter will be converted to an escape triple. 
   1.129 +	The parser is left in a state where its current parameter is the same one as before 
   1.130 +	the insertion.
   1.131 +						
   1.132 +	@warning		A re-parse is required to ensure that the parser is valid.
   1.133 +	@since			6.0
   1.134 +	@param			aParam	A descriptor with the unescaped path segment parameter.
   1.135 +	@pre 			The path segment must have been initially parsed.
   1.136 +	@post			The path segment will have been extended to include the new 
   1.137 +	parameter. The current segment will remain as the one before the insertion.
   1.138 +*/
   1.139 +EXPORT_C void CDelimitedPathSegment8::PushAndEscapeFrontL(const TDesC8& aParam)
   1.140 +	{
   1.141 +	// Create escaped version of the parameter
   1.142 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
   1.143 +	CleanupStack::PushL(escaped);
   1.144 +
   1.145 +	// Insert the segment
   1.146 +	PushFrontL(*escaped);
   1.147 +
   1.148 +	// Cleanup
   1.149 +	CleanupStack::PopAndDestroy(escaped);
   1.150 +	}
   1.151 +
   1.152 +/**
   1.153 +	Constructor. First phase of two-phase construction method. Does non-allocating 
   1.154 +	construction.
   1.155 +						
   1.156 +	@since			6.0
   1.157 +*/
   1.158 +CDelimitedPathSegment8::CDelimitedPathSegment8()
   1.159 +: CDelimitedDataBase8()
   1.160 +	{
   1.161 +	}
   1.162 +
   1.163 +/**
   1.164 +	Second phase of two-phase construction method. Does any allocations required to 
   1.165 +	fully construct the object.
   1.166 +						
   1.167 +	@since			6.0
   1.168 +	@param			aPathSegment	A descriptor with the initial path segment.
   1.169 +	@pre 			First phase of construction is complete.
   1.170 +	@post			The object is fully constructed.
   1.171 +*/
   1.172 +void CDelimitedPathSegment8::ConstructL(const TDesC8& aPathSegment)
   1.173 +	{
   1.174 +	// Call base class ConstructL()
   1.175 +	CDelimitedDataBase8::ConstructL(aPathSegment);
   1.176 +
   1.177 +	// Set the delimiter to ';'
   1.178 +	SetDelimiter(TChar(';'));
   1.179 +	}
   1.180 +
   1.181 +//
   1.182 +//
   1.183 +// Implemetation of CDelimitedPathSegment16
   1.184 +//
   1.185 +//
   1.186 +
   1.187 +/**
   1.188 +	Static factory constructor. Uses two phase construction and leaves nothing on the 
   1.189 +	CleanupStack.
   1.190 +						
   1.191 +	@since			6.0
   1.192 +	@param			aPathSegment	A descriptor with the initial path segment.
   1.193 +	@return			A pointer to created object.
   1.194 +	@post			Nothing left on the CleanupStack.
   1.195 + */
   1.196 +EXPORT_C CDelimitedPathSegment16* CDelimitedPathSegment16::NewL(const TDesC16& aPathSegment)
   1.197 +	{
   1.198 +	CDelimitedPathSegment16* self = NewLC(aPathSegment);
   1.199 +	CleanupStack::Pop(self);
   1.200 +	return self;
   1.201 +	}
   1.202 +
   1.203 +/**
   1.204 +	Static factory constructor. Uses two phase construction and leaves a pointer to created 
   1.205 +	object on the CleanupStack.
   1.206 +						
   1.207 +	@since			6.0
   1.208 +	@param			aPathSegment	A descriptor with the initial path segment.
   1.209 +	@return			A pointer to created object.
   1.210 +	@post			Pointer to created object left of CleanupStack.
   1.211 +*/
   1.212 +EXPORT_C CDelimitedPathSegment16* CDelimitedPathSegment16::NewLC(const TDesC16& aPathSegment)
   1.213 +	{
   1.214 +	CDelimitedPathSegment16* self = new (ELeave) CDelimitedPathSegment16;
   1.215 +	CleanupStack::PushL(self);
   1.216 +	self->ConstructL(aPathSegment);
   1.217 +	return self;
   1.218 +	}
   1.219 +
   1.220 +/**
   1.221 +	Destructor.
   1.222 +	
   1.223 +	@since			6.0
   1.224 +*/
   1.225 +EXPORT_C CDelimitedPathSegment16::~CDelimitedPathSegment16()
   1.226 +	{
   1.227 +	}
   1.228 +	
   1.229 +/**
   1.230 +	Escape encodes the parameter then inserts the escaped version in a position before the 
   1.231 +	current parsed parameter. The new parameter should only contain a single path segment 
   1.232 +	parameter, as any parameter delimiters in the parameter will be converted to an escape 
   1.233 +	triple. The parser is left in a state where its current parameter is the same one as before 
   1.234 +	the insertion.
   1.235 +						
   1.236 +	@since			6.0
   1.237 +	@param			aParam	A descriptor with the unescaped path segment parameter
   1.238 +	@pre 			The path segment must have been initially parsed.
   1.239 +	@post			The path segment will have been extended to include the new 
   1.240 +	parameter. The current segment will remain as the one before the insertion.
   1.241 +*/
   1.242 +EXPORT_C void CDelimitedPathSegment16::InsertAndEscapeCurrentL(const TDesC16& aParam)
   1.243 +	{
   1.244 +	// Need to convert to utf8 first
   1.245 +	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
   1.246 +	CleanupStack::PushL(utf8);
   1.247 +
   1.248 +	// Create escaped version of component
   1.249 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   1.250 +	CleanupStack::PushL(escaped);
   1.251 +
   1.252 +	// Convert back to 16-bits
   1.253 +	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   1.254 +	converted->Des().Copy(*escaped);
   1.255 +
   1.256 +	// Insert the segment
   1.257 +	InsertCurrentL(*converted);
   1.258 +
   1.259 +	// Cleanup
   1.260 +	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   1.261 +	}
   1.262 +
   1.263 +/**
   1.264 +	Escape encodes the parameter then inserts the escaped version at the back of the path 
   1.265 +	segment. The new parameter should only contain a single path segment parameter, as any 
   1.266 +	parameter delimiters in the parameter will be converted to an escape triple. The parser 
   1.267 +	is left in a state where its current parameter is the same one as before the insertion.
   1.268 +						
   1.269 +	@warning		A re-parse is required to ensure that the parser is valid.
   1.270 +	@since			6.0
   1.271 +	@param			aParam	A descriptor with the unescaped path segment parameter.
   1.272 +	@pre 			The path segment must have been initially parsed.
   1.273 +	@post			The path segment will have been extended to include the new 
   1.274 +	parameter. The current segment will remain as the one before the insertion.
   1.275 + */
   1.276 +EXPORT_C void CDelimitedPathSegment16::PushAndEscapeBackL(const TDesC16& aParam)
   1.277 +	{
   1.278 +	// Need to convert to utf8 first
   1.279 +	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
   1.280 +	CleanupStack::PushL(utf8);
   1.281 +
   1.282 +	// Create escaped version of component
   1.283 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   1.284 +	CleanupStack::PushL(escaped);
   1.285 +
   1.286 +	// Convert back to 16-bits
   1.287 +	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   1.288 +	converted->Des().Copy(*escaped);
   1.289 +
   1.290 +	// Insert the segment
   1.291 +	PushBackL(*converted);
   1.292 +
   1.293 +	// Cleanup
   1.294 +	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   1.295 +	}
   1.296 +
   1.297 +/**
   1.298 +	Escape encodes the parameter then inserts the escaped version at the front of the 
   1.299 +	path segment. The new parameter should only contain a single path segment parameter, 
   1.300 +	as any parameter delimiters in the parameter will be converted to an escape triple. 
   1.301 +	The parser is left in a state where its current parameter is the same one as before 
   1.302 +	the insertion.
   1.303 +						
   1.304 +	@warning		A re-parse is required to ensure that the parser is valid.
   1.305 +	@since			6.0
   1.306 +	@param			aParam	A descriptor with the unescaped path segment parameter
   1.307 +	@pre 			The path segment must have been initially parsed.
   1.308 +	@post			The path segment will have been extended to include the new 
   1.309 +	parameter. The current segment will remain as the one before the insertion.
   1.310 + */
   1.311 +EXPORT_C void CDelimitedPathSegment16::PushAndEscapeFrontL(const TDesC16& aParam)
   1.312 +	{
   1.313 +	// Need to convert to utf8 first
   1.314 +	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
   1.315 +	CleanupStack::PushL(utf8);
   1.316 +
   1.317 +	// Create escaped version of component
   1.318 +	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   1.319 +	CleanupStack::PushL(escaped);
   1.320 +
   1.321 +	// Convert back to 16-bits
   1.322 +	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   1.323 +	converted->Des().Copy(*escaped);
   1.324 +
   1.325 +	// Insert the segment
   1.326 +	PushFrontL(*converted);
   1.327 +
   1.328 +	// Cleanup
   1.329 +	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   1.330 +	}
   1.331 +
   1.332 +/**
   1.333 +	Constructor. First phase of two-phase construction method. Does non-allocating
   1.334 +	 construction.
   1.335 +						
   1.336 +	@since			6.0
   1.337 + */
   1.338 +CDelimitedPathSegment16::CDelimitedPathSegment16()
   1.339 +: CDelimitedDataBase16()
   1.340 +	{
   1.341 +	}
   1.342 +
   1.343 +/**
   1.344 +	Second phase of two-phase construction method. Does any allocations required to 
   1.345 +	fully construct the object.
   1.346 +						
   1.347 +	@since			6.0
   1.348 +	@param			aPathSegment	A descriptor with the initial path segment.
   1.349 +	@pre 			First phase of construction is complete.
   1.350 +	@post			The object is fully constructed.
   1.351 + */
   1.352 +void CDelimitedPathSegment16::ConstructL(const TDesC16& aPathSegment)
   1.353 +	{
   1.354 +	// Call base class ConstructL()
   1.355 +	CDelimitedDataBase16::ConstructL(aPathSegment);
   1.356 +
   1.357 +	// Set the delimiter to ';'
   1.358 +	SetDelimiter(TChar(';'));
   1.359 +	}
   1.360 +