Back to index

lightning-sunbird  0.9+nobinonly
nsISO2022CNToUnicode.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Ervin Yan <Ervin.Yan@Sun.Com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsISO2022CNToUnicode_h__
00039 #define nsISO2022CNToUnicode_h__
00040 #include "nsCOMPtr.h"
00041 #include "nsISupports.h"
00042 #include "nsUCSupport.h"
00043 
00044 #define MBYTE       0x8e
00045 #undef PMASK
00046 #define PMASK       0xa0
00047 
00048 #define SI          0x0f 
00049 #define SO          0x0e
00050 #define ESC         0x1b
00051 #define SS2         0x4e
00052 #define SS3         0x4f
00053 
00054 class nsISO2022CNToUnicode : public nsBasicDecoderSupport
00055 {
00056 public:
00057   nsISO2022CNToUnicode() : 
00058         mState(eState_ASCII), 
00059         mPlaneID(0),
00060         mRunLength(0) { };
00061 
00062   virtual ~nsISO2022CNToUnicode() {};
00063 
00064   NS_IMETHOD Convert(const char *aSrc, PRInt32 * aSrcLength,
00065      PRUnichar * aDest, PRInt32 * aDestLength) ;
00066 
00067   NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
00068      PRInt32 * aDestLength)
00069   {
00070     *aDestLength = aSrcLength;
00071     return NS_OK;
00072   };
00073 
00074   NS_IMETHOD Reset()
00075   {
00076     mState = eState_ASCII;
00077     mPlaneID = 0;
00078     mRunLength = 0;
00079 
00080     return NS_OK;
00081   };
00082 
00083 private:
00084   // State Machine ID
00085   enum {
00086     eState_ASCII,
00087     eState_ESC,                           // ESC
00088     eState_ESC_24,                        // ESC $
00089 
00090     eState_ESC_24_29,                     // ESC $ )
00091     eState_ESC_24_29_A,                   // ESC $ ) A
00092     eState_GB2312_1980,                   // ESC $ ) A SO
00093     eState_GB2312_1980_2ndbyte,           // ESC $ ) A SO
00094     eState_ESC_24_29_A_SO_SI,             // ESC $ ) A SO SI
00095     eState_ESC_24_29_G,                   // ESC $ ) G or H
00096     eState_CNS11643_1,                    // ESC $ ) G SO
00097     eState_CNS11643_1_2ndbyte,            // ESC $ ) G SO
00098     eState_ESC_24_29_G_SO_SI,             // ESC $ ) G SO SI
00099 
00100     eState_ESC_24_2A,                     // ESC $ *
00101     eState_ESC_24_2A_H,                   // ESC $ * H
00102     eState_ESC_24_2A_H_ESC,               // ESC $ * H ESC
00103     eState_CNS11643_2,                    // ESC $ * H ESC SS2
00104     eState_CNS11643_2_2ndbyte,            // ESC $ * H ESC SS2
00105     eState_ESC_24_2A_H_ESC_SS2_SI,        // ESC $ * H ESC SS2 SI
00106     eState_ESC_24_2A_H_ESC_SS2_SI_ESC,    // ESC $ * H ESC SS2 SI ESC
00107 
00108     eState_ESC_24_2B,                     // ESC $ +
00109     eState_ESC_24_2B_I,                   // ESC $ + I
00110     eState_ESC_24_2B_I_ESC,               // ESC $ + I ESC
00111     eState_CNS11643_3,                    // ESC $ + I ESC SS3
00112     eState_CNS11643_3_2ndbyte,            // ESC $ + I ESC SS3
00113     eState_ESC_24_2B_I_ESC_SS3_SI,        // ESC $ + I ESC SI
00114     eState_ESC_24_2B_I_ESC_SS3_SI_ESC,    // ESC $ + I ESC SI ESC
00115     eState_ERROR
00116   } mState;
00117 
00118   char mData;
00119 
00120   // Plane number for CNS11643 code
00121   int mPlaneID;
00122 
00123   // Length of non-ASCII run
00124   PRUint32 mRunLength;
00125 
00126   // Decoder handler
00127   nsCOMPtr<nsIUnicodeDecoder> mGB2312_Decoder;
00128   nsCOMPtr<nsIUnicodeDecoder> mEUCTW_Decoder;
00129 
00130   NS_IMETHOD GB2312_To_Unicode(unsigned char *aSrc, PRInt32 aSrcLength,
00131      PRUnichar * aDest, PRInt32 * aDestLength) ;
00132 
00133   NS_IMETHOD EUCTW_To_Unicode(unsigned char *aSrc, PRInt32 aSrcLength,
00134      PRUnichar * aDest, PRInt32 * aDestLength) ;
00135 };
00136 #endif // nsISO2022CNToUnicode_h__