Back to index

lightning-sunbird  0.9+nobinonly
nsJapaneseToUnicode.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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 Communicator client 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsShiftJISToUnicode_h__
00038 #define nsShiftJISToUnicode_h__
00039 #include "nsISupports.h"
00040 #include "nsUCSupport.h"
00041 
00042 
00043 class nsJapaneseToUnicode : public nsBasicDecoderSupport
00044 {
00045 protected:
00046 
00047  void setMapMode();
00048 
00049 protected:
00050  const PRUint16 * const *mMapIndex;
00051 };
00052 
00053 class nsShiftJISToUnicode : public nsJapaneseToUnicode
00054 {
00055 public:
00056 
00057  nsShiftJISToUnicode() 
00058      { 
00059          mState=0; mData=0; 
00060          setMapMode();
00061      };
00062  virtual ~nsShiftJISToUnicode() {};
00063 
00064  NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
00065      PRUnichar * aDest, PRInt32 * aDestLength) ;
00066  NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
00067      PRInt32 * aDestLength) 
00068      {
00069         *aDestLength = aSrcLength;
00070         return NS_OK;
00071      };
00072  NS_IMETHOD Reset()
00073      {
00074         mState = 0;
00075         setMapMode();
00076         return NS_OK;
00077      };
00078 
00079 private:
00080 
00081 private:
00082  PRInt32  mState;
00083  PRInt32 mData;
00084 };
00085 
00086 class nsEUCJPToUnicodeV2 : public nsJapaneseToUnicode
00087 {
00088 public:
00089 
00090  nsEUCJPToUnicodeV2() 
00091      { 
00092           mState=0; mData=0; 
00093           setMapMode();
00094      };
00095  virtual ~nsEUCJPToUnicodeV2() {};
00096 
00097  NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
00098      PRUnichar * aDest, PRInt32 * aDestLength) ;
00099  NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
00100      PRInt32 * aDestLength) 
00101      {
00102         *aDestLength = aSrcLength;
00103         return NS_OK;
00104      };
00105  NS_IMETHOD Reset()
00106      {
00107         mState = 0;
00108         setMapMode();
00109         return NS_OK;
00110      };
00111 
00112 private:
00113  PRInt32  mState;
00114  PRInt32 mData;
00115 };
00116  
00117 class nsISO2022JPToUnicodeV2 : public nsJapaneseToUnicode
00118 {
00119 public:
00120 
00121  nsISO2022JPToUnicodeV2() 
00122      { 
00123         mState = mState_ASCII;
00124         mLastLegalState = mState_ASCII;
00125         mData = 0;
00126         mRunLength = 0;
00127         G2charset = G2_unknown;
00128         mGB2312Decoder = nsnull;
00129         mEUCKRDecoder = nsnull;
00130         mISO88597Decoder = nsnull;
00131         setMapMode();
00132      };
00133  virtual ~nsISO2022JPToUnicodeV2()
00134      {
00135         NS_IF_RELEASE(mGB2312Decoder);
00136         NS_IF_RELEASE(mEUCKRDecoder);
00137         NS_IF_RELEASE(mISO88597Decoder);
00138      };
00139 
00140  NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
00141      PRUnichar * aDest, PRInt32 * aDestLength) ;
00142  NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
00143      PRInt32 * aDestLength) 
00144      {
00145         *aDestLength = aSrcLength;
00146         return NS_OK;
00147      };
00148  NS_IMETHOD Reset()
00149      {
00150         mState = mState_ASCII;
00151         mLastLegalState = mState_ASCII;
00152         mRunLength = 0;
00153         setMapMode();
00154         return NS_OK;
00155      };
00156 
00157 private:
00158  enum {
00159    mState_ASCII,
00160    mState_ESC,
00161    mState_ESC_28,
00162    mState_ESC_24,
00163    mState_ESC_24_28,
00164    mState_JISX0201_1976Roman,
00165    mState_JISX0201_1976Kana,
00166    mState_JISX0208_1978,
00167    mState_GB2312_1980,
00168    mState_JISX0208_1983,
00169    mState_KSC5601_1987,
00170    mState_JISX0212_1990,
00171    mState_JISX0208_1978_2ndbyte,
00172    mState_GB2312_1980_2ndbyte,
00173    mState_JISX0208_1983_2ndbyte,
00174    mState_KSC5601_1987_2ndbyte,
00175    mState_JISX0212_1990_2ndbyte,
00176    mState_ESC_2e,
00177    mState_ESC_4e,
00178    mState_ERROR
00179  } mState, mLastLegalState;
00180  PRInt32 mData;
00181  PRInt32 mRunLength; // the length of a non-ASCII run
00182  enum {
00183    G2_unknown,
00184    G2_ISO88591,
00185    G2_ISO88597
00186  } G2charset;
00187  nsIUnicodeDecoder *mGB2312Decoder;
00188  nsIUnicodeDecoder *mEUCKRDecoder;
00189  nsIUnicodeDecoder *mISO88597Decoder;
00190 };
00191 #endif // nsShiftJISToUnicode_h__