os/textandloc/charconvfw/charconvplugins/src/plugins/EucJpDirectmap.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002-2004 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 file is a source code file for a charconv plug-in.
sl@0
    15
*                This plug-in supports EUC-JP with direct mapped pictograph.
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
sl@0
    25
// INCLUDE FILES
sl@0
    26
sl@0
    27
#include <e32std.h>
sl@0
    28
sl@0
    29
#include <charconv.h>
sl@0
    30
sl@0
    31
sl@0
    32
sl@0
    33
#ifndef EKA2
sl@0
    34
sl@0
    35
#include <CONVPLUG.H>
sl@0
    36
sl@0
    37
#else
sl@0
    38
sl@0
    39
#include <convgeneratedcpp.h>
sl@0
    40
sl@0
    41
#include <ecom/implementationproxy.h>
sl@0
    42
sl@0
    43
#include "charactersetconverter.h"
sl@0
    44
sl@0
    45
#endif // !EKA2
sl@0
    46
sl@0
    47
sl@0
    48
sl@0
    49
#include <convutils.h>
sl@0
    50
sl@0
    51
#include "jisx0201.h"
sl@0
    52
sl@0
    53
#include "jisx0208.h"
sl@0
    54
sl@0
    55
#include "jisx0212.h"
sl@0
    56
sl@0
    57
#include "CnvShiftJisDirectmap.h"
sl@0
    58
sl@0
    59
// LOCAL CONSTANTS AND MACROS
sl@0
    60
sl@0
    61
const TUint KSingleShift2=0x8e;
sl@0
    62
sl@0
    63
const TUint KSingleShift3=0x8f;
sl@0
    64
sl@0
    65
const TUint KFirstByteRangeFirstBlockStart = 0xF5;
sl@0
    66
sl@0
    67
const TUint KFirstByteRangeFirstBlockEnd = 0xFE;
sl@0
    68
sl@0
    69
const TUint KSecondByteRangeSecondBlockStart = 0xA1;
sl@0
    70
sl@0
    71
const TUint KSecondByteRangeSecondBlockEnd = 0xFE;
sl@0
    72
sl@0
    73
const TUint KPictographStartFirstByte = 0xF0;
sl@0
    74
sl@0
    75
const TUint KPictographStartSecondByte = 0x40;
sl@0
    76
sl@0
    77
const TUint KEUCJPSecondBlockStart = 0xF5;
sl@0
    78
sl@0
    79
const TUint KEUCJPBlockSize = 0x5D;
sl@0
    80
sl@0
    81
const TUint KShiftJisTrailByteIllegal = 0x7F;
sl@0
    82
sl@0
    83
sl@0
    84
sl@0
    85
// SecureID for Brower app
sl@0
    86
sl@0
    87
const TUint32 KBrowserSecureId = 0x10008D39;
sl@0
    88
sl@0
    89
// Define for converting from YenSign to BackSlash
sl@0
    90
sl@0
    91
const TUint KCharacterCodeForYenSign = 0x00A5;
sl@0
    92
sl@0
    93
const TUint KCharacterCodeForBackSlash = 0x005C;
sl@0
    94
sl@0
    95
sl@0
    96
sl@0
    97
// fullwidth question mark
sl@0
    98
sl@0
    99
_LIT8(KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters, "\xa1\xa9");
sl@0
   100
sl@0
   101
#if defined(_DEBUG)
sl@0
   102
sl@0
   103
_LIT(KLitPanicText, "EucJpDirectmap");
sl@0
   104
sl@0
   105
enum TPanic
sl@0
   106
sl@0
   107
    {
sl@0
   108
sl@0
   109
    EPanicNothingToConvert1=1,
sl@0
   110
sl@0
   111
    EPanicNothingToConvert2,
sl@0
   112
sl@0
   113
    EPanicNothingToConvert3,
sl@0
   114
sl@0
   115
    EPanicNothingToConvert4,
sl@0
   116
sl@0
   117
    EPanicNothingToConvert5,
sl@0
   118
sl@0
   119
    EPanicNothingToConvert6,
sl@0
   120
sl@0
   121
    EPanicOddNumberOfBytes1,
sl@0
   122
sl@0
   123
    EPanicOddNumberOfBytes2,
sl@0
   124
sl@0
   125
    EPanicOddNumberOfBytes3,
sl@0
   126
sl@0
   127
    EPanicOddNumberOfBytes4,
sl@0
   128
sl@0
   129
    EPanicOddNumberOfBytes5,
sl@0
   130
sl@0
   131
    EPanicOddNumberOfBytes6,
sl@0
   132
sl@0
   133
    EPanicBadHighBit1,
sl@0
   134
sl@0
   135
    EPanicBadHighBit2,
sl@0
   136
sl@0
   137
    EPanicBadHighBit3,
sl@0
   138
sl@0
   139
    EPanicBadHighBit4,
sl@0
   140
sl@0
   141
    EPanicBadHighBit5,
sl@0
   142
sl@0
   143
    EPanicBadHighBit6,
sl@0
   144
sl@0
   145
    EPanicBadHighBit7,
sl@0
   146
sl@0
   147
    EPanicBadPointers1,
sl@0
   148
sl@0
   149
    EPanicBadPointers2,
sl@0
   150
sl@0
   151
    EPanicBadPointers3,
sl@0
   152
sl@0
   153
    EPanicBadPointers4,
sl@0
   154
sl@0
   155
    EPanicBadPointers5,
sl@0
   156
sl@0
   157
    EPanicBadPointers6,
sl@0
   158
sl@0
   159
    EPanicBadPointers7,
sl@0
   160
sl@0
   161
    EPanicBadPointers8,
sl@0
   162
sl@0
   163
    EPanicBadPointers9,
sl@0
   164
sl@0
   165
    EPanicBadPointers10,
sl@0
   166
sl@0
   167
    EPanicBadPointers11,
sl@0
   168
sl@0
   169
    EPanicBadPointers12,
sl@0
   170
sl@0
   171
    EPanicBadPointers13,
sl@0
   172
sl@0
   173
    EPanicBadPointers14,
sl@0
   174
sl@0
   175
    EPanicBadPointers15,
sl@0
   176
sl@0
   177
    EPanicBadPointers16,
sl@0
   178
sl@0
   179
    EPanicBadPointers17,
sl@0
   180
sl@0
   181
    EPanicBadPointers18,
sl@0
   182
sl@0
   183
    EPanicBadPointers19,
sl@0
   184
sl@0
   185
    EPanicBadPointers20,
sl@0
   186
sl@0
   187
    EPanicBadPointers21,
sl@0
   188
sl@0
   189
    EPanicBadPointers22,
sl@0
   190
sl@0
   191
    EPanicBadPointers23,
sl@0
   192
sl@0
   193
    EPanicBadPointers24,
sl@0
   194
sl@0
   195
    EPanicBadPointers25,
sl@0
   196
sl@0
   197
    EPanicBadPointers26,
sl@0
   198
sl@0
   199
    EPanicBadPointers27,
sl@0
   200
sl@0
   201
    EPanicBadPointers28,
sl@0
   202
sl@0
   203
    EPanicBadPointers29,
sl@0
   204
sl@0
   205
    EPanicBadPointers30,
sl@0
   206
sl@0
   207
    EPanicBadPointers31,
sl@0
   208
sl@0
   209
    EPanicBadPointers32,
sl@0
   210
sl@0
   211
    EPanicBadPointers33,
sl@0
   212
sl@0
   213
    EPanicBadPointers34,
sl@0
   214
sl@0
   215
    EPanicBadPointers35,
sl@0
   216
sl@0
   217
    EPanicBadPointers36,
sl@0
   218
sl@0
   219
    EPanicBadCalculation1,
sl@0
   220
sl@0
   221
    EPanicBadCalculation2,
sl@0
   222
sl@0
   223
    EPanicNumberOfBytesIsNotMultipleOfThree1,
sl@0
   224
sl@0
   225
    EPanicNumberOfBytesIsNotMultipleOfThree2,
sl@0
   226
sl@0
   227
    EPanicSingleShift2Expected,
sl@0
   228
sl@0
   229
    EPanicSingleShift3Expected
sl@0
   230
sl@0
   231
    };
sl@0
   232
sl@0
   233
sl@0
   234
sl@0
   235
LOCAL_C void Panic(TPanic aPanic)
sl@0
   236
sl@0
   237
    {
sl@0
   238
sl@0
   239
    User::Panic(KLitPanicText, aPanic);
sl@0
   240
sl@0
   241
    }
sl@0
   242
sl@0
   243
#endif
sl@0
   244
sl@0
   245
sl@0
   246
sl@0
   247
// -----------------------------------------------------------------------------
sl@0
   248
sl@0
   249
// DummyConvertFromIntermediateBufferInPlace
sl@0
   250
sl@0
   251
//
sl@0
   252
sl@0
   253
// -----------------------------------------------------------------------------
sl@0
   254
sl@0
   255
//
sl@0
   256
sl@0
   257
LOCAL_C void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&,
sl@0
   258
sl@0
   259
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   260
sl@0
   261
    {
sl@0
   262
sl@0
   263
    aNumberOfCharactersThatDroppedOut = 0;
sl@0
   264
sl@0
   265
    }
sl@0
   266
sl@0
   267
sl@0
   268
sl@0
   269
// -----------------------------------------------------------------------------
sl@0
   270
sl@0
   271
// ConvertFromJisX0208ToEucJpPackedInPlace
sl@0
   272
sl@0
   273
// Converts from JIS code to EUC-JP
sl@0
   274
sl@0
   275
// -----------------------------------------------------------------------------
sl@0
   276
sl@0
   277
//
sl@0
   278
sl@0
   279
LOCAL_C void ConvertFromJisX0208ToEucJpPackedInPlace(
sl@0
   280
sl@0
   281
        TInt aStartPositionInDescriptor, TDes8& aDescriptor,
sl@0
   282
sl@0
   283
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   284
sl@0
   285
    {
sl@0
   286
sl@0
   287
    aNumberOfCharactersThatDroppedOut = 0;
sl@0
   288
sl@0
   289
    const TInt descriptorLength = aDescriptor.Length();
sl@0
   290
sl@0
   291
    __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
sl@0
   292
sl@0
   293
        Panic(EPanicNothingToConvert1));
sl@0
   294
sl@0
   295
    __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
   296
sl@0
   297
        Panic(EPanicOddNumberOfBytes1));
sl@0
   298
sl@0
   299
    TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   300
sl@0
   301
    const TUint8* const pointerToLastByte =
sl@0
   302
sl@0
   303
        pointerToCurrentByte + (descriptorLength - 1);
sl@0
   304
sl@0
   305
    pointerToCurrentByte += aStartPositionInDescriptor;
sl@0
   306
sl@0
   307
    FOREVER
sl@0
   308
sl@0
   309
        {
sl@0
   310
sl@0
   311
        const TUint currentByte = *pointerToCurrentByte;
sl@0
   312
sl@0
   313
        __ASSERT_DEBUG((currentByte & 0x80) == 0, Panic(EPanicBadHighBit1));
sl@0
   314
sl@0
   315
        *pointerToCurrentByte = STATIC_CAST(TUint8, currentByte | 0x80);
sl@0
   316
sl@0
   317
        __ASSERT_DEBUG(pointerToCurrentByte <= pointerToLastByte,
sl@0
   318
sl@0
   319
            Panic(EPanicBadPointers1));
sl@0
   320
sl@0
   321
        if (pointerToCurrentByte >= pointerToLastByte)
sl@0
   322
sl@0
   323
            {
sl@0
   324
sl@0
   325
            break;
sl@0
   326
sl@0
   327
            }
sl@0
   328
sl@0
   329
        ++pointerToCurrentByte;
sl@0
   330
sl@0
   331
        }
sl@0
   332
sl@0
   333
    }
sl@0
   334
sl@0
   335
sl@0
   336
sl@0
   337
// -----------------------------------------------------------------------------
sl@0
   338
sl@0
   339
// ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace
sl@0
   340
sl@0
   341
// Converts from half width Katakana code to EUC-JP
sl@0
   342
sl@0
   343
// -----------------------------------------------------------------------------
sl@0
   344
sl@0
   345
//
sl@0
   346
sl@0
   347
LOCAL_C void ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace(
sl@0
   348
sl@0
   349
        TInt aStartPositionInDescriptor, TDes8& aDescriptor,
sl@0
   350
sl@0
   351
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   352
sl@0
   353
    {
sl@0
   354
sl@0
   355
    TInt descriptorLength = aDescriptor.Length();
sl@0
   356
sl@0
   357
    __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
sl@0
   358
sl@0
   359
        Panic(EPanicNothingToConvert2));
sl@0
   360
sl@0
   361
    aNumberOfCharactersThatDroppedOut = Max(0, (descriptorLength -
sl@0
   362
sl@0
   363
        aStartPositionInDescriptor) - ((aDescriptor.MaxLength() -
sl@0
   364
sl@0
   365
        aStartPositionInDescriptor) / 2));
sl@0
   366
sl@0
   367
    descriptorLength -= aNumberOfCharactersThatDroppedOut;
sl@0
   368
sl@0
   369
    __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
sl@0
   370
sl@0
   371
        Panic(EPanicBadCalculation1));
sl@0
   372
sl@0
   373
    if (descriptorLength <= aStartPositionInDescriptor)
sl@0
   374
sl@0
   375
        {
sl@0
   376
sl@0
   377
        aDescriptor.SetLength(descriptorLength);
sl@0
   378
sl@0
   379
        }
sl@0
   380
sl@0
   381
    else
sl@0
   382
sl@0
   383
        {
sl@0
   384
sl@0
   385
        // pointerToTargetByte is initialized properly when descriptorLength
sl@0
   386
sl@0
   387
        // has been offset to the actual final length of aDescriptor
sl@0
   388
sl@0
   389
        TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   390
sl@0
   391
        const TUint8* const pointerToFirstByte =
sl@0
   392
sl@0
   393
            pointerToTargetByte + aStartPositionInDescriptor;
sl@0
   394
sl@0
   395
        const TUint8* pointerToSourceByte =
sl@0
   396
sl@0
   397
            pointerToTargetByte + (descriptorLength - 1);
sl@0
   398
sl@0
   399
        descriptorLength =
sl@0
   400
sl@0
   401
            ((descriptorLength - aStartPositionInDescriptor) * 2) +
sl@0
   402
sl@0
   403
            aStartPositionInDescriptor;
sl@0
   404
sl@0
   405
        __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
   406
sl@0
   407
            Panic(EPanicOddNumberOfBytes2));
sl@0
   408
sl@0
   409
        aDescriptor.SetLength(descriptorLength);
sl@0
   410
sl@0
   411
        // pointerToTargetByte is is initialized properly here
sl@0
   412
sl@0
   413
        pointerToTargetByte += descriptorLength - 1;
sl@0
   414
sl@0
   415
        FOREVER
sl@0
   416
sl@0
   417
            {
sl@0
   418
sl@0
   419
            *pointerToTargetByte = *pointerToSourceByte;
sl@0
   420
sl@0
   421
            __ASSERT_DEBUG(pointerToTargetByte>pointerToFirstByte,
sl@0
   422
sl@0
   423
                Panic(EPanicBadPointers2));
sl@0
   424
sl@0
   425
            --pointerToTargetByte;
sl@0
   426
sl@0
   427
            *pointerToTargetByte = KSingleShift2;
sl@0
   428
sl@0
   429
            __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
sl@0
   430
sl@0
   431
                Panic(EPanicBadPointers3));
sl@0
   432
sl@0
   433
            if (pointerToTargetByte <= pointerToFirstByte)
sl@0
   434
sl@0
   435
                {
sl@0
   436
sl@0
   437
                break;
sl@0
   438
sl@0
   439
                }
sl@0
   440
sl@0
   441
            --pointerToTargetByte;
sl@0
   442
sl@0
   443
            __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
sl@0
   444
sl@0
   445
                Panic(EPanicBadPointers4));
sl@0
   446
sl@0
   447
            --pointerToSourceByte;
sl@0
   448
sl@0
   449
            }
sl@0
   450
sl@0
   451
        __ASSERT_DEBUG(pointerToTargetByte == pointerToFirstByte,
sl@0
   452
sl@0
   453
            Panic(EPanicBadPointers5));
sl@0
   454
sl@0
   455
        __ASSERT_DEBUG(pointerToSourceByte == pointerToFirstByte,
sl@0
   456
sl@0
   457
            Panic(EPanicBadPointers6));
sl@0
   458
sl@0
   459
        }
sl@0
   460
sl@0
   461
    }
sl@0
   462
sl@0
   463
sl@0
   464
sl@0
   465
// -----------------------------------------------------------------------------
sl@0
   466
sl@0
   467
// ConvertFromJisX0212ToEucJpPackedInPlace
sl@0
   468
sl@0
   469
// Converts from JIS code to EUC-JP
sl@0
   470
sl@0
   471
// -----------------------------------------------------------------------------
sl@0
   472
sl@0
   473
//
sl@0
   474
sl@0
   475
LOCAL_C void ConvertFromJisX0212ToEucJpPackedInPlace(
sl@0
   476
sl@0
   477
        TInt aStartPositionInDescriptor, TDes8& aDescriptor,
sl@0
   478
sl@0
   479
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   480
sl@0
   481
    {
sl@0
   482
sl@0
   483
    TInt descriptorLength=aDescriptor.Length();
sl@0
   484
sl@0
   485
    __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
sl@0
   486
sl@0
   487
        Panic(EPanicNothingToConvert3));
sl@0
   488
sl@0
   489
    __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
   490
sl@0
   491
        Panic(EPanicOddNumberOfBytes3));
sl@0
   492
sl@0
   493
    aNumberOfCharactersThatDroppedOut =
sl@0
   494
sl@0
   495
        Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) -
sl@0
   496
sl@0
   497
        ((aDescriptor.MaxLength() - aStartPositionInDescriptor) / 3));
sl@0
   498
sl@0
   499
    descriptorLength -= aNumberOfCharactersThatDroppedOut * 2;
sl@0
   500
sl@0
   501
    __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
sl@0
   502
sl@0
   503
        Panic(EPanicBadCalculation2));
sl@0
   504
sl@0
   505
    if (descriptorLength <= aStartPositionInDescriptor)
sl@0
   506
sl@0
   507
        {
sl@0
   508
sl@0
   509
        aDescriptor.SetLength(descriptorLength);
sl@0
   510
sl@0
   511
        }
sl@0
   512
sl@0
   513
    else
sl@0
   514
sl@0
   515
        {
sl@0
   516
sl@0
   517
        __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
   518
sl@0
   519
            Panic(EPanicOddNumberOfBytes4));
sl@0
   520
sl@0
   521
        // pointerToTargetByte is initialized properly when descriptorLength
sl@0
   522
sl@0
   523
        // has been offset to the actual final length of aDescriptor
sl@0
   524
sl@0
   525
        TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   526
sl@0
   527
        const TUint8* const pointerToFirstByte =
sl@0
   528
sl@0
   529
            pointerToTargetByte + aStartPositionInDescriptor;
sl@0
   530
sl@0
   531
        const TUint8* pointerToSourceByte =
sl@0
   532
sl@0
   533
            pointerToTargetByte + (descriptorLength - 1);
sl@0
   534
sl@0
   535
        descriptorLength = (((descriptorLength - aStartPositionInDescriptor)
sl@0
   536
sl@0
   537
            * 3) / 2) + aStartPositionInDescriptor;
sl@0
   538
sl@0
   539
        __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 3 ==0,
sl@0
   540
sl@0
   541
            Panic(EPanicNumberOfBytesIsNotMultipleOfThree1));
sl@0
   542
sl@0
   543
        aDescriptor.SetLength(descriptorLength);
sl@0
   544
sl@0
   545
        // pointerToTargetByte is is initialized properly here
sl@0
   546
sl@0
   547
        pointerToTargetByte += descriptorLength - 1;
sl@0
   548
sl@0
   549
        FOREVER
sl@0
   550
sl@0
   551
            {
sl@0
   552
sl@0
   553
            __ASSERT_DEBUG((*pointerToSourceByte & 0x80) == 0,
sl@0
   554
sl@0
   555
                Panic(EPanicBadHighBit2));
sl@0
   556
sl@0
   557
            *pointerToTargetByte =
sl@0
   558
sl@0
   559
                STATIC_CAST(TUint8, *pointerToSourceByte | 0x80);
sl@0
   560
sl@0
   561
            __ASSERT_DEBUG(pointerToTargetByte > pointerToFirstByte,
sl@0
   562
sl@0
   563
                Panic(EPanicBadPointers7));
sl@0
   564
sl@0
   565
            --pointerToTargetByte;
sl@0
   566
sl@0
   567
            __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
sl@0
   568
sl@0
   569
                Panic(EPanicBadPointers8));
sl@0
   570
sl@0
   571
            --pointerToSourceByte;
sl@0
   572
sl@0
   573
            __ASSERT_DEBUG((*pointerToSourceByte & 0x80) == 0,
sl@0
   574
sl@0
   575
                Panic(EPanicBadHighBit3));
sl@0
   576
sl@0
   577
            *pointerToTargetByte =
sl@0
   578
sl@0
   579
                STATIC_CAST(TUint8, *pointerToSourceByte | 0x80);
sl@0
   580
sl@0
   581
            __ASSERT_DEBUG(pointerToTargetByte > pointerToFirstByte,
sl@0
   582
sl@0
   583
                Panic(EPanicBadPointers9));
sl@0
   584
sl@0
   585
            --pointerToTargetByte;
sl@0
   586
sl@0
   587
            *pointerToTargetByte = KSingleShift3;
sl@0
   588
sl@0
   589
            __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
sl@0
   590
sl@0
   591
                Panic(EPanicBadPointers10));
sl@0
   592
sl@0
   593
            if (pointerToTargetByte <= pointerToFirstByte)
sl@0
   594
sl@0
   595
                {
sl@0
   596
sl@0
   597
                break;
sl@0
   598
sl@0
   599
                }
sl@0
   600
sl@0
   601
            --pointerToTargetByte;
sl@0
   602
sl@0
   603
            __ASSERT_DEBUG(pointerToSourceByte > pointerToFirstByte,
sl@0
   604
sl@0
   605
                Panic(EPanicBadPointers11));
sl@0
   606
sl@0
   607
            --pointerToSourceByte;
sl@0
   608
sl@0
   609
            }
sl@0
   610
sl@0
   611
        __ASSERT_DEBUG(pointerToTargetByte == pointerToFirstByte,
sl@0
   612
sl@0
   613
            Panic(EPanicBadPointers12));
sl@0
   614
sl@0
   615
        __ASSERT_DEBUG(pointerToSourceByte == pointerToFirstByte,
sl@0
   616
sl@0
   617
            Panic(EPanicBadPointers13));
sl@0
   618
sl@0
   619
        }
sl@0
   620
sl@0
   621
    }
sl@0
   622
sl@0
   623
sl@0
   624
sl@0
   625
// -----------------------------------------------------------------------------
sl@0
   626
sl@0
   627
// NumberOfBytesAbleToConvertToJisRoman
sl@0
   628
sl@0
   629
// Counts the bytes of be able to convert to JIS
sl@0
   630
sl@0
   631
// -----------------------------------------------------------------------------
sl@0
   632
sl@0
   633
//
sl@0
   634
sl@0
   635
LOCAL_C TInt NumberOfBytesAbleToConvertToJisRoman(const TDesC8& aDescriptor)
sl@0
   636
sl@0
   637
    {
sl@0
   638
sl@0
   639
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   640
sl@0
   641
    const TUint8* const pointerToLastByte =
sl@0
   642
sl@0
   643
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   644
sl@0
   645
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   646
sl@0
   647
        {
sl@0
   648
sl@0
   649
        return 0;
sl@0
   650
sl@0
   651
        }
sl@0
   652
sl@0
   653
    FOREVER
sl@0
   654
sl@0
   655
        {
sl@0
   656
sl@0
   657
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   658
sl@0
   659
            Panic(EPanicBadPointers14));
sl@0
   660
sl@0
   661
        const TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   662
sl@0
   663
        if (currentByte & 0x80)
sl@0
   664
sl@0
   665
            {
sl@0
   666
sl@0
   667
            break;
sl@0
   668
sl@0
   669
            }
sl@0
   670
sl@0
   671
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   672
sl@0
   673
            Panic(EPanicBadPointers15));
sl@0
   674
sl@0
   675
        ++pointerToPreviousByte;
sl@0
   676
sl@0
   677
        __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
sl@0
   678
sl@0
   679
            Panic(EPanicBadPointers16));
sl@0
   680
sl@0
   681
        if (pointerToPreviousByte >= pointerToLastByte)
sl@0
   682
sl@0
   683
            {
sl@0
   684
sl@0
   685
            break;
sl@0
   686
sl@0
   687
            }
sl@0
   688
sl@0
   689
        }
sl@0
   690
sl@0
   691
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   692
sl@0
   693
    }
sl@0
   694
sl@0
   695
sl@0
   696
sl@0
   697
// -----------------------------------------------------------------------------
sl@0
   698
sl@0
   699
// NumberOfBytesAbleToConvertToJisX0208
sl@0
   700
sl@0
   701
// Counts the bytes of be able to convert to JIS
sl@0
   702
sl@0
   703
// -----------------------------------------------------------------------------
sl@0
   704
sl@0
   705
//
sl@0
   706
sl@0
   707
LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0208(const TDesC8& aDescriptor)
sl@0
   708
sl@0
   709
    {
sl@0
   710
sl@0
   711
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   712
sl@0
   713
    const TUint8* const pointerToLastByte =
sl@0
   714
sl@0
   715
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   716
sl@0
   717
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   718
sl@0
   719
        {
sl@0
   720
sl@0
   721
        return 0;
sl@0
   722
sl@0
   723
        }
sl@0
   724
sl@0
   725
    FOREVER
sl@0
   726
sl@0
   727
        {
sl@0
   728
sl@0
   729
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   730
sl@0
   731
            Panic(EPanicBadPointers17));
sl@0
   732
sl@0
   733
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   734
sl@0
   735
        if (currentByte < 0xa0)
sl@0
   736
sl@0
   737
            {
sl@0
   738
sl@0
   739
            break;
sl@0
   740
sl@0
   741
            }
sl@0
   742
sl@0
   743
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   744
sl@0
   745
            Panic(EPanicBadPointers18));
sl@0
   746
sl@0
   747
        if (pointerToLastByte - pointerToPreviousByte < 2)
sl@0
   748
sl@0
   749
            {
sl@0
   750
sl@0
   751
            break;
sl@0
   752
sl@0
   753
            }
sl@0
   754
sl@0
   755
        ++pointerToPreviousByte;
sl@0
   756
sl@0
   757
        currentByte = *(pointerToPreviousByte + 1);
sl@0
   758
sl@0
   759
        if (currentByte < 0xa0)
sl@0
   760
sl@0
   761
            {
sl@0
   762
sl@0
   763
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   764
sl@0
   765
            }
sl@0
   766
sl@0
   767
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   768
sl@0
   769
            Panic(EPanicBadPointers19));
sl@0
   770
sl@0
   771
        ++pointerToPreviousByte;
sl@0
   772
sl@0
   773
        __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
sl@0
   774
sl@0
   775
            Panic(EPanicBadPointers20));
sl@0
   776
sl@0
   777
        if (pointerToPreviousByte >= pointerToLastByte)
sl@0
   778
sl@0
   779
            {
sl@0
   780
sl@0
   781
            break;
sl@0
   782
sl@0
   783
            }
sl@0
   784
sl@0
   785
        }
sl@0
   786
sl@0
   787
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   788
sl@0
   789
    }
sl@0
   790
sl@0
   791
sl@0
   792
sl@0
   793
// -----------------------------------------------------------------------------
sl@0
   794
sl@0
   795
// NumberOfBytesAbleToConvertToHalfWidthKatakana8
sl@0
   796
sl@0
   797
// Counts the bytes of be able to convert to half width Katakana
sl@0
   798
sl@0
   799
// -----------------------------------------------------------------------------
sl@0
   800
sl@0
   801
//
sl@0
   802
sl@0
   803
LOCAL_C TInt NumberOfBytesAbleToConvertToHalfWidthKatakana8(const TDesC8& aDescriptor)
sl@0
   804
sl@0
   805
    {
sl@0
   806
sl@0
   807
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   808
sl@0
   809
    const TUint8* const pointerToLastByte =
sl@0
   810
sl@0
   811
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   812
sl@0
   813
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   814
sl@0
   815
        {
sl@0
   816
sl@0
   817
        return 0;
sl@0
   818
sl@0
   819
        }
sl@0
   820
sl@0
   821
    FOREVER
sl@0
   822
sl@0
   823
        {
sl@0
   824
sl@0
   825
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   826
sl@0
   827
            Panic(EPanicBadPointers21));
sl@0
   828
sl@0
   829
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   830
sl@0
   831
        if (currentByte != KSingleShift2)
sl@0
   832
sl@0
   833
            {
sl@0
   834
sl@0
   835
            break;
sl@0
   836
sl@0
   837
            }
sl@0
   838
sl@0
   839
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   840
sl@0
   841
            Panic(EPanicBadPointers22));
sl@0
   842
sl@0
   843
        if (pointerToLastByte - pointerToPreviousByte < 2)
sl@0
   844
sl@0
   845
            {
sl@0
   846
sl@0
   847
            break;
sl@0
   848
sl@0
   849
            }
sl@0
   850
sl@0
   851
        ++pointerToPreviousByte;
sl@0
   852
sl@0
   853
        currentByte = *(pointerToPreviousByte + 1);
sl@0
   854
sl@0
   855
        if (currentByte < 0xa0)
sl@0
   856
sl@0
   857
            {
sl@0
   858
sl@0
   859
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   860
sl@0
   861
            }
sl@0
   862
sl@0
   863
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   864
sl@0
   865
            Panic(EPanicBadPointers23));
sl@0
   866
sl@0
   867
        ++pointerToPreviousByte;
sl@0
   868
sl@0
   869
        __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
sl@0
   870
sl@0
   871
            Panic(EPanicBadPointers24));
sl@0
   872
sl@0
   873
        if (pointerToPreviousByte >= pointerToLastByte)
sl@0
   874
sl@0
   875
            {
sl@0
   876
sl@0
   877
            break;
sl@0
   878
sl@0
   879
            }
sl@0
   880
sl@0
   881
        }
sl@0
   882
sl@0
   883
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   884
sl@0
   885
    }
sl@0
   886
sl@0
   887
sl@0
   888
sl@0
   889
// -----------------------------------------------------------------------------
sl@0
   890
sl@0
   891
// NumberOfBytesAbleToConvertToJisX0212
sl@0
   892
sl@0
   893
// Counts the bytes of be able to convert to JIS
sl@0
   894
sl@0
   895
// -----------------------------------------------------------------------------
sl@0
   896
sl@0
   897
//
sl@0
   898
sl@0
   899
LOCAL_C TInt NumberOfBytesAbleToConvertToJisX0212(const TDesC8& aDescriptor)
sl@0
   900
sl@0
   901
    {
sl@0
   902
sl@0
   903
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   904
sl@0
   905
    const TUint8* const pointerToLastByte =
sl@0
   906
sl@0
   907
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   908
sl@0
   909
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   910
sl@0
   911
        {
sl@0
   912
sl@0
   913
        return 0;
sl@0
   914
sl@0
   915
        }
sl@0
   916
sl@0
   917
    FOREVER
sl@0
   918
sl@0
   919
        {
sl@0
   920
sl@0
   921
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   922
sl@0
   923
            Panic(EPanicBadPointers25));
sl@0
   924
sl@0
   925
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   926
sl@0
   927
        if (currentByte != KSingleShift3)
sl@0
   928
sl@0
   929
            {
sl@0
   930
sl@0
   931
            break;
sl@0
   932
sl@0
   933
            }
sl@0
   934
sl@0
   935
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   936
sl@0
   937
            Panic(EPanicBadPointers26));
sl@0
   938
sl@0
   939
        if (pointerToLastByte - pointerToPreviousByte < 3)
sl@0
   940
sl@0
   941
            {
sl@0
   942
sl@0
   943
            break;
sl@0
   944
sl@0
   945
            }
sl@0
   946
sl@0
   947
        ++pointerToPreviousByte;
sl@0
   948
sl@0
   949
        currentByte = *(pointerToPreviousByte + 1);
sl@0
   950
sl@0
   951
        if (currentByte < 0xa0)
sl@0
   952
sl@0
   953
            {
sl@0
   954
sl@0
   955
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   956
sl@0
   957
            }
sl@0
   958
sl@0
   959
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   960
sl@0
   961
            Panic(EPanicBadPointers27));
sl@0
   962
sl@0
   963
        ++pointerToPreviousByte;
sl@0
   964
sl@0
   965
        currentByte = *(pointerToPreviousByte + 1);
sl@0
   966
sl@0
   967
        if (currentByte < 0xa0)
sl@0
   968
sl@0
   969
            {
sl@0
   970
sl@0
   971
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   972
sl@0
   973
            }
sl@0
   974
sl@0
   975
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
   976
sl@0
   977
            Panic(EPanicBadPointers28));
sl@0
   978
sl@0
   979
        ++pointerToPreviousByte;
sl@0
   980
sl@0
   981
        __ASSERT_DEBUG(pointerToPreviousByte <= pointerToLastByte,
sl@0
   982
sl@0
   983
            Panic(EPanicBadPointers29));
sl@0
   984
sl@0
   985
        if (pointerToPreviousByte >= pointerToLastByte)
sl@0
   986
sl@0
   987
            {
sl@0
   988
sl@0
   989
            break;
sl@0
   990
sl@0
   991
            }
sl@0
   992
sl@0
   993
        }
sl@0
   994
sl@0
   995
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   996
sl@0
   997
    }
sl@0
   998
sl@0
   999
sl@0
  1000
sl@0
  1001
// -----------------------------------------------------------------------------
sl@0
  1002
sl@0
  1003
// DummyConvertToIntermediateBufferInPlace
sl@0
  1004
sl@0
  1005
//
sl@0
  1006
sl@0
  1007
// -----------------------------------------------------------------------------
sl@0
  1008
sl@0
  1009
//
sl@0
  1010
sl@0
  1011
LOCAL_C void DummyConvertToIntermediateBufferInPlace(TDes8&)
sl@0
  1012
sl@0
  1013
    {
sl@0
  1014
sl@0
  1015
    }
sl@0
  1016
sl@0
  1017
sl@0
  1018
sl@0
  1019
// -----------------------------------------------------------------------------
sl@0
  1020
sl@0
  1021
// ConvertToJisX0208FromEucJpPackedInPlace
sl@0
  1022
sl@0
  1023
// Converts from EUC-JP to JIS code
sl@0
  1024
sl@0
  1025
// -----------------------------------------------------------------------------
sl@0
  1026
sl@0
  1027
//
sl@0
  1028
sl@0
  1029
LOCAL_C void ConvertToJisX0208FromEucJpPackedInPlace(TDes8& aDescriptor)
sl@0
  1030
sl@0
  1031
    {
sl@0
  1032
sl@0
  1033
    const TInt descriptorLength = aDescriptor.Length();
sl@0
  1034
sl@0
  1035
    __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert4));
sl@0
  1036
sl@0
  1037
    __ASSERT_DEBUG(descriptorLength % 2 == 0, Panic(EPanicOddNumberOfBytes5));
sl@0
  1038
sl@0
  1039
    TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
  1040
sl@0
  1041
    const TUint8* const pointerToLastByte =
sl@0
  1042
sl@0
  1043
        pointerToCurrentByte + (descriptorLength - 1);
sl@0
  1044
sl@0
  1045
    FOREVER
sl@0
  1046
sl@0
  1047
        {
sl@0
  1048
sl@0
  1049
        const TUint currentByte = *pointerToCurrentByte;
sl@0
  1050
sl@0
  1051
        __ASSERT_DEBUG(currentByte & 0x80, Panic(EPanicBadHighBit4));
sl@0
  1052
sl@0
  1053
        *pointerToCurrentByte = STATIC_CAST(TUint8, currentByte & ~0x80);
sl@0
  1054
sl@0
  1055
        __ASSERT_DEBUG(pointerToCurrentByte <= pointerToLastByte,
sl@0
  1056
sl@0
  1057
            Panic(EPanicBadPointers30));
sl@0
  1058
sl@0
  1059
        if (pointerToCurrentByte >= pointerToLastByte)
sl@0
  1060
sl@0
  1061
            {
sl@0
  1062
sl@0
  1063
            break;
sl@0
  1064
sl@0
  1065
            }
sl@0
  1066
sl@0
  1067
        ++pointerToCurrentByte;
sl@0
  1068
sl@0
  1069
        }
sl@0
  1070
sl@0
  1071
    }
sl@0
  1072
sl@0
  1073
sl@0
  1074
sl@0
  1075
// -----------------------------------------------------------------------------
sl@0
  1076
sl@0
  1077
// ConvertToHalfWidthKatakana8FromEucJpPackedInPlace
sl@0
  1078
sl@0
  1079
// Converts from EUC-JP to half width Katakana
sl@0
  1080
sl@0
  1081
// -----------------------------------------------------------------------------
sl@0
  1082
sl@0
  1083
//
sl@0
  1084
sl@0
  1085
LOCAL_C void ConvertToHalfWidthKatakana8FromEucJpPackedInPlace(
sl@0
  1086
sl@0
  1087
        TDes8& aDescriptor)
sl@0
  1088
sl@0
  1089
    {
sl@0
  1090
sl@0
  1091
    const TInt descriptorLength = aDescriptor.Length();
sl@0
  1092
sl@0
  1093
    __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert5));
sl@0
  1094
sl@0
  1095
    __ASSERT_DEBUG(descriptorLength % 2 == 0, Panic(EPanicOddNumberOfBytes6));
sl@0
  1096
sl@0
  1097
    TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
  1098
sl@0
  1099
    const TUint8* pointerToSourceByte = pointerToTargetByte;
sl@0
  1100
sl@0
  1101
    const TUint8* const pointerToLastByte = pointerToSourceByte +
sl@0
  1102
sl@0
  1103
        (descriptorLength - 1);
sl@0
  1104
sl@0
  1105
    FOREVER
sl@0
  1106
sl@0
  1107
        {
sl@0
  1108
sl@0
  1109
        __ASSERT_DEBUG(*pointerToSourceByte == KSingleShift2,
sl@0
  1110
sl@0
  1111
            Panic(EPanicSingleShift2Expected));
sl@0
  1112
sl@0
  1113
        __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
sl@0
  1114
sl@0
  1115
            Panic(EPanicBadPointers31));
sl@0
  1116
sl@0
  1117
        ++pointerToSourceByte;
sl@0
  1118
sl@0
  1119
        const TUint sourceByte = *pointerToSourceByte;
sl@0
  1120
sl@0
  1121
        __ASSERT_DEBUG(sourceByte & 0x80, Panic(EPanicBadHighBit5));
sl@0
  1122
sl@0
  1123
        *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte);
sl@0
  1124
sl@0
  1125
        __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
sl@0
  1126
sl@0
  1127
            Panic(EPanicBadPointers32));
sl@0
  1128
sl@0
  1129
        if (pointerToSourceByte >= pointerToLastByte)
sl@0
  1130
sl@0
  1131
            {
sl@0
  1132
sl@0
  1133
            break;
sl@0
  1134
sl@0
  1135
            }
sl@0
  1136
sl@0
  1137
        ++pointerToSourceByte;
sl@0
  1138
sl@0
  1139
        ++pointerToTargetByte;
sl@0
  1140
sl@0
  1141
        }
sl@0
  1142
sl@0
  1143
    aDescriptor.SetLength(descriptorLength / 2);
sl@0
  1144
sl@0
  1145
    }
sl@0
  1146
sl@0
  1147
sl@0
  1148
sl@0
  1149
// -----------------------------------------------------------------------------
sl@0
  1150
sl@0
  1151
// ConvertToJisX0212FromEucJpPackedInPlace
sl@0
  1152
sl@0
  1153
// Converts from EUC-JP to JIS
sl@0
  1154
sl@0
  1155
// -----------------------------------------------------------------------------
sl@0
  1156
sl@0
  1157
//
sl@0
  1158
sl@0
  1159
LOCAL_C void ConvertToJisX0212FromEucJpPackedInPlace(TDes8& aDescriptor)
sl@0
  1160
sl@0
  1161
    {
sl@0
  1162
sl@0
  1163
    const TInt descriptorLength = aDescriptor.Length();
sl@0
  1164
sl@0
  1165
    __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert6));
sl@0
  1166
sl@0
  1167
    __ASSERT_DEBUG(descriptorLength % 3 == 0,
sl@0
  1168
sl@0
  1169
        Panic(EPanicNumberOfBytesIsNotMultipleOfThree2));
sl@0
  1170
sl@0
  1171
    TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
  1172
sl@0
  1173
    const TUint8* pointerToSourceByte = pointerToTargetByte;
sl@0
  1174
sl@0
  1175
    const TUint8* const pointerToLastByte =
sl@0
  1176
sl@0
  1177
        pointerToSourceByte + (descriptorLength - 1);
sl@0
  1178
sl@0
  1179
    FOREVER
sl@0
  1180
sl@0
  1181
        {
sl@0
  1182
sl@0
  1183
        __ASSERT_DEBUG(*pointerToSourceByte == KSingleShift3,
sl@0
  1184
sl@0
  1185
            Panic(EPanicSingleShift3Expected));
sl@0
  1186
sl@0
  1187
        __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
sl@0
  1188
sl@0
  1189
            Panic(EPanicBadPointers33));
sl@0
  1190
sl@0
  1191
        ++pointerToSourceByte;
sl@0
  1192
sl@0
  1193
        TUint sourceByte = *pointerToSourceByte;
sl@0
  1194
sl@0
  1195
        __ASSERT_DEBUG(sourceByte & 0x80, Panic(EPanicBadHighBit6));
sl@0
  1196
sl@0
  1197
        *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte & ~0x80);
sl@0
  1198
sl@0
  1199
        __ASSERT_DEBUG(pointerToSourceByte<pointerToLastByte,
sl@0
  1200
sl@0
  1201
            Panic(EPanicBadPointers34));
sl@0
  1202
sl@0
  1203
        ++pointerToSourceByte;
sl@0
  1204
sl@0
  1205
        sourceByte = *pointerToSourceByte;
sl@0
  1206
sl@0
  1207
        __ASSERT_DEBUG(sourceByte&0x80, Panic(EPanicBadHighBit7));
sl@0
  1208
sl@0
  1209
        __ASSERT_DEBUG(pointerToTargetByte < pointerToLastByte,
sl@0
  1210
sl@0
  1211
            Panic(EPanicBadPointers35));
sl@0
  1212
sl@0
  1213
        ++pointerToTargetByte;
sl@0
  1214
sl@0
  1215
        *pointerToTargetByte = STATIC_CAST(TUint8, sourceByte & ~0x80);
sl@0
  1216
sl@0
  1217
        __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
sl@0
  1218
sl@0
  1219
            Panic(EPanicBadPointers36));
sl@0
  1220
sl@0
  1221
        if (pointerToSourceByte >= pointerToLastByte)
sl@0
  1222
sl@0
  1223
            {
sl@0
  1224
sl@0
  1225
            break;
sl@0
  1226
sl@0
  1227
            }
sl@0
  1228
sl@0
  1229
        ++pointerToSourceByte;
sl@0
  1230
sl@0
  1231
        ++pointerToTargetByte;
sl@0
  1232
sl@0
  1233
        }
sl@0
  1234
sl@0
  1235
    aDescriptor.SetLength((descriptorLength / 3) * 2);
sl@0
  1236
sl@0
  1237
    }
sl@0
  1238
sl@0
  1239
sl@0
  1240
sl@0
  1241
// -----------------------------------------------------------------------------
sl@0
  1242
sl@0
  1243
// NumberOfBytesAbleToConvertToPictograph
sl@0
  1244
sl@0
  1245
//
sl@0
  1246
sl@0
  1247
// -----------------------------------------------------------------------------
sl@0
  1248
sl@0
  1249
//
sl@0
  1250
sl@0
  1251
LOCAL_C TInt NumberOfBytesAbleToConvertToPictograph1(const TDesC8& aDescriptor)
sl@0
  1252
sl@0
  1253
    {
sl@0
  1254
sl@0
  1255
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
  1256
sl@0
  1257
    const TUint8* const pointerToLastByte =
sl@0
  1258
sl@0
  1259
        pointerToPreviousByte + aDescriptor.Length();
sl@0
  1260
sl@0
  1261
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
  1262
sl@0
  1263
        {
sl@0
  1264
sl@0
  1265
        return 0;
sl@0
  1266
sl@0
  1267
        }
sl@0
  1268
sl@0
  1269
    for (;pointerToPreviousByte < pointerToLastByte;)
sl@0
  1270
sl@0
  1271
        {
sl@0
  1272
sl@0
  1273
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
  1274
sl@0
  1275
            Panic(EPanicBadPointers14));
sl@0
  1276
sl@0
  1277
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
  1278
sl@0
  1279
        const TUint nextByte = *(pointerToPreviousByte + 2);
sl@0
  1280
sl@0
  1281
        if (((currentByte < KFirstByteRangeFirstBlockStart) ||
sl@0
  1282
sl@0
  1283
             (currentByte > KFirstByteRangeFirstBlockEnd)) ||
sl@0
  1284
sl@0
  1285
            ((nextByte < KSecondByteRangeSecondBlockStart) ||
sl@0
  1286
sl@0
  1287
             (nextByte > KSecondByteRangeSecondBlockEnd)))
sl@0
  1288
sl@0
  1289
            {
sl@0
  1290
sl@0
  1291
            break;
sl@0
  1292
sl@0
  1293
            }
sl@0
  1294
sl@0
  1295
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
  1296
sl@0
  1297
            Panic(EPanicBadPointers15));
sl@0
  1298
sl@0
  1299
        pointerToPreviousByte += 2;
sl@0
  1300
sl@0
  1301
        }
sl@0
  1302
sl@0
  1303
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
  1304
sl@0
  1305
    }
sl@0
  1306
sl@0
  1307
sl@0
  1308
sl@0
  1309
// -----------------------------------------------------------------------------
sl@0
  1310
sl@0
  1311
// NumberOfBytesAbleToConvertToPictograph
sl@0
  1312
sl@0
  1313
//
sl@0
  1314
sl@0
  1315
// -----------------------------------------------------------------------------
sl@0
  1316
sl@0
  1317
//
sl@0
  1318
sl@0
  1319
LOCAL_C TInt NumberOfBytesAbleToConvertToPictograph2(const TDesC8& aDescriptor)
sl@0
  1320
sl@0
  1321
    {
sl@0
  1322
sl@0
  1323
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
  1324
sl@0
  1325
    const TUint8* const pointerToLastByte =
sl@0
  1326
sl@0
  1327
        pointerToPreviousByte + aDescriptor.Length();
sl@0
  1328
sl@0
  1329
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
  1330
sl@0
  1331
        {
sl@0
  1332
sl@0
  1333
        return 0;
sl@0
  1334
sl@0
  1335
        }
sl@0
  1336
sl@0
  1337
    for (;pointerToPreviousByte < pointerToLastByte;)
sl@0
  1338
sl@0
  1339
        {
sl@0
  1340
sl@0
  1341
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
  1342
sl@0
  1343
            Panic(EPanicBadPointers14));
sl@0
  1344
sl@0
  1345
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
  1346
sl@0
  1347
        if (currentByte == KSingleShift3)
sl@0
  1348
sl@0
  1349
            {
sl@0
  1350
sl@0
  1351
            pointerToPreviousByte++;
sl@0
  1352
sl@0
  1353
            currentByte = *(pointerToPreviousByte + 1);
sl@0
  1354
sl@0
  1355
            }
sl@0
  1356
sl@0
  1357
        else
sl@0
  1358
sl@0
  1359
            {
sl@0
  1360
sl@0
  1361
            break;
sl@0
  1362
sl@0
  1363
            }
sl@0
  1364
sl@0
  1365
        if (currentByte < 0xa0)
sl@0
  1366
sl@0
  1367
            {
sl@0
  1368
sl@0
  1369
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
  1370
sl@0
  1371
            }
sl@0
  1372
sl@0
  1373
        const TUint nextByte = *(pointerToPreviousByte + 2);
sl@0
  1374
sl@0
  1375
        if (nextByte < 0xa0)
sl@0
  1376
sl@0
  1377
            {
sl@0
  1378
sl@0
  1379
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
  1380
sl@0
  1381
            }
sl@0
  1382
sl@0
  1383
        if (((currentByte < KFirstByteRangeFirstBlockStart) ||
sl@0
  1384
sl@0
  1385
             (currentByte > KFirstByteRangeFirstBlockEnd)) ||
sl@0
  1386
sl@0
  1387
            ((nextByte < KSecondByteRangeSecondBlockStart) ||
sl@0
  1388
sl@0
  1389
             (nextByte > KSecondByteRangeSecondBlockEnd)))
sl@0
  1390
sl@0
  1391
            {
sl@0
  1392
sl@0
  1393
            // return the previous byte to the beginning of loop.
sl@0
  1394
sl@0
  1395
            pointerToPreviousByte--;
sl@0
  1396
sl@0
  1397
            break;
sl@0
  1398
sl@0
  1399
            }
sl@0
  1400
sl@0
  1401
        __ASSERT_DEBUG(pointerToPreviousByte < pointerToLastByte,
sl@0
  1402
sl@0
  1403
            Panic(EPanicBadPointers15));
sl@0
  1404
sl@0
  1405
        pointerToPreviousByte += 2;
sl@0
  1406
sl@0
  1407
        }
sl@0
  1408
sl@0
  1409
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
  1410
sl@0
  1411
    }
sl@0
  1412
sl@0
  1413
sl@0
  1414
sl@0
  1415
// -----------------------------------------------------------------------------
sl@0
  1416
sl@0
  1417
// ConvertFromPictogaphToEucJpDirectmapInPlace
sl@0
  1418
sl@0
  1419
// Converts from EucJp packed Pictograph to Unicode
sl@0
  1420
sl@0
  1421
// -----------------------------------------------------------------------------
sl@0
  1422
sl@0
  1423
//
sl@0
  1424
sl@0
  1425
LOCAL_C void ConvertFromPictogaphToEucJpDirectmapInPlace(
sl@0
  1426
sl@0
  1427
        TInt aStartPositionInDescriptor, TDes8& aDescriptor,
sl@0
  1428
sl@0
  1429
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
  1430
sl@0
  1431
    {
sl@0
  1432
sl@0
  1433
    TInt descriptorLength=aDescriptor.Length();
sl@0
  1434
sl@0
  1435
    __ASSERT_DEBUG(descriptorLength > aStartPositionInDescriptor,
sl@0
  1436
sl@0
  1437
        Panic(EPanicNothingToConvert3));
sl@0
  1438
sl@0
  1439
    __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
  1440
sl@0
  1441
        Panic(EPanicOddNumberOfBytes3));
sl@0
  1442
sl@0
  1443
    TInt bytesPerCharacter = 2;
sl@0
  1444
sl@0
  1445
    if (aDescriptor[0] >= KEUCJPSecondBlockStart)
sl@0
  1446
sl@0
  1447
        {
sl@0
  1448
sl@0
  1449
        bytesPerCharacter = 3;
sl@0
  1450
sl@0
  1451
        }
sl@0
  1452
sl@0
  1453
sl@0
  1454
sl@0
  1455
    aNumberOfCharactersThatDroppedOut =
sl@0
  1456
sl@0
  1457
        Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) -
sl@0
  1458
sl@0
  1459
        ((aDescriptor.MaxLength() - aStartPositionInDescriptor) /
sl@0
  1460
sl@0
  1461
        bytesPerCharacter));
sl@0
  1462
sl@0
  1463
    descriptorLength -= aNumberOfCharactersThatDroppedOut * 2;
sl@0
  1464
sl@0
  1465
    __ASSERT_DEBUG(descriptorLength >= aStartPositionInDescriptor,
sl@0
  1466
sl@0
  1467
        Panic(EPanicBadCalculation2));
sl@0
  1468
sl@0
  1469
    if (descriptorLength <= aStartPositionInDescriptor)
sl@0
  1470
sl@0
  1471
        {
sl@0
  1472
sl@0
  1473
        aDescriptor.SetLength(descriptorLength);
sl@0
  1474
sl@0
  1475
        }
sl@0
  1476
sl@0
  1477
    else
sl@0
  1478
sl@0
  1479
        {
sl@0
  1480
sl@0
  1481
        __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) % 2 == 0,
sl@0
  1482
sl@0
  1483
            Panic(EPanicOddNumberOfBytes4));
sl@0
  1484
sl@0
  1485
        // pointerToTargetByte is initialized properly when descriptorLength
sl@0
  1486
sl@0
  1487
        // has been offset to the actual final length of aDescriptor
sl@0
  1488
sl@0
  1489
        TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
  1490
sl@0
  1491
        const TUint8* const pointerToFirstByte =
sl@0
  1492
sl@0
  1493
            pointerToTargetByte + aStartPositionInDescriptor;
sl@0
  1494
sl@0
  1495
        const TUint8* pointerToSourceByte =
sl@0
  1496
sl@0
  1497
            pointerToTargetByte + (descriptorLength - 1);
sl@0
  1498
sl@0
  1499
        descriptorLength = (((descriptorLength - aStartPositionInDescriptor)
sl@0
  1500
sl@0
  1501
            * bytesPerCharacter) / 2) + aStartPositionInDescriptor;
sl@0
  1502
sl@0
  1503
        __ASSERT_DEBUG((descriptorLength - aStartPositionInDescriptor) %
sl@0
  1504
sl@0
  1505
            bytesPerCharacter == 0, Panic(EPanicNumberOfBytesIsNotMultipleOfThree1));
sl@0
  1506
sl@0
  1507
        aDescriptor.SetLength(descriptorLength);
sl@0
  1508
sl@0
  1509
        // pointerToTargetByte is is initialized properly here
sl@0
  1510
sl@0
  1511
        pointerToTargetByte += descriptorLength - 1;
sl@0
  1512
sl@0
  1513
        for (;pointerToTargetByte > pointerToFirstByte; )
sl@0
  1514
sl@0
  1515
            {
sl@0
  1516
sl@0
  1517
            TInt secondByte = *pointerToSourceByte;
sl@0
  1518
sl@0
  1519
            TInt firstByte = *(pointerToSourceByte - 1);
sl@0
  1520
sl@0
  1521
sl@0
  1522
sl@0
  1523
            if (bytesPerCharacter == 3)
sl@0
  1524
sl@0
  1525
                {
sl@0
  1526
sl@0
  1527
                firstByte = (firstByte - KEUCJPSecondBlockStart) * 2 +
sl@0
  1528
sl@0
  1529
                    KFirstByteRangeFirstBlockStart;
sl@0
  1530
sl@0
  1531
                }
sl@0
  1532
sl@0
  1533
            else
sl@0
  1534
sl@0
  1535
                {
sl@0
  1536
sl@0
  1537
                firstByte = (firstByte - KPictographStartFirstByte) * 2 +
sl@0
  1538
sl@0
  1539
                    KFirstByteRangeFirstBlockStart;
sl@0
  1540
sl@0
  1541
                }
sl@0
  1542
sl@0
  1543
            if (static_cast<TInt>(KEUCJPBlockSize + KPictographStartSecondByte + 1)
sl@0
  1544
sl@0
  1545
                 < secondByte)
sl@0
  1546
sl@0
  1547
                {
sl@0
  1548
sl@0
  1549
                if (secondByte > KShiftJisTrailByteIllegal)
sl@0
  1550
sl@0
  1551
                    secondByte -= 1;
sl@0
  1552
sl@0
  1553
                secondByte = secondByte -(KPictographStartSecondByte +
sl@0
  1554
sl@0
  1555
                    KEUCJPBlockSize + 1) + KSecondByteRangeSecondBlockStart;
sl@0
  1556
sl@0
  1557
                firstByte++;
sl@0
  1558
sl@0
  1559
                }
sl@0
  1560
sl@0
  1561
            else
sl@0
  1562
sl@0
  1563
                {
sl@0
  1564
sl@0
  1565
                if (secondByte > KShiftJisTrailByteIllegal)
sl@0
  1566
sl@0
  1567
                    secondByte -= 1;
sl@0
  1568
sl@0
  1569
                secondByte += KSecondByteRangeSecondBlockStart - KPictographStartSecondByte;
sl@0
  1570
sl@0
  1571
                }
sl@0
  1572
sl@0
  1573
            *pointerToTargetByte = static_cast<TUint8>(secondByte);
sl@0
  1574
sl@0
  1575
            --pointerToTargetByte;
sl@0
  1576
sl@0
  1577
            *pointerToTargetByte = static_cast<TUint8>(firstByte);
sl@0
  1578
sl@0
  1579
            if (bytesPerCharacter == 3)
sl@0
  1580
sl@0
  1581
                {
sl@0
  1582
sl@0
  1583
                --pointerToTargetByte;
sl@0
  1584
sl@0
  1585
                *pointerToTargetByte = KSingleShift3;
sl@0
  1586
sl@0
  1587
                }
sl@0
  1588
sl@0
  1589
            __ASSERT_DEBUG(pointerToTargetByte >= pointerToFirstByte,
sl@0
  1590
sl@0
  1591
                Panic(EPanicBadPointers10));
sl@0
  1592
sl@0
  1593
            --pointerToTargetByte;
sl@0
  1594
sl@0
  1595
            pointerToSourceByte -= 2;
sl@0
  1596
sl@0
  1597
            }
sl@0
  1598
sl@0
  1599
        }
sl@0
  1600
sl@0
  1601
    }
sl@0
  1602
sl@0
  1603
sl@0
  1604
sl@0
  1605
// -----------------------------------------------------------------------------
sl@0
  1606
sl@0
  1607
// ConvertToPictographFromEucJpPackedInPlace1
sl@0
  1608
sl@0
  1609
// Converts from EucJp packed Pictograph to Unicode
sl@0
  1610
sl@0
  1611
// -----------------------------------------------------------------------------
sl@0
  1612
sl@0
  1613
//
sl@0
  1614
sl@0
  1615
LOCAL_C void ConvertToPictographFromEucJpPackedInPlace(TDes8& aDescriptor)
sl@0
  1616
sl@0
  1617
    {
sl@0
  1618
sl@0
  1619
    const TInt descriptorLength = aDescriptor.Length();
sl@0
  1620
sl@0
  1621
    __ASSERT_DEBUG(descriptorLength > 0, Panic(EPanicNothingToConvert6));
sl@0
  1622
sl@0
  1623
    TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
  1624
sl@0
  1625
    const TUint8* pointerToSourceByte = pointerToTargetByte;
sl@0
  1626
sl@0
  1627
    const TUint8* const pointerToLastByte =
sl@0
  1628
sl@0
  1629
        pointerToSourceByte + (descriptorLength - 1);
sl@0
  1630
sl@0
  1631
    TInt bytesPerCharacter = 2;
sl@0
  1632
sl@0
  1633
    TInt sjisStartbyte = KPictographStartFirstByte;
sl@0
  1634
sl@0
  1635
    if (*pointerToSourceByte == KSingleShift3)
sl@0
  1636
sl@0
  1637
        {
sl@0
  1638
sl@0
  1639
        ++pointerToSourceByte;
sl@0
  1640
sl@0
  1641
        bytesPerCharacter = 3;
sl@0
  1642
sl@0
  1643
        sjisStartbyte = KEUCJPSecondBlockStart;
sl@0
  1644
sl@0
  1645
        }
sl@0
  1646
sl@0
  1647
    for (;pointerToSourceByte < pointerToLastByte; )
sl@0
  1648
sl@0
  1649
        {
sl@0
  1650
sl@0
  1651
        __ASSERT_DEBUG(pointerToSourceByte < pointerToLastByte,
sl@0
  1652
sl@0
  1653
            Panic(EPanicBadPointers33));
sl@0
  1654
sl@0
  1655
        TUint firstByte = (*pointerToSourceByte
sl@0
  1656
sl@0
  1657
            - KFirstByteRangeFirstBlockStart) / 2 + sjisStartbyte;
sl@0
  1658
sl@0
  1659
        TUint secondByte = *(pointerToSourceByte + 1);
sl@0
  1660
sl@0
  1661
        if ((*pointerToSourceByte % 2) == 0)
sl@0
  1662
sl@0
  1663
            {
sl@0
  1664
sl@0
  1665
            secondByte += KPictographStartSecondByte -
sl@0
  1666
sl@0
  1667
                KSecondByteRangeSecondBlockStart + KEUCJPBlockSize + 1;
sl@0
  1668
sl@0
  1669
            if (secondByte >= KShiftJisTrailByteIllegal)
sl@0
  1670
sl@0
  1671
                secondByte++;
sl@0
  1672
sl@0
  1673
            }
sl@0
  1674
sl@0
  1675
        else
sl@0
  1676
sl@0
  1677
            {
sl@0
  1678
sl@0
  1679
            secondByte += KPictographStartSecondByte - KSecondByteRangeSecondBlockStart;
sl@0
  1680
sl@0
  1681
            if (secondByte >= KShiftJisTrailByteIllegal)
sl@0
  1682
sl@0
  1683
                secondByte++;
sl@0
  1684
sl@0
  1685
            }
sl@0
  1686
sl@0
  1687
        *pointerToTargetByte = static_cast<TUint8>(firstByte);
sl@0
  1688
sl@0
  1689
sl@0
  1690
sl@0
  1691
        __ASSERT_DEBUG(pointerToTargetByte < pointerToLastByte,
sl@0
  1692
sl@0
  1693
            Panic(EPanicBadPointers35));
sl@0
  1694
sl@0
  1695
        ++pointerToTargetByte;
sl@0
  1696
sl@0
  1697
        *pointerToTargetByte = static_cast<TUint8>(secondByte);
sl@0
  1698
sl@0
  1699
        __ASSERT_DEBUG(pointerToSourceByte <= pointerToLastByte,
sl@0
  1700
sl@0
  1701
            Panic(EPanicBadPointers36));
sl@0
  1702
sl@0
  1703
        pointerToSourceByte += 2;
sl@0
  1704
sl@0
  1705
        ++pointerToTargetByte;
sl@0
  1706
sl@0
  1707
        }
sl@0
  1708
sl@0
  1709
    aDescriptor.SetLength((descriptorLength / bytesPerCharacter) * 2);
sl@0
  1710
sl@0
  1711
    }
sl@0
  1712
sl@0
  1713
sl@0
  1714
sl@0
  1715
// New Interface class
sl@0
  1716
sl@0
  1717
class CEucJpDirectmapImplementation : public CCharacterSetConverterPluginInterface
sl@0
  1718
sl@0
  1719
{
sl@0
  1720
sl@0
  1721
    public:
sl@0
  1722
sl@0
  1723
        virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
sl@0
  1724
sl@0
  1725
sl@0
  1726
sl@0
  1727
        virtual TInt ConvertFromUnicode(
sl@0
  1728
sl@0
  1729
            CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
  1730
sl@0
  1731
            const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
sl@0
  1732
sl@0
  1733
            TDes8& aForeign,
sl@0
  1734
sl@0
  1735
            const TDesC16& aUnicode,
sl@0
  1736
sl@0
  1737
            CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters );
sl@0
  1738
sl@0
  1739
sl@0
  1740
sl@0
  1741
        virtual TInt ConvertToUnicode(
sl@0
  1742
sl@0
  1743
            CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
  1744
sl@0
  1745
            TDes16& aUnicode,
sl@0
  1746
sl@0
  1747
            const TDesC8& aForeign,
sl@0
  1748
sl@0
  1749
            TInt&,
sl@0
  1750
sl@0
  1751
            TInt& aNumberOfUnconvertibleCharacters,
sl@0
  1752
sl@0
  1753
            TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter );
sl@0
  1754
sl@0
  1755
sl@0
  1756
sl@0
  1757
        virtual TBool IsInThisCharacterSetL(
sl@0
  1758
sl@0
  1759
            TBool& aSetToTrue,
sl@0
  1760
sl@0
  1761
            TInt& aConfidenceLevel,
sl@0
  1762
sl@0
  1763
            const TDesC8& );
sl@0
  1764
sl@0
  1765
sl@0
  1766
sl@0
  1767
        static CEucJpDirectmapImplementation* NewL();
sl@0
  1768
sl@0
  1769
sl@0
  1770
sl@0
  1771
        virtual ~CEucJpDirectmapImplementation();
sl@0
  1772
sl@0
  1773
    private:
sl@0
  1774
sl@0
  1775
        CEucJpDirectmapImplementation();
sl@0
  1776
sl@0
  1777
};
sl@0
  1778
sl@0
  1779
sl@0
  1780
sl@0
  1781
// -----------------------------------------------------------------------------
sl@0
  1782
sl@0
  1783
// ReplacementForUnconvertibleUnicodeCharacters
sl@0
  1784
sl@0
  1785
// Retruns the character to replacement for unconvertible unicode character.
sl@0
  1786
sl@0
  1787
// Returns: '?':
sl@0
  1788
sl@0
  1789
// -----------------------------------------------------------------------------
sl@0
  1790
sl@0
  1791
//
sl@0
  1792
sl@0
  1793
const TDesC8& CEucJpDirectmapImplementation::ReplacementForUnconvertibleUnicodeCharacters()
sl@0
  1794
sl@0
  1795
    {
sl@0
  1796
sl@0
  1797
    return KLit8EucJpPackedReplacementForUnconvertibleUnicodeCharacters;
sl@0
  1798
sl@0
  1799
    }
sl@0
  1800
sl@0
  1801
sl@0
  1802
sl@0
  1803
// -----------------------------------------------------------------------------
sl@0
  1804
sl@0
  1805
// ConvertFromUnicode
sl@0
  1806
sl@0
  1807
// Converts from Unicode to EUC-JP
sl@0
  1808
sl@0
  1809
// Returns: The number of unconverted characters
sl@0
  1810
sl@0
  1811
// -----------------------------------------------------------------------------
sl@0
  1812
sl@0
  1813
//
sl@0
  1814
sl@0
  1815
TInt CEucJpDirectmapImplementation::ConvertFromUnicode(
sl@0
  1816
sl@0
  1817
        CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
  1818
sl@0
  1819
        const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
sl@0
  1820
sl@0
  1821
        TDes8& aForeign, const TDesC16& aUnicode,
sl@0
  1822
sl@0
  1823
        CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
sl@0
  1824
sl@0
  1825
    {
sl@0
  1826
sl@0
  1827
    TFixedArray<CnvUtilities::SCharacterSet, 6> characterSets;
sl@0
  1828
sl@0
  1829
    characterSets[0].iConversionData = &CnvJisRoman::ConversionData();
sl@0
  1830
sl@0
  1831
    characterSets[0].iConvertFromIntermediateBufferInPlace =
sl@0
  1832
sl@0
  1833
        DummyConvertFromIntermediateBufferInPlace;
sl@0
  1834
sl@0
  1835
    characterSets[0].iEscapeSequence = &KNullDesC8;
sl@0
  1836
sl@0
  1837
    characterSets[1].iConversionData = &CnvJisX0208::ConversionData();
sl@0
  1838
sl@0
  1839
    characterSets[1].iConvertFromIntermediateBufferInPlace =
sl@0
  1840
sl@0
  1841
        ConvertFromJisX0208ToEucJpPackedInPlace;
sl@0
  1842
sl@0
  1843
    characterSets[1].iEscapeSequence = &KNullDesC8;
sl@0
  1844
sl@0
  1845
    characterSets[2].iConversionData = &CnvHalfWidthKatakana8::ConversionData();
sl@0
  1846
sl@0
  1847
    characterSets[2].iConvertFromIntermediateBufferInPlace =
sl@0
  1848
sl@0
  1849
        ConvertFromHalfWidthKatakana8ToEucJpPackedInPlace;
sl@0
  1850
sl@0
  1851
    characterSets[2].iEscapeSequence = &KNullDesC8;
sl@0
  1852
sl@0
  1853
    characterSets[3].iConversionData = &CnvJisX0212::ConversionData();
sl@0
  1854
sl@0
  1855
    characterSets[3].iConvertFromIntermediateBufferInPlace =
sl@0
  1856
sl@0
  1857
        ConvertFromJisX0212ToEucJpPackedInPlace;
sl@0
  1858
sl@0
  1859
    characterSets[3].iEscapeSequence = &KNullDesC8;
sl@0
  1860
sl@0
  1861
    characterSets[4].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
  1862
sl@0
  1863
    characterSets[4].iConvertFromIntermediateBufferInPlace =
sl@0
  1864
sl@0
  1865
        ConvertFromPictogaphToEucJpDirectmapInPlace;
sl@0
  1866
sl@0
  1867
    characterSets[4].iEscapeSequence = &KNullDesC8;
sl@0
  1868
sl@0
  1869
    characterSets[5].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
  1870
sl@0
  1871
    characterSets[5].iConvertFromIntermediateBufferInPlace =
sl@0
  1872
sl@0
  1873
        ConvertFromPictogaphToEucJpDirectmapInPlace;
sl@0
  1874
sl@0
  1875
    characterSets[5].iEscapeSequence = &KNullDesC8;
sl@0
  1876
sl@0
  1877
sl@0
  1878
sl@0
  1879
    TInt unconvert = CnvUtilities::ConvertFromUnicode(
sl@0
  1880
sl@0
  1881
        aDefaultEndiannessOfForeignCharacters,
sl@0
  1882
sl@0
  1883
        aReplacementForUnconvertibleUnicodeCharacters,
sl@0
  1884
sl@0
  1885
        aForeign, aUnicode, aIndicesOfUnconvertibleCharacters,
sl@0
  1886
sl@0
  1887
        characterSets.Array());
sl@0
  1888
sl@0
  1889
sl@0
  1890
sl@0
  1891
    return unconvert;
sl@0
  1892
sl@0
  1893
    }
sl@0
  1894
sl@0
  1895
sl@0
  1896
sl@0
  1897
// -----------------------------------------------------------------------------
sl@0
  1898
sl@0
  1899
// ConvertToUnicode
sl@0
  1900
sl@0
  1901
// Converts from EUC-JP to Unicode.
sl@0
  1902
sl@0
  1903
// Returns: The number of unconverted bytes
sl@0
  1904
sl@0
  1905
// -----------------------------------------------------------------------------
sl@0
  1906
sl@0
  1907
//
sl@0
  1908
sl@0
  1909
TInt CEucJpDirectmapImplementation::ConvertToUnicode(
sl@0
  1910
sl@0
  1911
        CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
sl@0
  1912
sl@0
  1913
        TDes16& aUnicode, const TDesC8& aForeign, TInt&,
sl@0
  1914
sl@0
  1915
        TInt& aNumberOfUnconvertibleCharacters,
sl@0
  1916
sl@0
  1917
        TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
sl@0
  1918
sl@0
  1919
    {
sl@0
  1920
sl@0
  1921
    TFixedArray<CnvUtilities::SMethod, 6> methods;
sl@0
  1922
sl@0
  1923
sl@0
  1924
sl@0
  1925
    methods[0].iNumberOfBytesAbleToConvert =
sl@0
  1926
sl@0
  1927
        NumberOfBytesAbleToConvertToPictograph1;
sl@0
  1928
sl@0
  1929
    methods[0].iConvertToIntermediateBufferInPlace =
sl@0
  1930
sl@0
  1931
        ConvertToPictographFromEucJpPackedInPlace;
sl@0
  1932
sl@0
  1933
    methods[0].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
  1934
sl@0
  1935
    methods[0].iNumberOfBytesPerCharacter = 2;
sl@0
  1936
sl@0
  1937
    methods[0].iNumberOfCoreBytesPerCharacter = 2;
sl@0
  1938
sl@0
  1939
    methods[1].iNumberOfBytesAbleToConvert =
sl@0
  1940
sl@0
  1941
        NumberOfBytesAbleToConvertToPictograph2;
sl@0
  1942
sl@0
  1943
    methods[1].iConvertToIntermediateBufferInPlace =
sl@0
  1944
sl@0
  1945
        ConvertToPictographFromEucJpPackedInPlace;
sl@0
  1946
sl@0
  1947
    methods[1].iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
  1948
sl@0
  1949
    methods[1].iNumberOfBytesPerCharacter = 3;
sl@0
  1950
sl@0
  1951
    methods[1].iNumberOfCoreBytesPerCharacter = 2;
sl@0
  1952
sl@0
  1953
sl@0
  1954
sl@0
  1955
    methods[2].iNumberOfBytesAbleToConvert = NumberOfBytesAbleToConvertToJisRoman;
sl@0
  1956
sl@0
  1957
    methods[2].iConvertToIntermediateBufferInPlace =
sl@0
  1958
sl@0
  1959
        DummyConvertToIntermediateBufferInPlace;
sl@0
  1960
sl@0
  1961
    methods[2].iConversionData = &CnvJisRoman::ConversionData();
sl@0
  1962
sl@0
  1963
    methods[2].iNumberOfBytesPerCharacter = 1;
sl@0
  1964
sl@0
  1965
    methods[2].iNumberOfCoreBytesPerCharacter = 1;
sl@0
  1966
sl@0
  1967
    methods[3].iNumberOfBytesAbleToConvert = NumberOfBytesAbleToConvertToJisX0208;
sl@0
  1968
sl@0
  1969
    methods[3].iConvertToIntermediateBufferInPlace =
sl@0
  1970
sl@0
  1971
        ConvertToJisX0208FromEucJpPackedInPlace;
sl@0
  1972
sl@0
  1973
    methods[3].iConversionData = &CnvJisX0208::ConversionData();
sl@0
  1974
sl@0
  1975
    methods[3].iNumberOfBytesPerCharacter = 2;
sl@0
  1976
sl@0
  1977
    methods[3].iNumberOfCoreBytesPerCharacter = 2;
sl@0
  1978
sl@0
  1979
    methods[4].iNumberOfBytesAbleToConvert =
sl@0
  1980
sl@0
  1981
        NumberOfBytesAbleToConvertToHalfWidthKatakana8;
sl@0
  1982
sl@0
  1983
    methods[4].iConvertToIntermediateBufferInPlace =
sl@0
  1984
sl@0
  1985
        ConvertToHalfWidthKatakana8FromEucJpPackedInPlace;
sl@0
  1986
sl@0
  1987
    methods[4].iConversionData = &CnvHalfWidthKatakana8::ConversionData();
sl@0
  1988
sl@0
  1989
    methods[4].iNumberOfBytesPerCharacter = 2;
sl@0
  1990
sl@0
  1991
    methods[4].iNumberOfCoreBytesPerCharacter = 1;
sl@0
  1992
sl@0
  1993
    methods[5].iNumberOfBytesAbleToConvert =
sl@0
  1994
sl@0
  1995
        NumberOfBytesAbleToConvertToJisX0212;
sl@0
  1996
sl@0
  1997
    methods[5].iConvertToIntermediateBufferInPlace =
sl@0
  1998
sl@0
  1999
        ConvertToJisX0212FromEucJpPackedInPlace;
sl@0
  2000
sl@0
  2001
    methods[5].iConversionData = &CnvJisX0212::ConversionData();
sl@0
  2002
sl@0
  2003
    methods[5].iNumberOfBytesPerCharacter = 3;
sl@0
  2004
sl@0
  2005
    methods[5].iNumberOfCoreBytesPerCharacter = 2;
sl@0
  2006
sl@0
  2007
sl@0
  2008
sl@0
  2009
    TInt unconvert = CnvUtilities::ConvertToUnicodeFromHeterogeneousForeign(
sl@0
  2010
sl@0
  2011
        aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign,
sl@0
  2012
sl@0
  2013
        aNumberOfUnconvertibleCharacters,
sl@0
  2014
sl@0
  2015
        aIndexOfFirstByteOfFirstUnconvertibleCharacter, methods.Array());
sl@0
  2016
sl@0
  2017
sl@0
  2018
sl@0
  2019
    // The following is specific impelementation for brower.
sl@0
  2020
sl@0
  2021
    // If brower app calls this API, the yen sign code(0xA5)
sl@0
  2022
sl@0
  2023
    // must be converted to backslash code(0x5C).
sl@0
  2024
sl@0
  2025
    // Becasue Javascript supports backslash code ony.
sl@0
  2026
sl@0
  2027
    TBool browserProcess = (RProcess().SecureId().iId == KBrowserSecureId);
sl@0
  2028
sl@0
  2029
    if (browserProcess && aUnicode.Length() > 0)
sl@0
  2030
sl@0
  2031
        {
sl@0
  2032
sl@0
  2033
        const TUint16* pB = aUnicode.Ptr();
sl@0
  2034
sl@0
  2035
        const TUint16* pbase = pB;
sl@0
  2036
sl@0
  2037
        const TUint16* pE = pB + aUnicode.Length() -1;
sl@0
  2038
sl@0
  2039
        while (pE>=pbase)
sl@0
  2040
sl@0
  2041
            {
sl@0
  2042
sl@0
  2043
            if (*pbase == KCharacterCodeForYenSign)
sl@0
  2044
sl@0
  2045
                {
sl@0
  2046
sl@0
  2047
                aUnicode[pbase - pB] = KCharacterCodeForBackSlash;
sl@0
  2048
sl@0
  2049
                }
sl@0
  2050
sl@0
  2051
            pbase++;
sl@0
  2052
sl@0
  2053
            }
sl@0
  2054
sl@0
  2055
        }
sl@0
  2056
sl@0
  2057
sl@0
  2058
sl@0
  2059
    return unconvert;
sl@0
  2060
sl@0
  2061
    }
sl@0
  2062
sl@0
  2063
sl@0
  2064
sl@0
  2065
// -----------------------------------------------------------------------------
sl@0
  2066
sl@0
  2067
// IsInThisCharacterSetL
sl@0
  2068
sl@0
  2069
// Detects whether the text is the character code or not.
sl@0
  2070
sl@0
  2071
// Returns: ETrue:
sl@0
  2072
sl@0
  2073
// -----------------------------------------------------------------------------
sl@0
  2074
sl@0
  2075
//
sl@0
  2076
sl@0
  2077
TBool CEucJpDirectmapImplementation::IsInThisCharacterSetL(TBool& /*aSetToTrue*/, TInt& /*aConfidenceLevel*/,
sl@0
  2078
sl@0
  2079
        const TDesC8& /*aSample*/)
sl@0
  2080
sl@0
  2081
    {
sl@0
  2082
sl@0
  2083
    return EFalse;
sl@0
  2084
sl@0
  2085
    }
sl@0
  2086
sl@0
  2087
sl@0
  2088
sl@0
  2089
CEucJpDirectmapImplementation* CEucJpDirectmapImplementation::NewL()
sl@0
  2090
sl@0
  2091
    {
sl@0
  2092
sl@0
  2093
    CEucJpDirectmapImplementation* self = new(ELeave) CEucJpDirectmapImplementation;
sl@0
  2094
sl@0
  2095
    return self;
sl@0
  2096
sl@0
  2097
    }
sl@0
  2098
sl@0
  2099
sl@0
  2100
sl@0
  2101
CEucJpDirectmapImplementation::CEucJpDirectmapImplementation()
sl@0
  2102
sl@0
  2103
    {
sl@0
  2104
sl@0
  2105
    //default constructor.. do nothing
sl@0
  2106
sl@0
  2107
    }
sl@0
  2108
sl@0
  2109
sl@0
  2110
sl@0
  2111
CEucJpDirectmapImplementation::~CEucJpDirectmapImplementation()
sl@0
  2112
sl@0
  2113
    {
sl@0
  2114
sl@0
  2115
    //default destructor .. do nothing
sl@0
  2116
sl@0
  2117
    }
sl@0
  2118
sl@0
  2119
sl@0
  2120
sl@0
  2121
// ECOM CREATION FUNCTION
sl@0
  2122
sl@0
  2123
const TImplementationProxy ImplementationTable[] =
sl@0
  2124
sl@0
  2125
    {
sl@0
  2126
sl@0
  2127
    // Note: This is the same UID as defined in old mmp-file
sl@0
  2128
sl@0
  2129
    // Used also in 12221212.rss ( implementation_uid )
sl@0
  2130
sl@0
  2131
    IMPLEMENTATION_PROXY_ENTRY( 0x101F86A6, CEucJpDirectmapImplementation::NewL )
sl@0
  2132
sl@0
  2133
    };
sl@0
  2134
sl@0
  2135
sl@0
  2136
sl@0
  2137
EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
sl@0
  2138
sl@0
  2139
    {
sl@0
  2140
sl@0
  2141
    aTableCount = sizeof( ImplementationTable ) / sizeof(TImplementationProxy);
sl@0
  2142
sl@0
  2143
    return ImplementationTable;
sl@0
  2144
sl@0
  2145
    }
sl@0
  2146
sl@0
  2147
sl@0
  2148
sl@0
  2149
// End of file
sl@0
  2150