LCOV - code coverage report
Current view: directory - intl/uconv/util - nsUCSupport.h (source / functions) Found Hit Coverage
Test: app.info Lines: 5 5 100.0 %
Date: 2012-06-02 Functions: 3 3 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsUCvJaSupport_h___
      39                 : #define nsUCvJaSupport_h___
      40                 : 
      41                 : #include "nsCOMPtr.h"
      42                 : #include "nsIUnicodeEncoder.h"
      43                 : #include "nsIUnicodeDecoder.h"
      44                 : #include "uconvutil.h"
      45                 : #include "mozilla/Mutex.h"
      46                 : 
      47                 : #define ONE_BYTE_TABLE_SIZE 256
      48                 : 
      49             141 : inline bool WillOverrun(PRUnichar* aDest, PRUnichar* aDestEnd, PRUint32 aLength)
      50                 : {
      51             141 :   NS_ASSERTION(aDest <= aDestEnd, "Pointer overrun even before check");
      52             141 :   return ((aDestEnd - aDest) < aLength);
      53                 : }
      54                 : #define CHECK_OVERRUN(dest, destEnd, length) (WillOverrun(dest, destEnd, length))
      55                 : 
      56                 : #ifdef NS_DEBUG
      57                 : // {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E}
      58                 : #define NS_IBASICDECODER_IID \
      59                 : { 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } }
      60                 : 
      61                 : // {65968A7B-6467-4c4a-B50A-3E0C97A32F07}
      62                 : #define NS_IBASICENCODER_IID \
      63                 : { 0x65968a7b, 0x6467, 0x4c4a, { 0xb5, 0xa, 0x3e, 0xc, 0x97, 0xa3, 0x2f, 0x7 } }
      64                 : 
      65           15552 : class nsIBasicDecoder : public nsISupports {
      66                 : public:
      67                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICDECODER_IID)
      68                 : };
      69                 : 
      70                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicDecoder, NS_IBASICDECODER_IID)
      71                 : 
      72            9929 : class nsIBasicEncoder : public nsISupports {
      73                 : public:
      74                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICENCODER_IID)
      75                 : };
      76                 : 
      77                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicEncoder, NS_IBASICENCODER_IID)
      78                 : 
      79                 : #endif
      80                 : 
      81                 : //----------------------------------------------------------------------
      82                 : // Class nsBasicDecoderSupport [declaration]
      83                 : 
      84                 : /**
      85                 :  * Support class for the Unicode decoders. 
      86                 :  *
      87                 :  * The class source files for this class are in /ucvlatin/nsUCvJaSupport. 
      88                 :  * However, because these objects requires non-xpcom subclassing, local copies
      89                 :  * will be made into the other directories using them. Just don't forget to 
      90                 :  * keep in sync with the master copy!
      91                 :  * 
      92                 :  * This class implements:
      93                 :  * - nsISupports
      94                 :  * - nsIUnicodeDecoder
      95                 :  *
      96                 :  * @created         19/Apr/1999
      97                 :  * @author  Catalin Rotaru [CATA]
      98                 :  */
      99                 : class nsBasicDecoderSupport : public nsIUnicodeDecoder
     100                 : #ifdef NS_DEBUG
     101                 :                               ,public nsIBasicDecoder
     102                 : #endif
     103                 : {
     104                 :   NS_DECL_ISUPPORTS
     105                 : 
     106                 : public:
     107                 : 
     108                 :   /**
     109                 :    * Class constructor.
     110                 :    */
     111                 :   nsBasicDecoderSupport();
     112                 : 
     113                 :   /**
     114                 :    * Class destructor.
     115                 :    */
     116                 :   virtual ~nsBasicDecoderSupport();
     117                 : 
     118                 :   //--------------------------------------------------------------------
     119                 :   // Interface nsIUnicodeDecoder [declaration]
     120                 : 
     121                 :   virtual void SetInputErrorBehavior(PRInt32 aBehavior);
     122                 :   virtual PRUnichar GetCharacterForUnMapped();
     123                 : 
     124                 : protected:
     125                 :   PRInt32   mErrBehavior;
     126                 : };
     127                 : 
     128                 : //----------------------------------------------------------------------
     129                 : // Class nsBufferDecoderSupport [declaration]
     130                 : 
     131                 : /**
     132                 :  * Support class for the Unicode decoders. 
     133                 :  *
     134                 :  * This class implements:
     135                 :  * - the buffer management
     136                 :  *
     137                 :  * @created         15/Mar/1999
     138                 :  * @author  Catalin Rotaru [CATA]
     139                 :  */
     140                 : class nsBufferDecoderSupport : public nsBasicDecoderSupport
     141                 : {
     142                 : protected:
     143                 : 
     144                 :   /**
     145                 :    * Internal buffer for partial conversions.
     146                 :    */
     147                 :   char *    mBuffer;
     148                 :   PRInt32   mBufferCapacity;
     149                 :   PRInt32   mBufferLength;
     150                 : 
     151                 :   PRUint32  mMaxLengthFactor;
     152                 :   
     153                 :   /**
     154                 :    * Convert method but *without* the buffer management stuff.
     155                 :    */
     156                 :   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
     157                 :       PRUnichar * aDest, PRInt32 * aDestLength) = 0;
     158                 : 
     159                 :   void FillBuffer(const char ** aSrc, PRInt32 aSrcLength);
     160                 : 
     161                 : public:
     162                 : 
     163                 :   /**
     164                 :    * Class constructor.
     165                 :    */
     166                 :   nsBufferDecoderSupport(PRUint32 aMaxLengthFactor);
     167                 : 
     168                 :   /**
     169                 :    * Class destructor.
     170                 :    */
     171                 :   virtual ~nsBufferDecoderSupport();
     172                 : 
     173                 :   //--------------------------------------------------------------------
     174                 :   // Interface nsIUnicodeDecoder [declaration]
     175                 : 
     176                 :   NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength, 
     177                 :       PRUnichar * aDest, PRInt32 * aDestLength);
     178                 :   NS_IMETHOD Reset();
     179                 :   NS_IMETHOD GetMaxLength(const char *aSrc,
     180                 :                           PRInt32 aSrcLength,
     181                 :                           PRInt32* aDestLength);
     182                 : };
     183                 : 
     184                 : //----------------------------------------------------------------------
     185                 : // Class nsTableDecoderSupport [declaration]
     186                 : 
     187                 : /**
     188                 :  * Support class for a single-table-driven Unicode decoder.
     189                 :  * 
     190                 :  * @created         15/Mar/1999
     191                 :  * @author  Catalin Rotaru [CATA]
     192                 :  */
     193                 : class nsTableDecoderSupport : public nsBufferDecoderSupport
     194                 : {
     195                 : public:
     196                 : 
     197                 :   /**
     198                 :    * Class constructor.
     199                 :    */
     200                 :   nsTableDecoderSupport(uScanClassID aScanClass, uShiftInTable * aShiftInTable,
     201                 :       uMappingTable * aMappingTable, PRUint32 aMaxLengthFactor);
     202                 : 
     203                 :   /**
     204                 :    * Class destructor.
     205                 :    */
     206                 :   virtual ~nsTableDecoderSupport();
     207                 : 
     208                 : protected:
     209                 : 
     210                 :   uScanClassID              mScanClass;
     211                 :   uShiftInTable             * mShiftInTable;
     212                 :   uMappingTable             * mMappingTable;
     213                 : 
     214                 :   //--------------------------------------------------------------------
     215                 :   // Subclassing of nsBufferDecoderSupport class [declaration]
     216                 : 
     217                 :   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
     218                 :       PRUnichar * aDest, PRInt32 * aDestLength);
     219                 : };
     220                 : 
     221                 : //----------------------------------------------------------------------
     222                 : // Class nsMultiTableDecoderSupport [declaration]
     223                 : 
     224                 : /**
     225                 :  * Support class for a multi-table-driven Unicode decoder.
     226                 :  * 
     227                 :  * @created         24/Mar/1999
     228                 :  * @author  Catalin Rotaru [CATA]
     229                 :  */
     230                 : class nsMultiTableDecoderSupport : public nsBufferDecoderSupport
     231                 : {
     232                 : public:
     233                 : 
     234                 :   /**
     235                 :    * Class constructor.
     236                 :    */
     237                 :   nsMultiTableDecoderSupport(PRInt32 aTableCount, const uRange * aRangeArray, 
     238                 :                              uScanClassID * aScanClassArray,
     239                 :                              uMappingTable ** aMappingTable,
     240                 :                              PRUint32 aMaxLengthFactor);
     241                 : 
     242                 :   /**
     243                 :    * Class destructor.
     244                 :    */
     245                 :   virtual ~nsMultiTableDecoderSupport();
     246                 : 
     247                 : protected:
     248                 : 
     249                 :   PRInt32                   mTableCount;
     250                 :   const uRange              * mRangeArray;
     251                 :   uScanClassID              * mScanClassArray;
     252                 :   uMappingTable             ** mMappingTable;
     253                 : 
     254                 :   //--------------------------------------------------------------------
     255                 :   // Subclassing of nsBufferDecoderSupport class [declaration]
     256                 : 
     257                 :   NS_IMETHOD ConvertNoBuff(const char * aSrc, PRInt32 * aSrcLength, 
     258                 :       PRUnichar * aDest, PRInt32 * aDestLength);
     259                 : };
     260                 : 
     261                 : //----------------------------------------------------------------------
     262                 : // Class nsBufferDecoderSupport [declaration]
     263                 : 
     264                 : /**
     265                 :  * Support class for a single-byte Unicode decoder.
     266                 :  *
     267                 :  * @created         19/Apr/1999
     268                 :  * @author  Catalin Rotaru [CATA]
     269                 :  */
     270                 : class nsOneByteDecoderSupport : public nsBasicDecoderSupport
     271                 : {
     272                 : public:
     273                 : 
     274                 :   /**
     275                 :    * Class constructor.
     276                 :    */
     277                 :   nsOneByteDecoderSupport(uMappingTable * aMappingTable);
     278                 : 
     279                 :   /**
     280                 :    * Class destructor.
     281                 :    */
     282                 :   virtual ~nsOneByteDecoderSupport();
     283                 : 
     284                 : protected:
     285                 : 
     286                 :   uMappingTable             * mMappingTable;
     287                 :   PRUnichar                 mFastTable[ONE_BYTE_TABLE_SIZE];
     288                 :   bool                      mFastTableCreated;
     289                 :   mozilla::Mutex            mFastTableMutex;
     290                 : 
     291                 :   //--------------------------------------------------------------------
     292                 :   // Subclassing of nsBasicDecoderSupport class [declaration]
     293                 : 
     294                 :   NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength, 
     295                 :       PRUnichar * aDest, PRInt32 * aDestLength);
     296                 :   NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength, 
     297                 :       PRInt32 * aDestLength);
     298                 :   NS_IMETHOD Reset();
     299                 : };
     300                 : 
     301                 : //----------------------------------------------------------------------
     302                 : // Class nsBasicEncoder [declaration]
     303                 : 
     304                 : class nsBasicEncoder : public nsIUnicodeEncoder
     305                 : #ifdef NS_DEBUG
     306                 :                        ,public nsIBasicEncoder
     307                 : #endif
     308                 : {
     309                 :   NS_DECL_ISUPPORTS
     310                 : 
     311                 : public:
     312                 :   /**
     313                 :    * Class constructor.
     314                 :    */
     315                 :   nsBasicEncoder();
     316                 : 
     317                 :   /**
     318                 :    * Class destructor.
     319                 :    */
     320                 :   virtual ~nsBasicEncoder();
     321                 : 
     322                 : };
     323                 : //----------------------------------------------------------------------
     324                 : // Class nsEncoderSupport [declaration]
     325                 : 
     326                 : /**
     327                 :  * Support class for the Unicode encoders. 
     328                 :  *
     329                 :  * This class implements:
     330                 :  * - nsISupports
     331                 :  * - the buffer management
     332                 :  * - error handling procedure(s)
     333                 :  *
     334                 :  * @created         17/Feb/1999
     335                 :  * @author  Catalin Rotaru [CATA]
     336                 :  */
     337                 : class nsEncoderSupport :  public nsBasicEncoder
     338                 : {
     339                 : 
     340                 : protected:
     341                 : 
     342                 :   /**
     343                 :    * Internal buffer for partial conversions.
     344                 :    */
     345                 :   char *    mBuffer;
     346                 :   PRInt32   mBufferCapacity;
     347                 :   char *    mBufferStart;
     348                 :   char *    mBufferEnd;
     349                 : 
     350                 :   /**
     351                 :    * Error handling stuff
     352                 :    */
     353                 :   PRInt32   mErrBehavior;
     354                 :   nsCOMPtr<nsIUnicharEncoder> mErrEncoder;
     355                 :   PRUnichar mErrChar;
     356                 :   PRUint32  mMaxLengthFactor;
     357                 : 
     358                 :   /**
     359                 :    * Convert method but *without* the buffer management stuff and *with* 
     360                 :    * error handling stuff.
     361                 :    */
     362                 :   NS_IMETHOD ConvertNoBuff(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
     363                 :       char * aDest, PRInt32 * aDestLength);
     364                 : 
     365                 :   /**
     366                 :    * Convert method but *without* the buffer management stuff and *without*
     367                 :    * error handling stuff.
     368                 :    */
     369                 :   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
     370                 :       char * aDest, PRInt32 * aDestLength) = 0;
     371                 : 
     372                 :   /**
     373                 :    * Finish method but *without* the buffer management stuff.
     374                 :    */
     375                 :   NS_IMETHOD FinishNoBuff(char * aDest, PRInt32 * aDestLength);
     376                 : 
     377                 :   /**
     378                 :    * Copy as much as possible from the internal buffer to the destination.
     379                 :    */
     380                 :   nsresult FlushBuffer(char ** aDest, const char * aDestEnd);
     381                 : 
     382                 : public:
     383                 : 
     384                 :   /**
     385                 :    * Class constructor.
     386                 :    */
     387                 :   nsEncoderSupport(PRUint32 aMaxLengthFactor);
     388                 : 
     389                 :   /**
     390                 :    * Class destructor.
     391                 :    */
     392                 :   virtual ~nsEncoderSupport();
     393                 : 
     394                 :   //--------------------------------------------------------------------
     395                 :   // Interface nsIUnicodeEncoder [declaration]
     396                 : 
     397                 :   NS_IMETHOD Convert(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
     398                 :       char * aDest, PRInt32 * aDestLength);
     399                 :   NS_IMETHOD Finish(char * aDest, PRInt32 * aDestLength);
     400                 :   NS_IMETHOD Reset();
     401                 :   NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, 
     402                 :       nsIUnicharEncoder * aEncoder, PRUnichar aChar);
     403                 :   NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, 
     404                 :                           PRInt32 aSrcLength, 
     405                 :                           PRInt32 * aDestLength);
     406                 : };
     407                 : 
     408                 : //----------------------------------------------------------------------
     409                 : // Class nsTableEncoderSupport [declaration]
     410                 : 
     411                 : /**
     412                 :  * Support class for a single-table-driven Unicode encoder.
     413                 :  * 
     414                 :  * @created         17/Feb/1999
     415                 :  * @author  Catalin Rotaru [CATA]
     416                 :  */
     417                 : class nsTableEncoderSupport : public nsEncoderSupport
     418                 : {
     419                 : public:
     420                 : 
     421                 :   /**
     422                 :    * Class constructors.
     423                 :    */
     424                 :   nsTableEncoderSupport(uScanClassID  aScanClass,
     425                 :                         uShiftOutTable * aShiftOutTable,
     426                 :                         uMappingTable  * aMappingTable,
     427                 :                         PRUint32 aMaxLengthFactor);
     428                 : 
     429                 :   nsTableEncoderSupport(uScanClassID  aScanClass,
     430                 :                         uMappingTable  * aMappingTable,
     431                 :                         PRUint32 aMaxLengthFactor);
     432                 : 
     433                 :   /**
     434                 :    * Class destructor.
     435                 :    */
     436                 :   virtual ~nsTableEncoderSupport();
     437                 : 
     438                 : protected:
     439                 : 
     440                 :   uScanClassID              mScanClass;
     441                 :   uShiftOutTable            * mShiftOutTable;
     442                 :   uMappingTable             * mMappingTable;
     443                 : 
     444                 :   //--------------------------------------------------------------------
     445                 :   // Subclassing of nsEncoderSupport class [declaration]
     446                 : 
     447                 :   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
     448                 :       char * aDest, PRInt32 * aDestLength);
     449                 : };
     450                 : 
     451                 : //----------------------------------------------------------------------
     452                 : // Class nsMultiTableEncoderSupport [declaration]
     453                 : 
     454                 : /**
     455                 :  * Support class for a multi-table-driven Unicode encoder.
     456                 :  * 
     457                 :  * @created         11/Mar/1999
     458                 :  * @author  Catalin Rotaru [CATA]
     459                 :  */
     460                 : class nsMultiTableEncoderSupport : public nsEncoderSupport
     461                 : {
     462                 : public:
     463                 : 
     464                 :   /**
     465                 :    * Class constructor.
     466                 :    */
     467                 :   nsMultiTableEncoderSupport(PRInt32 aTableCount,
     468                 :                              uScanClassID * aScanClassArray,
     469                 :                              uShiftOutTable ** aShiftOutTable,
     470                 :                              uMappingTable  ** aMappingTable,
     471                 :                              PRUint32 aMaxLengthFactor);
     472                 : 
     473                 :   /**
     474                 :    * Class destructor.
     475                 :    */
     476                 :   virtual ~nsMultiTableEncoderSupport();
     477                 : 
     478                 : protected:
     479                 : 
     480                 :   PRInt32                   mTableCount;
     481                 :   uScanClassID              * mScanClassArray;
     482                 :   uShiftOutTable            ** mShiftOutTable;
     483                 :   uMappingTable             ** mMappingTable;
     484                 : 
     485                 :   //--------------------------------------------------------------------
     486                 :   // Subclassing of nsEncoderSupport class [declaration]
     487                 : 
     488                 :   NS_IMETHOD ConvertNoBuffNoErr(const PRUnichar * aSrc, PRInt32 * aSrcLength, 
     489                 :       char * aDest, PRInt32 * aDestLength);
     490                 : };
     491                 : 
     492                 :                         
     493                 : #endif /* nsUCvJaSupport_h___ */

Generated by: LCOV version 1.7