os/textandloc/charconvfw/charconvplugins/src/plugins/iso2022jp.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 <ecom/implementationproxy.h>
    26 #include <charactersetconverter.h>
    27 
    28 _LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    29 _LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");     
    30 _LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    31 _LIT8(KLit8Iso2022JpReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
    32 
    33 
    34 class CISO2022JPConverterImpl : public CCharacterSetConverterPluginInterface
    35 	{
    36 
    37 public:
    38 	virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
    39 
    40 	virtual TInt ConvertFromUnicode(
    41 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    42 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    43 		TDes8& aForeign, 
    44 		const TDesC16& aUnicode, 
    45 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
    46 
    47 	virtual TInt ConvertToUnicode(
    48 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    49 		TDes16& aUnicode, 
    50 		const TDesC8& aForeign, 
    51 		TInt& aState, 
    52 		TInt& aNumberOfUnconvertibleCharacters, 
    53 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
    54 
    55 	virtual TBool IsInThisCharacterSetL(
    56 		TBool& aSetToTrue, 
    57 		TInt& aConfidenceLevel, 
    58 		const TDesC8& aSample);
    59 
    60 	static CISO2022JPConverterImpl* NewL();
    61 	virtual ~CISO2022JPConverterImpl();
    62 
    63 private:
    64 	CISO2022JPConverterImpl();
    65 
    66 	};
    67 
    68 
    69 
    70 const TDesC8& CISO2022JPConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
    71 	{
    72 	return KLit8Iso2022JpReplacementForUnconvertibleUnicodeCharacters;
    73 	}
    74 
    75 LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    76 	{
    77 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
    78 	}
    79 
    80 LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    81 	{
    82 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
    83 	}
    84 
    85 LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    86 	{
    87 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
    88 	}
    89 
    90 TInt CISO2022JPConverterImpl::ConvertFromUnicode(
    91 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    92 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    93 		TDes8& aForeign, 
    94 		const TDesC16& aUnicode, 
    95 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
    96 	{
    97 	TFixedArray<CnvUtilities::SCharacterSet, 3> characterSets;
    98 	characterSets[0].iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
    99 	characterSets[0].iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   100 	characterSets[0].iEscapeSequence=&KLit8EscapeSequenceForAscii;
   101 	characterSets[1].iConversionData=&CnvJisRoman::ConversionData();
   102 	characterSets[1].iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   103 	characterSets[1].iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   104 	characterSets[2].iConversionData=&CnvJisX0208::ConversionData();
   105 	characterSets[2].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   106 	characterSets[2].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   107 	TUint notUsed;
   108 	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet |
   109 	                           CCnvCharacterSetConverter::EInputConversionFlagAssumeStartInDefaultCharacterSet;
   110 	return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, characterSets.Array(),notUsed,inputConversionFlags);
   111 	}
   112 
   113 TInt CISO2022JPConverterImpl::ConvertToUnicode(
   114 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   115 		TDes16& aUnicode, 
   116 		const TDesC8& aForeign, 
   117 		TInt& aState, 
   118 		TInt& aNumberOfUnconvertibleCharacters, 
   119 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   120 	{
   121 	return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
   122 	}
   123 
   124 TBool CISO2022JPConverterImpl::IsInThisCharacterSetL(
   125 		TBool& aSetToTrue, 
   126 		TInt& aConfidenceLevel, 
   127 		const TDesC8& aSample)
   128 	{
   129 	aSetToTrue=ETrue;
   130 	CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
   131 	return ETrue;
   132 	}
   133 
   134 CISO2022JPConverterImpl* CISO2022JPConverterImpl::NewL()
   135 	{
   136 	CISO2022JPConverterImpl* self = new(ELeave) CISO2022JPConverterImpl();
   137 	return self;
   138 	}
   139 
   140 CISO2022JPConverterImpl::~CISO2022JPConverterImpl()
   141 	{
   142 	}
   143 
   144 CISO2022JPConverterImpl::CISO2022JPConverterImpl()
   145 	{
   146 	}
   147 
   148 const TImplementationProxy ImplementationTable[] = 
   149 	{
   150 		IMPLEMENTATION_PROXY_ENTRY(0x100066A0,	CISO2022JPConverterImpl::NewL)
   151 	};
   152 
   153 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   154 	{
   155 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   156 
   157 	return ImplementationTable;
   158 	}
   159