os/textandloc/charconvfw/charconvplugins/src/plugins/iso2022jp1.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.
     1 /*
     2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <e32std.h>
    20 #include <charconv.h>
    21 #include <convutils.h>
    22 #include "jisbase.h"
    23 #include "jisx0201.h"
    24 #include "jisx0208.h"
    25 #include "jisx0212.h"
    26 #include <ecom/implementationproxy.h>
    27 #include <charactersetconverter.h>
    28 
    29 _LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    30 _LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
    31 _LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    32 _LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
    33 _LIT8(KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
    34 
    35 
    36 class CISO2022JP1ConverterImpl : public CCharacterSetConverterPluginInterface
    37 	{
    38 
    39 public:
    40 	virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
    41 
    42 	virtual TInt ConvertFromUnicode(
    43 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    44 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    45 		TDes8& aForeign, 
    46 		const TDesC16& aUnicode, 
    47 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
    48 
    49 	virtual TInt ConvertToUnicode(
    50 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    51 		TDes16& aUnicode, 
    52 		const TDesC8& aForeign, 
    53 		TInt& aState, 
    54 		TInt& aNumberOfUnconvertibleCharacters, 
    55 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
    56 
    57 	virtual TBool IsInThisCharacterSetL(
    58 		TBool& aSetToTrue, 
    59 		TInt& aConfidenceLevel, 
    60 		const TDesC8& aSample);
    61 
    62 	static CISO2022JP1ConverterImpl* NewL();
    63 	virtual ~CISO2022JP1ConverterImpl();
    64 
    65 private:
    66 	CISO2022JP1ConverterImpl();
    67 
    68 	};
    69 
    70 
    71 const TDesC8& CISO2022JP1ConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
    72 	{
    73 	return KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters;
    74 	}
    75 
    76 LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    77 	{
    78 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
    79 	}
    80 
    81 LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    82 	{
    83 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
    84 	}
    85 
    86 LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    87 	{
    88 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
    89 	}
    90 
    91 LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    92 	{
    93 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2);
    94 	}
    95 
    96 TInt CISO2022JP1ConverterImpl::ConvertFromUnicode(
    97 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    98 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    99 		TDes8& aForeign, 
   100 		const TDesC16& aUnicode, 
   101 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
   102 	{
   103 	TFixedArray<CnvUtilities::SCharacterSet, 4> characterSets;
   104 	characterSets[0].iConversionData=&CnvJisRoman::ConversionData();
   105 	characterSets[0].iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   106 	characterSets[0].iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   107 	characterSets[1].iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   108 	characterSets[1].iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   109 	characterSets[1].iEscapeSequence=&KLit8EscapeSequenceForAscii;
   110 	characterSets[2].iConversionData=&CnvJisX0208::ConversionData();
   111 	characterSets[2].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   112 	characterSets[2].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   113 	characterSets[3].iConversionData=&CnvJisX0212::ConversionData();
   114 	characterSets[3].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
   115 	characterSets[3].iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   116 	TUint notUsed;
   117 	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet;
   118 	return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, characterSets.Array(),notUsed,inputConversionFlags);
   119 	}
   120 
   121 TInt CISO2022JP1ConverterImpl::ConvertToUnicode(
   122 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   123 		TDes16& aUnicode, 
   124 		const TDesC8& aForeign, 
   125 		TInt& aState, 
   126 		TInt& aNumberOfUnconvertibleCharacters, 
   127 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   128 	{
   129 	return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
   130 	}
   131 
   132 TBool CISO2022JP1ConverterImpl::IsInThisCharacterSetL(
   133 		TBool& aSetToTrue, 
   134 		TInt& aConfidenceLevel, 
   135 		const TDesC8& aSample)
   136 	{
   137 	aSetToTrue=ETrue;
   138 	CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
   139 	return ETrue;
   140 	}
   141 
   142 CISO2022JP1ConverterImpl* CISO2022JP1ConverterImpl::NewL()
   143 	{
   144 	CISO2022JP1ConverterImpl* self = new(ELeave) CISO2022JP1ConverterImpl();
   145 	return self;
   146 	}
   147 
   148 CISO2022JP1ConverterImpl::~CISO2022JP1ConverterImpl()
   149 	{
   150 	}
   151 
   152 CISO2022JP1ConverterImpl::CISO2022JP1ConverterImpl()
   153 	{
   154 	}
   155 
   156 
   157 const TImplementationProxy ImplementationTable[] = 
   158 	{
   159 		IMPLEMENTATION_PROXY_ENTRY(0x100066A3,	CISO2022JP1ConverterImpl::NewL)
   160 	};
   161 
   162 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   163 	{
   164 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   165 
   166 	return ImplementationTable;
   167 	}
   168