Back to index

lightning-sunbird  0.9+nobinonly
nsGB2312ToUnicodeV2.cpp
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  * Intel Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Yueheng Xu <yuheng.xu@intel.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 // =======================================================================
00039 // Original Author: Yueheng Xu
00040 // email: yueheng.xu@intel.com
00041 // phone: (503)264-2248
00042 // Intel Corporation, Oregon, USA
00043 // Last Update: September 7, 1999
00044 // Revision History: 
00045 // 09/07/1999 - initial version. Based on exisiting nsGB2312ToUnicode.cpp. Removed
00046 //              dependecy on those shift/map tables. Now we only depend on gbku.h.
00047 // 09/28/1999 - changed to use the same table and code as GBKToUnicode converter
00048 // ======================================================================================
00049 
00050 #if 0
00051 #include "nsGB2312ToUnicodeV2.h"
00052 #include "nsUCvCnDll.h"
00053 #include "gbku.h"
00054 //----------------------------------------------------------------------
00055 // Class nsGB2312ToUnicodeV2 [implementation]
00056 //----------------------------------------------------------------------
00057 // Subclassing of nsTablesDecoderSupport class [implementation]
00058 NS_IMETHODIMP nsGB2312ToUnicodeV2::GetMaxLength(const char * aSrc, 
00059                                               PRInt32 aSrcLength, 
00060                                               PRInt32 * aDestLength)
00061 {
00062   *aDestLength = aSrcLength;
00063   return NS_OK;
00064 }
00065 NS_IMETHODIMP nsGB2312ToUnicodeV2::ConvertNoBuff(const char* aSrc,
00066                                                  PRInt32 * aSrcLength,
00067                                                  PRUnichar *aDest,
00068                                                  PRInt32 * aDestLength)
00069 {
00070   PRInt32 i=0;
00071   PRInt32 iSrcLength = (*aSrcLength);
00072   PRInt32 iDestlen = 0;
00073   nsresult rv = NS_OK;
00074   for (i=0;i<iSrcLength;i++)
00075   {
00076     if ( iDestlen >= (*aDestLength) )
00077     {
00078       rv = NS_OK_UDEC_MOREOUTPUT;
00079       break;
00080     }
00081     if(UINT8_IN_RANGE(0xa1, *aSrc, 0xfe))
00082     {
00083       if(i+1 >= iSrcLength)
00084       {
00085         rv = NS_OK_UDEC_MOREINPUT;
00086         break;
00087       }
00088       // To make sure, the second byte has to be checked as well
00089       // The valid 2nd byte range: [0xA1,0xFE]
00090       if(UINT8_IN_RANGE(0xa1, aSrc[1], 0xfe))
00091       {
00092         // Valid GB 2312 code point
00093         *aDest = mUtil.GBKCharToUnicode(aSrc[0], aSrc[1]);
00094         aSrc += 2;
00095         i++;
00096       } else {
00097         // Invalid GB 2312 code point 
00098         *aDest =  UCS2_NO_MAPPING;
00099         aSrc++;
00100       }
00101     } else {
00102       if(IS_ASCII(*aSrc))
00103       {
00104         // The source is an ASCII
00105         *aDest = CAST_CHAR_TO_UNICHAR(*aSrc);
00106       } else {
00107         *aDest =  UCS2_NO_MAPPING;
00108       }
00109       aSrc++;
00110     }
00111     iDestlen++;
00112     aDest++;
00113     *aSrcLength = i+1;
00114   }
00115   *aDestLength = iDestlen;
00116   return rv;
00117 }
00118 #endif