1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/unicode/CompareImp.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,241 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Folding and decomposition implementation
1.18 +//
1.19 +//
1.20 +
1.21 +#ifndef __COMPAREIMP_H__
1.22 +#define __COMPAREIMP_H__
1.23 +
1.24 +#include <e32std.h>
1.25 +#include <unicode.h>
1.26 +
1.27 +//Forward declarations
1.28 +class TUTF32Iterator;
1.29 +
1.30 +//////////////////////////////////////////////////////////////////////////////////////////////
1.31 +// Global functions
1.32 +//////////////////////////////////////////////////////////////////////////////////////////////
1.33 +
1.34 +TChar UTF16ToChar(const TText16* a);
1.35 +TBool IsBaseCharacter(TChar);
1.36 +
1.37 +TBool MatchSectionFolded(TUTF32Iterator& aCandidateString, TUTF32Iterator& aSearchTerm);
1.38 +
1.39 +TBool FindMatchSectionFolded(TUTF32Iterator& aCandidateString, TUTF32Iterator& aSearchTerm);
1.40 +
1.41 +TBool MatchStringFolded(const TText16* aCandidateStringStart, const TText16* aCandidateStringEnd,
1.42 + const TText16* aSearchTermStart, const TText16* aSearchTermEnd);
1.43 +
1.44 +TInt LocateMatchStringFolded(const TText16* aCandidateStringStart, const TText16* aCandidateStringEnd,
1.45 + const TText16* aSearchTermStart, const TText16* aSearchTermEnd);
1.46 +
1.47 +TInt FindFolded(TUTF32Iterator& aCandidateString, TUTF32Iterator& aSearchTerm);
1.48 +
1.49 +TInt CompareFolded(const TUTF32Iterator& aLeft, const TUTF32Iterator& aRight);
1.50 +
1.51 +TInt CombineAsMuchAsPossible(const TDesC16& aDes, TChar& aCombined);
1.52 +
1.53 +TBool DecomposeChar(TChar aCh, TPtrC16& aResult);
1.54 +
1.55 +inline void SkipCombiningCharacters(TUTF32Iterator& aUTF32It);
1.56 +
1.57 +/**
1.58 +Converts UTF16 into UTF32, ignoring non-characters and
1.59 +unpaired surrogates and combining paired surrogates.
1.60 +@internalComponent
1.61 +*/
1.62 +class TUTF32Iterator
1.63 + {
1.64 +public:
1.65 + enum TStartsWithValidCharacter { EStartsWithValidCharacter };
1.66 + inline TUTF32Iterator();
1.67 + inline explicit TUTF32Iterator(const TText16* aSingleton);
1.68 + inline TUTF32Iterator(const TText16* aStart, const TText16* aEnd);
1.69 + inline TUTF32Iterator(const TText16* aStart, const TText16* aEnd, TStartsWithValidCharacter);
1.70 +
1.71 + inline TUTF32Iterator CurrentAsIterator() const;
1.72 + inline TBool AtEnd() const;
1.73 + void Next();
1.74 + inline TChar Current() const;
1.75 + TBool LocateFoldedBaseCharacter(TChar aChar);
1.76 + inline const TText16* CurrentPosition() const;
1.77 + inline TInt Length() const;
1.78 + inline TInt operator[](TInt) const;
1.79 + inline void SetStart(const TText16*);
1.80 +private:
1.81 + const TText16* iStart;
1.82 + const TText16* iEnd;
1.83 + TChar iCurrent;
1.84 + };
1.85 +
1.86 +//////////////////////////////////////////////////////////////////////////////////////////////
1.87 +// FOLDING
1.88 +//////////////////////////////////////////////////////////////////////////////////////////////
1.89 +
1.90 +/**
1.91 +@internalComponent
1.92 +*/
1.93 +class TFoldedDecompIterator
1.94 + {
1.95 +public:
1.96 + inline TFoldedDecompIterator();
1.97 + explicit TFoldedDecompIterator(const TUTF32Iterator&);
1.98 + inline void Set(const TUTF32Iterator&);
1.99 + TBool AtEnd() const;
1.100 + TBool AtEndOrWildcard() const;
1.101 + TBool EnterFoldedSequence();
1.102 + TBool StrictEnterFoldedSequence();
1.103 + inline TBool IsInFoldedSequence() const;
1.104 + TBool CurrentIsBaseFoldedFromCombiner() const;
1.105 + TChar Current() const;
1.106 + TBool Match(TChar aCode);
1.107 + TBool Match(TFoldedDecompIterator& aThat);
1.108 + void Next();
1.109 + inline TUTF32Iterator BaseIterator() const;
1.110 +private:
1.111 + TUTF32Iterator iOriginal;
1.112 + TUTF32Iterator iFolded;
1.113 + };
1.114 +
1.115 +/**
1.116 +Sorts sequences of combining characters with non-zero combining classes into
1.117 +order of their combining classes.
1.118 +@internalComponent
1.119 +*/
1.120 +class TFoldedSortedDecompIterator
1.121 + {
1.122 +public:
1.123 + inline TFoldedSortedDecompIterator();
1.124 + TInt Set(TFoldedDecompIterator &aBase);
1.125 + void Set();
1.126 + TBool AtEnd() const;
1.127 + TChar Current() const;
1.128 + void Next();
1.129 +
1.130 +private:
1.131 + TFoldedDecompIterator iStart; // Starting code.
1.132 + TInt iLength; // Length in decomposed codes.
1.133 + TFoldedDecompIterator iCurrent; // Current code.
1.134 + TInt iCurrentCount; // Number of decomposed codes iCurrent is past iStart
1.135 + TInt iCurrentClass; // Current class being searched for.
1.136 + TInt iRemaining; // Number of Next()s left
1.137 + };
1.138 +
1.139 +/**
1.140 +Iterator that outputs canonically decomposed folded strings.
1.141 +This is much slower than using the matching functions, so should only
1.142 +be used where an ordering is required.
1.143 +@internalComponent
1.144 +*/
1.145 +class TFoldedCanonicalIterator
1.146 + {
1.147 +public:
1.148 + TFoldedCanonicalIterator(const TUTF32Iterator&);
1.149 + TBool AtEnd() const;
1.150 + TChar Current() const;
1.151 + void Next(const TUnicodeDataSet* aCharDataSet);
1.152 +private:
1.153 + TFoldedDecompIterator iBase;
1.154 + TFoldedSortedDecompIterator iSorted;
1.155 + };
1.156 +
1.157 +
1.158 +//////////////////////////////////////////////////////////////////////////////////////////////
1.159 +// COLLATION
1.160 +//////////////////////////////////////////////////////////////////////////////////////////////
1.161 +
1.162 +/**
1.163 +@internalComponent
1.164 +*/
1.165 +class TDecompositionIterator
1.166 + {
1.167 +public:
1.168 + inline TDecompositionIterator();
1.169 + void Set(const TUTF32Iterator&);
1.170 + explicit TDecompositionIterator(const TUTF32Iterator&);
1.171 + TBool AtEnd() const;
1.172 + TChar Current() const;
1.173 + void Next();
1.174 + const TText16* CurrentPosition() const;
1.175 +private:
1.176 + TUTF32Iterator iBase;
1.177 + TUTF32Iterator iDecomposition;
1.178 + };
1.179 +
1.180 +/**
1.181 +@internalComponent
1.182 +*/
1.183 +class TCanonicalDecompositionIterator
1.184 + {
1.185 +public:
1.186 + inline TCanonicalDecompositionIterator();
1.187 + void Set(const TUTF32Iterator&);
1.188 + TBool AtEnd() const;
1.189 + TChar Current() const;
1.190 + void Next();
1.191 + const TText16* CurrentPositionIfAtCharacter() const;
1.192 + TBool IsInOpenSequence() const;
1.193 +private:
1.194 + TDecompositionIterator iBase;
1.195 + // iBase.CurrentPosition() before the last move
1.196 + const TText16* iLastPosition;
1.197 + // If iCurrent is active, iCurrentCombiningClass
1.198 + // is nonzero, and represents the combining class
1.199 + // of the character it points to.
1.200 + TInt iCurrentCombiningClass;
1.201 + // contains true if more characters added to the end may change
1.202 + // the characters currently being output
1.203 + TBool iInOpenSequence;
1.204 + // Iterator that looks for characters to be sorted.
1.205 + TDecompositionIterator iCurrent;
1.206 + };
1.207 +
1.208 +/**
1.209 +Iterator that gives the canonically decomposed form of
1.210 +its input, and allows a limited amount of look-ahead (i.e.
1.211 +peeking further into the decomposition without moving
1.212 +the iterator)
1.213 +@internalComponent
1.214 +*/
1.215 +class TCanonicalDecompositionIteratorCached
1.216 + {
1.217 +public:
1.218 + void Set(const TUTF32Iterator&);
1.219 + TBool AtEnd() const;
1.220 + // Advance aOffset characters.
1.221 + void Next(TInt aOffset);
1.222 + // Get the character at the position of the iterator plus aOffset steps.
1.223 + // Returns FFFF if we are looking too far ahead.
1.224 + TChar Get(TInt aOffset);
1.225 + // If the current position in the original string is representable
1.226 + // as a pointer into it and we know what it is, return it.
1.227 + const TText16* CurrentPositionIfAtCharacter() const;
1.228 +private:
1.229 + // KMaxLookAhead must be a power of 2
1.230 + enum { KMaxLookAhead = 8 };
1.231 + TCanonicalDecompositionIterator iBase;
1.232 + struct TCache
1.233 + {
1.234 + TChar iChar;
1.235 + const TText16* iPos;
1.236 + };
1.237 + TCache iCache[KMaxLookAhead + 1];
1.238 + TInt iCacheStart;
1.239 + TInt iCacheSize;
1.240 + };
1.241 +
1.242 +#include "CompareImp.inl"
1.243 +
1.244 +#endif //__COMPAREIMP_H__