os/textandloc/charconvfw/charconvplugins/src/plugins/iso2022jp1.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconvplugins/src/plugins/iso2022jp1.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,168 @@
     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 <e32std.h>
    1.23 +#include <charconv.h>
    1.24 +#include <convutils.h>
    1.25 +#include "jisbase.h"
    1.26 +#include "jisx0201.h"
    1.27 +#include "jisx0208.h"
    1.28 +#include "jisx0212.h"
    1.29 +#include <ecom/implementationproxy.h>
    1.30 +#include <charactersetconverter.h>
    1.31 +
    1.32 +_LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    1.33 +_LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
    1.34 +_LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    1.35 +_LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
    1.36 +_LIT8(KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
    1.37 +
    1.38 +
    1.39 +class CISO2022JP1ConverterImpl : public CCharacterSetConverterPluginInterface
    1.40 +	{
    1.41 +
    1.42 +public:
    1.43 +	virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
    1.44 +
    1.45 +	virtual TInt ConvertFromUnicode(
    1.46 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    1.47 +		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    1.48 +		TDes8& aForeign, 
    1.49 +		const TDesC16& aUnicode, 
    1.50 +		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
    1.51 +
    1.52 +	virtual TInt ConvertToUnicode(
    1.53 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    1.54 +		TDes16& aUnicode, 
    1.55 +		const TDesC8& aForeign, 
    1.56 +		TInt& aState, 
    1.57 +		TInt& aNumberOfUnconvertibleCharacters, 
    1.58 +		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
    1.59 +
    1.60 +	virtual TBool IsInThisCharacterSetL(
    1.61 +		TBool& aSetToTrue, 
    1.62 +		TInt& aConfidenceLevel, 
    1.63 +		const TDesC8& aSample);
    1.64 +
    1.65 +	static CISO2022JP1ConverterImpl* NewL();
    1.66 +	virtual ~CISO2022JP1ConverterImpl();
    1.67 +
    1.68 +private:
    1.69 +	CISO2022JP1ConverterImpl();
    1.70 +
    1.71 +	};
    1.72 +
    1.73 +
    1.74 +const TDesC8& CISO2022JP1ConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
    1.75 +	{
    1.76 +	return KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters;
    1.77 +	}
    1.78 +
    1.79 +LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.80 +	{
    1.81 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
    1.82 +	}
    1.83 +
    1.84 +LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.85 +	{
    1.86 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
    1.87 +	}
    1.88 +
    1.89 +LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.90 +	{
    1.91 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
    1.92 +	}
    1.93 +
    1.94 +LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.95 +	{
    1.96 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2);
    1.97 +	}
    1.98 +
    1.99 +TInt CISO2022JP1ConverterImpl::ConvertFromUnicode(
   1.100 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   1.101 +		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
   1.102 +		TDes8& aForeign, 
   1.103 +		const TDesC16& aUnicode, 
   1.104 +		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
   1.105 +	{
   1.106 +	TFixedArray<CnvUtilities::SCharacterSet, 4> characterSets;
   1.107 +	characterSets[0].iConversionData=&CnvJisRoman::ConversionData();
   1.108 +	characterSets[0].iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   1.109 +	characterSets[0].iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   1.110 +	characterSets[1].iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   1.111 +	characterSets[1].iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   1.112 +	characterSets[1].iEscapeSequence=&KLit8EscapeSequenceForAscii;
   1.113 +	characterSets[2].iConversionData=&CnvJisX0208::ConversionData();
   1.114 +	characterSets[2].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   1.115 +	characterSets[2].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   1.116 +	characterSets[3].iConversionData=&CnvJisX0212::ConversionData();
   1.117 +	characterSets[3].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
   1.118 +	characterSets[3].iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   1.119 +	TUint notUsed;
   1.120 +	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet;
   1.121 +	return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, characterSets.Array(),notUsed,inputConversionFlags);
   1.122 +	}
   1.123 +
   1.124 +TInt CISO2022JP1ConverterImpl::ConvertToUnicode(
   1.125 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   1.126 +		TDes16& aUnicode, 
   1.127 +		const TDesC8& aForeign, 
   1.128 +		TInt& aState, 
   1.129 +		TInt& aNumberOfUnconvertibleCharacters, 
   1.130 +		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   1.131 +	{
   1.132 +	return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
   1.133 +	}
   1.134 +
   1.135 +TBool CISO2022JP1ConverterImpl::IsInThisCharacterSetL(
   1.136 +		TBool& aSetToTrue, 
   1.137 +		TInt& aConfidenceLevel, 
   1.138 +		const TDesC8& aSample)
   1.139 +	{
   1.140 +	aSetToTrue=ETrue;
   1.141 +	CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
   1.142 +	return ETrue;
   1.143 +	}
   1.144 +
   1.145 +CISO2022JP1ConverterImpl* CISO2022JP1ConverterImpl::NewL()
   1.146 +	{
   1.147 +	CISO2022JP1ConverterImpl* self = new(ELeave) CISO2022JP1ConverterImpl();
   1.148 +	return self;
   1.149 +	}
   1.150 +
   1.151 +CISO2022JP1ConverterImpl::~CISO2022JP1ConverterImpl()
   1.152 +	{
   1.153 +	}
   1.154 +
   1.155 +CISO2022JP1ConverterImpl::CISO2022JP1ConverterImpl()
   1.156 +	{
   1.157 +	}
   1.158 +
   1.159 +
   1.160 +const TImplementationProxy ImplementationTable[] = 
   1.161 +	{
   1.162 +		IMPLEMENTATION_PROXY_ENTRY(0x100066A3,	CISO2022JP1ConverterImpl::NewL)
   1.163 +	};
   1.164 +
   1.165 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   1.166 +	{
   1.167 +	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   1.168 +
   1.169 +	return ImplementationTable;
   1.170 +	}
   1.171 +