0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
// Some internals of the Unicode collation system.
|
|
17 |
#ifndef __COLLATEIMP_H__
|
|
18 |
#define __COLLATEIMP_H__
|
|
19 |
|
|
20 |
#include <e32std.h>
|
|
21 |
#include "collate.h"
|
|
22 |
#include "CompareImp.h"
|
|
23 |
|
|
24 |
//Forward declarations
|
|
25 |
struct TCollationKeyTable;
|
|
26 |
|
|
27 |
//External declarations
|
|
28 |
const TCollationKeyTable* StandardCollationMethod();
|
|
29 |
|
|
30 |
/**
|
|
31 |
@internalComponent
|
|
32 |
*/
|
|
33 |
struct TCollationKey
|
|
34 |
{
|
|
35 |
enum { KHighValue = 0x00FFFFFF, KFlagIsStarter = 0x80000000 };
|
|
36 |
TUint32 Level(TInt aLevel) const
|
|
37 |
{
|
|
38 |
static const TUint32 mask[3] = { 0xFFFF0000, 0xFF00, 0xFC };
|
|
39 |
return aLevel == 3 ? iHigh & KHighValue : iLow & mask[aLevel];
|
|
40 |
}
|
|
41 |
TBool IsStarter() const
|
|
42 |
{
|
|
43 |
return (TBool)(iHigh & (TUint32)KFlagIsStarter);
|
|
44 |
}
|
|
45 |
|
|
46 |
enum {KLevel0KeySize=2, KLevel1KeySize=1,KLevel2KeySize=1,KLevel3KeySize=3 };
|
|
47 |
|
|
48 |
static TInt MaxSizePerKey(TInt aLevel)
|
|
49 |
{
|
|
50 |
if (aLevel==0)
|
|
51 |
return KLevel0KeySize;
|
|
52 |
if (aLevel==1 || aLevel==2)
|
|
53 |
return KLevel1KeySize;
|
|
54 |
return KLevel3KeySize;
|
|
55 |
}
|
|
56 |
|
|
57 |
void AppendToDescriptor(TPtr8 aLevelBuffer,TInt aLevel) const
|
|
58 |
{
|
|
59 |
TBuf8<4> buffer;
|
|
60 |
switch (aLevel)
|
|
61 |
{
|
|
62 |
//for each level need to check for zero key
|
|
63 |
//i.e. only append non zero key
|
|
64 |
case 0:
|
|
65 |
{
|
|
66 |
if (((iLow>>16)&0xFFFF)!=0)
|
|
67 |
{
|
|
68 |
buffer.SetLength(KLevel0KeySize);
|
|
69 |
buffer[0]=(TUint8)((iLow>>24)&0xFF);
|
|
70 |
buffer[1]=(TUint8)((iLow>>16)&0xFF);
|
|
71 |
}
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
case 1:
|
|
75 |
{
|
|
76 |
if (((iLow>>8)&0xFF)!=0)
|
|
77 |
{
|
|
78 |
buffer.SetLength(KLevel1KeySize);
|
|
79 |
buffer[0]=(TUint8)((iLow>>8)&0xFF);
|
|
80 |
}
|
|
81 |
break;
|
|
82 |
}
|
|
83 |
case 2:
|
|
84 |
{
|
|
85 |
if ((iLow&0xFC)!=0)
|
|
86 |
{
|
|
87 |
buffer.SetLength(KLevel2KeySize);
|
|
88 |
buffer[0]=(TUint8)(iLow&0xFC);
|
|
89 |
}
|
|
90 |
break;
|
|
91 |
}
|
|
92 |
case 3:
|
|
93 |
{
|
|
94 |
if ((iHigh&0xFFFFFF)!=0)
|
|
95 |
{
|
|
96 |
buffer.SetLength(KLevel3KeySize);
|
|
97 |
buffer[0]=(TUint8)((iHigh>>16)&0xFF);
|
|
98 |
buffer[1]=(TUint8)((iHigh>>8)&0xFF);
|
|
99 |
buffer[2]=(TUint8)(iHigh&0xFF);
|
|
100 |
}
|
|
101 |
break;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
aLevelBuffer.Append(buffer);
|
|
105 |
}
|
|
106 |
|
|
107 |
TUint32 iLow; // primary, secondary and tertiary keys
|
|
108 |
TUint32 iHigh; // quaternary key; usually the Unicode value
|
|
109 |
};
|
|
110 |
|
|
111 |
/**
|
|
112 |
@internalComponent
|
|
113 |
*/
|
|
114 |
struct TKeyInfo
|
|
115 |
{
|
|
116 |
enum { EMaxKeys = 8 };
|
|
117 |
|
|
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
|
|
121 |
};
|
|
122 |
|
|
123 |
/**
|
|
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.
|
|
128 |
@internalComponent
|
|
129 |
*/
|
|
130 |
class TCollationValueIterator
|
|
131 |
{
|
|
132 |
public:
|
|
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();
|
|
141 |
TBool Increment();
|
|
142 |
inline TBool IgnoringNone() const;
|
|
143 |
inline const TCollationMethod& CollationMethod() const;
|
|
144 |
const TText16* CurrentPositionIfAtCharacter();
|
|
145 |
|
|
146 |
private:
|
|
147 |
TBool ProduceCollationKeys();
|
|
148 |
void GetNextRawKeySequence();
|
|
149 |
void GetKeyFromTable(const TCollationKeyTable* aTable);
|
|
150 |
|
|
151 |
private:
|
|
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
|
|
159 |
};
|
|
160 |
|
|
161 |
#include "CollateImp.inl"
|
|
162 |
|
|
163 |
#endif //__COLLATEIMP_H__
|