intl/uconv/ucvcn/nsISO2022CNToUnicode.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/uconv/ucvcn/nsISO2022CNToUnicode.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsISO2022CNToUnicode_h__
     1.9 +#define nsISO2022CNToUnicode_h__
    1.10 +#include "nsCOMPtr.h"
    1.11 +#include "nsUCSupport.h"
    1.12 +#include "mozilla/Telemetry.h"
    1.13 +
    1.14 +#define MBYTE       0x8e
    1.15 +#undef PMASK
    1.16 +#define PMASK       0xa0
    1.17 +
    1.18 +#define SI          0x0f 
    1.19 +#define SO          0x0e
    1.20 +#define ESC         0x1b
    1.21 +#define SS2         0x4e
    1.22 +#define SS3         0x4f
    1.23 +
    1.24 +class nsISO2022CNToUnicode : public nsBasicDecoderSupport
    1.25 +{
    1.26 +public:
    1.27 +  nsISO2022CNToUnicode() : 
    1.28 +        mState(eState_ASCII), 
    1.29 +        mPlaneID(0),
    1.30 +        mRunLength(0)
    1.31 +  {
    1.32 +    mozilla::Telemetry::Accumulate(
    1.33 +      mozilla::Telemetry::DECODER_INSTANTIATED_ISO2022CN, true);
    1.34 +  }
    1.35 +
    1.36 +  virtual ~nsISO2022CNToUnicode() {}
    1.37 +
    1.38 +  NS_IMETHOD Convert(const char *aSrc, int32_t * aSrcLength,
    1.39 +     char16_t * aDest, int32_t * aDestLength) ;
    1.40 +
    1.41 +  NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
    1.42 +     int32_t * aDestLength)
    1.43 +  {
    1.44 +    *aDestLength = aSrcLength;
    1.45 +    return NS_OK;
    1.46 +  }
    1.47 +
    1.48 +  NS_IMETHOD Reset()
    1.49 +  {
    1.50 +    mState = eState_ASCII;
    1.51 +    mPlaneID = 0;
    1.52 +    mRunLength = 0;
    1.53 +
    1.54 +    return NS_OK;
    1.55 +  }
    1.56 +
    1.57 +private:
    1.58 +  // State Machine ID
    1.59 +  enum {
    1.60 +    eState_ASCII,
    1.61 +    eState_ESC,                           // ESC
    1.62 +    eState_ESC_24,                        // ESC $
    1.63 +
    1.64 +    eState_ESC_24_29,                     // ESC $ )
    1.65 +    eState_ESC_24_29_A,                   // ESC $ ) A
    1.66 +    eState_GB2312_1980,                   // ESC $ ) A SO
    1.67 +    eState_GB2312_1980_2ndbyte,           // ESC $ ) A SO
    1.68 +    eState_ESC_24_29_A_SO_SI,             // ESC $ ) A SO SI
    1.69 +    eState_ESC_24_29_G,                   // ESC $ ) G or H
    1.70 +    eState_CNS11643_1,                    // ESC $ ) G SO
    1.71 +    eState_CNS11643_1_2ndbyte,            // ESC $ ) G SO
    1.72 +    eState_ESC_24_29_G_SO_SI,             // ESC $ ) G SO SI
    1.73 +
    1.74 +    eState_ESC_24_2A,                     // ESC $ *
    1.75 +    eState_ESC_24_2A_H,                   // ESC $ * H
    1.76 +    eState_ESC_24_2A_H_ESC,               // ESC $ * H ESC
    1.77 +    eState_CNS11643_2,                    // ESC $ * H ESC SS2
    1.78 +    eState_CNS11643_2_2ndbyte,            // ESC $ * H ESC SS2
    1.79 +    eState_ESC_24_2A_H_ESC_SS2_SI,        // ESC $ * H ESC SS2 SI
    1.80 +    eState_ESC_24_2A_H_ESC_SS2_SI_ESC,    // ESC $ * H ESC SS2 SI ESC
    1.81 +
    1.82 +    eState_ESC_24_2B,                     // ESC $ +
    1.83 +    eState_ESC_24_2B_I,                   // ESC $ + I
    1.84 +    eState_ESC_24_2B_I_ESC,               // ESC $ + I ESC
    1.85 +    eState_CNS11643_3,                    // ESC $ + I ESC SS3
    1.86 +    eState_CNS11643_3_2ndbyte,            // ESC $ + I ESC SS3
    1.87 +    eState_ESC_24_2B_I_ESC_SS3_SI,        // ESC $ + I ESC SI
    1.88 +    eState_ESC_24_2B_I_ESC_SS3_SI_ESC,    // ESC $ + I ESC SI ESC
    1.89 +    eState_ERROR
    1.90 +  } mState;
    1.91 +
    1.92 +  char mData;
    1.93 +
    1.94 +  // Plane number for CNS11643 code
    1.95 +  int mPlaneID;
    1.96 +
    1.97 +  // Length of non-ASCII run
    1.98 +  uint32_t mRunLength;
    1.99 +
   1.100 +  // Decoder handler
   1.101 +  nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder;
   1.102 +  nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder;
   1.103 +
   1.104 +  NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
   1.105 +     char16_t * aDest, int32_t * aDestLength) ;
   1.106 +
   1.107 +  NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, int32_t aSrcLength,
   1.108 +     char16_t * aDest, int32_t * aDestLength) ;
   1.109 +};
   1.110 +#endif // nsISO2022CNToUnicode_h__

mercurial