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