os/textandloc/charconvfw/charconvplugins/src/shared/jisbase_shared.cpp
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
/*
sl@0
     2
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <charconv.h>
sl@0
    21
#include <convdata.h>
sl@0
    22
#include <convutils.h>
sl@0
    23
#include "jisx0201.h"
sl@0
    24
#include "jisx0208.h"
sl@0
    25
#include "jisx0212.h"
sl@0
    26
#include "jisbase.h"
sl@0
    27
sl@0
    28
const TUint KControlCharacterEscape=0x1b;
sl@0
    29
const TUint KControlCharacterShiftOut=0x0e;
sl@0
    30
const TUint KControlCharacterShiftIn=0x0f;
sl@0
    31
const TUint KBitsForNonStandardStates=0x03;
sl@0
    32
sl@0
    33
_LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
sl@0
    34
_LIT8(KLit8EscapeSequenceForJisRomanIncorrect, "\x1b\x28\x48");
sl@0
    35
_LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
sl@0
    36
_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49");
sl@0
    37
_LIT8(KLit8EscapeSequenceForJisC6226_1978, "\x1b\x24\x40");
sl@0
    38
_LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
sl@0
    39
_LIT8(KLit8EscapeSequenceForJisX0208_199x, "\x1b\x26\x40\x1b\x24\x42");
sl@0
    40
_LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
sl@0
    41
sl@0
    42
typedef TInt (*FChangeState)(TInt aState);
sl@0
    43
typedef TInt (*FAppendConvertToUnicode)(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>& aArrayOfStates, TUint& aOutputConversionFlags, TUint aInputConversionFlags);
sl@0
    44
sl@0
    45
enum TNonStandardState // each of these values must fit into KBitsForNonStandardStates and each must also be non-zero
sl@0
    46
	{
sl@0
    47
	ENonStandardStateJis7=1,
sl@0
    48
	ENonStandardStateJis8
sl@0
    49
	};
sl@0
    50
sl@0
    51
sl@0
    52
LOCAL_D const SCnvConversionData::SVariableByteData::SRange halfWidthKatakana7VariableByteDataRange=
sl@0
    53
	{
sl@0
    54
	0x00,
sl@0
    55
	0xff,
sl@0
    56
	0,
sl@0
    57
	0
sl@0
    58
	};
sl@0
    59
sl@0
    60
LOCAL_D const SCnvConversionData::SOneDirectionData::SRange halfWidthKatakana7ToUnicodeDataRange=
sl@0
    61
	{
sl@0
    62
	0x21,
sl@0
    63
	0x5f,
sl@0
    64
	SCnvConversionData::SOneDirectionData::SRange::EOffset,
sl@0
    65
	0,
sl@0
    66
	0,
sl@0
    67
		{
sl@0
    68
		STATIC_CAST(TUint, 65344),
sl@0
    69
		0
sl@0
    70
		}
sl@0
    71
	};
sl@0
    72
sl@0
    73
LOCAL_D const SCnvConversionData::SOneDirectionData::SRange unicodeToHalfWidthKatakana7DataRange=
sl@0
    74
	{
sl@0
    75
	0xff61,
sl@0
    76
	0xff9f,
sl@0
    77
	SCnvConversionData::SOneDirectionData::SRange::EOffset,
sl@0
    78
	1,
sl@0
    79
	0,
sl@0
    80
		{
sl@0
    81
		STATIC_CAST(TUint, -65344),
sl@0
    82
		0
sl@0
    83
		}
sl@0
    84
	};
sl@0
    85
sl@0
    86
LOCAL_D const SCnvConversionData halfWidthKatakana7ConversionData=
sl@0
    87
	{
sl@0
    88
	SCnvConversionData::EUnspecified,
sl@0
    89
		{
sl@0
    90
		1,
sl@0
    91
		&halfWidthKatakana7VariableByteDataRange
sl@0
    92
		},
sl@0
    93
		{
sl@0
    94
		1,
sl@0
    95
		&halfWidthKatakana7ToUnicodeDataRange
sl@0
    96
		},
sl@0
    97
		{
sl@0
    98
		1,
sl@0
    99
		&unicodeToHalfWidthKatakana7DataRange
sl@0
   100
		}
sl@0
   101
	};
sl@0
   102
sl@0
   103
#if defined(_DEBUG)
sl@0
   104
sl@0
   105
_LIT(KLitPanicText, "JISBASE_SHARED");
sl@0
   106
sl@0
   107
enum TPanic
sl@0
   108
	{
sl@0
   109
	EPanicNotAppending1=1,
sl@0
   110
	EPanicNotAppending2,
sl@0
   111
	EPanicNotAppending3,
sl@0
   112
	EPanicBadNonStandardState,
sl@0
   113
	EPanicBadPointers1,
sl@0
   114
	EPanicBadPointers2,
sl@0
   115
	EPanicBadPointers3,
sl@0
   116
	EPanicBadPointers4,
sl@0
   117
	EPanicBadFunctionPointer
sl@0
   118
	};
sl@0
   119
sl@0
   120
LOCAL_C void Panic(TPanic aPanic)
sl@0
   121
	{
sl@0
   122
	User::Panic(KLitPanicText, aPanic);
sl@0
   123
	}
sl@0
   124
sl@0
   125
#endif
sl@0
   126
sl@0
   127
TInt CnvJisBase::ChangeToNonStandardStateJis7(TInt aState)
sl@0
   128
	{
sl@0
   129
	return (aState&~KBitsForNonStandardStates)|ENonStandardStateJis7;
sl@0
   130
	}
sl@0
   131
sl@0
   132
TInt CnvJisBase::ChangeToNonStandardStateJis8(TInt aState)
sl@0
   133
	{
sl@0
   134
	return (aState&~KBitsForNonStandardStates)|ENonStandardStateJis8;
sl@0
   135
	}
sl@0
   136
sl@0
   137
TInt CnvJisBase::ChangeToStandardState(TInt)
sl@0
   138
	{
sl@0
   139
	return CCnvCharacterSetConverter::KStateDefault; // I actually thought that the correct behaviour for this would be to return "aState&~KBitsForNonStandardStates", but I asked Ken Lunde about it in an email and he said that after a run of JIS7 or JIS8, the bytes should always be interpreted as JIS-Roman
sl@0
   140
	}
sl@0
   141
sl@0
   142
TInt CnvJisBase::AppendConvertToUnicodeFromModalForeign(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aModalForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>& aArrayOfStates, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
sl@0
   143
	{
sl@0
   144
	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending1));
sl@0
   145
	return CnvUtilities::ConvertToUnicodeFromModalForeign(aDefaultEndiannessOfForeignCharacters, aUnicode, aModalForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aArrayOfStates, aOutputConversionFlags, aInputConversionFlags);
sl@0
   146
	}
sl@0
   147
sl@0
   148
TInt CnvJisBase::AppendConvertToUnicodeFromJis7(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aJis7, TInt&, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>&, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
sl@0
   149
	{
sl@0
   150
	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending2));
sl@0
   151
	return CCnvCharacterSetConverter::DoConvertToUnicode(halfWidthKatakana7ConversionData, aDefaultEndiannessOfForeignCharacters, aUnicode, aJis7, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
sl@0
   152
	}
sl@0
   153
sl@0
   154
TInt CnvJisBase::AppendConvertToUnicodeFromJis8(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aJis8, TInt&, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>&, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
sl@0
   155
	{
sl@0
   156
	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending3));
sl@0
   157
	return CCnvCharacterSetConverter::DoConvertToUnicode(CnvHalfWidthKatakana8::ConversionData(), aDefaultEndiannessOfForeignCharacters, aUnicode, aJis8, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
sl@0
   158
	}
sl@0
   159
sl@0
   160
EXPORT_C TInt CnvJisBase::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
sl@0
   161
	{
sl@0
   162
	TFixedArray<CnvUtilities::SState, 8> states;
sl@0
   163
	states[0].iEscapeSequence=&KLit8EscapeSequenceForJisRoman; // Jis-Roman is the default state, so it must come first in the array
sl@0
   164
	states[0].iConversionData=&CnvJisRoman::ConversionData();
sl@0
   165
	states[1].iEscapeSequence=&KLit8EscapeSequenceForJisRomanIncorrect;
sl@0
   166
	states[1].iConversionData=&CnvJisRoman::ConversionData();	
sl@0
   167
	states[2].iEscapeSequence=&KLit8EscapeSequenceForAscii;
sl@0
   168
	states[2].iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
sl@0
   169
	states[3].iEscapeSequence=&KLit8EscapeSequenceForHalfWidthKatakana;
sl@0
   170
	states[3].iConversionData=&halfWidthKatakana7ConversionData;
sl@0
   171
	states[4].iEscapeSequence=&KLit8EscapeSequenceForJisC6226_1978;
sl@0
   172
	states[4].iConversionData=&CnvJisX0208::ConversionData();
sl@0
   173
	states[5].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
sl@0
   174
	states[5].iConversionData=&CnvJisX0208::ConversionData();
sl@0
   175
	states[6].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_199x;
sl@0
   176
	states[6].iConversionData=&CnvJisX0208::ConversionData();
sl@0
   177
	states[7].iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
sl@0
   178
	states[7].iConversionData=&CnvJisX0212::ConversionData();
sl@0
   179
	const TArray<CnvUtilities::SState> arrayOfStates(states.Array());
sl@0
   180
	aUnicode.SetLength(0);
sl@0
   181
	const TUint8* const pointerToFirstByte=aForeign.Ptr();
sl@0
   182
	const TUint8* pointerToCurrentByte=pointerToFirstByte;
sl@0
   183
	const TUint8* pointerToStartOfNextRunToConvert=pointerToFirstByte;
sl@0
   184
	const TUint8* const pointerToLastByte=pointerToFirstByte+(aForeign.Length()-1);
sl@0
   185
	TUint outputConversionFlags=0;
sl@0
   186
	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagAppend;
sl@0
   187
	FOREVER
sl@0
   188
		{
sl@0
   189
		FChangeState changeState=NULL;
sl@0
   190
		FAppendConvertToUnicode appendConvertToUnicode=NULL;
sl@0
   191
		TBool skipThisByte=EFalse;
sl@0
   192
		const TUint currentByte=*pointerToCurrentByte;
sl@0
   193
		switch (aState&KBitsForNonStandardStates)
sl@0
   194
			{
sl@0
   195
		case 0:
sl@0
   196
			if (currentByte==KControlCharacterShiftOut)
sl@0
   197
				{
sl@0
   198
				changeState=ChangeToNonStandardStateJis7;
sl@0
   199
				skipThisByte=ETrue;
sl@0
   200
				}
sl@0
   201
			else if (currentByte&0x80)
sl@0
   202
				{
sl@0
   203
				changeState=ChangeToNonStandardStateJis8;
sl@0
   204
				}
sl@0
   205
			appendConvertToUnicode=AppendConvertToUnicodeFromModalForeign;
sl@0
   206
			break;
sl@0
   207
		case ENonStandardStateJis7:
sl@0
   208
			if (currentByte==KControlCharacterEscape)
sl@0
   209
				{
sl@0
   210
				changeState=ChangeToStandardState; // it doesn't matter what function changeState is set to (as its return value won't actually be used), as long as changeState!=NULL so that the test below (after the end of this switch) passes
sl@0
   211
				}
sl@0
   212
			else if (currentByte==KControlCharacterShiftIn)
sl@0
   213
				{
sl@0
   214
				changeState=ChangeToStandardState;
sl@0
   215
				skipThisByte=ETrue;
sl@0
   216
				}
sl@0
   217
			else if (currentByte&0x80)
sl@0
   218
				{
sl@0
   219
				changeState=ChangeToNonStandardStateJis8;
sl@0
   220
				}
sl@0
   221
			appendConvertToUnicode=AppendConvertToUnicodeFromJis7;
sl@0
   222
			break;
sl@0
   223
		case ENonStandardStateJis8:
sl@0
   224
			if (currentByte==KControlCharacterEscape)
sl@0
   225
				{
sl@0
   226
				changeState=ChangeToStandardState; // it doesn't matter what function changeState is set to (as its return value won't actually be used), as long as changeState!=NULL so that the test below (after the end of this switch) passes
sl@0
   227
				}
sl@0
   228
			else if (currentByte==KControlCharacterShiftOut)
sl@0
   229
				{
sl@0
   230
				changeState=ChangeToNonStandardStateJis7;
sl@0
   231
				skipThisByte=ETrue;
sl@0
   232
				}
sl@0
   233
			else if ((currentByte&0x80)==0)
sl@0
   234
				{
sl@0
   235
				changeState=ChangeToStandardState;
sl@0
   236
				}
sl@0
   237
			appendConvertToUnicode=AppendConvertToUnicodeFromJis8;
sl@0
   238
			break;
sl@0
   239
#if defined(_DEBUG)
sl@0
   240
		default:
sl@0
   241
			Panic(EPanicBadNonStandardState);
sl@0
   242
			break;
sl@0
   243
#endif
sl@0
   244
			}
sl@0
   245
		__ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers1));
sl@0
   246
		if ((pointerToCurrentByte>=pointerToLastByte) || (changeState!=NULL))
sl@0
   247
			{
sl@0
   248
			TBool lastIteration=EFalse;
sl@0
   249
			__ASSERT_DEBUG(pointerToCurrentByte>=pointerToStartOfNextRunToConvert, Panic(EPanicBadPointers2));
sl@0
   250
			if (changeState==NULL)
sl@0
   251
				{
sl@0
   252
				++pointerToCurrentByte; // this may make pointerToCurrentByte greater than pointerToLastByte
sl@0
   253
				lastIteration=ETrue;
sl@0
   254
				}
sl@0
   255
			if (pointerToCurrentByte>pointerToStartOfNextRunToConvert)
sl@0
   256
				{
sl@0
   257
				TPtrC8 runToConvert(pointerToStartOfNextRunToConvert, pointerToCurrentByte-pointerToStartOfNextRunToConvert);
sl@0
   258
				TInt numberOfUnconvertibleCharacters;
sl@0
   259
				TInt indexOfFirstByteOfFirstUnconvertibleCharacter;
sl@0
   260
				__ASSERT_DEBUG(appendConvertToUnicode!=NULL, Panic(EPanicBadFunctionPointer));
sl@0
   261
				const TInt returnValue=(*appendConvertToUnicode)(aDefaultEndiannessOfForeignCharacters, aUnicode, runToConvert, aState, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter, arrayOfStates, outputConversionFlags, inputConversionFlags);
sl@0
   262
				if (returnValue<0)
sl@0
   263
					{
sl@0
   264
					return returnValue; // this is an error-code
sl@0
   265
					}
sl@0
   266
				if (numberOfUnconvertibleCharacters>0)
sl@0
   267
					{
sl@0
   268
					if (aNumberOfUnconvertibleCharacters==0)
sl@0
   269
						{
sl@0
   270
						aIndexOfFirstByteOfFirstUnconvertibleCharacter=(pointerToStartOfNextRunToConvert-pointerToFirstByte)+indexOfFirstByteOfFirstUnconvertibleCharacter;
sl@0
   271
						}
sl@0
   272
					aNumberOfUnconvertibleCharacters+=numberOfUnconvertibleCharacters;
sl@0
   273
					}
sl@0
   274
				if (returnValue>0)
sl@0
   275
					{
sl@0
   276
					pointerToCurrentByte-=returnValue; // pointerToStartOfNextRunToConvert (which also needs adjusting in the same way) gets set below
sl@0
   277
					lastIteration=ETrue;
sl@0
   278
					changeState=NULL;
sl@0
   279
					skipThisByte=EFalse;
sl@0
   280
					}
sl@0
   281
				__ASSERT_DEBUG(pointerToCurrentByte>=pointerToFirstByte, Panic(EPanicBadPointers3));
sl@0
   282
				if (pointerToCurrentByte>pointerToFirstByte)
sl@0
   283
					{
sl@0
   284
					inputConversionFlags|=CCnvCharacterSetConverter::EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable;
sl@0
   285
					}
sl@0
   286
				}
sl@0
   287
			if (changeState!=NULL)
sl@0
   288
				{
sl@0
   289
				aState=(*changeState)(aState);
sl@0
   290
				}
sl@0
   291
			if (skipThisByte)
sl@0
   292
				{
sl@0
   293
				if (pointerToCurrentByte==pointerToLastByte) // pointerToCurrentByte may already be greater than pointerToLastByte, in which case lastIteration will already be ETrue
sl@0
   294
					{
sl@0
   295
					lastIteration=ETrue;
sl@0
   296
					}
sl@0
   297
				++pointerToCurrentByte;
sl@0
   298
				}
sl@0
   299
			pointerToStartOfNextRunToConvert=pointerToCurrentByte;
sl@0
   300
			if (lastIteration) // check this first as pointerToCurrentByte may be greater than pointerToLastByte (but it will only be if lastIteration is EFalse)
sl@0
   301
				{
sl@0
   302
				break;
sl@0
   303
				}
sl@0
   304
			__ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers4));
sl@0
   305
			if (pointerToCurrentByte>=pointerToLastByte)
sl@0
   306
				{
sl@0
   307
				break;
sl@0
   308
				}
sl@0
   309
			}
sl@0
   310
		++pointerToCurrentByte;
sl@0
   311
		}
sl@0
   312
	// no checking with outputConversionFlags need to be done here
sl@0
   313
	return pointerToLastByte-(pointerToCurrentByte-1);
sl@0
   314
	}
sl@0
   315
sl@0
   316
EXPORT_C const SCnvConversionData& CnvJisBase::HalfWidthKatakana7ConversionData()
sl@0
   317
	{
sl@0
   318
	return halfWidthKatakana7ConversionData;
sl@0
   319
	}
sl@0
   320
sl@0
   321
EXPORT_C void CnvJisBase::IsCharacterJISBased(TInt& aConfidenceLevel, const TDesC8& aSample) 
sl@0
   322
	{
sl@0
   323
	// JIS is modal... so start off with a confidence of 0 and to begin with look 
sl@0
   324
	// for JIS escape sequences....Escape sequences defined above in the KLITs
sl@0
   325
	// For each escape sequence, increase the confidenceLevel ..... 
sl@0
   326
	aConfidenceLevel = 55;
sl@0
   327
	TInt jisRomanResult = 0;
sl@0
   328
	TInt asciiResult = 0;
sl@0
   329
	TInt jisX0208Result = 0;
sl@0
   330
	TInt jisC6226Result = 0;
sl@0
   331
	TInt jixX0212Result = 0;
sl@0
   332
	TInt hwKanaResult = 0;
sl@0
   333
sl@0
   334
	TInt EscSequences = 0;
sl@0
   335
	
sl@0
   336
	TInt sampleLength = aSample.Length();
sl@0
   337
	for (TInt i = 0; i < sampleLength; ++i)
sl@0
   338
		{
sl@0
   339
	
sl@0
   340
		// JIS is 7 bit encoding
sl@0
   341
		if((aSample[i]&0x80)!=0x00)
sl@0
   342
			{
sl@0
   343
			aConfidenceLevel=0;
sl@0
   344
			break;
sl@0
   345
			}
sl@0
   346
		// JIS supports the following character sets 
sl@0
   347
		if (i > jisC6226Result)
sl@0
   348
			{
sl@0
   349
			jisC6226Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisC6226_1978);
sl@0
   350
			if (jisC6226Result!=KErrNotFound)
sl@0
   351
				EscSequences += 15; 
sl@0
   352
			}
sl@0
   353
sl@0
   354
		if (i > jisRomanResult)
sl@0
   355
			{
sl@0
   356
			jisRomanResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisRoman);
sl@0
   357
			if (jisRomanResult!=KErrNotFound)
sl@0
   358
				EscSequences += 15; 
sl@0
   359
			}
sl@0
   360
sl@0
   361
		if (i > asciiResult)
sl@0
   362
			{
sl@0
   363
			asciiResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForAscii);
sl@0
   364
			if (asciiResult!=KErrNotFound)
sl@0
   365
				EscSequences += 15; 
sl@0
   366
			}
sl@0
   367
sl@0
   368
		if (i > jisX0208Result)
sl@0
   369
			{
sl@0
   370
			jisX0208Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisX0208_1983);
sl@0
   371
			if (jisX0208Result!=KErrNotFound)
sl@0
   372
				EscSequences += 15; 
sl@0
   373
			}
sl@0
   374
sl@0
   375
		if (i > jixX0212Result)
sl@0
   376
			{
sl@0
   377
			jixX0212Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisX0212_1990);
sl@0
   378
			if (jixX0212Result!=KErrNotFound)
sl@0
   379
				EscSequences += 15; 
sl@0
   380
			}
sl@0
   381
sl@0
   382
		if (i > hwKanaResult)
sl@0
   383
			{
sl@0
   384
			hwKanaResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForHalfWidthKatakana);
sl@0
   385
			if (hwKanaResult!=KErrNotFound)
sl@0
   386
				EscSequences += 15; 
sl@0
   387
			}
sl@0
   388
		}
sl@0
   389
sl@0
   390
	aConfidenceLevel = 0 < sampleLength?
sl@0
   391
		aConfidenceLevel + ((EscSequences*100)/sampleLength) : 90;
sl@0
   392
	aConfidenceLevel=(aConfidenceLevel >100)?100:aConfidenceLevel;
sl@0
   393
	}