intl/uconv/public/nsUCSupport.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial