os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedPathSegment.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.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <delimitedpathsegment8.h>
sl@0
    17
#include <delimitedpathsegment16.h>
sl@0
    18
#include <escapeutils.h>
sl@0
    19
sl@0
    20
//
sl@0
    21
//
sl@0
    22
// Implemetation of CDelimitedPathSegment8
sl@0
    23
//
sl@0
    24
//
sl@0
    25
sl@0
    26
/**
sl@0
    27
	Static factory constructor. Uses two phase construction and leaves nothing on 
sl@0
    28
	the CleanupStack.
sl@0
    29
	
sl@0
    30
	@since			6.0
sl@0
    31
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
    32
	@return			A pointer to created object.
sl@0
    33
	@post			Nothing left on the CleanupStack.
sl@0
    34
*/
sl@0
    35
EXPORT_C CDelimitedPathSegment8* CDelimitedPathSegment8::NewL(const TDesC8& aPathSegment)
sl@0
    36
	{
sl@0
    37
	CDelimitedPathSegment8* self = NewLC(aPathSegment);
sl@0
    38
	CleanupStack::Pop(self);
sl@0
    39
	return self;
sl@0
    40
	}
sl@0
    41
sl@0
    42
/**
sl@0
    43
	Static factory constructor. Uses two phase construction and leaves a pointer to 
sl@0
    44
	created object on the CleanupStack.
sl@0
    45
	
sl@0
    46
	@since			6.0
sl@0
    47
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
    48
	@return			A pointer to created object.
sl@0
    49
	@post			Pointer to created object left of CleanupStack.
sl@0
    50
*/
sl@0
    51
EXPORT_C CDelimitedPathSegment8* CDelimitedPathSegment8::NewLC(const TDesC8& aPathSegment)
sl@0
    52
	{
sl@0
    53
	CDelimitedPathSegment8* self = new (ELeave) CDelimitedPathSegment8;
sl@0
    54
	CleanupStack::PushL(self);
sl@0
    55
	self->ConstructL(aPathSegment);
sl@0
    56
	return self;
sl@0
    57
	}
sl@0
    58
sl@0
    59
/**
sl@0
    60
	Destructor.
sl@0
    61
	
sl@0
    62
	@since			6.0
sl@0
    63
*/
sl@0
    64
EXPORT_C CDelimitedPathSegment8::~CDelimitedPathSegment8()
sl@0
    65
	{
sl@0
    66
	}
sl@0
    67
sl@0
    68
/**
sl@0
    69
sl@0
    70
	Escape encodes the parameter then inserts the escaped version in a position before the 
sl@0
    71
	current parsed parameter. The new parameter should only contain a single path segment 
sl@0
    72
	parameter, as any parameter delimiters in the parameter will be converted to an escape 
sl@0
    73
	triple. The parser is left in a state where its current parameter is the same one as before 
sl@0
    74
	the insertion.
sl@0
    75
						
sl@0
    76
	@since			6.0
sl@0
    77
	@param			aParam	A descriptor with the unescaped path segment parameter
sl@0
    78
	@pre 			The path segment must have been initially parsed.
sl@0
    79
	@post			The path segment will have been extended to include the new 
sl@0
    80
	parameter. The current segment will remain as the one before the insertion.
sl@0
    81
*/
sl@0
    82
EXPORT_C void CDelimitedPathSegment8::InsertAndEscapeCurrentL(const TDesC8& aParam)
sl@0
    83
	{
sl@0
    84
	// Create escaped version of the parameter
sl@0
    85
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
sl@0
    86
	CleanupStack::PushL(escaped);
sl@0
    87
sl@0
    88
	// Insert the segment
sl@0
    89
	InsertCurrentL(*escaped);
sl@0
    90
sl@0
    91
	// Cleanup
sl@0
    92
	CleanupStack::PopAndDestroy(escaped);
sl@0
    93
	}
sl@0
    94
sl@0
    95
/**
sl@0
    96
	Escape encodes the parameter then inserts the escaped version at the front of the 
sl@0
    97
	path segment. The new parameter should only contain a single path segment parameter, 
sl@0
    98
	as any parameter delimiters in the parameter will be converted to an escape triple. 
sl@0
    99
	The parser is left in a state where its current parameter is the same one as before 
sl@0
   100
	the insertion.
sl@0
   101
						
sl@0
   102
	@warning		A re-parse is required to ensure that the parser is valid.
sl@0
   103
	@since			6.0
sl@0
   104
	@param			aParam	A descriptor with the unescaped path segment parameter
sl@0
   105
	@pre 			The path segment must have been initially parsed.
sl@0
   106
	@post			The path segment will have been extended to include the new 
sl@0
   107
	parameter. The current segment will remain as the one before the insertion.
sl@0
   108
*/
sl@0
   109
EXPORT_C void CDelimitedPathSegment8::PushAndEscapeBackL(const TDesC8& aParam)
sl@0
   110
	{
sl@0
   111
	// Create escaped version of the parameter
sl@0
   112
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
sl@0
   113
	CleanupStack::PushL(escaped);
sl@0
   114
sl@0
   115
	// Insert the segment
sl@0
   116
	PushBackL(*escaped);
sl@0
   117
sl@0
   118
	// Cleanup
sl@0
   119
	CleanupStack::PopAndDestroy(escaped);
sl@0
   120
	}
sl@0
   121
sl@0
   122
/**
sl@0
   123
	Escape encodes the parameter then inserts the escaped version at the back of the 
sl@0
   124
	path segment. The new parameter should only contain a single path segment parameter, 
sl@0
   125
	as any parameter delimiters in the parameter will be converted to an escape triple. 
sl@0
   126
	The parser is left in a state where its current parameter is the same one as before 
sl@0
   127
	the insertion.
sl@0
   128
						
sl@0
   129
	@warning		A re-parse is required to ensure that the parser is valid.
sl@0
   130
	@since			6.0
sl@0
   131
	@param			aParam	A descriptor with the unescaped path segment parameter.
sl@0
   132
	@pre 			The path segment must have been initially parsed.
sl@0
   133
	@post			The path segment will have been extended to include the new 
sl@0
   134
	parameter. The current segment will remain as the one before the insertion.
sl@0
   135
*/
sl@0
   136
EXPORT_C void CDelimitedPathSegment8::PushAndEscapeFrontL(const TDesC8& aParam)
sl@0
   137
	{
sl@0
   138
	// Create escaped version of the parameter
sl@0
   139
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aParam, EscapeUtils::EEscapePath);
sl@0
   140
	CleanupStack::PushL(escaped);
sl@0
   141
sl@0
   142
	// Insert the segment
sl@0
   143
	PushFrontL(*escaped);
sl@0
   144
sl@0
   145
	// Cleanup
sl@0
   146
	CleanupStack::PopAndDestroy(escaped);
sl@0
   147
	}
sl@0
   148
sl@0
   149
/**
sl@0
   150
	Constructor. First phase of two-phase construction method. Does non-allocating 
sl@0
   151
	construction.
sl@0
   152
						
sl@0
   153
	@since			6.0
sl@0
   154
*/
sl@0
   155
CDelimitedPathSegment8::CDelimitedPathSegment8()
sl@0
   156
: CDelimitedDataBase8()
sl@0
   157
	{
sl@0
   158
	}
sl@0
   159
sl@0
   160
/**
sl@0
   161
	Second phase of two-phase construction method. Does any allocations required to 
sl@0
   162
	fully construct the object.
sl@0
   163
						
sl@0
   164
	@since			6.0
sl@0
   165
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
   166
	@pre 			First phase of construction is complete.
sl@0
   167
	@post			The object is fully constructed.
sl@0
   168
*/
sl@0
   169
void CDelimitedPathSegment8::ConstructL(const TDesC8& aPathSegment)
sl@0
   170
	{
sl@0
   171
	// Call base class ConstructL()
sl@0
   172
	CDelimitedDataBase8::ConstructL(aPathSegment);
sl@0
   173
sl@0
   174
	// Set the delimiter to ';'
sl@0
   175
	SetDelimiter(TChar(';'));
sl@0
   176
	}
sl@0
   177
sl@0
   178
//
sl@0
   179
//
sl@0
   180
// Implemetation of CDelimitedPathSegment16
sl@0
   181
//
sl@0
   182
//
sl@0
   183
sl@0
   184
/**
sl@0
   185
	Static factory constructor. Uses two phase construction and leaves nothing on the 
sl@0
   186
	CleanupStack.
sl@0
   187
						
sl@0
   188
	@since			6.0
sl@0
   189
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
   190
	@return			A pointer to created object.
sl@0
   191
	@post			Nothing left on the CleanupStack.
sl@0
   192
 */
sl@0
   193
EXPORT_C CDelimitedPathSegment16* CDelimitedPathSegment16::NewL(const TDesC16& aPathSegment)
sl@0
   194
	{
sl@0
   195
	CDelimitedPathSegment16* self = NewLC(aPathSegment);
sl@0
   196
	CleanupStack::Pop(self);
sl@0
   197
	return self;
sl@0
   198
	}
sl@0
   199
sl@0
   200
/**
sl@0
   201
	Static factory constructor. Uses two phase construction and leaves a pointer to created 
sl@0
   202
	object on the CleanupStack.
sl@0
   203
						
sl@0
   204
	@since			6.0
sl@0
   205
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
   206
	@return			A pointer to created object.
sl@0
   207
	@post			Pointer to created object left of CleanupStack.
sl@0
   208
*/
sl@0
   209
EXPORT_C CDelimitedPathSegment16* CDelimitedPathSegment16::NewLC(const TDesC16& aPathSegment)
sl@0
   210
	{
sl@0
   211
	CDelimitedPathSegment16* self = new (ELeave) CDelimitedPathSegment16;
sl@0
   212
	CleanupStack::PushL(self);
sl@0
   213
	self->ConstructL(aPathSegment);
sl@0
   214
	return self;
sl@0
   215
	}
sl@0
   216
sl@0
   217
/**
sl@0
   218
	Destructor.
sl@0
   219
	
sl@0
   220
	@since			6.0
sl@0
   221
*/
sl@0
   222
EXPORT_C CDelimitedPathSegment16::~CDelimitedPathSegment16()
sl@0
   223
	{
sl@0
   224
	}
sl@0
   225
	
sl@0
   226
/**
sl@0
   227
	Escape encodes the parameter then inserts the escaped version in a position before the 
sl@0
   228
	current parsed parameter. The new parameter should only contain a single path segment 
sl@0
   229
	parameter, as any parameter delimiters in the parameter will be converted to an escape 
sl@0
   230
	triple. The parser is left in a state where its current parameter is the same one as before 
sl@0
   231
	the insertion.
sl@0
   232
						
sl@0
   233
	@since			6.0
sl@0
   234
	@param			aParam	A descriptor with the unescaped path segment parameter
sl@0
   235
	@pre 			The path segment must have been initially parsed.
sl@0
   236
	@post			The path segment will have been extended to include the new 
sl@0
   237
	parameter. The current segment will remain as the one before the insertion.
sl@0
   238
*/
sl@0
   239
EXPORT_C void CDelimitedPathSegment16::InsertAndEscapeCurrentL(const TDesC16& aParam)
sl@0
   240
	{
sl@0
   241
	// Need to convert to utf8 first
sl@0
   242
	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
sl@0
   243
	CleanupStack::PushL(utf8);
sl@0
   244
sl@0
   245
	// Create escaped version of component
sl@0
   246
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
sl@0
   247
	CleanupStack::PushL(escaped);
sl@0
   248
sl@0
   249
	// Convert back to 16-bits
sl@0
   250
	HBufC16* converted = HBufC16::NewLC(escaped->Length());
sl@0
   251
	converted->Des().Copy(*escaped);
sl@0
   252
sl@0
   253
	// Insert the segment
sl@0
   254
	InsertCurrentL(*converted);
sl@0
   255
sl@0
   256
	// Cleanup
sl@0
   257
	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
sl@0
   258
	}
sl@0
   259
sl@0
   260
/**
sl@0
   261
	Escape encodes the parameter then inserts the escaped version at the back of the path 
sl@0
   262
	segment. The new parameter should only contain a single path segment parameter, as any 
sl@0
   263
	parameter delimiters in the parameter will be converted to an escape triple. The parser 
sl@0
   264
	is left in a state where its current parameter is the same one as before the insertion.
sl@0
   265
						
sl@0
   266
	@warning		A re-parse is required to ensure that the parser is valid.
sl@0
   267
	@since			6.0
sl@0
   268
	@param			aParam	A descriptor with the unescaped path segment parameter.
sl@0
   269
	@pre 			The path segment must have been initially parsed.
sl@0
   270
	@post			The path segment will have been extended to include the new 
sl@0
   271
	parameter. The current segment will remain as the one before the insertion.
sl@0
   272
 */
sl@0
   273
EXPORT_C void CDelimitedPathSegment16::PushAndEscapeBackL(const TDesC16& aParam)
sl@0
   274
	{
sl@0
   275
	// Need to convert to utf8 first
sl@0
   276
	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
sl@0
   277
	CleanupStack::PushL(utf8);
sl@0
   278
sl@0
   279
	// Create escaped version of component
sl@0
   280
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
sl@0
   281
	CleanupStack::PushL(escaped);
sl@0
   282
sl@0
   283
	// Convert back to 16-bits
sl@0
   284
	HBufC16* converted = HBufC16::NewLC(escaped->Length());
sl@0
   285
	converted->Des().Copy(*escaped);
sl@0
   286
sl@0
   287
	// Insert the segment
sl@0
   288
	PushBackL(*converted);
sl@0
   289
sl@0
   290
	// Cleanup
sl@0
   291
	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
sl@0
   292
	}
sl@0
   293
sl@0
   294
/**
sl@0
   295
	Escape encodes the parameter then inserts the escaped version at the front of the 
sl@0
   296
	path segment. The new parameter should only contain a single path segment parameter, 
sl@0
   297
	as any parameter delimiters in the parameter will be converted to an escape triple. 
sl@0
   298
	The parser is left in a state where its current parameter is the same one as before 
sl@0
   299
	the insertion.
sl@0
   300
						
sl@0
   301
	@warning		A re-parse is required to ensure that the parser is valid.
sl@0
   302
	@since			6.0
sl@0
   303
	@param			aParam	A descriptor with the unescaped path segment parameter
sl@0
   304
	@pre 			The path segment must have been initially parsed.
sl@0
   305
	@post			The path segment will have been extended to include the new 
sl@0
   306
	parameter. The current segment will remain as the one before the insertion.
sl@0
   307
 */
sl@0
   308
EXPORT_C void CDelimitedPathSegment16::PushAndEscapeFrontL(const TDesC16& aParam)
sl@0
   309
	{
sl@0
   310
	// Need to convert to utf8 first
sl@0
   311
	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aParam);
sl@0
   312
	CleanupStack::PushL(utf8);
sl@0
   313
sl@0
   314
	// Create escaped version of component
sl@0
   315
	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
sl@0
   316
	CleanupStack::PushL(escaped);
sl@0
   317
sl@0
   318
	// Convert back to 16-bits
sl@0
   319
	HBufC16* converted = HBufC16::NewLC(escaped->Length());
sl@0
   320
	converted->Des().Copy(*escaped);
sl@0
   321
sl@0
   322
	// Insert the segment
sl@0
   323
	PushFrontL(*converted);
sl@0
   324
sl@0
   325
	// Cleanup
sl@0
   326
	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
sl@0
   327
	}
sl@0
   328
sl@0
   329
/**
sl@0
   330
	Constructor. First phase of two-phase construction method. Does non-allocating
sl@0
   331
	 construction.
sl@0
   332
						
sl@0
   333
	@since			6.0
sl@0
   334
 */
sl@0
   335
CDelimitedPathSegment16::CDelimitedPathSegment16()
sl@0
   336
: CDelimitedDataBase16()
sl@0
   337
	{
sl@0
   338
	}
sl@0
   339
sl@0
   340
/**
sl@0
   341
	Second phase of two-phase construction method. Does any allocations required to 
sl@0
   342
	fully construct the object.
sl@0
   343
						
sl@0
   344
	@since			6.0
sl@0
   345
	@param			aPathSegment	A descriptor with the initial path segment.
sl@0
   346
	@pre 			First phase of construction is complete.
sl@0
   347
	@post			The object is fully constructed.
sl@0
   348
 */
sl@0
   349
void CDelimitedPathSegment16::ConstructL(const TDesC16& aPathSegment)
sl@0
   350
	{
sl@0
   351
	// Call base class ConstructL()
sl@0
   352
	CDelimitedDataBase16::ConstructL(aPathSegment);
sl@0
   353
sl@0
   354
	// Set the delimiter to ';'
sl@0
   355
	SetDelimiter(TChar(';'));
sl@0
   356
	}
sl@0
   357