1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/public/nsUCSupport.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,461 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsUCvJaSupport_h___ 1.10 +#define nsUCvJaSupport_h___ 1.11 + 1.12 +#include "nsCOMPtr.h" 1.13 +#include "nsIUnicodeEncoder.h" 1.14 +#include "nsIUnicodeDecoder.h" 1.15 +#include "uconvutil.h" 1.16 +#include "mozilla/Mutex.h" 1.17 + 1.18 +#define ONE_BYTE_TABLE_SIZE 256 1.19 + 1.20 +inline bool WillOverrun(char16_t* aDest, char16_t* aDestEnd, uint32_t aLength) 1.21 +{ 1.22 + NS_ASSERTION(aDest <= aDestEnd, "Pointer overrun even before check"); 1.23 + return (uint32_t(aDestEnd - aDest) < aLength); 1.24 +} 1.25 +#define CHECK_OVERRUN(dest, destEnd, length) (WillOverrun(dest, destEnd, length)) 1.26 + 1.27 +#ifdef DEBUG 1.28 +// {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E} 1.29 +#define NS_IBASICDECODER_IID \ 1.30 +{ 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } } 1.31 + 1.32 +// {65968A7B-6467-4c4a-B50A-3E0C97A32F07} 1.33 +#define NS_IBASICENCODER_IID \ 1.34 +{ 0x65968a7b, 0x6467, 0x4c4a, { 0xb5, 0xa, 0x3e, 0xc, 0x97, 0xa3, 0x2f, 0x7 } } 1.35 + 1.36 +class nsIBasicDecoder : public nsISupports { 1.37 +public: 1.38 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICDECODER_IID) 1.39 +}; 1.40 + 1.41 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicDecoder, NS_IBASICDECODER_IID) 1.42 + 1.43 +class nsIBasicEncoder : public nsISupports { 1.44 +public: 1.45 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICENCODER_IID) 1.46 +}; 1.47 + 1.48 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicEncoder, NS_IBASICENCODER_IID) 1.49 + 1.50 +#endif 1.51 + 1.52 +//---------------------------------------------------------------------- 1.53 +// Class nsBasicDecoderSupport [declaration] 1.54 + 1.55 +/** 1.56 + * Support class for the Unicode decoders. 1.57 + * 1.58 + * The class source files for this class are in /ucvlatin/nsUCvJaSupport. 1.59 + * However, because these objects requires non-xpcom subclassing, local copies 1.60 + * will be made into the other directories using them. Just don't forget to 1.61 + * keep in sync with the master copy! 1.62 + * 1.63 + * This class implements: 1.64 + * - nsISupports 1.65 + * - nsIUnicodeDecoder 1.66 + * 1.67 + * @created 19/Apr/1999 1.68 + * @author Catalin Rotaru [CATA] 1.69 + */ 1.70 +class nsBasicDecoderSupport : public nsIUnicodeDecoder 1.71 +#ifdef DEBUG 1.72 + ,public nsIBasicDecoder 1.73 +#endif 1.74 +{ 1.75 + NS_DECL_THREADSAFE_ISUPPORTS 1.76 + 1.77 +public: 1.78 + 1.79 + /** 1.80 + * Class constructor. 1.81 + */ 1.82 + nsBasicDecoderSupport(); 1.83 + 1.84 + /** 1.85 + * Class destructor. 1.86 + */ 1.87 + virtual ~nsBasicDecoderSupport(); 1.88 + 1.89 + //-------------------------------------------------------------------- 1.90 + // Interface nsIUnicodeDecoder [declaration] 1.91 + 1.92 + virtual void SetInputErrorBehavior(int32_t aBehavior); 1.93 + virtual char16_t GetCharacterForUnMapped(); 1.94 + 1.95 +protected: 1.96 + int32_t mErrBehavior; 1.97 +}; 1.98 + 1.99 +//---------------------------------------------------------------------- 1.100 +// Class nsBufferDecoderSupport [declaration] 1.101 + 1.102 +/** 1.103 + * Support class for the Unicode decoders. 1.104 + * 1.105 + * This class implements: 1.106 + * - the buffer management 1.107 + * 1.108 + * @created 15/Mar/1999 1.109 + * @author Catalin Rotaru [CATA] 1.110 + */ 1.111 +class nsBufferDecoderSupport : public nsBasicDecoderSupport 1.112 +{ 1.113 +protected: 1.114 + 1.115 + /** 1.116 + * Internal buffer for partial conversions. 1.117 + */ 1.118 + char * mBuffer; 1.119 + int32_t mBufferCapacity; 1.120 + int32_t mBufferLength; 1.121 + 1.122 + uint32_t mMaxLengthFactor; 1.123 + 1.124 + /** 1.125 + * Convert method but *without* the buffer management stuff. 1.126 + */ 1.127 + NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, 1.128 + char16_t * aDest, int32_t * aDestLength) = 0; 1.129 + 1.130 + void FillBuffer(const char ** aSrc, int32_t aSrcLength); 1.131 + 1.132 +public: 1.133 + 1.134 + /** 1.135 + * Class constructor. 1.136 + */ 1.137 + nsBufferDecoderSupport(uint32_t aMaxLengthFactor); 1.138 + 1.139 + /** 1.140 + * Class destructor. 1.141 + */ 1.142 + virtual ~nsBufferDecoderSupport(); 1.143 + 1.144 + //-------------------------------------------------------------------- 1.145 + // Interface nsIUnicodeDecoder [declaration] 1.146 + 1.147 + NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, 1.148 + char16_t * aDest, int32_t * aDestLength); 1.149 + NS_IMETHOD Reset(); 1.150 + NS_IMETHOD GetMaxLength(const char *aSrc, 1.151 + int32_t aSrcLength, 1.152 + int32_t* aDestLength); 1.153 +}; 1.154 + 1.155 +//---------------------------------------------------------------------- 1.156 +// Class nsTableDecoderSupport [declaration] 1.157 + 1.158 +/** 1.159 + * Support class for a single-table-driven Unicode decoder. 1.160 + * 1.161 + * @created 15/Mar/1999 1.162 + * @author Catalin Rotaru [CATA] 1.163 + */ 1.164 +class nsTableDecoderSupport : public nsBufferDecoderSupport 1.165 +{ 1.166 +public: 1.167 + 1.168 + /** 1.169 + * Class constructor. 1.170 + */ 1.171 + nsTableDecoderSupport(uScanClassID aScanClass, uShiftInTable * aShiftInTable, 1.172 + uMappingTable * aMappingTable, uint32_t aMaxLengthFactor); 1.173 + 1.174 + /** 1.175 + * Class destructor. 1.176 + */ 1.177 + virtual ~nsTableDecoderSupport(); 1.178 + 1.179 +protected: 1.180 + 1.181 + uScanClassID mScanClass; 1.182 + uShiftInTable * mShiftInTable; 1.183 + uMappingTable * mMappingTable; 1.184 + 1.185 + //-------------------------------------------------------------------- 1.186 + // Subclassing of nsBufferDecoderSupport class [declaration] 1.187 + 1.188 + NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, 1.189 + char16_t * aDest, int32_t * aDestLength); 1.190 +}; 1.191 + 1.192 +//---------------------------------------------------------------------- 1.193 +// Class nsMultiTableDecoderSupport [declaration] 1.194 + 1.195 +/** 1.196 + * Support class for a multi-table-driven Unicode decoder. 1.197 + * 1.198 + * @created 24/Mar/1999 1.199 + * @author Catalin Rotaru [CATA] 1.200 + */ 1.201 +class nsMultiTableDecoderSupport : public nsBufferDecoderSupport 1.202 +{ 1.203 +public: 1.204 + 1.205 + /** 1.206 + * Class constructor. 1.207 + */ 1.208 + nsMultiTableDecoderSupport(int32_t aTableCount, const uRange * aRangeArray, 1.209 + uScanClassID * aScanClassArray, 1.210 + uMappingTable ** aMappingTable, 1.211 + uint32_t aMaxLengthFactor); 1.212 + 1.213 + /** 1.214 + * Class destructor. 1.215 + */ 1.216 + virtual ~nsMultiTableDecoderSupport(); 1.217 + 1.218 +protected: 1.219 + 1.220 + int32_t mTableCount; 1.221 + const uRange * mRangeArray; 1.222 + uScanClassID * mScanClassArray; 1.223 + uMappingTable ** mMappingTable; 1.224 + 1.225 + //-------------------------------------------------------------------- 1.226 + // Subclassing of nsBufferDecoderSupport class [declaration] 1.227 + 1.228 + NS_IMETHOD ConvertNoBuff(const char * aSrc, int32_t * aSrcLength, 1.229 + char16_t * aDest, int32_t * aDestLength); 1.230 +}; 1.231 + 1.232 +//---------------------------------------------------------------------- 1.233 +// Class nsBufferDecoderSupport [declaration] 1.234 + 1.235 +/** 1.236 + * Support class for a single-byte Unicode decoder. 1.237 + * 1.238 + * @created 19/Apr/1999 1.239 + * @author Catalin Rotaru [CATA] 1.240 + */ 1.241 +class nsOneByteDecoderSupport : public nsBasicDecoderSupport 1.242 +{ 1.243 +public: 1.244 + 1.245 + /** 1.246 + * Class constructor. 1.247 + */ 1.248 + nsOneByteDecoderSupport(uMappingTable * aMappingTable); 1.249 + 1.250 + /** 1.251 + * Class destructor. 1.252 + */ 1.253 + virtual ~nsOneByteDecoderSupport(); 1.254 + 1.255 +protected: 1.256 + 1.257 + uMappingTable * mMappingTable; 1.258 + char16_t mFastTable[ONE_BYTE_TABLE_SIZE]; 1.259 + bool mFastTableCreated; 1.260 + mozilla::Mutex mFastTableMutex; 1.261 + 1.262 + //-------------------------------------------------------------------- 1.263 + // Subclassing of nsBasicDecoderSupport class [declaration] 1.264 + 1.265 + NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength, 1.266 + char16_t * aDest, int32_t * aDestLength); 1.267 + NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength, 1.268 + int32_t * aDestLength); 1.269 + NS_IMETHOD Reset(); 1.270 +}; 1.271 + 1.272 +//---------------------------------------------------------------------- 1.273 +// Class nsBasicEncoder [declaration] 1.274 + 1.275 +class nsBasicEncoder : public nsIUnicodeEncoder 1.276 +#ifdef DEBUG 1.277 + ,public nsIBasicEncoder 1.278 +#endif 1.279 +{ 1.280 + NS_DECL_ISUPPORTS 1.281 + 1.282 +public: 1.283 + /** 1.284 + * Class constructor. 1.285 + */ 1.286 + nsBasicEncoder(); 1.287 + 1.288 + /** 1.289 + * Class destructor. 1.290 + */ 1.291 + virtual ~nsBasicEncoder(); 1.292 + 1.293 +}; 1.294 +//---------------------------------------------------------------------- 1.295 +// Class nsEncoderSupport [declaration] 1.296 + 1.297 +/** 1.298 + * Support class for the Unicode encoders. 1.299 + * 1.300 + * This class implements: 1.301 + * - nsISupports 1.302 + * - the buffer management 1.303 + * - error handling procedure(s) 1.304 + * 1.305 + * @created 17/Feb/1999 1.306 + * @author Catalin Rotaru [CATA] 1.307 + */ 1.308 +class nsEncoderSupport : public nsBasicEncoder 1.309 +{ 1.310 + 1.311 +protected: 1.312 + 1.313 + /** 1.314 + * Internal buffer for partial conversions. 1.315 + */ 1.316 + char * mBuffer; 1.317 + int32_t mBufferCapacity; 1.318 + char * mBufferStart; 1.319 + char * mBufferEnd; 1.320 + 1.321 + /** 1.322 + * Error handling stuff 1.323 + */ 1.324 + int32_t mErrBehavior; 1.325 + nsCOMPtr<nsIUnicharEncoder> mErrEncoder; 1.326 + char16_t mErrChar; 1.327 + uint32_t mMaxLengthFactor; 1.328 + 1.329 + /** 1.330 + * Convert method but *without* the buffer management stuff and *with* 1.331 + * error handling stuff. 1.332 + */ 1.333 + NS_IMETHOD ConvertNoBuff(const char16_t * aSrc, int32_t * aSrcLength, 1.334 + char * aDest, int32_t * aDestLength); 1.335 + 1.336 + /** 1.337 + * Convert method but *without* the buffer management stuff and *without* 1.338 + * error handling stuff. 1.339 + */ 1.340 + NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, 1.341 + char * aDest, int32_t * aDestLength) = 0; 1.342 + 1.343 + /** 1.344 + * Finish method but *without* the buffer management stuff. 1.345 + */ 1.346 + NS_IMETHOD FinishNoBuff(char * aDest, int32_t * aDestLength); 1.347 + 1.348 + /** 1.349 + * Copy as much as possible from the internal buffer to the destination. 1.350 + */ 1.351 + nsresult FlushBuffer(char ** aDest, const char * aDestEnd); 1.352 + 1.353 +public: 1.354 + 1.355 + /** 1.356 + * Class constructor. 1.357 + */ 1.358 + nsEncoderSupport(uint32_t aMaxLengthFactor); 1.359 + 1.360 + /** 1.361 + * Class destructor. 1.362 + */ 1.363 + virtual ~nsEncoderSupport(); 1.364 + 1.365 + //-------------------------------------------------------------------- 1.366 + // Interface nsIUnicodeEncoder [declaration] 1.367 + 1.368 + NS_IMETHOD Convert(const char16_t * aSrc, int32_t * aSrcLength, 1.369 + char * aDest, int32_t * aDestLength); 1.370 + NS_IMETHOD Finish(char * aDest, int32_t * aDestLength); 1.371 + NS_IMETHOD Reset(); 1.372 + NS_IMETHOD SetOutputErrorBehavior(int32_t aBehavior, 1.373 + nsIUnicharEncoder * aEncoder, char16_t aChar); 1.374 + NS_IMETHOD GetMaxLength(const char16_t * aSrc, 1.375 + int32_t aSrcLength, 1.376 + int32_t * aDestLength); 1.377 +}; 1.378 + 1.379 +//---------------------------------------------------------------------- 1.380 +// Class nsTableEncoderSupport [declaration] 1.381 + 1.382 +/** 1.383 + * Support class for a single-table-driven Unicode encoder. 1.384 + * 1.385 + * @created 17/Feb/1999 1.386 + * @author Catalin Rotaru [CATA] 1.387 + */ 1.388 +class nsTableEncoderSupport : public nsEncoderSupport 1.389 +{ 1.390 +public: 1.391 + 1.392 + /** 1.393 + * Class constructors. 1.394 + */ 1.395 + nsTableEncoderSupport(uScanClassID aScanClass, 1.396 + uShiftOutTable * aShiftOutTable, 1.397 + uMappingTable * aMappingTable, 1.398 + uint32_t aMaxLengthFactor); 1.399 + 1.400 + nsTableEncoderSupport(uScanClassID aScanClass, 1.401 + uMappingTable * aMappingTable, 1.402 + uint32_t aMaxLengthFactor); 1.403 + 1.404 + /** 1.405 + * Class destructor. 1.406 + */ 1.407 + virtual ~nsTableEncoderSupport(); 1.408 + 1.409 +protected: 1.410 + 1.411 + uScanClassID mScanClass; 1.412 + uShiftOutTable * mShiftOutTable; 1.413 + uMappingTable * mMappingTable; 1.414 + 1.415 + //-------------------------------------------------------------------- 1.416 + // Subclassing of nsEncoderSupport class [declaration] 1.417 + 1.418 + NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, 1.419 + char * aDest, int32_t * aDestLength); 1.420 +}; 1.421 + 1.422 +//---------------------------------------------------------------------- 1.423 +// Class nsMultiTableEncoderSupport [declaration] 1.424 + 1.425 +/** 1.426 + * Support class for a multi-table-driven Unicode encoder. 1.427 + * 1.428 + * @created 11/Mar/1999 1.429 + * @author Catalin Rotaru [CATA] 1.430 + */ 1.431 +class nsMultiTableEncoderSupport : public nsEncoderSupport 1.432 +{ 1.433 +public: 1.434 + 1.435 + /** 1.436 + * Class constructor. 1.437 + */ 1.438 + nsMultiTableEncoderSupport(int32_t aTableCount, 1.439 + uScanClassID * aScanClassArray, 1.440 + uShiftOutTable ** aShiftOutTable, 1.441 + uMappingTable ** aMappingTable, 1.442 + uint32_t aMaxLengthFactor); 1.443 + 1.444 + /** 1.445 + * Class destructor. 1.446 + */ 1.447 + virtual ~nsMultiTableEncoderSupport(); 1.448 + 1.449 +protected: 1.450 + 1.451 + int32_t mTableCount; 1.452 + uScanClassID * mScanClassArray; 1.453 + uShiftOutTable ** mShiftOutTable; 1.454 + uMappingTable ** mMappingTable; 1.455 + 1.456 + //-------------------------------------------------------------------- 1.457 + // Subclassing of nsEncoderSupport class [declaration] 1.458 + 1.459 + NS_IMETHOD ConvertNoBuffNoErr(const char16_t * aSrc, int32_t * aSrcLength, 1.460 + char * aDest, int32_t * aDestLength); 1.461 +}; 1.462 + 1.463 + 1.464 +#endif /* nsUCvJaSupport_h___ */