sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: #include "PictographObserver.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "jisx0201.h" sl@0: #include "jisx0208.h" sl@0: #include "jisx0212.h" sl@0: #include sl@0: #include "charactersetconverter.h" sl@0: #include "featmgr/featmgr.h" sl@0: sl@0: const TUint KSingleShift2=0x8e; sl@0: const TUint KSingleShift3=0x8f; sl@0: sl@0: // SecureID for Brower app sl@0: const TUint32 KBrowserSecureId = 0x10008D39; sl@0: // Define for converting from YenSign to BackSlash sl@0: const TUint KCharacterCodeForYenSign = 0x00A5; sl@0: const TUint KCharacterCodeForBackSlash = 0x005C; sl@0: sl@0: _LIT8(KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters, "\xa1\xa9"); // fullwidth question mark sl@0: sl@0: #if defined(_DEBUG) sl@0: sl@0: _LIT(KLitPanicText, "EUCJP_PACKED"); sl@0: sl@0: enum TPanic sl@0: { sl@0: EPanicNothingToConvert1=1, sl@0: EPanicNothingToConvert2, sl@0: EPanicNothingToConvert3, sl@0: EPanicNothingToConvert4, sl@0: EPanicNothingToConvert5, sl@0: EPanicNothingToConvert6, sl@0: EPanicOddNumberOfBytes1, sl@0: EPanicOddNumberOfBytes2, sl@0: EPanicOddNumberOfBytes3, sl@0: EPanicOddNumberOfBytes4, sl@0: EPanicOddNumberOfBytes5, sl@0: EPanicOddNumberOfBytes6, sl@0: EPanicBadHighBit1, sl@0: EPanicBadHighBit2, sl@0: EPanicBadHighBit3, sl@0: EPanicBadHighBit4, sl@0: EPanicBadHighBit5, sl@0: EPanicBadHighBit6, sl@0: EPanicBadHighBit7, sl@0: EPanicBadPointers1, sl@0: EPanicBadPointers2, sl@0: EPanicBadPointers3, sl@0: EPanicBadPointers4, sl@0: EPanicBadPointers5, sl@0: EPanicBadPointers6, sl@0: EPanicBadPointers7, sl@0: EPanicBadPointers8, sl@0: EPanicBadPointers9, sl@0: EPanicBadPointers10, sl@0: EPanicBadPointers11, sl@0: EPanicBadPointers12, sl@0: EPanicBadPointers13, sl@0: EPanicBadPointers14, sl@0: EPanicBadPointers15, sl@0: EPanicBadPointers16, sl@0: EPanicBadPointers17, sl@0: EPanicBadPointers18, sl@0: EPanicBadPointers19, sl@0: EPanicBadPointers20, sl@0: EPanicBadPointers21, sl@0: EPanicBadPointers22, sl@0: EPanicBadPointers23, sl@0: EPanicBadPointers24, sl@0: EPanicBadPointers25, sl@0: EPanicBadPointers26, sl@0: EPanicBadPointers27, sl@0: EPanicBadPointers28, sl@0: EPanicBadPointers29, sl@0: EPanicBadPointers30, sl@0: EPanicBadPointers31, sl@0: EPanicBadPointers32, sl@0: EPanicBadPointers33, sl@0: EPanicBadPointers34, sl@0: EPanicBadPointers35, sl@0: EPanicBadPointers36, sl@0: EPanicBadCalculation1, sl@0: EPanicBadCalculation2, sl@0: EPanicNumberOfBytesIsNotMultipleOfThree1, sl@0: EPanicNumberOfBytesIsNotMultipleOfThree2, sl@0: EPanicSingleShift2Expected, sl@0: EPanicSingleShift3Expected sl@0: }; sl@0: sl@0: LOCAL_C void Panic(TPanic aPanic) sl@0: { sl@0: User::Panic(KLitPanicText, aPanic); sl@0: } sl@0: sl@0: #endif sl@0: sl@0: sl@0: class CEucjpPackedConverterImpl : public CCharacterSetConverterPluginInterface sl@0: { sl@0: sl@0: public: sl@0: virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters(); sl@0: sl@0: virtual TInt ConvertFromUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, sl@0: TDes8& aForeign, sl@0: const TDesC16& aUnicode, sl@0: CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters); sl@0: sl@0: virtual TInt ConvertToUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: TDes16& aUnicode, sl@0: const TDesC8& aForeign, sl@0: TInt& aState, sl@0: TInt& aNumberOfUnconvertibleCharacters, sl@0: TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter); sl@0: sl@0: virtual TBool IsInThisCharacterSetL( sl@0: TBool& aSetToTrue, sl@0: TInt& aConfidenceLevel, sl@0: const TDesC8& aSample); sl@0: sl@0: static CEucjpPackedConverterImpl* NewL(); sl@0: virtual ~CEucjpPackedConverterImpl(); sl@0: sl@0: private: sl@0: CEucjpPackedConverterImpl(); sl@0: void ConstructL(); sl@0: sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: const TDesC8& CEucjpPackedConverterImpl::ReplacementForUnconvertibleUnicodeCharacters() sl@0: { sl@0: return KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters; sl@0: } sl@0: sl@0: LOCAL_C void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: aNumberOfCharactersThatDroppedOut=0; sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromJisX0208ToEucJpPackedInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: aNumberOfCharactersThatDroppedOut=0; sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>aStartPositionInDescriptor, Panic(EPanicNothingToConvert1)); sl@0: __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes1)); sl@0: TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1); sl@0: pointerToCurrentByte+=aStartPositionInDescriptor; sl@0: FOREVER sl@0: { sl@0: const TUint currentByte=*pointerToCurrentByte; sl@0: __ASSERT_DEBUG((currentByte&0x80)==0, Panic(EPanicBadHighBit1)); sl@0: *pointerToCurrentByte=STATIC_CAST(TUint8, currentByte|0x80); sl@0: __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers1)); sl@0: if (pointerToCurrentByte>=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToCurrentByte; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>aStartPositionInDescriptor, Panic(EPanicNothingToConvert2)); sl@0: aNumberOfCharactersThatDroppedOut=Max(0, (descriptorLength-aStartPositionInDescriptor)-((aDescriptor.MaxLength()-aStartPositionInDescriptor)/2)); sl@0: descriptorLength-=aNumberOfCharactersThatDroppedOut; sl@0: __ASSERT_DEBUG(descriptorLength>=aStartPositionInDescriptor, Panic(EPanicBadCalculation1)); sl@0: if (descriptorLength<=aStartPositionInDescriptor) sl@0: { sl@0: aDescriptor.SetLength(descriptorLength); sl@0: } sl@0: else sl@0: { sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); // pointerToTargetByte is initialized properly when descriptorLength has been offset to the actual final length of aDescriptor sl@0: const TUint8* const pointerToFirstByte=pointerToTargetByte+aStartPositionInDescriptor; sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte+(descriptorLength-1); sl@0: descriptorLength=((descriptorLength-aStartPositionInDescriptor)*2)+aStartPositionInDescriptor; sl@0: __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes2)); sl@0: aDescriptor.SetLength(descriptorLength); sl@0: pointerToTargetByte+=descriptorLength-1; // pointerToTargetByte is is initialized properly here sl@0: FOREVER sl@0: { sl@0: *pointerToTargetByte=*pointerToSourceByte; sl@0: __ASSERT_DEBUG(pointerToTargetByte>pointerToFirstByte, Panic(EPanicBadPointers2)); sl@0: --pointerToTargetByte; sl@0: *pointerToTargetByte=KSingleShift2; sl@0: __ASSERT_DEBUG(pointerToTargetByte>=pointerToFirstByte, Panic(EPanicBadPointers3)); sl@0: if (pointerToTargetByte<=pointerToFirstByte) sl@0: { sl@0: break; sl@0: } sl@0: --pointerToTargetByte; sl@0: __ASSERT_DEBUG(pointerToSourceByte>pointerToFirstByte, Panic(EPanicBadPointers4)); sl@0: --pointerToSourceByte; sl@0: } sl@0: __ASSERT_DEBUG(pointerToTargetByte==pointerToFirstByte, Panic(EPanicBadPointers5)); sl@0: __ASSERT_DEBUG(pointerToSourceByte==pointerToFirstByte, Panic(EPanicBadPointers6)); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromJisX0212ToEucJpPackedInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>aStartPositionInDescriptor, Panic(EPanicNothingToConvert3)); sl@0: __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes3)); sl@0: aNumberOfCharactersThatDroppedOut=Max(0, ((descriptorLength-aStartPositionInDescriptor)/2)-((aDescriptor.MaxLength()-aStartPositionInDescriptor)/3)); sl@0: descriptorLength-=aNumberOfCharactersThatDroppedOut*2; sl@0: __ASSERT_DEBUG(descriptorLength>=aStartPositionInDescriptor, Panic(EPanicBadCalculation2)); sl@0: if (descriptorLength<=aStartPositionInDescriptor) sl@0: { sl@0: aDescriptor.SetLength(descriptorLength); sl@0: } sl@0: else sl@0: { sl@0: __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes4)); sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); // pointerToTargetByte is initialized properly when descriptorLength has been offset to the actual final length of aDescriptor sl@0: const TUint8* const pointerToFirstByte=pointerToTargetByte+aStartPositionInDescriptor; sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte+(descriptorLength-1); sl@0: descriptorLength=(((descriptorLength-aStartPositionInDescriptor)*3)/2)+aStartPositionInDescriptor; sl@0: __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%3==0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree1)); sl@0: aDescriptor.SetLength(descriptorLength); sl@0: pointerToTargetByte+=descriptorLength-1; // pointerToTargetByte is is initialized properly here sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG((*pointerToSourceByte&0x80)==0, Panic(EPanicBadHighBit2)); sl@0: *pointerToTargetByte=STATIC_CAST(TUint8, *pointerToSourceByte|0x80); sl@0: __ASSERT_DEBUG(pointerToTargetByte>pointerToFirstByte, Panic(EPanicBadPointers7)); sl@0: --pointerToTargetByte; sl@0: __ASSERT_DEBUG(pointerToSourceByte>pointerToFirstByte, Panic(EPanicBadPointers8)); sl@0: --pointerToSourceByte; sl@0: __ASSERT_DEBUG((*pointerToSourceByte&0x80)==0, Panic(EPanicBadHighBit3)); sl@0: *pointerToTargetByte=STATIC_CAST(TUint8, *pointerToSourceByte|0x80); sl@0: __ASSERT_DEBUG(pointerToTargetByte>pointerToFirstByte, Panic(EPanicBadPointers9)); sl@0: --pointerToTargetByte; sl@0: *pointerToTargetByte=KSingleShift3; sl@0: __ASSERT_DEBUG(pointerToTargetByte>=pointerToFirstByte, Panic(EPanicBadPointers10)); sl@0: if (pointerToTargetByte<=pointerToFirstByte) sl@0: { sl@0: break; sl@0: } sl@0: --pointerToTargetByte; sl@0: __ASSERT_DEBUG(pointerToSourceByte>pointerToFirstByte, Panic(EPanicBadPointers11)); sl@0: --pointerToSourceByte; sl@0: } sl@0: __ASSERT_DEBUG(pointerToTargetByte==pointerToFirstByte, Panic(EPanicBadPointers12)); sl@0: __ASSERT_DEBUG(pointerToSourceByte==pointerToFirstByte, Panic(EPanicBadPointers13)); sl@0: } sl@0: } sl@0: sl@0: TInt CEucjpPackedConverterImpl::ConvertFromUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, sl@0: TDes8& aForeign, sl@0: const TDesC16& aUnicode, sl@0: CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters) sl@0: { sl@0: TInt ret = KErrNone; sl@0: RArray characterSets; sl@0: if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) ) sl@0: { sl@0: CnvUtilities::SCharacterSet characterSet; sl@0: sl@0: characterSet.iConversionData=&CnvJisRoman::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=DummyConvertFromIntermediateBufferInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0208::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvHalfWidthKatakana8::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0212::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: sl@0: SetCharacterSetsForPictograph(characterSets, ECharsetEucJp); sl@0: } sl@0: else sl@0: { sl@0: CnvUtilities::SCharacterSet characterSet; sl@0: characterSet.iConversionData=&CnvJisRoman::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=DummyConvertFromIntermediateBufferInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0208::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvHalfWidthKatakana8::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0212::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToEucJpPackedInPlace; sl@0: characterSet.iEscapeSequence=&KNullDesC8; sl@0: ret |= characterSets.Append(characterSet); sl@0: } sl@0: __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret)); sl@0: TInt unconvert = CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, characterSets.Array()); sl@0: sl@0: characterSets.Close(); sl@0: return unconvert; sl@0: } sl@0: sl@0: LOCAL_C TInt NumberOfBytesAbleToConvertToJisRoman(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: LOCAL_C TInt NumberOfBytesAbleToConvertToHalfWidthKatakana8(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0212(const TDesC8& aDescriptor) sl@0: { sl@0: const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1; sl@0: const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length(); sl@0: if (pointerToPreviousByte==pointerToLastByte) sl@0: { sl@0: return 0; sl@0: } sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(pointerToPreviousByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: return (pointerToPreviousByte+1)-aDescriptor.Ptr(); sl@0: } sl@0: sl@0: LOCAL_C void DummyConvertToIntermediateBufferInPlace(TDes8&) sl@0: { sl@0: } sl@0: sl@0: LOCAL_C void ConvertToJisX0208FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert4)); sl@0: __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes5)); sl@0: TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: const TUint currentByte=*pointerToCurrentByte; sl@0: __ASSERT_DEBUG(currentByte&0x80, Panic(EPanicBadHighBit4)); sl@0: *pointerToCurrentByte=STATIC_CAST(TUint8, currentByte&~0x80); sl@0: __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers30)); sl@0: if (pointerToCurrentByte>=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToCurrentByte; sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void ConvertToHalfWidthKatakana8FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert5)); sl@0: __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes6)); sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte; sl@0: const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift2, Panic(EPanicSingleShift2Expected)); sl@0: __ASSERT_DEBUG(pointerToSourceByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToSourceByte; sl@0: ++pointerToTargetByte; sl@0: } sl@0: aDescriptor.SetLength(descriptorLength/2); sl@0: } sl@0: sl@0: LOCAL_C void ConvertToJisX0212FromEucJpPackedInPlace(TDes8& aDescriptor) sl@0: { sl@0: const TInt descriptorLength=aDescriptor.Length(); sl@0: __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert6)); sl@0: __ASSERT_DEBUG(descriptorLength%3==0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree2)); sl@0: TUint8* pointerToTargetByte=CONST_CAST(TUint8*, aDescriptor.Ptr()); sl@0: const TUint8* pointerToSourceByte=pointerToTargetByte; sl@0: const TUint8* const pointerToLastByte=pointerToSourceByte+(descriptorLength-1); sl@0: FOREVER sl@0: { sl@0: __ASSERT_DEBUG(*pointerToSourceByte==KSingleShift3, Panic(EPanicSingleShift3Expected)); sl@0: __ASSERT_DEBUG(pointerToSourceByte=pointerToLastByte) sl@0: { sl@0: break; sl@0: } sl@0: ++pointerToSourceByte; sl@0: ++pointerToTargetByte; sl@0: } sl@0: aDescriptor.SetLength((descriptorLength/3)*2); sl@0: } sl@0: sl@0: TInt CEucjpPackedConverterImpl::ConvertToUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: TDes16& aUnicode, sl@0: const TDesC8& aForeign, sl@0: TInt& /*aState*/, sl@0: TInt& aNumberOfUnconvertibleCharacters, sl@0: TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter) sl@0: { sl@0: TInt ret =KErrNone; sl@0: RArray methods; sl@0: if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) ) sl@0: { sl@0: CnvUtilities::SMethod method; sl@0: SetMethodsForPictograph(methods, ECharsetEucJp); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisRoman; sl@0: method.iConvertToIntermediateBufferInPlace=DummyConvertToIntermediateBufferInPlace; sl@0: method.iConversionData=&CnvJisRoman::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=1; sl@0: method.iNumberOfCoreBytesPerCharacter=1; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisX0208; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToJisX0208FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvJisX0208::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=2; sl@0: method.iNumberOfCoreBytesPerCharacter=2; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToHalfWidthKatakana8; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToHalfWidthKatakana8FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvHalfWidthKatakana8::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=2; sl@0: method.iNumberOfCoreBytesPerCharacter=1; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisX0212; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToJisX0212FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvJisX0212::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=3; sl@0: method.iNumberOfCoreBytesPerCharacter=2; sl@0: ret |= methods.Append(method); sl@0: } sl@0: else sl@0: { sl@0: CnvUtilities::SMethod method; sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisRoman; sl@0: method.iConvertToIntermediateBufferInPlace=DummyConvertToIntermediateBufferInPlace; sl@0: method.iConversionData=&CnvJisRoman::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=1; sl@0: method.iNumberOfCoreBytesPerCharacter=1; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisX0208; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToJisX0208FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvJisX0208::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=2; sl@0: method.iNumberOfCoreBytesPerCharacter=2; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToHalfWidthKatakana8; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToHalfWidthKatakana8FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvHalfWidthKatakana8::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=2; sl@0: method.iNumberOfCoreBytesPerCharacter=1; sl@0: ret |= methods.Append(method); sl@0: method.iNumberOfBytesAbleToConvert=NumberOfBytesAbleToConvertToJisX0212; sl@0: method.iConvertToIntermediateBufferInPlace=ConvertToJisX0212FromEucJpPackedInPlace; sl@0: method.iConversionData=&CnvJisX0212::ConversionData(); sl@0: method.iNumberOfBytesPerCharacter=3; sl@0: method.iNumberOfCoreBytesPerCharacter=2; sl@0: ret |= methods.Append(method); sl@0: } sl@0: __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret)); sl@0: TInt unconvert = CnvUtilities::ConvertToUnicodeFromHeterogeneousForeign(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter, methods.Array()); sl@0: sl@0: // The following is specific impelementation for brower. sl@0: // If brower app calls this API, the yen sign code(0xA5) sl@0: // must be converted to backslash code(0x5C). sl@0: // Becasue Javascript supports backslash code ony. sl@0: TBool browserProcess = (RProcess().SecureId().iId == KBrowserSecureId); sl@0: if (browserProcess && aUnicode.Length() > 0) sl@0: { sl@0: const TUint16* pB = aUnicode.Ptr(); sl@0: const TUint16* pbase = pB; sl@0: const TUint16* pE = pB + aUnicode.Length() -1; sl@0: while (pE>=pbase) sl@0: { sl@0: if (*pbase == KCharacterCodeForYenSign) sl@0: { sl@0: aUnicode[pbase - pB] = KCharacterCodeForBackSlash; sl@0: } sl@0: pbase++; sl@0: } sl@0: } sl@0: sl@0: methods.Close(); sl@0: return unconvert; sl@0: } sl@0: sl@0: TBool CEucjpPackedConverterImpl::IsInThisCharacterSetL( sl@0: TBool& aSetToTrue, sl@0: TInt& aConfidenceLevel, sl@0: const TDesC8& aSample) sl@0: { sl@0: aSetToTrue=ETrue; sl@0: // check for the SS2 and SS3 which specifies Code Set 2 & 3 respectively from the Code space sl@0: // between 00-7f only... then ambiguous sl@0: aSetToTrue = ETrue; sl@0: TInt sampleLength = aSample.Length(); sl@0: TInt eucjpPacked = 0; sl@0: aConfidenceLevel = 0; sl@0: sl@0: for (TInt i = 0; i < sampleLength; ++i) sl@0: { sl@0: // Code set 1 JISX 0208 support sl@0: TInt increment1 = i+1; sl@0: if (increment1 >= sampleLength) sl@0: break; sl@0: if (((aSample[i] >= 0xa1) && (aSample[i] <= 0xfe)) && sl@0: ((aSample[increment1] >= 0xa1) && (aSample[increment1] <= 0xfe))) sl@0: { sl@0: eucjpPacked = eucjpPacked +2; sl@0: i++; sl@0: } sl@0: // Single Shift 2 (SS2) sequence - Code Set 2 sl@0: if (aSample[i]==0x8e) sl@0: { sl@0: TInt increment1 = i+1; sl@0: if (increment1 >= sampleLength) sl@0: break; sl@0: if ((aSample[increment1] >= 0xa1) && (aSample[increment1] <= 0xdf)) sl@0: { sl@0: eucjpPacked = eucjpPacked+2; sl@0: i++; sl@0: } sl@0: else sl@0: { sl@0: eucjpPacked = 0; sl@0: break; sl@0: } sl@0: } sl@0: // Single Shift 3 (SS3) sequence - Code Set 3 sl@0: if (aSample[i]==0x8f) sl@0: { sl@0: TInt increment1 = i+1; sl@0: TInt increment2 = i+2; sl@0: if ((increment1 >= sampleLength) || (increment2 >= sampleLength)) sl@0: break; sl@0: if (((aSample[increment1] >= 0xa1) && (aSample[increment1] <= 0xfe)) && sl@0: ((aSample[increment2] >= 0xa1) && (aSample[increment2] <= 0xfe))) sl@0: { sl@0: eucjpPacked = eucjpPacked +3; sl@0: i+=2; sl@0: } sl@0: else sl@0: { sl@0: eucjpPacked =0; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: if (eucjpPacked) sl@0: aConfidenceLevel = (eucjpPacked*100)/sampleLength; sl@0: else sl@0: aConfidenceLevel = 0; sl@0: aConfidenceLevel=(aConfidenceLevel >100)?100:aConfidenceLevel; sl@0: return ETrue; sl@0: } sl@0: sl@0: CEucjpPackedConverterImpl* CEucjpPackedConverterImpl::NewL() sl@0: { sl@0: CEucjpPackedConverterImpl* self = new(ELeave) CEucjpPackedConverterImpl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CEucjpPackedConverterImpl::~CEucjpPackedConverterImpl() sl@0: { sl@0: FeatureManager::UnInitializeLib(); sl@0: } sl@0: sl@0: CEucjpPackedConverterImpl::CEucjpPackedConverterImpl() sl@0: { sl@0: } sl@0: sl@0: void CEucjpPackedConverterImpl::ConstructL() sl@0: { sl@0: FeatureManager::InitializeLibL(); sl@0: } sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: #ifdef S60_TEST sl@0: IMPLEMENTATION_PROXY_ENTRY(0x01000005,CEucjpPackedConverterImpl::NewL) sl@0: #else sl@0: IMPLEMENTATION_PROXY_ENTRY(0x10006067,CEucjpPackedConverterImpl::NewL) sl@0: #endif sl@0: }; sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: sl@0: return ImplementationTable; sl@0: } sl@0: