sl@0: // Copyright (c) 2000-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 the License "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: // Some internals of the Unicode collation system. sl@0: #ifndef __COLLATEIMP_H__ sl@0: #define __COLLATEIMP_H__ sl@0: sl@0: #include sl@0: #include "collate.h" sl@0: #include "CompareImp.h" sl@0: sl@0: //Forward declarations sl@0: struct TCollationKeyTable; sl@0: sl@0: //External declarations sl@0: const TCollationKeyTable* StandardCollationMethod(); sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: struct TCollationKey sl@0: { sl@0: enum { KHighValue = 0x00FFFFFF, KFlagIsStarter = 0x80000000 }; sl@0: TUint32 Level(TInt aLevel) const sl@0: { sl@0: static const TUint32 mask[3] = { 0xFFFF0000, 0xFF00, 0xFC }; sl@0: return aLevel == 3 ? iHigh & KHighValue : iLow & mask[aLevel]; sl@0: } sl@0: TBool IsStarter() const sl@0: { sl@0: return (TBool)(iHigh & (TUint32)KFlagIsStarter); sl@0: } sl@0: sl@0: enum {KLevel0KeySize=2, KLevel1KeySize=1,KLevel2KeySize=1,KLevel3KeySize=3 }; sl@0: sl@0: static TInt MaxSizePerKey(TInt aLevel) sl@0: { sl@0: if (aLevel==0) sl@0: return KLevel0KeySize; sl@0: if (aLevel==1 || aLevel==2) sl@0: return KLevel1KeySize; sl@0: return KLevel3KeySize; sl@0: } sl@0: sl@0: void AppendToDescriptor(TPtr8 aLevelBuffer,TInt aLevel) const sl@0: { sl@0: TBuf8<4> buffer; sl@0: switch (aLevel) sl@0: { sl@0: //for each level need to check for zero key sl@0: //i.e. only append non zero key sl@0: case 0: sl@0: { sl@0: if (((iLow>>16)&0xFFFF)!=0) sl@0: { sl@0: buffer.SetLength(KLevel0KeySize); sl@0: buffer[0]=(TUint8)((iLow>>24)&0xFF); sl@0: buffer[1]=(TUint8)((iLow>>16)&0xFF); sl@0: } sl@0: break; sl@0: } sl@0: case 1: sl@0: { sl@0: if (((iLow>>8)&0xFF)!=0) sl@0: { sl@0: buffer.SetLength(KLevel1KeySize); sl@0: buffer[0]=(TUint8)((iLow>>8)&0xFF); sl@0: } sl@0: break; sl@0: } sl@0: case 2: sl@0: { sl@0: if ((iLow&0xFC)!=0) sl@0: { sl@0: buffer.SetLength(KLevel2KeySize); sl@0: buffer[0]=(TUint8)(iLow&0xFC); sl@0: } sl@0: break; sl@0: } sl@0: case 3: sl@0: { sl@0: if ((iHigh&0xFFFFFF)!=0) sl@0: { sl@0: buffer.SetLength(KLevel3KeySize); sl@0: buffer[0]=(TUint8)((iHigh>>16)&0xFF); sl@0: buffer[1]=(TUint8)((iHigh>>8)&0xFF); sl@0: buffer[2]=(TUint8)(iHigh&0xFF); sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: aLevelBuffer.Append(buffer); sl@0: } sl@0: sl@0: TUint32 iLow; // primary, secondary and tertiary keys sl@0: TUint32 iHigh; // quaternary key; usually the Unicode value sl@0: }; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: struct TKeyInfo sl@0: { sl@0: enum { EMaxKeys = 8 }; sl@0: sl@0: TCollationKey iKey[EMaxKeys]; // the keys sl@0: TInt iKeys; // the number of keys returned sl@0: TInt iCharactersConsumed; // number of characters consumed from the input to generate the keys sl@0: }; sl@0: sl@0: /** sl@0: Steps through a decomposed unicode string (using iDecompStrIt iterator), sl@0: outputting raw collation keys. sl@0: Every Increment() call will move to the next collation key (from iKey array), if available. sl@0: Every GetCurrentKey() call will retrieve current collation key, if available. sl@0: @internalComponent sl@0: */ sl@0: class TCollationValueIterator sl@0: { sl@0: public: sl@0: inline TCollationValueIterator(const TCollationMethod& aMethod); sl@0: void SetSourceIt(TUTF32Iterator& aSourceIt); sl@0: TBool GetCurrentKey(TCollationKey& aKey); sl@0: TBool GetCurrentKey(TInt aLevel, TUint32& aKey); sl@0: TUint32 GetNextNonZeroKey(TInt aLevel); sl@0: TBool MatchChar(TChar aMatch); sl@0: TBool AtCombiningCharacter(); sl@0: TInt SkipCombiningCharacters(); sl@0: TBool Increment(); sl@0: inline TBool IgnoringNone() const; sl@0: inline const TCollationMethod& CollationMethod() const; sl@0: const TText16* CurrentPositionIfAtCharacter(); sl@0: sl@0: private: sl@0: TBool ProduceCollationKeys(); sl@0: void GetNextRawKeySequence(); sl@0: void GetKeyFromTable(const TCollationKeyTable* aTable); sl@0: sl@0: private: sl@0: TCanonicalDecompositionIteratorCached iDecompStrIt;//Used to iterate through the canonically decomposed input string sl@0: // Current position in the underlying iterator (if well defined) sl@0: // of the start of the keys stored in iKey. sl@0: const TText16* iCurrentPosition; sl@0: const TCollationMethod& iMethod;//Current (locale dependend) collation method sl@0: TKeyInfo iKey;//Each ProduceCollationKeys() call fills it with the longest possible collation keys sequence sl@0: TInt iCurrentKeyPos;//Current position in iKey array. Incremented/set to 0 after each Increment() call sl@0: }; sl@0: sl@0: #include "CollateImp.inl" sl@0: sl@0: #endif //__COLLATEIMP_H__