os/textandloc/charconvfw/charconvplugins/src/plugins/ShiftJisDirectmap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2022 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:     This module is a plug-in module for Shift-JIS with Pictograph.
sl@0
    15
*                Basicaly, Vodafone Pictograph is encoded by ISO2022,
sl@0
    16
*                but Japanese FEP needs a pictograph as one character code
sl@0
    17
*                in Shift-JIS character code set.
sl@0
    18
*
sl@0
    19
*/
sl@0
    20
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
sl@0
    25
sl@0
    26
// INCLUDE FILES
sl@0
    27
#include "CnvShiftJisDirectmap.h"
sl@0
    28
#include <e32std.h>
sl@0
    29
#include <charconv.h>
sl@0
    30
#include "jisx0201.h"
sl@0
    31
#include "jisx0208.h"
sl@0
    32
#include <convutils.h>
sl@0
    33
sl@0
    34
#ifdef EKA2
sl@0
    35
#include <convgeneratedcpp.h>
sl@0
    36
#include <ecom/implementationproxy.h>
sl@0
    37
#include "charactersetconverter.h"
sl@0
    38
#endif // EKA2
sl@0
    39
sl@0
    40
const TUint KSingleByteRangeFirstBlockEnd = 0x7f;
sl@0
    41
const TUint KSingleByteRangeSecondBlockStart = 0xa1;
sl@0
    42
const TUint KSingleByteRangeSecondBlockEnd = 0xdf;
sl@0
    43
const TUint KFirstByteRangeFirstBlockStart = 0x81;
sl@0
    44
const TUint KFirstByteRangeFirstBlockEnd = 0x9f;
sl@0
    45
const TUint KFirstByteRangeFirstBlockLength = (KFirstByteRangeFirstBlockEnd+1)-KFirstByteRangeFirstBlockStart;
sl@0
    46
const TUint KFirstByteRangeSecondBlockStart = 0xe0;
sl@0
    47
const TUint KFirstByteRangeSecondBlockEnd = 0xfc;
sl@0
    48
const TUint KSecondByteRangeFirstBlockStart = 0x40;
sl@0
    49
const TUint KSecondByteRangeFirstBlockEnd = 0x7e;
sl@0
    50
const TUint KSecondByteRangeFirstBlockLength = (KSecondByteRangeFirstBlockEnd+1)-KSecondByteRangeFirstBlockStart;
sl@0
    51
const TUint KSecondByteRangeSecondBlockStart = 0x80;
sl@0
    52
const TUint KSecondByteRangeSecondBlockEnd = 0xfc;
sl@0
    53
sl@0
    54
const TUint KPictoFirstByteStart = 0xF0;
sl@0
    55
const TUint KPictoFirstByteEnd = 0xF9;
sl@0
    56
const TUint KPictoSecondByteStart = 0x40;
sl@0
    57
//const TUint KPictoSecondByteEnd = 0xFB;
sl@0
    58
const TUint KPictoSecondByteEnd = 0xFC;
sl@0
    59
sl@0
    60
// SecureID for Brower app
sl@0
    61
const TUint32 KBrowserSecureId = 0x10008D39;
sl@0
    62
// Define for converting from YenSign to BackSlash
sl@0
    63
const TUint KCharacterCodeForYenSign = 0x00A5;
sl@0
    64
const TUint KCharacterCodeForBackSlash = 0x005C;
sl@0
    65
sl@0
    66
#ifdef _DEBUG
sl@0
    67
sl@0
    68
_LIT(KLitPanicText, "SHIFTJIS_FORFEP");
sl@0
    69
sl@0
    70
enum TPanic
sl@0
    71
    {
sl@0
    72
    EPanicIndexOverflow1=1,
sl@0
    73
    EPanicIndexOverflow2,
sl@0
    74
    EPanicNothingToConvert1,
sl@0
    75
    EPanicNothingToConvert2,
sl@0
    76
    EPanicOddNumberOfBytes1,
sl@0
    77
    EPanicOddNumberOfBytes2,
sl@0
    78
    EPanicBadPointers1,
sl@0
    79
    EPanicBadPointers2,
sl@0
    80
    EPanicBadPointers3,
sl@0
    81
    EPanicBadPointers4,
sl@0
    82
    EPanicBadPointers5,
sl@0
    83
    EPanicBadPointers6,
sl@0
    84
    EPanicBadPointers7,
sl@0
    85
    EPanicBadPointers8,
sl@0
    86
    EPanicBadPointers9
sl@0
    87
    };
sl@0
    88
sl@0
    89
// ============================= LOCAL FUNCTIONS ===============================
sl@0
    90
// -----------------------------------------------------------------------------
sl@0
    91
// Panic ?description.
sl@0
    92
// ?description
sl@0
    93
// -----------------------------------------------------------------------------
sl@0
    94
//
sl@0
    95
LOCAL_C void Panic(TPanic aPanic)
sl@0
    96
    {
sl@0
    97
    User::Panic(KLitPanicText, aPanic);
sl@0
    98
    }
sl@0
    99
#endif
sl@0
   100
sl@0
   101
// -----------------------------------------------------------------------------
sl@0
   102
// DummyConvertFromIntermediateBufferInPlace ?description.
sl@0
   103
// ?description
sl@0
   104
// Returns: ?value_1: ?description
sl@0
   105
//          ?value_n: ?description_line1
sl@0
   106
//                    ?description_line2
sl@0
   107
// -----------------------------------------------------------------------------
sl@0
   108
//
sl@0
   109
void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&, TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   110
    {
sl@0
   111
    aNumberOfCharactersThatDroppedOut = 0;
sl@0
   112
    }
sl@0
   113
sl@0
   114
// -----------------------------------------------------------------------------
sl@0
   115
// ConvertFromJisX0208ToShiftJisInPlace ?description.
sl@0
   116
// ?description
sl@0
   117
// Returns: ?value_1: ?description
sl@0
   118
//          ?value_n: ?description_line1
sl@0
   119
//                    ?description_line2
sl@0
   120
// -----------------------------------------------------------------------------
sl@0
   121
//
sl@0
   122
void ConvertFromJisX0208ToShiftJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   123
    {
sl@0
   124
    aNumberOfCharactersThatDroppedOut=0;
sl@0
   125
    const TInt descriptorLength=aDescriptor.Length();
sl@0
   126
    __ASSERT_DEBUG(descriptorLength>aStartPositionInDescriptor, Panic(EPanicNothingToConvert1));
sl@0
   127
    __ASSERT_DEBUG((descriptorLength-aStartPositionInDescriptor)%2==0, Panic(EPanicOddNumberOfBytes1));
sl@0
   128
    TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   129
    const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1);
sl@0
   130
    pointerToCurrentByte+=aStartPositionInDescriptor;
sl@0
   131
    FOREVER
sl@0
   132
        {
sl@0
   133
        TUint firstByte=*pointerToCurrentByte-0x21;
sl@0
   134
        TUint secondByte=*(pointerToCurrentByte+1)-0x21;
sl@0
   135
        if (firstByte%2!=0)
sl@0
   136
            {
sl@0
   137
            secondByte+=94;
sl@0
   138
            }
sl@0
   139
        firstByte/=2;
sl@0
   140
        if (firstByte<KFirstByteRangeFirstBlockLength)
sl@0
   141
            {
sl@0
   142
            firstByte+=KFirstByteRangeFirstBlockStart;
sl@0
   143
            }
sl@0
   144
        else
sl@0
   145
            {
sl@0
   146
            firstByte+=KFirstByteRangeSecondBlockStart-KFirstByteRangeFirstBlockLength;
sl@0
   147
            }
sl@0
   148
        if (secondByte<KSecondByteRangeFirstBlockLength)
sl@0
   149
            {
sl@0
   150
            secondByte+=KSecondByteRangeFirstBlockStart;
sl@0
   151
            }
sl@0
   152
        else
sl@0
   153
            {
sl@0
   154
            secondByte+=KSecondByteRangeSecondBlockStart-KSecondByteRangeFirstBlockLength;
sl@0
   155
            }
sl@0
   156
        *pointerToCurrentByte=STATIC_CAST(TUint8, firstByte);
sl@0
   157
        ++pointerToCurrentByte;
sl@0
   158
        *pointerToCurrentByte=STATIC_CAST(TUint8, secondByte);
sl@0
   159
        __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers1));
sl@0
   160
        if (pointerToCurrentByte>=pointerToLastByte)
sl@0
   161
            {
sl@0
   162
            break;
sl@0
   163
            }
sl@0
   164
        ++pointerToCurrentByte;
sl@0
   165
        }
sl@0
   166
    }
sl@0
   167
sl@0
   168
// -----------------------------------------------------------------------------
sl@0
   169
// NumberOfBytesAbleToConvertToJisX0201 ?description.
sl@0
   170
// ?description
sl@0
   171
// Returns: ?value_1: ?description
sl@0
   172
//          ?value_n: ?description_line1
sl@0
   173
//                    ?description_line2
sl@0
   174
// -----------------------------------------------------------------------------
sl@0
   175
//
sl@0
   176
TInt NumberOfBytesAbleToConvertToJisX0201(const TDesC8& aDescriptor)
sl@0
   177
    {
sl@0
   178
    const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
sl@0
   179
    const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
sl@0
   180
    if (pointerToPreviousByte==pointerToLastByte)
sl@0
   181
        {
sl@0
   182
        return 0;
sl@0
   183
        }
sl@0
   184
    FOREVER
sl@0
   185
        {
sl@0
   186
        __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers2));
sl@0
   187
        const TUint currentByte = *(pointerToPreviousByte+1);
sl@0
   188
        if (((currentByte > KSingleByteRangeFirstBlockEnd)
sl@0
   189
             && (currentByte < KSingleByteRangeSecondBlockStart)) ||
sl@0
   190
            (currentByte > KSingleByteRangeSecondBlockEnd))
sl@0
   191
            {
sl@0
   192
            break;
sl@0
   193
            }
sl@0
   194
        __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers3));
sl@0
   195
        ++pointerToPreviousByte;
sl@0
   196
        __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers4));
sl@0
   197
        if (pointerToPreviousByte>=pointerToLastByte)
sl@0
   198
            {
sl@0
   199
            break;
sl@0
   200
            }
sl@0
   201
        }
sl@0
   202
    return (pointerToPreviousByte+1)-aDescriptor.Ptr();
sl@0
   203
    }
sl@0
   204
sl@0
   205
// -----------------------------------------------------------------------------
sl@0
   206
// NumberOfBytesAbleToConvertToJisX0208 ?description.
sl@0
   207
// ?description
sl@0
   208
// Returns: ?value_1: ?description
sl@0
   209
//          ?value_n: ?description_line1
sl@0
   210
//                    ?description_line2
sl@0
   211
// -----------------------------------------------------------------------------
sl@0
   212
//
sl@0
   213
TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor)
sl@0
   214
    {
sl@0
   215
    const TUint8* pointerToPreviousByte=aDescriptor.Ptr()-1;
sl@0
   216
    const TUint8* const pointerToLastByte=pointerToPreviousByte+aDescriptor.Length();
sl@0
   217
    if (pointerToPreviousByte==pointerToLastByte)
sl@0
   218
        {
sl@0
   219
        return 0;
sl@0
   220
        }
sl@0
   221
    FOREVER
sl@0
   222
        {
sl@0
   223
        __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers5));
sl@0
   224
        TUint currentByte=*(pointerToPreviousByte+1);
sl@0
   225
        if ((currentByte<KFirstByteRangeFirstBlockStart) ||
sl@0
   226
            ((currentByte>KFirstByteRangeFirstBlockEnd) && (currentByte<KFirstByteRangeSecondBlockStart)) ||
sl@0
   227
            (currentByte>KFirstByteRangeSecondBlockEnd) ||
sl@0
   228
            ((currentByte >= KPictoFirstByteStart) && (currentByte <= KPictoFirstByteEnd))
sl@0
   229
           )
sl@0
   230
            {
sl@0
   231
            break;
sl@0
   232
            }
sl@0
   233
sl@0
   234
        __ASSERT_DEBUG(pointerToPreviousByte<pointerToLastByte, Panic(EPanicBadPointers6));
sl@0
   235
        if (pointerToPreviousByte+1>=pointerToLastByte)
sl@0
   236
            {
sl@0
   237
            break;
sl@0
   238
            }
sl@0
   239
        __ASSERT_DEBUG(pointerToPreviousByte+2<=pointerToLastByte, Panic(EPanicBadPointers7));
sl@0
   240
        currentByte=*(pointerToPreviousByte+2);
sl@0
   241
        if ((currentByte<KSecondByteRangeFirstBlockStart) ||
sl@0
   242
            ((currentByte>KSecondByteRangeFirstBlockEnd) && (currentByte<KSecondByteRangeSecondBlockStart)) ||
sl@0
   243
            (currentByte>KSecondByteRangeSecondBlockEnd))
sl@0
   244
            {
sl@0
   245
            break;
sl@0
   246
            }
sl@0
   247
        pointerToPreviousByte+=2;
sl@0
   248
        __ASSERT_DEBUG(pointerToPreviousByte<=pointerToLastByte, Panic(EPanicBadPointers8));
sl@0
   249
        if (pointerToPreviousByte>=pointerToLastByte)
sl@0
   250
            {
sl@0
   251
            break;
sl@0
   252
            }
sl@0
   253
        }
sl@0
   254
    return (pointerToPreviousByte+1)-aDescriptor.Ptr();
sl@0
   255
    }
sl@0
   256
sl@0
   257
// -----------------------------------------------------------------------------
sl@0
   258
// NumberOfBytesAbleToConvertToPictograph ?description.
sl@0
   259
// ?description
sl@0
   260
// Returns: ?value_1: ?description
sl@0
   261
//          ?value_n: ?description_line1
sl@0
   262
//                    ?description_line2
sl@0
   263
// -----------------------------------------------------------------------------
sl@0
   264
//
sl@0
   265
TInt NumberOfBytesAbleToConvertToPictograph(const TDesC8& aDescriptor)
sl@0
   266
    {
sl@0
   267
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   268
    const TUint8* const pointerToLastByte = pointerToPreviousByte + aDescriptor.Length();
sl@0
   269
sl@0
   270
    for (; pointerToPreviousByte < pointerToLastByte;)
sl@0
   271
        {
sl@0
   272
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte, Panic(EPanicBadPointers5));
sl@0
   273
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   274
        if ((currentByte < KPictoFirstByteStart) || (currentByte > KPictoFirstByteEnd))
sl@0
   275
            {
sl@0
   276
            break;
sl@0
   277
            }
sl@0
   278
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte, Panic(EPanicBadPointers6));
sl@0
   279
        if (pointerToPreviousByte + 1 >= pointerToLastByte)
sl@0
   280
            {
sl@0
   281
            break;
sl@0
   282
            }
sl@0
   283
        __ASSERT_DEBUG(pointerToPreviousByte + 2 <= pointerToLastByte, Panic(EPanicBadPointers7));
sl@0
   284
        currentByte = *(pointerToPreviousByte + 2);
sl@0
   285
        if ((currentByte < KPictoSecondByteStart) || (currentByte> KPictoSecondByteEnd))
sl@0
   286
            {
sl@0
   287
            break;
sl@0
   288
            }
sl@0
   289
        pointerToPreviousByte += 2;
sl@0
   290
        __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte, Panic(EPanicBadPointers8));
sl@0
   291
        if (pointerToPreviousByte >= pointerToLastByte)
sl@0
   292
            {
sl@0
   293
            break;
sl@0
   294
            }
sl@0
   295
        }
sl@0
   296
    return (pointerToPreviousByte + 1)-aDescriptor.Ptr();
sl@0
   297
    }
sl@0
   298
sl@0
   299
// -----------------------------------------------------------------------------
sl@0
   300
// DummyConvertToIntermediateBufferInPlace ?description.
sl@0
   301
// ?description
sl@0
   302
// Returns: ?value_1: ?description
sl@0
   303
//          ?value_n: ?description_line1
sl@0
   304
//                    ?description_line2
sl@0
   305
// -----------------------------------------------------------------------------
sl@0
   306
//
sl@0
   307
void DummyConvertToIntermediateBufferInPlace(TDes8&)
sl@0
   308
    {
sl@0
   309
    }
sl@0
   310
sl@0
   311
// -----------------------------------------------------------------------------
sl@0
   312
// ConvertToJisX0208FromShiftJisInPlace ?description.
sl@0
   313
// ?description
sl@0
   314
// Returns: ?value_1: ?description
sl@0
   315
//          ?value_n: ?description_line1
sl@0
   316
//                    ?description_line2
sl@0
   317
// -----------------------------------------------------------------------------
sl@0
   318
//
sl@0
   319
void ConvertToJisX0208FromShiftJisInPlace(TDes8& aDescriptor)
sl@0
   320
    {
sl@0
   321
    const TInt descriptorLength=aDescriptor.Length();
sl@0
   322
    __ASSERT_DEBUG(descriptorLength>0, Panic(EPanicNothingToConvert2));
sl@0
   323
    __ASSERT_DEBUG(descriptorLength%2==0, Panic(EPanicOddNumberOfBytes2));
sl@0
   324
    TUint8* pointerToCurrentByte=CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   325
    const TUint8* const pointerToLastByte=pointerToCurrentByte+(descriptorLength-1);
sl@0
   326
    FOREVER
sl@0
   327
        {
sl@0
   328
        TUint firstByte=*pointerToCurrentByte;
sl@0
   329
        TUint secondByte=*(pointerToCurrentByte+1);
sl@0
   330
        if (firstByte<KFirstByteRangeSecondBlockStart)
sl@0
   331
            {
sl@0
   332
            firstByte-=KFirstByteRangeFirstBlockStart;
sl@0
   333
            }
sl@0
   334
        else
sl@0
   335
            {
sl@0
   336
            firstByte-=KFirstByteRangeSecondBlockStart-KFirstByteRangeFirstBlockLength;
sl@0
   337
            }
sl@0
   338
        if (secondByte<KSecondByteRangeSecondBlockStart)
sl@0
   339
            {
sl@0
   340
            secondByte-=KSecondByteRangeFirstBlockStart;
sl@0
   341
            }
sl@0
   342
        else
sl@0
   343
            {
sl@0
   344
            secondByte-=KSecondByteRangeSecondBlockStart-KSecondByteRangeFirstBlockLength;
sl@0
   345
            }
sl@0
   346
        firstByte*=2;
sl@0
   347
        if (secondByte>=94)
sl@0
   348
            {
sl@0
   349
            ++firstByte;
sl@0
   350
            secondByte-=94;
sl@0
   351
            }
sl@0
   352
        firstByte+=0x21;
sl@0
   353
        secondByte+=0x21;
sl@0
   354
        *pointerToCurrentByte=STATIC_CAST(TUint8, firstByte);
sl@0
   355
        ++pointerToCurrentByte;
sl@0
   356
        *pointerToCurrentByte=STATIC_CAST(TUint8, secondByte);
sl@0
   357
        __ASSERT_DEBUG(pointerToCurrentByte<=pointerToLastByte, Panic(EPanicBadPointers9));
sl@0
   358
        if (pointerToCurrentByte>=pointerToLastByte)
sl@0
   359
            {
sl@0
   360
            break;
sl@0
   361
            }
sl@0
   362
        ++pointerToCurrentByte;
sl@0
   363
        }
sl@0
   364
    }
sl@0
   365
sl@0
   366
// New Interface class
sl@0
   367
class ShiftJisDirectmapImplementation : public CCharacterSetConverterPluginInterface
sl@0
   368
{
sl@0
   369
    public:
sl@0
   370
        virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
sl@0
   371
sl@0
   372
        virtual TInt ConvertFromUnicode(
sl@0
   373
            CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
   374
            const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
sl@0
   375
            TDes8& aForeign,
sl@0
   376
            const TDesC16& aUnicode,
sl@0
   377
            CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters );
sl@0
   378
sl@0
   379
        virtual TInt ConvertToUnicode(
sl@0
   380
            CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
   381
            TDes16& aUnicode,
sl@0
   382
            const TDesC8& aForeign,
sl@0
   383
            TInt&,
sl@0
   384
            TInt& aNumberOfUnconvertibleCharacters,
sl@0
   385
            TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter );
sl@0
   386
sl@0
   387
        virtual TBool IsInThisCharacterSetL(
sl@0
   388
            TBool& aSetToTrue,
sl@0
   389
            TInt& aConfidenceLevel,
sl@0
   390
            const TDesC8& );
sl@0
   391
sl@0
   392
        static ShiftJisDirectmapImplementation* NewL();
sl@0
   393
sl@0
   394
        virtual ~ShiftJisDirectmapImplementation();
sl@0
   395
    private:
sl@0
   396
        ShiftJisDirectmapImplementation();
sl@0
   397
};
sl@0
   398
sl@0
   399
// -----------------------------------------------------------------------------
sl@0
   400
// ReplacementForUnconvertibleUnicodeCharacters returns the character which
sl@0
   401
// which is used by default as the replacement for unconvertible Unicode
sl@0
   402
// characters.
sl@0
   403
// Returns: a character
sl@0
   404
// -----------------------------------------------------------------------------
sl@0
   405
//
sl@0
   406
_LIT8(KLit8ShiftJisReplacementForUnconvertibleUnicodeCharacters, "\x81\x48");
sl@0
   407
const TDesC8& ShiftJisDirectmapImplementation::ReplacementForUnconvertibleUnicodeCharacters()
sl@0
   408
    {
sl@0
   409
    return KLit8ShiftJisReplacementForUnconvertibleUnicodeCharacters;//CnvShiftJis::ReplacementForUnconvertibleUnicodeCharacters();
sl@0
   410
    }
sl@0
   411
sl@0
   412
// -----------------------------------------------------------------------------
sl@0
   413
// ConvertFromUnicode converts from an Unicode string to a Shift-Jis string
sl@0
   414
// with Pictograph.
sl@0
   415
// Returns: The number of unconverted characters left at the end of the input
sl@0
   416
//          descriptor
sl@0
   417
// -----------------------------------------------------------------------------
sl@0
   418
//
sl@0
   419
TInt ShiftJisDirectmapImplementation::ConvertFromUnicode(
sl@0
   420
    CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
   421
    const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
sl@0
   422
    TDes8& aForeign, const TDesC16& aUnicode,
sl@0
   423
    CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
sl@0
   424
    {
sl@0
   425
    TFixedArray<CnvUtilities::SCharacterSet, 3> arrayOfCoreCharacterSets;
sl@0
   426
    arrayOfCoreCharacterSets[0].iConversionData = &CnvJisX0201::ConversionData();
sl@0
   427
    arrayOfCoreCharacterSets[0].iConvertFromIntermediateBufferInPlace =
sl@0
   428
        DummyConvertFromIntermediateBufferInPlace;
sl@0
   429
    arrayOfCoreCharacterSets[0].iEscapeSequence = &KNullDesC8;
sl@0
   430
    arrayOfCoreCharacterSets[1].iConversionData = &CnvJisX0208::ConversionData();
sl@0
   431
    arrayOfCoreCharacterSets[1].iConvertFromIntermediateBufferInPlace =
sl@0
   432
        ConvertFromJisX0208ToShiftJisInPlace;
sl@0
   433
    arrayOfCoreCharacterSets[1].iEscapeSequence = &KNullDesC8;
sl@0
   434
    arrayOfCoreCharacterSets[2].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
   435
    arrayOfCoreCharacterSets[2].iConvertFromIntermediateBufferInPlace =
sl@0
   436
        DummyConvertFromIntermediateBufferInPlace;
sl@0
   437
    arrayOfCoreCharacterSets[2].iEscapeSequence = &KNullDesC8;
sl@0
   438
sl@0
   439
    return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters,
sl@0
   440
        aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode,
sl@0
   441
        aIndicesOfUnconvertibleCharacters, arrayOfCoreCharacterSets.Array());
sl@0
   442
    }
sl@0
   443
sl@0
   444
// -----------------------------------------------------------------------------
sl@0
   445
// ConvertToUnicode converts from a Shift-Jis string with Pictograph to
sl@0
   446
// an Unicode string .
sl@0
   447
// Returns: The number of unconverted bytes left at the end of the input
sl@0
   448
//          descriptor
sl@0
   449
// -----------------------------------------------------------------------------
sl@0
   450
//
sl@0
   451
TInt ShiftJisDirectmapImplementation::ConvertToUnicode(
sl@0
   452
    CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
   453
    TDes16& aUnicode, const TDesC8& aForeign, TInt&,
sl@0
   454
    TInt& aNumberOfUnconvertibleCharacters,
sl@0
   455
    TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
sl@0
   456
    {
sl@0
   457
    TFixedArray<CnvUtilities::SMethod, 3> arrayOfCoreMethods;
sl@0
   458
    arrayOfCoreMethods[0].iNumberOfBytesAbleToConvert =
sl@0
   459
        NumberOfBytesAbleToConvertToJisX0201;
sl@0
   460
    arrayOfCoreMethods[0].iConvertToIntermediateBufferInPlace =
sl@0
   461
        DummyConvertToIntermediateBufferInPlace;
sl@0
   462
    arrayOfCoreMethods[0].iConversionData = &CnvJisX0201::ConversionData();
sl@0
   463
    arrayOfCoreMethods[0].iNumberOfBytesPerCharacter = 1;
sl@0
   464
    arrayOfCoreMethods[0].iNumberOfCoreBytesPerCharacter = 1;
sl@0
   465
    arrayOfCoreMethods[1].iNumberOfBytesAbleToConvert =
sl@0
   466
        NumberOfBytesAbleToConvertToPictograph;
sl@0
   467
    arrayOfCoreMethods[1].iConvertToIntermediateBufferInPlace =
sl@0
   468
        DummyConvertToIntermediateBufferInPlace;
sl@0
   469
    arrayOfCoreMethods[1].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
   470
    arrayOfCoreMethods[1].iNumberOfBytesPerCharacter = 2;
sl@0
   471
    arrayOfCoreMethods[1].iNumberOfCoreBytesPerCharacter = 2;
sl@0
   472
    arrayOfCoreMethods[2].iNumberOfBytesAbleToConvert =
sl@0
   473
        NumberOfBytesAbleToConvertToJisX0208;
sl@0
   474
    arrayOfCoreMethods[2].iConvertToIntermediateBufferInPlace =
sl@0
   475
        ConvertToJisX0208FromShiftJisInPlace;
sl@0
   476
    arrayOfCoreMethods[2].iConversionData = &CnvJisX0208::ConversionData();
sl@0
   477
    arrayOfCoreMethods[2].iNumberOfBytesPerCharacter = 2;
sl@0
   478
    arrayOfCoreMethods[2].iNumberOfCoreBytesPerCharacter = 2;
sl@0
   479
sl@0
   480
    TInt unconvert = CnvUtilities::ConvertToUnicodeFromHeterogeneousForeign(
sl@0
   481
                        aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign,
sl@0
   482
                        aNumberOfUnconvertibleCharacters,
sl@0
   483
                        aIndexOfFirstByteOfFirstUnconvertibleCharacter,
sl@0
   484
                        arrayOfCoreMethods.Array());
sl@0
   485
sl@0
   486
    // The following is specific impelementation for brower.
sl@0
   487
    // If brower app calls this API, the yen sign code(0xA5)
sl@0
   488
    // must be converted to backslash code(0x5C).
sl@0
   489
    // Becasue Javascript supports backslash code ony.
sl@0
   490
    TBool browserProcess = (RProcess().SecureId().iId == KBrowserSecureId);
sl@0
   491
    if (browserProcess && aUnicode.Length() > 0)
sl@0
   492
        {
sl@0
   493
        const TUint16* pB = aUnicode.Ptr();
sl@0
   494
        const TUint16* pbase = pB;
sl@0
   495
        const TUint16* pE = pB + aUnicode.Length() -1;
sl@0
   496
        while (pE>=pbase)
sl@0
   497
            {
sl@0
   498
            if (*pbase == KCharacterCodeForYenSign)
sl@0
   499
                {
sl@0
   500
                aUnicode[pbase - pB] = KCharacterCodeForBackSlash;
sl@0
   501
                }
sl@0
   502
            pbase++;
sl@0
   503
            }
sl@0
   504
        }
sl@0
   505
sl@0
   506
    return unconvert;
sl@0
   507
    }
sl@0
   508
sl@0
   509
// -----------------------------------------------------------------------------
sl@0
   510
// IsInThisCharacterSetL tests whether the aSample is Shift-JIS or not.
sl@0
   511
// But, This .cpl is only used for FEP.
sl@0
   512
// So, it's not need to correspond auto code detection.
sl@0
   513
// Returns: EFalse: ?description
sl@0
   514
// -----------------------------------------------------------------------------
sl@0
   515
//
sl@0
   516
TBool ShiftJisDirectmapImplementation::IsInThisCharacterSetL(TBool& /*aSetToTrue*/, TInt& /*aConfidenceLevel*/,
sl@0
   517
    const TDesC8& /*aSample*/)
sl@0
   518
    {
sl@0
   519
    return EFalse;
sl@0
   520
    }
sl@0
   521
sl@0
   522
ShiftJisDirectmapImplementation* ShiftJisDirectmapImplementation::NewL()
sl@0
   523
    {
sl@0
   524
    ShiftJisDirectmapImplementation* self = new(ELeave) ShiftJisDirectmapImplementation;
sl@0
   525
    return self;
sl@0
   526
    }
sl@0
   527
sl@0
   528
ShiftJisDirectmapImplementation::ShiftJisDirectmapImplementation()
sl@0
   529
    {
sl@0
   530
    //default constructor.. do nothing
sl@0
   531
    }
sl@0
   532
sl@0
   533
ShiftJisDirectmapImplementation::~ShiftJisDirectmapImplementation()
sl@0
   534
    {
sl@0
   535
    //default destructor .. do nothing
sl@0
   536
    }
sl@0
   537
sl@0
   538
// ECOM CREATION FUNCTION
sl@0
   539
const TImplementationProxy ImplementationTable[] =
sl@0
   540
    {
sl@0
   541
    // Note: This is the same UID as defined in old mmp-file
sl@0
   542
    // Used also in 12221212.rss ( implementation_uid )
sl@0
   543
    IMPLEMENTATION_PROXY_ENTRY( 0x101F8691, ShiftJisDirectmapImplementation::NewL )
sl@0
   544
    };
sl@0
   545
sl@0
   546
EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
sl@0
   547
    {
sl@0
   548
    aTableCount = sizeof( ImplementationTable ) / sizeof(TImplementationProxy);
sl@0
   549
    return ImplementationTable;
sl@0
   550
    }
sl@0
   551
sl@0
   552
//  End of File