sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // sl@0: // sl@0: // Implemetation of CDelimitedPath8 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: Static factory constructor. Uses two phase construction and leaves sl@0: nothing on the CleanupStack. sl@0: sl@0: @param aPath A descriptor with the initial path. sl@0: @return A pointer to the newly created object. sl@0: */ sl@0: EXPORT_C CDelimitedPath8* CDelimitedPath8::NewL(const TDesC8& aPath) sl@0: { sl@0: CDelimitedPath8* self = NewLC(aPath); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Static factory constructor. Uses two phase construction and leaves a pointer sl@0: to created object on the CleanupStack. sl@0: sl@0: @param aPath A descriptor with the initial path. sl@0: @return A pointer to the newly created object. sl@0: */ sl@0: EXPORT_C CDelimitedPath8* CDelimitedPath8::NewLC(const TDesC8& aPath) sl@0: { sl@0: CDelimitedPath8* self = new (ELeave) CDelimitedPath8; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aPath); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: EXPORT_C CDelimitedPath8::~CDelimitedPath8() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version in a position before sl@0: the current parsed segment. The new segment should only contain a single path segment, sl@0: as any path delimiters in the segment will be converted to an escape triple. sl@0: The parser is left in a state where its current segment is the same one as before the insertion. sl@0: sl@0: @pre The path must have been initially parsed. sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @post The path will have been extended to include the new segment. sl@0: The current segment will remain as the one before the insertion. sl@0: */ sl@0: EXPORT_C void CDelimitedPath8::InsertAndEscapeCurrentL(const TDesC8& aSegment) sl@0: { sl@0: // Create escaped version of the segment sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Insert the segment sl@0: InsertCurrentL(*escaped); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(escaped); sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version at the back of the path. sl@0: The new segment should only contain a single path segment, as any path delimiters in sl@0: the segment will be converted to an escape triple. The parser is left in a state sl@0: where its current segment is the same one as before the insertion. sl@0: sl@0: @pre The delimiter must have been set. sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @post The path will have been extended to include the new segment sl@0: */ sl@0: EXPORT_C void CDelimitedPath8::PushAndEscapeBackL(const TDesC8& aSegment) sl@0: { sl@0: // Create escaped version of the segment sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Insert the segment sl@0: PushBackL(*escaped); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(escaped); sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version at the front of the path. sl@0: The new segment should only contain a single path segment, as any path delimiters in sl@0: the segment will be converted to an escape triple. The parser is left in a state where sl@0: its current segment is the same one as before the insertion. sl@0: sl@0: @pre The delimiter must have been set. sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @post The path will have been extended to include the new segment sl@0: */ sl@0: EXPORT_C void CDelimitedPath8::PushAndEscapeFrontL(const TDesC8& aSegment) sl@0: { sl@0: // Create escaped version of the segment sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Insert the segment sl@0: PushFrontL(*escaped); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(escaped); sl@0: } sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDelimitedPath8::CDelimitedPath8() sl@0: : CDelimitedDataBase8() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Second phase of two-phase construction method. Does any allocations required to fully construct sl@0: the object. sl@0: sl@0: @param aPath A descriptor with the initial string. sl@0: @pre First phase of construction is complete. sl@0: @post The object is fully constructed. sl@0: */ sl@0: void CDelimitedPath8::ConstructL(const TDesC8& aPath) sl@0: { sl@0: // Call base class ConstructL() sl@0: CDelimitedDataBase8::ConstructL(aPath); sl@0: sl@0: // Set the delimiter to '/' sl@0: SetDelimiter(TChar('/')); sl@0: } sl@0: sl@0: // sl@0: // sl@0: // Implemetation of CDelimitedPath16 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: Static factory constructor. Uses two phase construction and leaves nothing on sl@0: the CleanupStack. sl@0: sl@0: @since 6.0 sl@0: @param aPath A descriptor with the initial path. sl@0: @return A pointer to created object. sl@0: @post Nothing left on the CleanupStack. sl@0: */ sl@0: EXPORT_C CDelimitedPath16* CDelimitedPath16::NewL(const TDesC16& aPath) sl@0: { sl@0: CDelimitedPath16* self = NewLC(aPath); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Static factory constructor. Uses two phase construction and leaves a pointer to sl@0: created object on the CleanupStack. sl@0: sl@0: @since 6.0 sl@0: @param aPath A descriptor with the initial path. sl@0: @return A pointer to created object. sl@0: @post Pointer to created object left of CleanupStack. sl@0: */ sl@0: EXPORT_C CDelimitedPath16* CDelimitedPath16::NewLC(const TDesC16& aPath) sl@0: { sl@0: CDelimitedPath16* self = new (ELeave) CDelimitedPath16; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aPath); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: @since 6.0 sl@0: */ sl@0: EXPORT_C CDelimitedPath16::~CDelimitedPath16() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version in a position before the sl@0: current parsed segment. The new segment should only contain a single path segment, as sl@0: any path delimiters in the segment will be converted to an escape triple. The parser sl@0: is left in a state where its current segment is the same one as before the insertion. sl@0: sl@0: @since 6.0 sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @pre The path must have been initially parsed. sl@0: @post The path will have been extended to include the new segment. The sl@0: current segment will remain as the one before the insertion. sl@0: */ sl@0: EXPORT_C void CDelimitedPath16::InsertAndEscapeCurrentL(const TDesC16& aSegment) sl@0: { sl@0: // Need to convert to utf8 first sl@0: HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment); sl@0: CleanupStack::PushL(utf8); sl@0: sl@0: // Create escaped version of component sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Convert back to 16-bits sl@0: HBufC16* converted = HBufC16::NewLC(escaped->Length()); sl@0: converted->Des().Copy(*escaped); sl@0: sl@0: // Insert the segment sl@0: InsertCurrentL(*converted); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version at the back of the path. sl@0: The new segment should only contain a single path segment, as any path delimiters in sl@0: the segment will be converted to an escape triple. The parser is left in a state where sl@0: its current segment is the same one as before the insertion. sl@0: sl@0: @warning A re-parse is required to ensure that the parser is valid. sl@0: @since 6.0 sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @pre The delimiter must have been set. sl@0: @post The path will have been extended to include the new segment. sl@0: */ sl@0: EXPORT_C void CDelimitedPath16::PushAndEscapeBackL(const TDesC16& aSegment) sl@0: { sl@0: // Need to convert to utf8 first sl@0: HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment); sl@0: CleanupStack::PushL(utf8); sl@0: sl@0: // Create escaped version of component sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Convert back to 16-bits sl@0: HBufC16* converted = HBufC16::NewLC(escaped->Length()); sl@0: converted->Des().Copy(*escaped); sl@0: sl@0: // Insert the segment sl@0: PushBackL(*converted); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted sl@0: } sl@0: sl@0: /** sl@0: Escape encodes the segment then inserts the escaped version at the front of the path. sl@0: The new segment should only contain a single path segment, as any path delimiters in sl@0: the segment will be converted to an escape triple. The parser is left in a state where sl@0: its current segment is the same one as before the insertion. sl@0: sl@0: @warning A re-parse is required to ensure that the parser is valid. sl@0: @since 6.0 sl@0: @param aSegment A descriptor with the unescaped path segment. sl@0: @pre The delimiter must have been set. sl@0: @post The path will have been extended to include the new segment. sl@0: */ sl@0: EXPORT_C void CDelimitedPath16::PushAndEscapeFrontL(const TDesC16& aSegment) sl@0: { sl@0: // Need to convert to utf8 first sl@0: HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment); sl@0: CleanupStack::PushL(utf8); sl@0: sl@0: // Create escaped version of component sl@0: HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath); sl@0: CleanupStack::PushL(escaped); sl@0: sl@0: // Convert back to 16-bits sl@0: HBufC16* converted = HBufC16::NewLC(escaped->Length()); sl@0: converted->Des().Copy(*escaped); sl@0: sl@0: // Insert the segment sl@0: PushFrontL(*converted); sl@0: sl@0: // Cleanup sl@0: CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted sl@0: } sl@0: sl@0: /** sl@0: Constructor. First phase of two-phase construction method. Does non-allocating construction. sl@0: sl@0: @since 6.0 sl@0: */ sl@0: CDelimitedPath16::CDelimitedPath16() sl@0: : CDelimitedDataBase16() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Second phase of two-phase construction method. Does any allocations required to fully construct sl@0: the object. sl@0: sl@0: @since 6.0 sl@0: @param aPath A descriptor with the initial path. sl@0: @pre First phase of construction is complete. sl@0: @post The object is fully constructed. sl@0: */ sl@0: void CDelimitedPath16::ConstructL(const TDesC16& aPath) sl@0: { sl@0: // Call base class ConstructL() sl@0: CDelimitedDataBase16::ConstructL(aPath); sl@0: sl@0: // Set the delimiter to '/' sl@0: SetDelimiter(TChar('/')); sl@0: }