os/kernelhwsrv/kernel/eka/euser/unicode/collateimp.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
// Some internals of the Unicode collation system.
sl@0
    17
#ifndef __COLLATEIMP_H__
sl@0
    18
#define __COLLATEIMP_H__
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
#include "collate.h"
sl@0
    22
#include "CompareImp.h"
sl@0
    23
sl@0
    24
//Forward declarations
sl@0
    25
struct TCollationKeyTable;
sl@0
    26
sl@0
    27
//External declarations
sl@0
    28
const TCollationKeyTable* StandardCollationMethod();
sl@0
    29
sl@0
    30
/**
sl@0
    31
@internalComponent
sl@0
    32
*/
sl@0
    33
struct TCollationKey
sl@0
    34
	{
sl@0
    35
	enum { KHighValue = 0x00FFFFFF, KFlagIsStarter = 0x80000000 };
sl@0
    36
	TUint32 Level(TInt aLevel) const
sl@0
    37
		{
sl@0
    38
		static const TUint32 mask[3] = { 0xFFFF0000, 0xFF00, 0xFC };
sl@0
    39
		return aLevel == 3 ? iHigh & KHighValue : iLow & mask[aLevel];
sl@0
    40
		}
sl@0
    41
	TBool IsStarter() const
sl@0
    42
        { 
sl@0
    43
        return (TBool)(iHigh & (TUint32)KFlagIsStarter);
sl@0
    44
        }
sl@0
    45
    
sl@0
    46
    enum {KLevel0KeySize=2, KLevel1KeySize=1,KLevel2KeySize=1,KLevel3KeySize=3 };
sl@0
    47
        
sl@0
    48
	static TInt MaxSizePerKey(TInt aLevel)
sl@0
    49
		{
sl@0
    50
		if (aLevel==0)
sl@0
    51
			return KLevel0KeySize;
sl@0
    52
		if (aLevel==1 || aLevel==2)
sl@0
    53
			return KLevel1KeySize;
sl@0
    54
		return KLevel3KeySize;			
sl@0
    55
		}
sl@0
    56
sl@0
    57
	void AppendToDescriptor(TPtr8 aLevelBuffer,TInt aLevel) const
sl@0
    58
		{
sl@0
    59
		TBuf8<4> buffer;
sl@0
    60
		switch (aLevel)
sl@0
    61
			{
sl@0
    62
			//for each level need to check for zero key
sl@0
    63
			//i.e. only append non zero key
sl@0
    64
			case 0:
sl@0
    65
				{
sl@0
    66
				if (((iLow>>16)&0xFFFF)!=0)
sl@0
    67
					{
sl@0
    68
					buffer.SetLength(KLevel0KeySize);
sl@0
    69
					buffer[0]=(TUint8)((iLow>>24)&0xFF);
sl@0
    70
					buffer[1]=(TUint8)((iLow>>16)&0xFF);
sl@0
    71
					}
sl@0
    72
				break;
sl@0
    73
				}
sl@0
    74
			case 1:
sl@0
    75
				{
sl@0
    76
				if (((iLow>>8)&0xFF)!=0)
sl@0
    77
					{
sl@0
    78
					buffer.SetLength(KLevel1KeySize);
sl@0
    79
					buffer[0]=(TUint8)((iLow>>8)&0xFF);
sl@0
    80
					}
sl@0
    81
				break;
sl@0
    82
				}
sl@0
    83
			case 2:
sl@0
    84
				{
sl@0
    85
				if ((iLow&0xFC)!=0)
sl@0
    86
					{
sl@0
    87
					buffer.SetLength(KLevel2KeySize);
sl@0
    88
					buffer[0]=(TUint8)(iLow&0xFC);
sl@0
    89
					}
sl@0
    90
				break;
sl@0
    91
				}
sl@0
    92
			case 3:
sl@0
    93
				{
sl@0
    94
				if ((iHigh&0xFFFFFF)!=0)
sl@0
    95
					{
sl@0
    96
					buffer.SetLength(KLevel3KeySize);
sl@0
    97
					buffer[0]=(TUint8)((iHigh>>16)&0xFF);
sl@0
    98
					buffer[1]=(TUint8)((iHigh>>8)&0xFF);
sl@0
    99
					buffer[2]=(TUint8)(iHigh&0xFF);
sl@0
   100
					}
sl@0
   101
				break;
sl@0
   102
				}
sl@0
   103
			}
sl@0
   104
			aLevelBuffer.Append(buffer);
sl@0
   105
		}
sl@0
   106
 
sl@0
   107
	TUint32 iLow;				// primary, secondary and tertiary keys
sl@0
   108
	TUint32 iHigh;				// quaternary key; usually the Unicode value
sl@0
   109
	};
sl@0
   110
sl@0
   111
/**
sl@0
   112
@internalComponent
sl@0
   113
*/
sl@0
   114
struct TKeyInfo
sl@0
   115
	{
sl@0
   116
	enum { EMaxKeys = 8 };
sl@0
   117
sl@0
   118
	TCollationKey iKey[EMaxKeys];	// the keys
sl@0
   119
	TInt iKeys;						// the number of keys returned
sl@0
   120
	TInt iCharactersConsumed;		// number of characters consumed from the input to generate the keys
sl@0
   121
	};
sl@0
   122
sl@0
   123
/**
sl@0
   124
Steps through a decomposed unicode string (using iDecompStrIt iterator), 
sl@0
   125
outputting raw collation keys.
sl@0
   126
Every Increment() call will move to the next collation key (from iKey array), if available.
sl@0
   127
Every GetCurrentKey() call will retrieve current collation key, if available.
sl@0
   128
@internalComponent
sl@0
   129
*/
sl@0
   130
class TCollationValueIterator
sl@0
   131
	{
sl@0
   132
public:
sl@0
   133
	inline TCollationValueIterator(const TCollationMethod& aMethod);
sl@0
   134
	void SetSourceIt(TUTF32Iterator& aSourceIt);
sl@0
   135
	TBool GetCurrentKey(TCollationKey& aKey);
sl@0
   136
    TBool GetCurrentKey(TInt aLevel, TUint32& aKey);
sl@0
   137
    TUint32 GetNextNonZeroKey(TInt aLevel);
sl@0
   138
    TBool MatchChar(TChar aMatch);
sl@0
   139
    TBool AtCombiningCharacter();
sl@0
   140
    TInt SkipCombiningCharacters();
sl@0
   141
	TBool Increment();
sl@0
   142
	inline TBool IgnoringNone() const;
sl@0
   143
	inline const TCollationMethod& CollationMethod() const;
sl@0
   144
	const TText16* CurrentPositionIfAtCharacter();
sl@0
   145
sl@0
   146
private:
sl@0
   147
	TBool ProduceCollationKeys();
sl@0
   148
	void GetNextRawKeySequence();
sl@0
   149
	void GetKeyFromTable(const TCollationKeyTable* aTable);
sl@0
   150
sl@0
   151
private:
sl@0
   152
	TCanonicalDecompositionIteratorCached iDecompStrIt;//Used to iterate through the canonically decomposed input string
sl@0
   153
	// Current position in the underlying iterator (if well defined)
sl@0
   154
	// of the start of the keys stored in iKey.
sl@0
   155
	const TText16* iCurrentPosition;
sl@0
   156
	const TCollationMethod& iMethod;//Current (locale dependend) collation method
sl@0
   157
	TKeyInfo iKey;//Each ProduceCollationKeys() call fills it with the longest possible collation keys sequence
sl@0
   158
    TInt iCurrentKeyPos;//Current position in iKey array. Incremented/set to 0 after each Increment() call
sl@0
   159
	};
sl@0
   160
sl@0
   161
#include "CollateImp.inl"
sl@0
   162
sl@0
   163
#endif //__COLLATEIMP_H__