genericservices/httputils/inc/DelimitedParser16.h
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 // This file contains the API definition for the classes TDelimitedParserBase16
       
    15 // and CDelimitedData16.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file DelimitedParser16.h
       
    21  @publishedAll
       
    22  @released	
       
    23 */
       
    24 
       
    25 #ifndef __DELIMITEDPARSER16_H__
       
    26 #define __DELIMITEDPARSER16_H__
       
    27 
       
    28 // System includes
       
    29 //
       
    30 #include <e32base.h>
       
    31 #include <delimitedparsercommon.h>
       
    32 
       
    33 
       
    34 /**
       
    35 Comments : Provides non-modifying functionality for parsing data delimited by
       
    36 a single character. The data is delimited into segments. Uses 16-bit descriptors.
       
    37 
       
    38 The object contains a descriptor with the data which can be parsed from left
       
    39 to right, or right to left. It is non-owning. The current segment can be extracted,
       
    40 which then parses the string for the next segment.
       
    41 
       
    42 This is a base class and an object of this type cannot be instantiated. It should
       
    43 be derived. The derived class should ensure that the data iDataDes is set before
       
    44 calling one of the protected parsing functions. The derived class should also ensure
       
    45 that the delimiting character has been set.
       
    46 
       
    47 If the data iDataDes has not been parsed, then calling any functionality that
       
    48 requires the data to have been parsed will result in a panic
       
    49 KDelimitedParserErrNotParsed. The data can only be parsed by calling one of the
       
    50 protected parsing functions from the derived class.
       
    51 
       
    52 If the delimiting character iDelimiter has not been set, then calling the protected
       
    53 parsing functions and some of the other public functionality that requires the
       
    54 delimiter to be set will result in a panic KDelimitingParserErrNoDelimiter.
       
    55 @publishedAll
       
    56 @released
       
    57 @since 6.0
       
    58 */
       
    59 class TDelimitedParserBase16
       
    60 	{
       
    61 public:	// Methods
       
    62 
       
    63 	IMPORT_C void Reset() const;
       
    64 	
       
    65 	IMPORT_C TInt GetNext(TPtrC16& aSegment) const;
       
    66 
       
    67 	IMPORT_C TInt Inc() const;
       
    68 
       
    69 	IMPORT_C TInt Dec() const;
       
    70 
       
    71 	IMPORT_C TInt Peek(TPtrC16& aSegment) const;
       
    72 
       
    73 	IMPORT_C TBool Eos() const;
       
    74 
       
    75 	IMPORT_C TBool FrontDelimiter() const;
       
    76 
       
    77 	IMPORT_C TBool BackDelimiter() const;
       
    78 
       
    79 	IMPORT_C const TDesC16& Des() const;
       
    80 
       
    81 	IMPORT_C TInt Remainder(TPtrC16& aRemainder) const;
       
    82 
       
    83 protected:	// Methods
       
    84 
       
    85 	IMPORT_C TDelimitedParserBase16();
       
    86 
       
    87 	IMPORT_C void Parse(const TDesC16& aData);
       
    88 
       
    89 	IMPORT_C void ParseReverse(const TDesC16& aData);
       
    90 
       
    91 	IMPORT_C void SetDelimiter(TChar aDelimiter);
       
    92 
       
    93 private:	// Methods
       
    94 
       
    95 	void DoParse(const TDesC16& aData);
       
    96 
       
    97 	TInt FindNextSegment(TInt aStartPos) const;
       
    98 
       
    99 	TInt FindPrevSegment(TInt aStartPos) const;
       
   100 
       
   101 private:	// Attributes
       
   102 
       
   103 	/** Descriptor with the string
       
   104 	 */
       
   105 	TPtrC16						iDataDes;
       
   106 
       
   107 	/** Descriptor with the current segment.
       
   108 	 */
       
   109 	mutable TPtrC16				iCurrentSegment;
       
   110 
       
   111 	/** Position of next segment.
       
   112 	 */
       
   113 	mutable TInt				iNextSegmentPos;
       
   114 
       
   115 	/** Direction of parsing.
       
   116 	 */
       
   117 	TDelimitedDataParseMode		iMode;
       
   118 
       
   119 	/** Delimiting character
       
   120 	*/
       
   121 	TInt						iDelimiter;
       
   122 
       
   123 /**
       
   124 	A friend class.
       
   125 	@see		CDelimitedDataBase16
       
   126 	@since		6.0
       
   127  */
       
   128 	friend class CDelimitedDataBase16;
       
   129 
       
   130 	};
       
   131 
       
   132 /**
       
   133 typedef 
       
   134 @publishedAll
       
   135 @released
       
   136 */
       
   137 typedef TDelimitedParserBase16 TDelimitedParserBase;
       
   138 
       
   139 /**
       
   140 Dependencies : CBase, TDelimitedParserBase16
       
   141 Comments : Provides functionality for creating and editing a delimited data object.
       
   142 Uses 16-bit descriptors
       
   143 
       
   144 The object contains a descriptor buffer with the data. Functionality is provided
       
   145 to allow segments to be added or removed from the data. There is access to the
       
   146 internal delimited data parser to provide parsing functionality to be excercised
       
   147 on the created data.
       
   148 
       
   149 This a base class that cannot be instantiated. It should be derived. The derived
       
   150 class must set the delimited data parser, which is an object derived from
       
   151 TDelimitedParserBase. This helper class must set the delimiting object
       
   152 
       
   153 If the delimiting character has not been set, then calling any of the functionality
       
   154 will cause a panic KDelimitedParserErrNoDelimiter.
       
   155 @publishedAll
       
   156 @released
       
   157 @since 6.0
       
   158 */
       
   159 class CDelimitedDataBase16 : public CBase
       
   160 	{
       
   161 public: // Methods
       
   162 
       
   163 
       
   164 	IMPORT_C ~CDelimitedDataBase16();
       
   165 
       
   166 	IMPORT_C void InsertCurrentL(const TDesC16& aSegment);
       
   167 
       
   168 	IMPORT_C void RemoveCurrentL();
       
   169 
       
   170 	IMPORT_C void PushBackL(const TDesC16& aSegment);
       
   171 
       
   172 	IMPORT_C void PopBackL();
       
   173 
       
   174 	IMPORT_C void PushFrontL(const TDesC16& aSegment);
       
   175 
       
   176 	IMPORT_C void PopFrontL();
       
   177 
       
   178 	IMPORT_C void TrimFrontDelimiterL();
       
   179 
       
   180 	IMPORT_C void AddFrontDelimiterL();
       
   181 
       
   182 	IMPORT_C void TrimBackDelimiterL();
       
   183 
       
   184 	IMPORT_C void AddBackDelimiterL();
       
   185 
       
   186 	IMPORT_C void Parse();
       
   187 
       
   188 	IMPORT_C void ParseReverse();
       
   189 
       
   190 	IMPORT_C const TDelimitedParserBase16& Parser() const;
       
   191 
       
   192 protected:	// Methods
       
   193 
       
   194 	IMPORT_C CDelimitedDataBase16();
       
   195 
       
   196 	IMPORT_C void ConstructL(const TDesC16& aData);
       
   197 
       
   198 	IMPORT_C void SetDelimiter(TChar aDelimiter);
       
   199 
       
   200 private:	// Methods
       
   201 
       
   202 	void SetDataL(const TDesC16& aData);
       
   203 
       
   204 	void SetData(HBufC16* aDataBuf);
       
   205 
       
   206 	void DoInsertL(const TDesC16& aSegment);
       
   207 
       
   208 	void DoRemoveL();
       
   209 
       
   210 private:	// Attributes
       
   211 
       
   212 	/** Descriptor buffer.
       
   213 	 */
       
   214 	HBufC16*				iDataBuf;
       
   215 
       
   216 	/** Parser object
       
   217 	 */
       
   218 	TDelimitedParserBase16	iParser;
       
   219 
       
   220 	};
       
   221 
       
   222 /**
       
   223 typedef 
       
   224 @publishedAll
       
   225 @released
       
   226 */
       
   227 typedef CDelimitedDataBase16 CDelimitedDataBase;
       
   228 
       
   229 #endif	// __DELIMITEDPARSER16_H__