First public contribution.
1 // Copyright (c) 2000-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 // Some internals of the Unicode collation system.
17 #ifndef __COLLATEIMP_H__
18 #define __COLLATEIMP_H__
22 #include "CompareImp.h"
24 //Forward declarations
25 struct TCollationKeyTable;
27 //External declarations
28 const TCollationKeyTable* StandardCollationMethod();
35 enum { KHighValue = 0x00FFFFFF, KFlagIsStarter = 0x80000000 };
36 TUint32 Level(TInt aLevel) const
38 static const TUint32 mask[3] = { 0xFFFF0000, 0xFF00, 0xFC };
39 return aLevel == 3 ? iHigh & KHighValue : iLow & mask[aLevel];
41 TBool IsStarter() const
43 return (TBool)(iHigh & (TUint32)KFlagIsStarter);
46 enum {KLevel0KeySize=2, KLevel1KeySize=1,KLevel2KeySize=1,KLevel3KeySize=3 };
48 static TInt MaxSizePerKey(TInt aLevel)
51 return KLevel0KeySize;
52 if (aLevel==1 || aLevel==2)
53 return KLevel1KeySize;
54 return KLevel3KeySize;
57 void AppendToDescriptor(TPtr8 aLevelBuffer,TInt aLevel) const
62 //for each level need to check for zero key
63 //i.e. only append non zero key
66 if (((iLow>>16)&0xFFFF)!=0)
68 buffer.SetLength(KLevel0KeySize);
69 buffer[0]=(TUint8)((iLow>>24)&0xFF);
70 buffer[1]=(TUint8)((iLow>>16)&0xFF);
76 if (((iLow>>8)&0xFF)!=0)
78 buffer.SetLength(KLevel1KeySize);
79 buffer[0]=(TUint8)((iLow>>8)&0xFF);
87 buffer.SetLength(KLevel2KeySize);
88 buffer[0]=(TUint8)(iLow&0xFC);
94 if ((iHigh&0xFFFFFF)!=0)
96 buffer.SetLength(KLevel3KeySize);
97 buffer[0]=(TUint8)((iHigh>>16)&0xFF);
98 buffer[1]=(TUint8)((iHigh>>8)&0xFF);
99 buffer[2]=(TUint8)(iHigh&0xFF);
104 aLevelBuffer.Append(buffer);
107 TUint32 iLow; // primary, secondary and tertiary keys
108 TUint32 iHigh; // quaternary key; usually the Unicode value
116 enum { EMaxKeys = 8 };
118 TCollationKey iKey[EMaxKeys]; // the keys
119 TInt iKeys; // the number of keys returned
120 TInt iCharactersConsumed; // number of characters consumed from the input to generate the keys
124 Steps through a decomposed unicode string (using iDecompStrIt iterator),
125 outputting raw collation keys.
126 Every Increment() call will move to the next collation key (from iKey array), if available.
127 Every GetCurrentKey() call will retrieve current collation key, if available.
130 class TCollationValueIterator
133 inline TCollationValueIterator(const TCollationMethod& aMethod);
134 void SetSourceIt(TUTF32Iterator& aSourceIt);
135 TBool GetCurrentKey(TCollationKey& aKey);
136 TBool GetCurrentKey(TInt aLevel, TUint32& aKey);
137 TUint32 GetNextNonZeroKey(TInt aLevel);
138 TBool MatchChar(TChar aMatch);
139 TBool AtCombiningCharacter();
140 TInt SkipCombiningCharacters();
142 inline TBool IgnoringNone() const;
143 inline const TCollationMethod& CollationMethod() const;
144 const TText16* CurrentPositionIfAtCharacter();
147 TBool ProduceCollationKeys();
148 void GetNextRawKeySequence();
149 void GetKeyFromTable(const TCollationKeyTable* aTable);
152 TCanonicalDecompositionIteratorCached iDecompStrIt;//Used to iterate through the canonically decomposed input string
153 // Current position in the underlying iterator (if well defined)
154 // of the start of the keys stored in iKey.
155 const TText16* iCurrentPosition;
156 const TCollationMethod& iMethod;//Current (locale dependend) collation method
157 TKeyInfo iKey;//Each ProduceCollationKeys() call fills it with the longest possible collation keys sequence
158 TInt iCurrentKeyPos;//Current position in iKey array. Incremented/set to 0 after each Increment() call
161 #include "CollateImp.inl"
163 #endif //__COLLATEIMP_H__