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