williamr@2: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // A string class implementation which allows quick addition of partial strings williamr@2: // (no copying) by using an internal array of fragmented strings. williamr@2: // The class allows comprehensive character based matching functionality williamr@2: // along with infinite depth marking. williamr@2: // williamr@2: // williamr@2: williamr@2: #ifndef __CFRAGMENTEDSTRING_H__ williamr@2: #define __CFRAGMENTEDSTRING_H__ williamr@2: williamr@2: // includes williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: // williamr@2: // CFragmentedString williamr@2: williamr@2: //##ModelId=3B666BC6034A williamr@2: williamr@2: williamr@2: williamr@2: class CFragmentedString : protected CArrayPtrFlat williamr@2: /** williamr@2: Utility that allows a single string to be built from an array of consecutive sub-strings. williamr@2: williamr@2: The sub-strings can be inserted by reference or copied. williamr@2: williamr@2: The object maintains information that points to a current position within the string. A typical williamr@2: use is to test the contents of the string using one of the Match...() functions, and then use williamr@2: ConsumeMatched() to advance past the matched area. williamr@2: williamr@2: The class also supports inserting an unlimited number of marks in the string, and performing williamr@2: operations relative to the head (i.e. last inserted) mark. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: protected: williamr@2: class TStringMark williamr@2: /** A mark at a string position. */ williamr@2: { williamr@2: public: williamr@2: /** Constructor. williamr@2: williamr@2: @param aIndex Array index of the marked sub-string williamr@2: @param aCharacter Character position within the sub-string for the mark williamr@2: */ williamr@2: TStringMark(TInt aIndex, TInt aCharacter) williamr@2: : iMarkIndex(aIndex), iMarkCharacter(aCharacter) williamr@2: { williamr@2: } williamr@2: williamr@2: public: williamr@2: /** Array index of the marked sub-string. */ williamr@2: TInt iMarkIndex; williamr@2: /** Character position within the sub-string for the mark. */ williamr@2: TInt iMarkCharacter; williamr@2: }; williamr@2: /** A stack of string position marks. */ williamr@2: typedef CStack CMarkStack; williamr@2: williamr@2: public: williamr@2: /** Defines possible results of a string matching operation for this class. */ williamr@2: enum TStringMatch williamr@2: { williamr@2: /** There was no match. */ williamr@2: ENoMatch, williamr@2: /** There was a complete match. */ williamr@2: EMatch, williamr@2: /** String contained insufficient data to perform the match operation. williamr@2: williamr@2: This can mean that the start of the target string was matched, but the string williamr@2: being searched ended before a complete match was found. */ williamr@2: EInsufficientData williamr@2: }; williamr@2: williamr@2: public: williamr@2: IMPORT_C CFragmentedString(); williamr@2: //##ModelId=3B666BC700AD williamr@2: IMPORT_C ~CFragmentedString(); williamr@2: williamr@2: //##ModelId=3B666BC70099 williamr@2: IMPORT_C void AddStringL(HBufC* aString); // this version is more efficient williamr@2: //##ModelId=3B666BC700A3 williamr@2: IMPORT_C void AddStringL(const TDesC& aString); williamr@2: williamr@2: //##ModelId=3B666BC70090 williamr@2: IMPORT_C TInt Length() const; williamr@2: //##ModelId=3B666BC70071 williamr@2: IMPORT_C HBufC* StringL() const; williamr@2: //##ModelId=3B666BC70068 williamr@2: IMPORT_C HBufC* ContentL() const; williamr@2: //##ModelId=3B666BC70067 williamr@2: IMPORT_C void Reset(); williamr@2: williamr@2: //##ModelId=3B666BC7005D williamr@2: IMPORT_C TStringMatch Match(const TDesC& aString); williamr@2: //##ModelId=3B666BC70049 williamr@2: IMPORT_C TStringMatch MatchRange(const TUint aLower, const TUint aUpper); williamr@2: //##ModelId=3B666BC7003F williamr@2: IMPORT_C TStringMatch MatchSelect(const TDesC& aSelection); williamr@2: //##ModelId=3B666BC70037 williamr@2: IMPORT_C TStringMatch MatchNotSelect(const TDesC& aSelection); williamr@2: //##ModelId=3B666BC70036 williamr@2: IMPORT_C void ConsumeMatched(); williamr@2: williamr@2: //##ModelId=3B666BC70035 williamr@2: IMPORT_C HBufC* MarkedL(); williamr@2: //##ModelId=3B666BC7002B williamr@2: IMPORT_C HBufC* MarkedWithInitialTextL(const TDesC& aInitialText); williamr@2: //##ModelId=3B666BC70022 williamr@2: IMPORT_C void Mark(); // Mark can leave williamr@2: //##ModelId=3B666BC70021 williamr@2: IMPORT_C void DeleteMark(); williamr@2: //##ModelId=3B666BC70018 williamr@2: IMPORT_C void ResetToMark(); williamr@2: williamr@2: //##ModelId=3B666BC7000E williamr@2: IMPORT_C void ReplaceMarkedL(HBufC* aString); williamr@2: //##ModelId=3B666BC70005 williamr@2: IMPORT_C void ReplaceMarkedAndSkipL(HBufC* aString); williamr@2: //##ModelId=3B666BC70003 williamr@2: IMPORT_C void InsertStringL(HBufC* aString); williamr@2: williamr@2: protected: williamr@2: //##ModelId=3B666BC603E1 williamr@2: IMPORT_C void DeleteToMark(const TStringMark& aStringMark); williamr@2: //##ModelId=3B666BC603C4 williamr@2: IMPORT_C void InsertStringToL(HBufC* aString, TInt aStringIndex, TInt aLengthIntoString); williamr@2: //##ModelId=3B666BC70072 williamr@2: HBufC* StringL(TInt aStartIndex, TInt aStartCharacter, TInt aEndIndex, TInt aEndCharacter, const TDesC* aInitialText=NULL) const; williamr@2: //##ModelId=3B666BC603C3 williamr@2: void StartMatch(); williamr@2: //##ModelId=3B666BC603B8 williamr@2: CFragmentedString::TStringMatch DoMatchSelect(const TDesC& aSelection, TBool aInSelection); williamr@2: //##ModelId=3B666BC603AE williamr@2: TBool FindNextMatchChar(TUint& aChar); williamr@2: williamr@2: protected: williamr@2: //##ModelId=3B666BC603A4 williamr@2: /** Result of the last match operation. */ williamr@2: TStringMatch iMatched; williamr@2: williamr@2: /** Array index of the sub-string found in the last match operation. */ williamr@2: //##ModelId=3B666BC6039A williamr@2: TInt iMatchedToIndex; williamr@2: /** Current character position within the iMatchedToIndex sub-string found in the last match operation. */ williamr@2: //##ModelId=3B666BC60390 williamr@2: TInt iMatchedToCharacter; williamr@2: /** Array index of the current sub-string. */ williamr@2: //##ModelId=3B666BC60386 williamr@2: TInt iCurrentIndex; williamr@2: /** Current character position within the current sub-string. */ williamr@2: //##ModelId=3B666BC6037C williamr@2: TInt iCurrentCharacter; williamr@2: /** Stack of marks in the string. williamr@2: williamr@2: Mark() pushes a mark on the stack; DeleteMark() pops one off. williamr@2: */ williamr@2: //##ModelId=3B666BC60372 williamr@2: CMarkStack iMarkStack; williamr@2: }; williamr@2: williamr@2: #endif // __CFRAGMENTEDSTRING_H__