Back to index

lightning-sunbird  0.9+nobinonly
nsUCSupport.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 
00038 #ifndef nsUCvJaSupport_h___
00039 #define nsUCvJaSupport_h___
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIUnicodeEncoder.h"
00043 #include "nsIUnicodeDecoder.h"
00044 #include "nsIUnicodeEncodeHelper.h"
00045 #include "nsIUnicodeDecodeHelper.h"
00046 #include "nsICharRepresentable.h"
00047 
00048 #define ONE_BYTE_TABLE_SIZE 256
00049 
00050 #ifdef NS_DEBUG
00051 // {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E}
00052 #define NS_IBASICDECODER_IID \
00053 { 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } }
00054 
00055 // {65968A7B-6467-4c4a-B50A-3E0C97A32F07}
00056 #define NS_IBASICENCODER_IID \
00057 { 0x65968a7b, 0x6467, 0x4c4a, { 0xb5, 0xa, 0x3e, 0xc, 0x97, 0xa3, 0x2f, 0x7 } }
00058 
00059 class nsIBasicDecoder : public nsISupports {
00060 public:
00061   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBASICDECODER_IID);
00062 };
00063 
00064 class nsIBasicEncoder : public nsISupports {
00065 public:
00066   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBASICENCODER_IID);
00067 };
00068 
00069 #endif
00070 
00071 //----------------------------------------------------------------------
00072 // Class nsBasicDecoderSupport [declaration]
00073 
00089 class nsBasicDecoderSupport : public nsIUnicodeDecoder
00090 #ifdef NS_DEBUG
00091                               ,public nsIBasicDecoder
00092 #endif
00093 {
00094   NS_DECL_ISUPPORTS
00095 
00096 public:
00097 
00101   nsBasicDecoderSupport();
00102 
00106   virtual ~nsBasicDecoderSupport();
00107 
00108   //--------------------------------------------------------------------
00109   // Interface nsIUnicodeDecoder [declaration]
00110 };
00111 
00112 //----------------------------------------------------------------------
00113 // Class nsBufferDecoderSupport [declaration]
00114 
00124 class nsBufferDecoderSupport : public nsBasicDecoderSupport
00125 {
00126 protected:
00127 
00131   char *    mBuffer;
00132   PRInt32   mBufferCapacity;
00133   PRInt32   mBufferLength;
00134 
00135   PRUint32  mMaxLengthFactor;
00136   
00140   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
00141       PRUnichar * aDest, PRInt32 * aDestLength) = 0;
00142 
00143   void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
00144   void DoubleBuffer();
00145 
00146 public:
00147 
00151   nsBufferDecoderSupport(PRUint32 aMaxLengthFactor);
00152 
00156   virtual ~nsBufferDecoderSupport();
00157 
00158   //--------------------------------------------------------------------
00159   // Interface nsIUnicodeDecoder [declaration]
00160 
00161   NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength, 
00162       PRUnichar * aDest, PRInt32 * aDestLength);
00163   NS_IMETHOD Reset();
00164   NS_IMETHOD GetMaxLength(const char *aSrc,
00165                           PRInt32 aSrcLength,
00166                           PRInt32* aDestLength);
00167 };
00168 
00169 //----------------------------------------------------------------------
00170 // Class nsTableDecoderSupport [declaration]
00171 
00178 class nsTableDecoderSupport : public nsBufferDecoderSupport
00179 {
00180 public:
00181 
00185   nsTableDecoderSupport(uShiftTable * aShiftTable, 
00186       uMappingTable * aMappingTable, PRUint32 aMaxLengthFactor);
00187 
00191   virtual ~nsTableDecoderSupport();
00192 
00193 protected:
00194 
00195   nsIUnicodeDecodeHelper    * mHelper;      // decoder helper object
00196   uShiftTable               * mShiftTable;
00197   uMappingTable             * mMappingTable;
00198 
00199   //--------------------------------------------------------------------
00200   // Subclassing of nsBufferDecoderSupport class [declaration]
00201 
00202   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
00203       PRUnichar * aDest, PRInt32 * aDestLength);
00204 };
00205 
00206 //----------------------------------------------------------------------
00207 // Class nsMultiTableDecoderSupport [declaration]
00208 
00215 class nsMultiTableDecoderSupport : public nsBufferDecoderSupport
00216 {
00217 public:
00218 
00222   nsMultiTableDecoderSupport(PRInt32 aTableCount, const uRange * aRangeArray, 
00223                              uShiftTable ** aShiftTable,
00224                              uMappingTable ** aMappingTable,
00225                              PRUint32 aMaxLengthFactor);
00226 
00230   virtual ~nsMultiTableDecoderSupport();
00231 
00232 protected:
00233 
00234   nsIUnicodeDecodeHelper    * mHelper;      // decoder helper object
00235   PRInt32                   mTableCount;
00236   const uRange              * mRangeArray;
00237   uShiftTable               ** mShiftTable;
00238   uMappingTable             ** mMappingTable;
00239 
00240   //--------------------------------------------------------------------
00241   // Subclassing of nsBufferDecoderSupport class [declaration]
00242 
00243   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
00244       PRUnichar * aDest, PRInt32 * aDestLength);
00245 };
00246 
00247 //----------------------------------------------------------------------
00248 // Class nsBufferDecoderSupport [declaration]
00249 
00256 class nsOneByteDecoderSupport : public nsBasicDecoderSupport
00257 {
00258 public:
00259 
00263   nsOneByteDecoderSupport(uShiftTable * aShiftTable, 
00264       uMappingTable * aMappingTable);
00265 
00269   virtual ~nsOneByteDecoderSupport();
00270 
00271 protected:
00272 
00273   nsIUnicodeDecodeHelper    * mHelper;      // decoder helper object
00274   uShiftTable               * mShiftTable;
00275   uMappingTable             * mMappingTable;
00276   PRUnichar                 mFastTable[ONE_BYTE_TABLE_SIZE];
00277 
00278   //--------------------------------------------------------------------
00279   // Subclassing of nsBasicDecoderSupport class [declaration]
00280 
00281   NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength, 
00282       PRUnichar * aDest, PRInt32 * aDestLength);
00283   NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength, 
00284       PRInt32 * aDestLength);
00285   NS_IMETHOD Reset();
00286 };
00287 
00288 //----------------------------------------------------------------------
00289 // Class nsBasicEncoder [declaration]
00290 
00291 class nsBasicEncoder : public nsIUnicodeEncoder, public nsICharRepresentable
00292 #ifdef NS_DEBUG
00293                        ,public nsIBasicEncoder
00294 #endif
00295 {
00296   NS_DECL_ISUPPORTS
00297 
00298 public:
00302   nsBasicEncoder();
00303 
00307   virtual ~nsBasicEncoder();
00308 
00309 };
00310 //----------------------------------------------------------------------
00311 // Class nsEncoderSupport [declaration]
00312 
00324 class nsEncoderSupport :  public nsBasicEncoder
00325 {
00326 
00327 protected:
00328 
00332   char *    mBuffer;
00333   PRInt32   mBufferCapacity;
00334   char *    mBufferStart;
00335   char *    mBufferEnd;
00336 
00340   PRInt32   mErrBehavior;
00341   nsCOMPtr<nsIUnicharEncoder> mErrEncoder;
00342   PRUnichar mErrChar;
00343   PRUint32  mMaxLengthFactor;
00344 
00349   NS_IMETHOD ConvertNoBuff(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
00350       char * aDest, PRInt32 * aDestLength);
00351 
00356   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
00357       char * aDest, PRInt32 * aDestLength) = 0;
00358 
00362   NS_IMETHOD FinishNoBuff(char * aDest, PRInt32 * aDestLength);
00363 
00367   nsresult FlushBuffer(char ** aDest, const char * aDestEnd);
00368 
00369 public:
00370 
00374   nsEncoderSupport(PRUint32 aMaxLengthFactor);
00375 
00379   virtual ~nsEncoderSupport();
00380 
00381   //--------------------------------------------------------------------
00382   // Interface nsIUnicodeEncoder [declaration]
00383 
00384   NS_IMETHOD Convert(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
00385       char * aDest, PRInt32 * aDestLength);
00386   NS_IMETHOD Finish(char * aDest, PRInt32 * aDestLength);
00387   NS_IMETHOD Reset();
00388   NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, 
00389       nsIUnicharEncoder * aEncoder, PRUnichar aChar);
00390   NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, 
00391                           PRInt32 aSrcLength, 
00392                           PRInt32 * aDestLength);
00393 
00394   //--------------------------------------------------------------------
00395   // Interface nsICharRepresentable [declaration]
00396   NS_IMETHOD FillInfo(PRUint32 *aInfo) = 0;
00397 };
00398 
00399 //----------------------------------------------------------------------
00400 // Class nsTableEncoderSupport [declaration]
00401 
00408 class nsTableEncoderSupport : public nsEncoderSupport
00409 {
00410 public:
00411 
00415   nsTableEncoderSupport(uShiftTable * aShiftTable, 
00416                         uMappingTable  * aMappingTable,
00417                         PRUint32 aMaxLengthFactor);
00418 
00422   virtual ~nsTableEncoderSupport();
00423   NS_IMETHOD FillInfo( PRUint32 *aInfo);
00424 
00425 protected:
00426 
00427   nsIUnicodeEncodeHelper    * mHelper;      // encoder helper object
00428   uShiftTable               * mShiftTable;
00429   uMappingTable             * mMappingTable;
00430 
00431   //--------------------------------------------------------------------
00432   // Subclassing of nsEncoderSupport class [declaration]
00433 
00434   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
00435       char * aDest, PRInt32 * aDestLength);
00436 };
00437 
00438 //----------------------------------------------------------------------
00439 // Class nsMultiTableEncoderSupport [declaration]
00440 
00447 class nsMultiTableEncoderSupport : public nsEncoderSupport
00448 {
00449 public:
00450 
00454   nsMultiTableEncoderSupport(PRInt32 aTableCount,
00455                              uShiftTable ** aShiftTable,
00456                              uMappingTable  ** aMappingTable,
00457                              PRUint32 aMaxLengthFactor);
00458 
00462   virtual ~nsMultiTableEncoderSupport();
00463   NS_IMETHOD FillInfo( PRUint32 *aInfo);
00464 
00465 protected:
00466 
00467   nsIUnicodeEncodeHelper    * mHelper;      // encoder helper object
00468   PRInt32                   mTableCount;
00469   uShiftTable               ** mShiftTable;
00470   uMappingTable             ** mMappingTable;
00471 
00472   //--------------------------------------------------------------------
00473   // Subclassing of nsEncoderSupport class [declaration]
00474 
00475   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
00476       char * aDest, PRInt32 * aDestLength);
00477 };
00478 
00479                         
00480 #endif /* nsUCvJaSupport_h___ */