os/textandloc/charconvfw/charconvplugins/src/shared/JISBASE_SHARED_2.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconvplugins/src/shared/JISBASE_SHARED_2.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,451 @@
     1.4 +/*
     1.5 +* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:       
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "PictographObserver.h"
    1.23 +#include <e32std.h>
    1.24 +#include <charconv.h>
    1.25 +#include <convdata.h>
    1.26 +#include <convutils.h>
    1.27 +#include "jisx0201.h"
    1.28 +#include "jisx0208.h"
    1.29 +#include "jisx0212.h"
    1.30 +#include "jisbase.h"
    1.31 +#include "featmgr/featmgr.h"
    1.32 +
    1.33 +const TUint KControlCharacterEscape=0x1b;
    1.34 +const TUint KControlCharacterShiftOut=0x0e;
    1.35 +const TUint KControlCharacterShiftIn=0x0f;
    1.36 +const TUint KBitsForNonStandardStates=0x03;
    1.37 +
    1.38 +_LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    1.39 +_LIT8(KLit8EscapeSequenceForJisRomanIncorrect, "\x1b\x28\x48");
    1.40 +_LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
    1.41 +_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49");
    1.42 +_LIT8(KLit8EscapeSequenceForJisC6226_1978, "\x1b\x24\x40");
    1.43 +_LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    1.44 +_LIT8(KLit8EscapeSequenceForJisX0208_199x, "\x1b\x26\x40\x1b\x24\x42");
    1.45 +_LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
    1.46 +
    1.47 +typedef TInt (*FChangeState)(TInt aState);
    1.48 +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);
    1.49 +
    1.50 +enum TNonStandardState // each of these values must fit into KBitsForNonStandardStates and each must also be non-zero
    1.51 +	{
    1.52 +	ENonStandardStateJis7=1,
    1.53 +	ENonStandardStateJis8
    1.54 +	};
    1.55 +
    1.56 +
    1.57 +LOCAL_D const SCnvConversionData::SVariableByteData::SRange halfWidthKatakana7VariableByteDataRange=
    1.58 +	{
    1.59 +	0x00,
    1.60 +	0xff,
    1.61 +	0,
    1.62 +	0
    1.63 +	};
    1.64 +
    1.65 +LOCAL_D const SCnvConversionData::SOneDirectionData::SRange halfWidthKatakana7ToUnicodeDataRange=
    1.66 +	{
    1.67 +	0x21,
    1.68 +	0x5f,
    1.69 +	SCnvConversionData::SOneDirectionData::SRange::EOffset,
    1.70 +	0,
    1.71 +	0,
    1.72 +		{
    1.73 +		STATIC_CAST(TUint, 65344),
    1.74 +		0
    1.75 +		}
    1.76 +	};
    1.77 +
    1.78 +LOCAL_D const SCnvConversionData::SOneDirectionData::SRange unicodeToHalfWidthKatakana7DataRange=
    1.79 +	{
    1.80 +	0xff61,
    1.81 +	0xff9f,
    1.82 +	SCnvConversionData::SOneDirectionData::SRange::EOffset,
    1.83 +	1,
    1.84 +	0,
    1.85 +		{
    1.86 +		STATIC_CAST(TUint, -65344),
    1.87 +		0
    1.88 +		}
    1.89 +	};
    1.90 +
    1.91 +LOCAL_D const SCnvConversionData halfWidthKatakana7ConversionData=
    1.92 +	{
    1.93 +	SCnvConversionData::EUnspecified,
    1.94 +		{
    1.95 +		1,
    1.96 +		&halfWidthKatakana7VariableByteDataRange
    1.97 +		},
    1.98 +		{
    1.99 +		1,
   1.100 +		&halfWidthKatakana7ToUnicodeDataRange
   1.101 +		},
   1.102 +		{
   1.103 +		1,
   1.104 +		&unicodeToHalfWidthKatakana7DataRange
   1.105 +		}
   1.106 +	};
   1.107 +
   1.108 +#if defined(_DEBUG)
   1.109 +
   1.110 +_LIT(KLitPanicText, "JISBASE_SHARED");
   1.111 +
   1.112 +enum TPanic
   1.113 +	{
   1.114 +	EPanicNotAppending1=1,
   1.115 +	EPanicNotAppending2,
   1.116 +	EPanicNotAppending3,
   1.117 +	EPanicBadNonStandardState,
   1.118 +	EPanicBadPointers1,
   1.119 +	EPanicBadPointers2,
   1.120 +	EPanicBadPointers3,
   1.121 +	EPanicBadPointers4,
   1.122 +	EPanicBadFunctionPointer
   1.123 +	};
   1.124 +
   1.125 +LOCAL_C void Panic(TPanic aPanic)
   1.126 +	{
   1.127 +	User::Panic(KLitPanicText, aPanic);
   1.128 +	}
   1.129 +
   1.130 +#endif
   1.131 +
   1.132 +TInt CnvJisBase::ChangeToNonStandardStateJis7(TInt aState)
   1.133 +	{
   1.134 +	return (aState&~KBitsForNonStandardStates)|ENonStandardStateJis7;
   1.135 +	}
   1.136 +
   1.137 +TInt CnvJisBase::ChangeToNonStandardStateJis8(TInt aState)
   1.138 +	{
   1.139 +	return (aState&~KBitsForNonStandardStates)|ENonStandardStateJis8;
   1.140 +	}
   1.141 +
   1.142 +TInt CnvJisBase::ChangeToStandardState(TInt)
   1.143 +	{
   1.144 +	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
   1.145 +	}
   1.146 +
   1.147 +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)
   1.148 +	{
   1.149 +	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending1));
   1.150 +	return CnvUtilities::ConvertToUnicodeFromModalForeign(aDefaultEndiannessOfForeignCharacters, aUnicode, aModalForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aArrayOfStates, aOutputConversionFlags, aInputConversionFlags);
   1.151 +	}
   1.152 +
   1.153 +TInt CnvJisBase::AppendConvertToUnicodeFromJis7(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aJis7, TInt&, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>&, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
   1.154 +	{
   1.155 +	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending2));
   1.156 +	return CCnvCharacterSetConverter::DoConvertToUnicode(halfWidthKatakana7ConversionData, aDefaultEndiannessOfForeignCharacters, aUnicode, aJis7, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
   1.157 +	}
   1.158 +
   1.159 +TInt CnvJisBase::AppendConvertToUnicodeFromJis8(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aJis8, TInt&, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter, const TArray<CnvUtilities::SState>&, TUint& aOutputConversionFlags, TUint aInputConversionFlags)
   1.160 +	{
   1.161 +	__ASSERT_DEBUG(aInputConversionFlags&CCnvCharacterSetConverter::EInputConversionFlagAppend, Panic(EPanicNotAppending3));
   1.162 +	return CCnvCharacterSetConverter::DoConvertToUnicode(CnvHalfWidthKatakana8::ConversionData(), aDefaultEndiannessOfForeignCharacters, aUnicode, aJis8, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, aOutputConversionFlags, aInputConversionFlags);
   1.163 +	}
   1.164 +
   1.165 +EXPORT_C TInt CnvJisBase::ConvertToUnicode(CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, TDes16& aUnicode, const TDesC8& aForeign, TInt& aState, TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   1.166 +	{
   1.167 +    TInt ret =KErrNone;
   1.168 +    TBool pictographsSupported = FeatureManager::FeatureSupported(KFeatureIdJapanesePicto);
   1.169 +    RArray<CnvUtilities::SState> states;
   1.170 +    if ( pictographsSupported )
   1.171 +        {        
   1.172 +
   1.173 +        CnvUtilities::SState state;
   1.174 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisRoman; // Jis-Roman is the default state, so it must come first in the array
   1.175 +        state.iConversionData=&CnvJisRoman::ConversionData();
   1.176 +        ret |= states.Append(state);
   1.177 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisRomanIncorrect;
   1.178 +        state.iConversionData=&CnvJisRoman::ConversionData();
   1.179 +        ret |= states.Append(state);
   1.180 +        state.iEscapeSequence=&KLit8EscapeSequenceForAscii;
   1.181 +        state.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   1.182 +        ret |= states.Append(state);
   1.183 +    
   1.184 +        SetStatesForPictograph(states);
   1.185 +
   1.186 +        state.iEscapeSequence=&KLit8EscapeSequenceForHalfWidthKatakana;
   1.187 +        state.iConversionData=&halfWidthKatakana7ConversionData;
   1.188 +        ret |= states.Append(state);
   1.189 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisC6226_1978;
   1.190 +        state.iConversionData=&CnvJisX0208::ConversionData();
   1.191 +        ret |= states.Append(state);
   1.192 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   1.193 +        state.iConversionData=&CnvJisX0208::ConversionData();
   1.194 +        ret |= states.Append(state);
   1.195 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_199x;
   1.196 +        state.iConversionData=&CnvJisX0208::ConversionData();
   1.197 +        ret |= states.Append(state);
   1.198 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   1.199 +        state.iConversionData=&CnvJisX0212::ConversionData();
   1.200 +        ret |= states.Append(state);
   1.201 +        }
   1.202 +    else
   1.203 +        {            
   1.204 +        CnvUtilities::SState state;
   1.205 +    	state.iEscapeSequence=&KLit8EscapeSequenceForJisRoman; // Jis-Roman is the default state, so it must come first in the array
   1.206 +    	state.iConversionData=&CnvJisRoman::ConversionData();
   1.207 +    	ret |= states.Append(state);
   1.208 +        state.iEscapeSequence=&KLit8EscapeSequenceForJisRomanIncorrect;
   1.209 +    	state.iConversionData=&CnvJisRoman::ConversionData();	
   1.210 +    	ret |= states.Append(state);
   1.211 +    	state.iEscapeSequence=&KLit8EscapeSequenceForAscii;
   1.212 +    	state.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   1.213 +    	ret |= states.Append(state);
   1.214 +    	state.iEscapeSequence=&KLit8EscapeSequenceForHalfWidthKatakana;
   1.215 +    	state.iConversionData=&halfWidthKatakana7ConversionData;
   1.216 +    	ret |= states.Append(state);
   1.217 +    	state.iEscapeSequence=&KLit8EscapeSequenceForJisC6226_1978;
   1.218 +    	state.iConversionData=&CnvJisX0208::ConversionData();
   1.219 +    	ret |= states.Append(state);
   1.220 +    	state.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   1.221 +    	state.iConversionData=&CnvJisX0208::ConversionData();
   1.222 +    	ret |= states.Append(state);
   1.223 +    	state.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_199x;
   1.224 +    	state.iConversionData=&CnvJisX0208::ConversionData();
   1.225 +    	ret |= states.Append(state);
   1.226 +    	state.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   1.227 +    	state.iConversionData=&CnvJisX0212::ConversionData();
   1.228 +    	ret |= states.Append(state);
   1.229 +        }
   1.230 +    __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret));
   1.231 +    
   1.232 +	const TArray<CnvUtilities::SState> arrayOfStates(states.Array());
   1.233 +	aUnicode.SetLength(0);
   1.234 +	const TUint8* const pointerToFirstByte=aForeign.Ptr();
   1.235 +	const TUint8* pointerToCurrentByte=pointerToFirstByte;
   1.236 +	const TUint8* pointerToStartOfNextRunToConvert=pointerToFirstByte;
   1.237 +	const TUint8* const pointerToLastByte=pointerToFirstByte+(aForeign.Length()-1);
   1.238 +	TUint outputConversionFlags=0;
   1.239 +	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagAppend;
   1.240 +	FOREVER
   1.241 +		{
   1.242 +		FChangeState changeState=NULL;
   1.243 +		FAppendConvertToUnicode appendConvertToUnicode=NULL;
   1.244 +		TBool skipThisByte=EFalse;
   1.245 +		const TUint currentByte=*pointerToCurrentByte;
   1.246 +		switch (aState&KBitsForNonStandardStates)
   1.247 +			{
   1.248 +		case 0:
   1.249 +			if (currentByte==KControlCharacterShiftOut)
   1.250 +				{
   1.251 +				changeState=ChangeToNonStandardStateJis7;
   1.252 +				skipThisByte=ETrue;
   1.253 +				}
   1.254 +            else if (pictographsSupported && (currentByte==KControlCharacterShiftIn))
   1.255 +                {
   1.256 +                changeState=ChangeToStandardState;
   1.257 +                skipThisByte=ETrue;
   1.258 +                }
   1.259 +			else if (currentByte&0x80)
   1.260 +				{
   1.261 +				changeState=ChangeToNonStandardStateJis8;
   1.262 +				}
   1.263 +			appendConvertToUnicode=AppendConvertToUnicodeFromModalForeign;
   1.264 +			break;
   1.265 +		case ENonStandardStateJis7:
   1.266 +			if (currentByte==KControlCharacterEscape)
   1.267 +				{
   1.268 +				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
   1.269 +				}
   1.270 +			else if (currentByte==KControlCharacterShiftIn)
   1.271 +				{
   1.272 +				changeState=ChangeToStandardState;
   1.273 +				skipThisByte=ETrue;
   1.274 +				}
   1.275 +			else if (currentByte&0x80)
   1.276 +				{
   1.277 +				changeState=ChangeToNonStandardStateJis8;
   1.278 +				}
   1.279 +			appendConvertToUnicode=AppendConvertToUnicodeFromJis7;
   1.280 +			break;
   1.281 +		case ENonStandardStateJis8:
   1.282 +			if (currentByte==KControlCharacterEscape)
   1.283 +				{
   1.284 +				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
   1.285 +				}
   1.286 +			else if (currentByte==KControlCharacterShiftOut)
   1.287 +				{
   1.288 +				changeState=ChangeToNonStandardStateJis7;
   1.289 +				skipThisByte=ETrue;
   1.290 +				}
   1.291 +			else if ((currentByte&0x80)==0)
   1.292 +				{
   1.293 +				changeState=ChangeToStandardState;
   1.294 +				}
   1.295 +			appendConvertToUnicode=AppendConvertToUnicodeFromJis8;
   1.296 +			break;
   1.297 +#if defined(_DEBUG)
   1.298 +		default:
   1.299 +			Panic(EPanicBadNonStandardState);
   1.300 +			break;
   1.301 +#endif
   1.302 +			}
   1.303 +		__ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers1));
   1.304 +		if ((pointerToCurrentByte>=pointerToLastByte) || (changeState!=NULL))
   1.305 +			{
   1.306 +			TBool lastIteration=EFalse;
   1.307 +			__ASSERT_DEBUG(pointerToCurrentByte>=pointerToStartOfNextRunToConvert, Panic(EPanicBadPointers2));
   1.308 +			if (changeState==NULL)
   1.309 +				{
   1.310 +				++pointerToCurrentByte; // this may make pointerToCurrentByte greater than pointerToLastByte
   1.311 +				lastIteration=ETrue;
   1.312 +				}
   1.313 +			if (pointerToCurrentByte>pointerToStartOfNextRunToConvert)
   1.314 +				{
   1.315 +				TPtrC8 runToConvert(pointerToStartOfNextRunToConvert, pointerToCurrentByte-pointerToStartOfNextRunToConvert);
   1.316 +				TInt numberOfUnconvertibleCharacters;
   1.317 +				TInt indexOfFirstByteOfFirstUnconvertibleCharacter;
   1.318 +				__ASSERT_DEBUG(appendConvertToUnicode!=NULL, Panic(EPanicBadFunctionPointer));
   1.319 +				const TInt returnValue=(*appendConvertToUnicode)(aDefaultEndiannessOfForeignCharacters, aUnicode, runToConvert, aState, numberOfUnconvertibleCharacters, indexOfFirstByteOfFirstUnconvertibleCharacter, arrayOfStates, outputConversionFlags, inputConversionFlags);
   1.320 +				if (returnValue<0)
   1.321 +					{
   1.322 +                    states.Close();
   1.323 +					return returnValue; // this is an error-code
   1.324 +					}
   1.325 +				if (numberOfUnconvertibleCharacters>0)
   1.326 +					{
   1.327 +					if (aNumberOfUnconvertibleCharacters==0)
   1.328 +						{
   1.329 +						aIndexOfFirstByteOfFirstUnconvertibleCharacter=(pointerToStartOfNextRunToConvert-pointerToFirstByte)+indexOfFirstByteOfFirstUnconvertibleCharacter;
   1.330 +						}
   1.331 +					aNumberOfUnconvertibleCharacters+=numberOfUnconvertibleCharacters;
   1.332 +					}
   1.333 +				if (returnValue>0)
   1.334 +					{
   1.335 +					pointerToCurrentByte-=returnValue; // pointerToStartOfNextRunToConvert (which also needs adjusting in the same way) gets set below
   1.336 +					lastIteration=ETrue;
   1.337 +					changeState=NULL;
   1.338 +					skipThisByte=EFalse;
   1.339 +					}
   1.340 +				__ASSERT_DEBUG(pointerToCurrentByte>=pointerToFirstByte, Panic(EPanicBadPointers3));
   1.341 +				if (pointerToCurrentByte>pointerToFirstByte)
   1.342 +					{
   1.343 +					inputConversionFlags|=CCnvCharacterSetConverter::EInputConversionFlagAllowTruncatedInputNotEvenPartlyConsumable;
   1.344 +					}
   1.345 +				}
   1.346 +			if (changeState!=NULL)
   1.347 +				{
   1.348 +				aState=(*changeState)(aState);
   1.349 +				}
   1.350 +			if (skipThisByte)
   1.351 +				{
   1.352 +				if (pointerToCurrentByte==pointerToLastByte) // pointerToCurrentByte may already be greater than pointerToLastByte, in which case lastIteration will already be ETrue
   1.353 +					{
   1.354 +					lastIteration=ETrue;
   1.355 +					}
   1.356 +				++pointerToCurrentByte;
   1.357 +				}
   1.358 +			pointerToStartOfNextRunToConvert=pointerToCurrentByte;
   1.359 +			if (lastIteration) // check this first as pointerToCurrentByte may be greater than pointerToLastByte (but it will only be if lastIteration is EFalse)
   1.360 +				{
   1.361 +				break;
   1.362 +				}
   1.363 +			__ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers4));
   1.364 +			if (pointerToCurrentByte>=pointerToLastByte)
   1.365 +				{
   1.366 +				break;
   1.367 +				}
   1.368 +			}
   1.369 +		++pointerToCurrentByte;
   1.370 +		}
   1.371 +
   1.372 +    states.Close();
   1.373 +	// no checking with outputConversionFlags need to be done here
   1.374 +	return pointerToLastByte-(pointerToCurrentByte-1);
   1.375 +	}
   1.376 +
   1.377 +EXPORT_C const SCnvConversionData& CnvJisBase::HalfWidthKatakana7ConversionData()
   1.378 +	{
   1.379 +	return halfWidthKatakana7ConversionData;
   1.380 +	}
   1.381 +
   1.382 +EXPORT_C void CnvJisBase::IsCharacterJISBased(TInt& aConfidenceLevel, const TDesC8& aSample) 
   1.383 +	{
   1.384 +	// JIS is modal... so start off with a confidence of 0 and to begin with look 
   1.385 +	// for JIS escape sequences....Escape sequences defined above in the KLITs
   1.386 +	// For each escape sequence, increase the confidenceLevel ..... 
   1.387 +	aConfidenceLevel = 55;
   1.388 +	TInt jisRomanResult = 0;
   1.389 +	TInt asciiResult = 0;
   1.390 +	TInt jisX0208Result = 0;
   1.391 +	TInt jisC6226Result = 0;
   1.392 +	TInt jixX0212Result = 0;
   1.393 +	TInt hwKanaResult = 0;
   1.394 +
   1.395 +	TInt EscSequences = 0;
   1.396 +	
   1.397 +	TInt sampleLength = aSample.Length();
   1.398 +	for (TInt i = 0; i < sampleLength; ++i)
   1.399 +		{
   1.400 +	
   1.401 +		// JIS is 7 bit encoding
   1.402 +		if((aSample[i]&0x80)!=0x00)
   1.403 +			{
   1.404 +			aConfidenceLevel=0;
   1.405 +			break;
   1.406 +			}
   1.407 +		// JIS supports the following character sets 
   1.408 +		if (i > jisC6226Result)
   1.409 +			{
   1.410 +			jisC6226Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisC6226_1978);
   1.411 +			if (jisC6226Result!=KErrNotFound)
   1.412 +				EscSequences += 15; 
   1.413 +			}
   1.414 +
   1.415 +		if (i > jisRomanResult)
   1.416 +			{
   1.417 +			jisRomanResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisRoman);
   1.418 +			if (jisRomanResult!=KErrNotFound)
   1.419 +				EscSequences += 15; 
   1.420 +			}
   1.421 +
   1.422 +		if (i > asciiResult)
   1.423 +			{
   1.424 +			asciiResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForAscii);
   1.425 +			if (asciiResult!=KErrNotFound)
   1.426 +				EscSequences += 15; 
   1.427 +			}
   1.428 +
   1.429 +		if (i > jisX0208Result)
   1.430 +			{
   1.431 +			jisX0208Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisX0208_1983);
   1.432 +			if (jisX0208Result!=KErrNotFound)
   1.433 +				EscSequences += 15; 
   1.434 +			}
   1.435 +
   1.436 +		if (i > jixX0212Result)
   1.437 +			{
   1.438 +			jixX0212Result=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForJisX0212_1990);
   1.439 +			if (jixX0212Result!=KErrNotFound)
   1.440 +				EscSequences += 15; 
   1.441 +			}
   1.442 +
   1.443 +		if (i > hwKanaResult)
   1.444 +			{
   1.445 +			hwKanaResult=(aSample.Right(sampleLength-i)).Find(KLit8EscapeSequenceForHalfWidthKatakana);
   1.446 +			if (hwKanaResult!=KErrNotFound)
   1.447 +				EscSequences += 15; 
   1.448 +			}
   1.449 +		}
   1.450 +
   1.451 +	aConfidenceLevel = 0 < sampleLength?
   1.452 +		aConfidenceLevel + ((EscSequences*100)/sampleLength) : 90;
   1.453 +	aConfidenceLevel=(aConfidenceLevel >100)?100:aConfidenceLevel;
   1.454 +	}