charconvfw/Charconvplugin/src/EucJpDirectmap.CPP
changeset 32 8b9155204a54
equal deleted inserted replaced
31:b9ad20498fb4 32:8b9155204a54
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 the License "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:    This file is a source code file for a charconv plug-in.
       
    15 *                This plug-in supports EUC-JP with direct mapped pictograph.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32std.h>
       
    24 #include <charconv.h>
       
    25 
       
    26 #ifndef EKA2
       
    27 #include <CONVPLUG.H>
       
    28 #else
       
    29 #include <convgeneratedcpp.h>
       
    30 #include <ecom/implementationproxy.h>
       
    31 #include "charactersetconverter.h"
       
    32 #endif // !EKA2
       
    33 
       
    34 #include <convutils.h>
       
    35 #include <jisx0201.h>
       
    36 #include <jisx0208.h>
       
    37 #include <jisx0212.h>
       
    38 #include <CnvShiftJisDirectmap.h>
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 const TUint KSingleShift2=0x8e;
       
    41 const TUint KSingleShift3=0x8f;
       
    42 const TUint KFirstByteRangeFirstBlockStart = 0xF5;
       
    43 const TUint KFirstByteRangeFirstBlockEnd = 0xFE;
       
    44 const TUint KSecondByteRangeSecondBlockStart = 0xA1;
       
    45 const TUint KSecondByteRangeSecondBlockEnd = 0xFE;
       
    46 const TUint KPictographStartFirstByte = 0xF0;
       
    47 const TUint KPictographStartSecondByte = 0x40;
       
    48 const TUint KEUCJPSecondBlockStart = 0xF5;
       
    49 const TUint KEUCJPBlockSize = 0x5D;
       
    50 const TUint KShiftJisTrailByteIllegal = 0x7F;
       
    51 
       
    52 // SecureID for Brower app
       
    53 const TUint32 KBrowserSecureId = 0x10008D39;
       
    54 // Define for converting from YenSign to BackSlash
       
    55 const TUint KCharacterCodeForYenSign = 0x00A5;
       
    56 const TUint KCharacterCodeForBackSlash = 0x005C;
       
    57 
       
    58 // fullwidth question mark
       
    59 _LIT8(KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters, "\xa1\xa9");
       
    60 #if defined(_DEBUG)
       
    61 _LIT(KLitPanicText, "EucJpDirectmap");
       
    62 enum TPanic
       
    63     {
       
    64     EPanicNothingToConvert1=1,
       
    65     EPanicNothingToConvert2,
       
    66     EPanicNothingToConvert3,
       
    67     EPanicNothingToConvert4,
       
    68     EPanicNothingToConvert5,
       
    69     EPanicNothingToConvert6,
       
    70     EPanicOddNumberOfBytes1,
       
    71     EPanicOddNumberOfBytes2,
       
    72     EPanicOddNumberOfBytes3,
       
    73     EPanicOddNumberOfBytes4,
       
    74     EPanicOddNumberOfBytes5,
       
    75     EPanicOddNumberOfBytes6,
       
    76     EPanicBadHighBit1,
       
    77     EPanicBadHighBit2,
       
    78     EPanicBadHighBit3,
       
    79     EPanicBadHighBit4,
       
    80     EPanicBadHighBit5,
       
    81     EPanicBadHighBit6,
       
    82     EPanicBadHighBit7,
       
    83     EPanicBadPointers1,
       
    84     EPanicBadPointers2,
       
    85     EPanicBadPointers3,
       
    86     EPanicBadPointers4,
       
    87     EPanicBadPointers5,
       
    88     EPanicBadPointers6,
       
    89     EPanicBadPointers7,
       
    90     EPanicBadPointers8,
       
    91     EPanicBadPointers9,
       
    92     EPanicBadPointers10,
       
    93     EPanicBadPointers11,
       
    94     EPanicBadPointers12,
       
    95     EPanicBadPointers13,
       
    96     EPanicBadPointers14,
       
    97     EPanicBadPointers15,
       
    98     EPanicBadPointers16,
       
    99     EPanicBadPointers17,
       
   100     EPanicBadPointers18,
       
   101     EPanicBadPointers19,
       
   102     EPanicBadPointers20,
       
   103     EPanicBadPointers21,
       
   104     EPanicBadPointers22,
       
   105     EPanicBadPointers23,
       
   106     EPanicBadPointers24,
       
   107     EPanicBadPointers25,
       
   108     EPanicBadPointers26,
       
   109     EPanicBadPointers27,
       
   110     EPanicBadPointers28,
       
   111     EPanicBadPointers29,
       
   112     EPanicBadPointers30,
       
   113     EPanicBadPointers31,
       
   114     EPanicBadPointers32,
       
   115     EPanicBadPointers33,
       
   116     EPanicBadPointers34,
       
   117     EPanicBadPointers35,
       
   118     EPanicBadPointers36,
       
   119     EPanicBadCalculation1,
       
   120     EPanicBadCalculation2,
       
   121     EPanicNumberOfBytesIsNotMultipleOfThree1,
       
   122     EPanicNumberOfBytesIsNotMultipleOfThree2,
       
   123     EPanicSingleShift2Expected,
       
   124     EPanicSingleShift3Expected
       
   125     };
       
   126 
       
   127 LOCAL_C void Panic(TPanic aPanic)
       
   128     {
       
   129     User::Panic(KLitPanicText, aPanic);
       
   130     }
       
   131 #endif
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // DummyConvertFromIntermediateBufferInPlace
       
   135 //
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 LOCAL_C void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&,
       
   139         TInt& aNumberOfCharactersThatDroppedOut)
       
   140     {
       
   141     aNumberOfCharactersThatDroppedOut = 0;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // ConvertFromJisX0208ToEucJpPackedInPlace
       
   146 // Converts from JIS code to EUC-JP
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 LOCAL_C void ConvertFromJisX0208ToEucJpPackedInPlace(
       
   150         TInt aStartPositionInDescriptor, TDes8& aDescriptor,
       
   151         TInt& aNumberOfCharactersThatDroppedOut)
       
   152     {
       
   153     aNumberOfCharactersThatDroppedOut = 0;
       
   154     const TInt descriptorLength = aDescriptor.Length();
       
   155     __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
       
   156         Panic(EPanicNothingToConvert1));
       
   157     __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   158         Panic(EPanicOddNumberOfBytes1));
       
   159     TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   160     const TUint8* const pointerToLastByte =
       
   161         pointerToCurrentByte + (descriptorLength - 1);
       
   162     pointerToCurrentByte += aStartPositionInDescriptor;
       
   163     FOREVER
       
   164         {
       
   165         const TUint currentByte = *pointerToCurrentByte;
       
   166         __ASSERT_DEBUG((currentByte & 0x80) == 0, Panic(EPanicBadHighBit1));
       
   167         *pointerToCurrentByte = STATIC_CAST(TUint8, currentByte | 0x80);
       
   168         __ASSERT_DEBUG(pointerToCurrentByte <= pointerToLastByte,
       
   169             Panic(EPanicBadPointers1));
       
   170         if (pointerToCurrentByte >= pointerToLastByte)
       
   171             {
       
   172             break;
       
   173             }
       
   174         ++pointerToCurrentByte;
       
   175         }
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace
       
   180 // Converts from half width Katakana code to EUC-JP
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 LOCAL_C void ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace(
       
   184         TInt aStartPositionInDescriptor, TDes8& aDescriptor,
       
   185         TInt& aNumberOfCharactersThatDroppedOut)
       
   186     {
       
   187     TInt descriptorLength = aDescriptor.Length();
       
   188     __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
       
   189         Panic(EPanicNothingToConvert2));
       
   190     aNumberOfCharactersThatDroppedOut = Max(0, (descriptorLength -
       
   191         aStartPositionInDescriptor) - ((aDescriptor.MaxLength() -
       
   192         aStartPositionInDescriptor) / 2));
       
   193     descriptorLength -= aNumberOfCharactersThatDroppedOut;
       
   194     __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
       
   195         Panic(EPanicBadCalculation1));
       
   196     if (descriptorLength <= aStartPositionInDescriptor)
       
   197         {
       
   198         aDescriptor.SetLength(descriptorLength);
       
   199         }
       
   200     else
       
   201         {
       
   202         // pointerToTargetByte is initialized properly when descriptorLength
       
   203         // has been offset to the actual final length of aDescriptor
       
   204         TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   205         const TUint8* const pointerToFirstByte =
       
   206             pointerToTargetByte + aStartPositionInDescriptor;
       
   207         const TUint8* pointerToSourceByte =
       
   208             pointerToTargetByte + (descriptorLength - 1);
       
   209         descriptorLength =
       
   210             ((descriptorLength - aStartPositionInDescriptor) * 2) +
       
   211             aStartPositionInDescriptor;
       
   212         __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   213             Panic(EPanicOddNumberOfBytes2));
       
   214         aDescriptor.SetLength(descriptorLength);
       
   215         // pointerToTargetByte is is initialized properly here
       
   216         pointerToTargetByte += descriptorLength - 1;
       
   217         FOREVER
       
   218             {
       
   219             *pointerToTargetByte = *pointerToSourceByte;
       
   220             __ASSERT_DEBUG(pointerToTargetByte>pointerToFirstByte,
       
   221                 Panic(EPanicBadPointers2));
       
   222             --pointerToTargetByte;
       
   223             *pointerToTargetByte = KSingleShift2;
       
   224             __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
       
   225                 Panic(EPanicBadPointers3));
       
   226             if (pointerToTargetByte <= pointerToFirstByte)
       
   227                 {
       
   228                 break;
       
   229                 }
       
   230             --pointerToTargetByte;
       
   231             __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
       
   232                 Panic(EPanicBadPointers4));
       
   233             --pointerToSourceByte;
       
   234             }
       
   235         __ASSERT_DEBUG(pointerToTargetByte == pointerToFirstByte,
       
   236             Panic(EPanicBadPointers5));
       
   237         __ASSERT_DEBUG(pointerToSourceByte == pointerToFirstByte,
       
   238             Panic(EPanicBadPointers6));
       
   239         }
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // ConvertFromJisX0212ToEucJpPackedInPlace
       
   244 // Converts from JIS code to EUC-JP
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 LOCAL_C void ConvertFromJisX0212ToEucJpPackedInPlace(
       
   248         TInt aStartPositionInDescriptor, TDes8& aDescriptor,
       
   249         TInt& aNumberOfCharactersThatDroppedOut)
       
   250     {
       
   251     TInt descriptorLength=aDescriptor.Length();
       
   252     __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
       
   253         Panic(EPanicNothingToConvert3));
       
   254     __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   255         Panic(EPanicOddNumberOfBytes3));
       
   256     aNumberOfCharactersThatDroppedOut =
       
   257         Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) -
       
   258         ((aDescriptor.MaxLength() - aStartPositionInDescriptor) / 3));
       
   259     descriptorLength -= aNumberOfCharactersThatDroppedOut * 2;
       
   260     __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
       
   261         Panic(EPanicBadCalculation2));
       
   262     if (descriptorLength <= aStartPositionInDescriptor)
       
   263         {
       
   264         aDescriptor.SetLength(descriptorLength);
       
   265         }
       
   266     else
       
   267         {
       
   268         __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   269             Panic(EPanicOddNumberOfBytes4));
       
   270         // pointerToTargetByte is initialized properly when descriptorLength
       
   271         // has been offset to the actual final length of aDescriptor
       
   272         TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   273         const TUint8* const pointerToFirstByte =
       
   274             pointerToTargetByte + aStartPositionInDescriptor;
       
   275         const TUint8* pointerToSourceByte =
       
   276             pointerToTargetByte + (descriptorLength - 1);
       
   277         descriptorLength = (((descriptorLength - aStartPositionInDescriptor)
       
   278             * 3) / 2) + aStartPositionInDescriptor;
       
   279         __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 3 ==0,
       
   280             Panic(EPanicNumberOfBytesIsNotMultipleOfThree1));
       
   281         aDescriptor.SetLength(descriptorLength);
       
   282         // pointerToTargetByte is is initialized properly here
       
   283         pointerToTargetByte += descriptorLength - 1;
       
   284         FOREVER
       
   285             {
       
   286             __ASSERT_DEBUG((*pointerToSourceByte & 0x80) == 0,
       
   287                 Panic(EPanicBadHighBit2));
       
   288             *pointerToTargetByte =
       
   289                 STATIC_CAST(TUint8, *pointerToSourceByte | 0x80);
       
   290             __ASSERT_DEBUG(pointerToTargetByte > pointerToFirstByte,
       
   291                 Panic(EPanicBadPointers7));
       
   292             --pointerToTargetByte;
       
   293             __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
       
   294                 Panic(EPanicBadPointers8));
       
   295             --pointerToSourceByte;
       
   296             __ASSERT_DEBUG((*pointerToSourceByte & 0x80) == 0,
       
   297                 Panic(EPanicBadHighBit3));
       
   298             *pointerToTargetByte =
       
   299                 STATIC_CAST(TUint8, *pointerToSourceByte | 0x80);
       
   300             __ASSERT_DEBUG(pointerToTargetByte > pointerToFirstByte,
       
   301                 Panic(EPanicBadPointers9));
       
   302             --pointerToTargetByte;
       
   303             *pointerToTargetByte = KSingleShift3;
       
   304             __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
       
   305                 Panic(EPanicBadPointers10));
       
   306             if (pointerToTargetByte <= pointerToFirstByte)
       
   307                 {
       
   308                 break;
       
   309                 }
       
   310             --pointerToTargetByte;
       
   311             __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
       
   312                 Panic(EPanicBadPointers11));
       
   313             --pointerToSourceByte;
       
   314             }
       
   315         __ASSERT_DEBUG(pointerToTargetByte == pointerToFirstByte,
       
   316             Panic(EPanicBadPointers12));
       
   317         __ASSERT_DEBUG(pointerToSourceByte == pointerToFirstByte,
       
   318             Panic(EPanicBadPointers13));
       
   319         }
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // NumberOfBytesAbleToConvertToJisRoman
       
   324 // Counts the bytes of be able to convert to JIS
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 LOCAL_C TInt NumberOfBytesAbleToConvertToJisRoman(const TDesC8& aDescriptor)
       
   328     {
       
   329     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   330     const TUint8* const pointerToLastByte =
       
   331         pointerToPreviousByte + aDescriptor.Length();
       
   332     if (pointerToPreviousByte == pointerToLastByte)
       
   333         {
       
   334         return 0;
       
   335         }
       
   336     FOREVER
       
   337         {
       
   338         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   339             Panic(EPanicBadPointers14));
       
   340         const TUint currentByte = *(pointerToPreviousByte + 1);
       
   341         if (currentByte & 0x80)
       
   342             {
       
   343             break;
       
   344             }
       
   345         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   346             Panic(EPanicBadPointers15));
       
   347         ++pointerToPreviousByte;
       
   348         __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
       
   349             Panic(EPanicBadPointers16));
       
   350         if (pointerToPreviousByte >= pointerToLastByte)
       
   351             {
       
   352             break;
       
   353             }
       
   354         }
       
   355     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // NumberOfBytesAbleToConvertToJisX0208
       
   360 // Counts the bytes of be able to convert to JIS
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor)
       
   364     {
       
   365     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   366     const TUint8* const pointerToLastByte =
       
   367         pointerToPreviousByte + aDescriptor.Length();
       
   368     if (pointerToPreviousByte == pointerToLastByte)
       
   369         {
       
   370         return 0;
       
   371         }
       
   372     FOREVER
       
   373         {
       
   374         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   375             Panic(EPanicBadPointers17));
       
   376         TUint currentByte = *(pointerToPreviousByte + 1);
       
   377         if (currentByte < 0xa0)
       
   378             {
       
   379             break;
       
   380             }
       
   381         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   382             Panic(EPanicBadPointers18));
       
   383         if (pointerToLastByte - pointerToPreviousByte < 2)
       
   384             {
       
   385             break;
       
   386             }
       
   387         ++pointerToPreviousByte;
       
   388         currentByte = *(pointerToPreviousByte + 1);
       
   389         if (currentByte < 0xa0)
       
   390             {
       
   391             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   392             }
       
   393         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   394             Panic(EPanicBadPointers19));
       
   395         ++pointerToPreviousByte;
       
   396         __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
       
   397             Panic(EPanicBadPointers20));
       
   398         if (pointerToPreviousByte >= pointerToLastByte)
       
   399             {
       
   400             break;
       
   401             }
       
   402         }
       
   403     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // NumberOfBytesAbleToConvertToHalfWidthKatakana8
       
   408 // Counts the bytes of be able to convert to half width Katakana
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 LOCAL_C TInt NumberOfBytesAbleToConvertToHalfWidthKatakana8(const TDesC8& aDescriptor)
       
   412     {
       
   413     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   414     const TUint8* const pointerToLastByte =
       
   415         pointerToPreviousByte + aDescriptor.Length();
       
   416     if (pointerToPreviousByte == pointerToLastByte)
       
   417         {
       
   418         return 0;
       
   419         }
       
   420     FOREVER
       
   421         {
       
   422         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   423             Panic(EPanicBadPointers21));
       
   424         TUint currentByte = *(pointerToPreviousByte + 1);
       
   425         if (currentByte != KSingleShift2)
       
   426             {
       
   427             break;
       
   428             }
       
   429         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   430             Panic(EPanicBadPointers22));
       
   431         if (pointerToLastByte - pointerToPreviousByte < 2)
       
   432             {
       
   433             break;
       
   434             }
       
   435         ++pointerToPreviousByte;
       
   436         currentByte = *(pointerToPreviousByte + 1);
       
   437         if (currentByte < 0xa0)
       
   438             {
       
   439             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   440             }
       
   441         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   442             Panic(EPanicBadPointers23));
       
   443         ++pointerToPreviousByte;
       
   444         __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
       
   445             Panic(EPanicBadPointers24));
       
   446         if (pointerToPreviousByte >= pointerToLastByte)
       
   447             {
       
   448             break;
       
   449             }
       
   450         }
       
   451     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // NumberOfBytesAbleToConvertToJisX0212
       
   456 // Counts the bytes of be able to convert to JIS
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0212(const TDesC8& aDescriptor)
       
   460     {
       
   461     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   462     const TUint8* const pointerToLastByte =
       
   463         pointerToPreviousByte + aDescriptor.Length();
       
   464     if (pointerToPreviousByte == pointerToLastByte)
       
   465         {
       
   466         return 0;
       
   467         }
       
   468     FOREVER
       
   469         {
       
   470         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   471             Panic(EPanicBadPointers25));
       
   472         TUint currentByte = *(pointerToPreviousByte + 1);
       
   473         if (currentByte != KSingleShift3)
       
   474             {
       
   475             break;
       
   476             }
       
   477         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   478             Panic(EPanicBadPointers26));
       
   479         if (pointerToLastByte - pointerToPreviousByte < 3)
       
   480             {
       
   481             break;
       
   482             }
       
   483         ++pointerToPreviousByte;
       
   484         currentByte = *(pointerToPreviousByte + 1);
       
   485         if (currentByte < 0xa0)
       
   486             {
       
   487             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   488             }
       
   489         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   490             Panic(EPanicBadPointers27));
       
   491         ++pointerToPreviousByte;
       
   492         currentByte = *(pointerToPreviousByte + 1);
       
   493         if (currentByte < 0xa0)
       
   494             {
       
   495             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   496             }
       
   497         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   498             Panic(EPanicBadPointers28));
       
   499         ++pointerToPreviousByte;
       
   500         __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
       
   501             Panic(EPanicBadPointers29));
       
   502         if (pointerToPreviousByte >= pointerToLastByte)
       
   503             {
       
   504             break;
       
   505             }
       
   506         }
       
   507     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // DummyConvertToIntermediateBufferInPlace
       
   512 //
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 LOCAL_C void DummyConvertToIntermediateBufferInPlace(TDes8&)
       
   516     {
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // ConvertToJisX0208FromEucJpPackedInPlace
       
   521 // Converts from EUC-JP to JIS code
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 LOCAL_C void ConvertToJisX0208FromEucJpPackedInPlace(TDes8& aDescriptor)
       
   525     {
       
   526     const TInt descriptorLength = aDescriptor.Length();
       
   527     __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert4));
       
   528     __ASSERT_DEBUG(descriptorLength % 2 == 0, Panic(EPanicOddNumberOfBytes5));
       
   529     TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   530     const TUint8* const pointerToLastByte =
       
   531         pointerToCurrentByte + (descriptorLength - 1);
       
   532     FOREVER
       
   533         {
       
   534         const TUint currentByte = *pointerToCurrentByte;
       
   535         __ASSERT_DEBUG(currentByte & 0x80, Panic(EPanicBadHighBit4));
       
   536         *pointerToCurrentByte = STATIC_CAST(TUint8, currentByte & ~0x80);
       
   537         __ASSERT_DEBUG(pointerToCurrentByte <= pointerToLastByte,
       
   538             Panic(EPanicBadPointers30));
       
   539         if (pointerToCurrentByte >= pointerToLastByte)
       
   540             {
       
   541             break;
       
   542             }
       
   543         ++pointerToCurrentByte;
       
   544         }
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // ConvertToHalfWidthKatakana8FromEucJpPackedInPlace
       
   549 // Converts from EUC-JP to half width Katakana
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 LOCAL_C void ConvertToHalfWidthKatakana8FromEucJpPackedInPlace(
       
   553         TDes8& aDescriptor)
       
   554     {
       
   555     const TInt descriptorLength = aDescriptor.Length();
       
   556     __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert5));
       
   557     __ASSERT_DEBUG(descriptorLength % 2 == 0, Panic(EPanicOddNumberOfBytes6));
       
   558     TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   559     const TUint8* pointerToSourceByte = pointerToTargetByte;
       
   560     const TUint8* const pointerToLastByte = pointerToSourceByte +
       
   561         (descriptorLength - 1);
       
   562     FOREVER
       
   563         {
       
   564         __ASSERT_DEBUG(*pointerToSourceByte == KSingleShift2,
       
   565             Panic(EPanicSingleShift2Expected));
       
   566         __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
       
   567             Panic(EPanicBadPointers31));
       
   568         ++pointerToSourceByte;
       
   569         const TUint sourceByte = *pointerToSourceByte;
       
   570         __ASSERT_DEBUG(sourceByte & 0x80, Panic(EPanicBadHighBit5));
       
   571         *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte);
       
   572         __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
       
   573             Panic(EPanicBadPointers32));
       
   574         if (pointerToSourceByte >= pointerToLastByte)
       
   575             {
       
   576             break;
       
   577             }
       
   578         ++pointerToSourceByte;
       
   579         ++pointerToTargetByte;
       
   580         }
       
   581     aDescriptor.SetLength(descriptorLength / 2);
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // ConvertToJisX0212FromEucJpPackedInPlace
       
   586 // Converts from EUC-JP to JIS
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 LOCAL_C void ConvertToJisX0212FromEucJpPackedInPlace(TDes8& aDescriptor)
       
   590     {
       
   591     const TInt descriptorLength = aDescriptor.Length();
       
   592     __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert6));
       
   593     __ASSERT_DEBUG(descriptorLength % 3 == 0,
       
   594         Panic(EPanicNumberOfBytesIsNotMultipleOfThree2));
       
   595     TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   596     const TUint8* pointerToSourceByte = pointerToTargetByte;
       
   597     const TUint8* const pointerToLastByte =
       
   598         pointerToSourceByte + (descriptorLength - 1);
       
   599     FOREVER
       
   600         {
       
   601         __ASSERT_DEBUG(*pointerToSourceByte == KSingleShift3,
       
   602             Panic(EPanicSingleShift3Expected));
       
   603         __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
       
   604             Panic(EPanicBadPointers33));
       
   605         ++pointerToSourceByte;
       
   606         TUint sourceByte = *pointerToSourceByte;
       
   607         __ASSERT_DEBUG(sourceByte & 0x80, Panic(EPanicBadHighBit6));
       
   608         *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte & ~0x80);
       
   609         __ASSERT_DEBUG(pointerToSourceByte<pointerToLastByte,
       
   610             Panic(EPanicBadPointers34));
       
   611         ++pointerToSourceByte;
       
   612         sourceByte = *pointerToSourceByte;
       
   613         __ASSERT_DEBUG(sourceByte&0x80, Panic(EPanicBadHighBit7));
       
   614         __ASSERT_DEBUG(pointerToTargetByte < pointerToLastByte,
       
   615             Panic(EPanicBadPointers35));
       
   616         ++pointerToTargetByte;
       
   617         *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte & ~0x80);
       
   618         __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
       
   619             Panic(EPanicBadPointers36));
       
   620         if (pointerToSourceByte >= pointerToLastByte)
       
   621             {
       
   622             break;
       
   623             }
       
   624         ++pointerToSourceByte;
       
   625         ++pointerToTargetByte;
       
   626         }
       
   627     aDescriptor.SetLength((descriptorLength / 3) * 2);
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // NumberOfBytesAbleToConvertToPictograph
       
   632 //
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 LOCAL_C TInt NumberOfBytesAbleToConvertToPictograph1(const TDesC8& aDescriptor)
       
   636     {
       
   637     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   638     const TUint8* const pointerToLastByte =
       
   639         pointerToPreviousByte + aDescriptor.Length();
       
   640     if (pointerToPreviousByte == pointerToLastByte)
       
   641         {
       
   642         return 0;
       
   643         }
       
   644     for (;pointerToPreviousByte < pointerToLastByte;)
       
   645         {
       
   646         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   647             Panic(EPanicBadPointers14));
       
   648         TUint currentByte = *(pointerToPreviousByte + 1);
       
   649         const TUint nextByte = *(pointerToPreviousByte + 2);
       
   650         if (((currentByte < KFirstByteRangeFirstBlockStart) ||
       
   651              (currentByte > KFirstByteRangeFirstBlockEnd)) ||
       
   652             ((nextByte < KSecondByteRangeSecondBlockStart) ||
       
   653              (nextByte > KSecondByteRangeSecondBlockEnd)))
       
   654             {
       
   655             break;
       
   656             }
       
   657         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   658             Panic(EPanicBadPointers15));
       
   659         pointerToPreviousByte += 2;
       
   660         }
       
   661     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // NumberOfBytesAbleToConvertToPictograph
       
   666 //
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 LOCAL_C TInt NumberOfBytesAbleToConvertToPictograph2(const TDesC8& aDescriptor)
       
   670     {
       
   671     const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
       
   672     const TUint8* const pointerToLastByte =
       
   673         pointerToPreviousByte + aDescriptor.Length();
       
   674     if (pointerToPreviousByte == pointerToLastByte)
       
   675         {
       
   676         return 0;
       
   677         }
       
   678     for (;pointerToPreviousByte < pointerToLastByte;)
       
   679         {
       
   680         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   681             Panic(EPanicBadPointers14));
       
   682         TUint currentByte = *(pointerToPreviousByte + 1);
       
   683         if (currentByte == KSingleShift3)
       
   684             {
       
   685             pointerToPreviousByte++;
       
   686             currentByte = *(pointerToPreviousByte + 1);
       
   687             }
       
   688         else
       
   689             {
       
   690             break;
       
   691             }
       
   692         if (currentByte < 0xa0)
       
   693             {
       
   694             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   695             }
       
   696         const TUint nextByte = *(pointerToPreviousByte + 2);
       
   697         if (nextByte < 0xa0)
       
   698             {
       
   699             return CCnvCharacterSetConverter::EErrorIllFormedInput;
       
   700             }
       
   701         if (((currentByte < KFirstByteRangeFirstBlockStart) ||
       
   702              (currentByte > KFirstByteRangeFirstBlockEnd)) ||
       
   703             ((nextByte < KSecondByteRangeSecondBlockStart) ||
       
   704              (nextByte > KSecondByteRangeSecondBlockEnd)))
       
   705             {
       
   706             // return the previous byte to the beginning of loop.
       
   707             pointerToPreviousByte--;
       
   708             break;
       
   709             }
       
   710         __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
       
   711             Panic(EPanicBadPointers15));
       
   712         pointerToPreviousByte += 2;
       
   713         }
       
   714     return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // ConvertFromPictogaphToEucJpDirectmapInPlace
       
   719 // Converts from EucJp packed Pictograph to Unicode
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 LOCAL_C void ConvertFromPictogaphToEucJpDirectmapInPlace(
       
   723         TInt aStartPositionInDescriptor, TDes8& aDescriptor,
       
   724         TInt& aNumberOfCharactersThatDroppedOut)
       
   725     {
       
   726     TInt descriptorLength=aDescriptor.Length();
       
   727     __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
       
   728         Panic(EPanicNothingToConvert3));
       
   729     __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   730         Panic(EPanicOddNumberOfBytes3));
       
   731     TInt bytesPerCharacter = 2;
       
   732     if (aDescriptor[0] >= KEUCJPSecondBlockStart)
       
   733         {
       
   734         bytesPerCharacter = 3;
       
   735         }
       
   736 
       
   737     aNumberOfCharactersThatDroppedOut =
       
   738         Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) -
       
   739         ((aDescriptor.MaxLength() - aStartPositionInDescriptor) /
       
   740         bytesPerCharacter));
       
   741     descriptorLength -= aNumberOfCharactersThatDroppedOut * 2;
       
   742     __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
       
   743         Panic(EPanicBadCalculation2));
       
   744     if (descriptorLength <= aStartPositionInDescriptor)
       
   745         {
       
   746         aDescriptor.SetLength(descriptorLength);
       
   747         }
       
   748     else
       
   749         {
       
   750         __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
       
   751             Panic(EPanicOddNumberOfBytes4));
       
   752         // pointerToTargetByte is initialized properly when descriptorLength
       
   753         // has been offset to the actual final length of aDescriptor
       
   754         TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   755         const TUint8* const pointerToFirstByte =
       
   756             pointerToTargetByte + aStartPositionInDescriptor;
       
   757         const TUint8* pointerToSourceByte =
       
   758             pointerToTargetByte + (descriptorLength - 1);
       
   759         descriptorLength = (((descriptorLength - aStartPositionInDescriptor)
       
   760             * bytesPerCharacter) / 2) + aStartPositionInDescriptor;
       
   761         __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) %
       
   762             bytesPerCharacter == 0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree1));
       
   763         aDescriptor.SetLength(descriptorLength);
       
   764         // pointerToTargetByte is is initialized properly here
       
   765         pointerToTargetByte += descriptorLength - 1;
       
   766         for (;pointerToTargetByte > pointerToFirstByte; )
       
   767             {
       
   768             TInt secondByte = *pointerToSourceByte;
       
   769             TInt firstByte = *(pointerToSourceByte - 1);
       
   770 
       
   771             if (bytesPerCharacter == 3)
       
   772                 {
       
   773                 firstByte = (firstByte - KEUCJPSecondBlockStart) * 2 +
       
   774                     KFirstByteRangeFirstBlockStart;
       
   775                 }
       
   776             else
       
   777                 {
       
   778                 firstByte = (firstByte - KPictographStartFirstByte) * 2 +
       
   779                     KFirstByteRangeFirstBlockStart;
       
   780                 }
       
   781             if (static_cast<TInt>(KEUCJPBlockSize + KPictographStartSecondByte + 1)
       
   782                  < secondByte)
       
   783                 {
       
   784                 if (secondByte > KShiftJisTrailByteIllegal)
       
   785                     secondByte -= 1;
       
   786                 secondByte = secondByte -(KPictographStartSecondByte +
       
   787                     KEUCJPBlockSize + 1) + KSecondByteRangeSecondBlockStart;
       
   788                 firstByte++;
       
   789                 }
       
   790             else
       
   791                 {
       
   792                 if (secondByte > KShiftJisTrailByteIllegal)
       
   793                     secondByte -= 1;
       
   794                 secondByte += KSecondByteRangeSecondBlockStart - KPictographStartSecondByte;
       
   795                 }
       
   796             *pointerToTargetByte = static_cast<TUint8>(secondByte);
       
   797             --pointerToTargetByte;
       
   798             *pointerToTargetByte = static_cast<TUint8>(firstByte);
       
   799             if (bytesPerCharacter == 3)
       
   800                 {
       
   801                 --pointerToTargetByte;
       
   802                 *pointerToTargetByte = KSingleShift3;
       
   803                 }
       
   804             __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
       
   805                 Panic(EPanicBadPointers10));
       
   806             --pointerToTargetByte;
       
   807             pointerToSourceByte -= 2;
       
   808             }
       
   809         }
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // ConvertToPictographFromEucJpPackedInPlace1
       
   814 // Converts from EucJp packed Pictograph to Unicode
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 LOCAL_C void ConvertToPictographFromEucJpPackedInPlace(TDes8& aDescriptor)
       
   818     {
       
   819     const TInt descriptorLength = aDescriptor.Length();
       
   820     __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert6));
       
   821     TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
       
   822     const TUint8* pointerToSourceByte = pointerToTargetByte;
       
   823     const TUint8* const pointerToLastByte =
       
   824         pointerToSourceByte + (descriptorLength - 1);
       
   825     TInt bytesPerCharacter = 2;
       
   826     TInt sjisStartbyte = KPictographStartFirstByte;
       
   827     if (*pointerToSourceByte == KSingleShift3)
       
   828         {
       
   829         ++pointerToSourceByte;
       
   830         bytesPerCharacter = 3;
       
   831         sjisStartbyte = KEUCJPSecondBlockStart;
       
   832         }
       
   833     for (;pointerToSourceByte < pointerToLastByte; )
       
   834         {
       
   835         __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
       
   836             Panic(EPanicBadPointers33));
       
   837         TUint firstByte = (*pointerToSourceByte
       
   838             - KFirstByteRangeFirstBlockStart) / 2 + sjisStartbyte;
       
   839         TUint secondByte = *(pointerToSourceByte + 1);
       
   840         if ((*pointerToSourceByte % 2) == 0)
       
   841             {
       
   842             secondByte += KPictographStartSecondByte -
       
   843                 KSecondByteRangeSecondBlockStart + KEUCJPBlockSize + 1;
       
   844             if (secondByte >= KShiftJisTrailByteIllegal)
       
   845                 secondByte++;
       
   846             }
       
   847         else
       
   848             {
       
   849             secondByte += KPictographStartSecondByte - KSecondByteRangeSecondBlockStart;
       
   850             if (secondByte >= KShiftJisTrailByteIllegal)
       
   851                 secondByte++;
       
   852             }
       
   853         *pointerToTargetByte = static_cast<TUint8>(firstByte);
       
   854 
       
   855         __ASSERT_DEBUG(pointerToTargetByte < pointerToLastByte,
       
   856             Panic(EPanicBadPointers35));
       
   857         ++pointerToTargetByte;
       
   858         *pointerToTargetByte = static_cast<TUint8>(secondByte);
       
   859         __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
       
   860             Panic(EPanicBadPointers36));
       
   861         pointerToSourceByte += 2;
       
   862         ++pointerToTargetByte;
       
   863         }
       
   864     aDescriptor.SetLength((descriptorLength / bytesPerCharacter) * 2);
       
   865     }
       
   866 
       
   867 // New Interface class
       
   868 class CEucJpDirectmapImplementation : public CCharacterSetConverterPluginInterface
       
   869 {
       
   870     public:
       
   871         virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
       
   872 
       
   873         virtual TInt ConvertFromUnicode(
       
   874             CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
       
   875             const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
       
   876             TDes8& aForeign,
       
   877             const TDesC16& aUnicode,
       
   878             CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters );
       
   879 
       
   880         virtual TInt ConvertToUnicode(
       
   881             CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
       
   882             TDes16& aUnicode,
       
   883             const TDesC8& aForeign,
       
   884             TInt&,
       
   885             TInt& aNumberOfUnconvertibleCharacters,
       
   886             TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter );
       
   887 
       
   888         virtual TBool IsInThisCharacterSetL(
       
   889             TBool& aSetToTrue,
       
   890             TInt& aConfidenceLevel,
       
   891             const TDesC8& );
       
   892 
       
   893         static CEucJpDirectmapImplementation* NewL();
       
   894 
       
   895         virtual ~CEucJpDirectmapImplementation();
       
   896     private:
       
   897         CEucJpDirectmapImplementation();
       
   898 };
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 // ReplacementForUnconvertibleUnicodeCharacters
       
   902 // Retruns the character to replacement for unconvertible unicode character.
       
   903 // Returns: '?':
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 const TDesC8& CEucJpDirectmapImplementation::ReplacementForUnconvertibleUnicodeCharacters()
       
   907     {
       
   908     return KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters;
       
   909     }
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 // ConvertFromUnicode
       
   913 // Converts from Unicode to EUC-JP
       
   914 // Returns: The number of unconverted characters
       
   915 // -----------------------------------------------------------------------------
       
   916 //
       
   917 TInt CEucJpDirectmapImplementation::ConvertFromUnicode(
       
   918         CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
       
   919         const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
       
   920         TDes8& aForeign, const TDesC16& aUnicode,
       
   921         CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
       
   922     {
       
   923     TFixedArray<CnvUtilities::SCharacterSet, 6> characterSets;
       
   924     characterSets[0].iConversionData = &CnvJisRoman::ConversionData();
       
   925     characterSets[0].iConvertFromIntermediateBufferInPlace =
       
   926         DummyConvertFromIntermediateBufferInPlace;
       
   927     characterSets[0].iEscapeSequence = &KNullDesC8;
       
   928     characterSets[1].iConversionData = &CnvJisX0208::ConversionData();
       
   929     characterSets[1].iConvertFromIntermediateBufferInPlace =
       
   930         ConvertFromJisX0208ToEucJpPackedInPlace;
       
   931     characterSets[1].iEscapeSequence = &KNullDesC8;
       
   932     characterSets[2].iConversionData = &CnvHalfWidthKatakana8::ConversionData();
       
   933     characterSets[2].iConvertFromIntermediateBufferInPlace =
       
   934         ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace;
       
   935     characterSets[2].iEscapeSequence = &KNullDesC8;
       
   936     characterSets[3].iConversionData = &CnvJisX0212::ConversionData();
       
   937     characterSets[3].iConvertFromIntermediateBufferInPlace =
       
   938         ConvertFromJisX0212ToEucJpPackedInPlace;
       
   939     characterSets[3].iEscapeSequence = &KNullDesC8;
       
   940     characterSets[4].iConversionData = &CnvShiftJisDirectmap::ConversionData();
       
   941     characterSets[4].iConvertFromIntermediateBufferInPlace =
       
   942         ConvertFromPictogaphToEucJpDirectmapInPlace;
       
   943     characterSets[4].iEscapeSequence = &KNullDesC8;
       
   944     characterSets[5].iConversionData = &CnvShiftJisDirectmap::ConversionData();
       
   945     characterSets[5].iConvertFromIntermediateBufferInPlace =
       
   946         ConvertFromPictogaphToEucJpDirectmapInPlace;
       
   947     characterSets[5].iEscapeSequence = &KNullDesC8;
       
   948 
       
   949     TInt unconvert = CnvUtilities::ConvertFromUnicode(
       
   950         aDefaultEndiannessOfForeignCharacters,
       
   951         aReplacementForUnconvertibleUnicodeCharacters,
       
   952         aForeign, aUnicode, aIndicesOfUnconvertibleCharacters,
       
   953         characterSets.Array());
       
   954 
       
   955     return unconvert;
       
   956     }
       
   957 
       
   958 // -----------------------------------------------------------------------------
       
   959 // ConvertToUnicode
       
   960 // Converts from EUC-JP to Unicode.
       
   961 // Returns: The number of unconverted bytes
       
   962 // -----------------------------------------------------------------------------
       
   963 //
       
   964 TInt CEucJpDirectmapImplementation::ConvertToUnicode(
       
   965         CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
       
   966         TDes16& aUnicode, const TDesC8& aForeign, TInt&,
       
   967         TInt& aNumberOfUnconvertibleCharacters,
       
   968         TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
       
   969     {
       
   970     TFixedArray<CnvUtilities::SMethod, 6> methods;
       
   971 
       
   972     methods[0].iNumberOfBytesAbleToConvert =
       
   973         NumberOfBytesAbleToConvertToPictograph1;
       
   974     methods[0].iConvertToIntermediateBufferInPlace =
       
   975         ConvertToPictographFromEucJpPackedInPlace;
       
   976     methods[0].iConversionData = &CnvShiftJisDirectmap::ConversionData();
       
   977     methods[0].iNumberOfBytesPerCharacter = 2;
       
   978     methods[0].iNumberOfCoreBytesPerCharacter = 2;
       
   979     methods[1].iNumberOfBytesAbleToConvert =
       
   980         NumberOfBytesAbleToConvertToPictograph2;
       
   981     methods[1].iConvertToIntermediateBufferInPlace =
       
   982         ConvertToPictographFromEucJpPackedInPlace;
       
   983     methods[1].iConversionData = &CnvShiftJisDirectmap::ConversionData();
       
   984     methods[1].iNumberOfBytesPerCharacter = 3;
       
   985     methods[1].iNumberOfCoreBytesPerCharacter = 2;
       
   986 
       
   987     methods[2].iNumberOfBytesAbleToConvert = NumberOfBytesAbleToConvertToJisRoman;
       
   988     methods[2].iConvertToIntermediateBufferInPlace =
       
   989         DummyConvertToIntermediateBufferInPlace;
       
   990     methods[2].iConversionData = &CnvJisRoman::ConversionData();
       
   991     methods[2].iNumberOfBytesPerCharacter = 1;
       
   992     methods[2].iNumberOfCoreBytesPerCharacter = 1;
       
   993     methods[3].iNumberOfBytesAbleToConvert = NumberOfBytesAbleToConvertToJisX0208;
       
   994     methods[3].iConvertToIntermediateBufferInPlace =
       
   995         ConvertToJisX0208FromEucJpPackedInPlace;
       
   996     methods[3].iConversionData = &CnvJisX0208::ConversionData();
       
   997     methods[3].iNumberOfBytesPerCharacter = 2;
       
   998     methods[3].iNumberOfCoreBytesPerCharacter = 2;
       
   999     methods[4].iNumberOfBytesAbleToConvert =
       
  1000         NumberOfBytesAbleToConvertToHalfWidthKatakana8;
       
  1001     methods[4].iConvertToIntermediateBufferInPlace =
       
  1002         ConvertToHalfWidthKatakana8FromEucJpPackedInPlace;
       
  1003     methods[4].iConversionData = &CnvHalfWidthKatakana8::ConversionData();
       
  1004     methods[4].iNumberOfBytesPerCharacter = 2;
       
  1005     methods[4].iNumberOfCoreBytesPerCharacter = 1;
       
  1006     methods[5].iNumberOfBytesAbleToConvert =
       
  1007         NumberOfBytesAbleToConvertToJisX0212;
       
  1008     methods[5].iConvertToIntermediateBufferInPlace =
       
  1009         ConvertToJisX0212FromEucJpPackedInPlace;
       
  1010     methods[5].iConversionData = &CnvJisX0212::ConversionData();
       
  1011     methods[5].iNumberOfBytesPerCharacter = 3;
       
  1012     methods[5].iNumberOfCoreBytesPerCharacter = 2;
       
  1013 
       
  1014     TInt unconvert = CnvUtilities::ConvertToUnicodeFromHeterogeneousForeign(
       
  1015         aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign,
       
  1016         aNumberOfUnconvertibleCharacters,
       
  1017         aIndexOfFirstByteOfFirstUnconvertibleCharacter, methods.Array());
       
  1018 
       
  1019     // The following is specific impelementation for brower.
       
  1020     // If brower app calls this API, the yen sign code(0xA5)
       
  1021     // must be converted to backslash code(0x5C).
       
  1022     // Becasue Javascript supports backslash code ony.
       
  1023     TBool browserProcess = (RProcess().SecureId().iId == KBrowserSecureId);
       
  1024     if (browserProcess && aUnicode.Length() > 0)
       
  1025         {
       
  1026         const TUint16* pB = aUnicode.Ptr();
       
  1027         const TUint16* pbase = pB;
       
  1028         const TUint16* pE = pB + aUnicode.Length() -1;
       
  1029         while (pE>=pbase)
       
  1030             {
       
  1031             if (*pbase == KCharacterCodeForYenSign)
       
  1032                 {
       
  1033                 aUnicode[pbase - pB] = KCharacterCodeForBackSlash;
       
  1034                 }
       
  1035             pbase++;
       
  1036             }
       
  1037         }
       
  1038 
       
  1039     return unconvert;
       
  1040     }
       
  1041 
       
  1042 // -----------------------------------------------------------------------------
       
  1043 // IsInThisCharacterSetL
       
  1044 // Detects whether the text is the character code or not.
       
  1045 // Returns: ETrue:
       
  1046 // -----------------------------------------------------------------------------
       
  1047 //
       
  1048 TBool CEucJpDirectmapImplementation::IsInThisCharacterSetL(TBool& /*aSetToTrue*/, TInt& /*aConfidenceLevel*/,
       
  1049         const TDesC8& /*aSample*/)
       
  1050     {
       
  1051     return EFalse;
       
  1052     }
       
  1053 
       
  1054 CEucJpDirectmapImplementation* CEucJpDirectmapImplementation::NewL()
       
  1055     {
       
  1056     CEucJpDirectmapImplementation* self = new(ELeave) CEucJpDirectmapImplementation;
       
  1057     return self;
       
  1058     }
       
  1059 
       
  1060 CEucJpDirectmapImplementation::CEucJpDirectmapImplementation()
       
  1061     {
       
  1062     //default constructor.. do nothing
       
  1063     }
       
  1064 
       
  1065 CEucJpDirectmapImplementation::~CEucJpDirectmapImplementation()
       
  1066     {
       
  1067     //default destructor .. do nothing
       
  1068     }
       
  1069 
       
  1070 // ECOM CREATION FUNCTION
       
  1071 const TImplementationProxy ImplementationTable[] =
       
  1072     {
       
  1073     // Note: This is the same UID as defined in old mmp-file
       
  1074     // Used also in 12221212.rss ( implementation_uid )
       
  1075     IMPLEMENTATION_PROXY_ENTRY( 0x101F86A6, CEucJpDirectmapImplementation::NewL )
       
  1076     };
       
  1077 
       
  1078 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  1079     {
       
  1080     aTableCount = sizeof( ImplementationTable ) / sizeof(TImplementationProxy);
       
  1081     return ImplementationTable;
       
  1082     }
       
  1083 
       
  1084 // End of file