1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsUCvJaSupport_h___
7 #define nsUCvJaSupport_h___
10 #include "nsIUnicodeEncoder.h"
11 #include "nsIUnicodeDecoder.h"
12 #include "uconvutil.h"
13 #include "mozilla/Mutex.h"
15 #define ONE_BYTE_TABLE_SIZE 256
17 inline bool WillOverrun(char16_t
* aDest
, char16_t
* aDestEnd
, uint32_t aLength
)
19 NS_ASSERTION(aDest
<= aDestEnd
, "Pointer overrun even before check");
20 return (uint32_t(aDestEnd
- aDest
) < aLength
);
22 #define CHECK_OVERRUN(dest, destEnd, length) (WillOverrun(dest, destEnd, length))
25 // {7AFC9F0A-CFE1-44ea-A755-E3B86AB1226E}
26 #define NS_IBASICDECODER_IID \
27 { 0x7afc9f0a, 0xcfe1, 0x44ea, { 0xa7, 0x55, 0xe3, 0xb8, 0x6a, 0xb1, 0x22, 0x6e } }
29 // {65968A7B-6467-4c4a-B50A-3E0C97A32F07}
30 #define NS_IBASICENCODER_IID \
31 { 0x65968a7b, 0x6467, 0x4c4a, { 0xb5, 0xa, 0x3e, 0xc, 0x97, 0xa3, 0x2f, 0x7 } }
33 class nsIBasicDecoder
: public nsISupports
{
35 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICDECODER_IID
)
38 NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicDecoder
, NS_IBASICDECODER_IID
)
40 class nsIBasicEncoder
: public nsISupports
{
42 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASICENCODER_IID
)
45 NS_DEFINE_STATIC_IID_ACCESSOR(nsIBasicEncoder
, NS_IBASICENCODER_IID
)
49 //----------------------------------------------------------------------
50 // Class nsBasicDecoderSupport [declaration]
53 * Support class for the Unicode decoders.
55 * The class source files for this class are in /ucvlatin/nsUCvJaSupport.
56 * However, because these objects requires non-xpcom subclassing, local copies
57 * will be made into the other directories using them. Just don't forget to
58 * keep in sync with the master copy!
60 * This class implements:
64 * @created 19/Apr/1999
65 * @author Catalin Rotaru [CATA]
67 class nsBasicDecoderSupport
: public nsIUnicodeDecoder
69 ,public nsIBasicDecoder
72 NS_DECL_THREADSAFE_ISUPPORTS
79 nsBasicDecoderSupport();
81 //--------------------------------------------------------------------
82 // Interface nsIUnicodeDecoder [declaration]
84 virtual void SetInputErrorBehavior(int32_t aBehavior
) MOZ_OVERRIDE
;
85 virtual char16_t
GetCharacterForUnMapped() MOZ_OVERRIDE
;
93 virtual ~nsBasicDecoderSupport();
96 //----------------------------------------------------------------------
97 // Class nsBufferDecoderSupport [declaration]
100 * Support class for the Unicode decoders.
102 * This class implements:
103 * - the buffer management
105 * @created 15/Mar/1999
106 * @author Catalin Rotaru [CATA]
108 class nsBufferDecoderSupport
: public nsBasicDecoderSupport
113 * Internal buffer for partial conversions.
116 int32_t mBufferCapacity
;
117 int32_t mBufferLength
;
119 uint32_t mMaxLengthFactor
;
122 * Convert method but *without* the buffer management stuff.
124 NS_IMETHOD
ConvertNoBuff(const char * aSrc
, int32_t * aSrcLength
,
125 char16_t
* aDest
, int32_t * aDestLength
) = 0;
127 void FillBuffer(const char ** aSrc
, int32_t aSrcLength
);
134 explicit nsBufferDecoderSupport(uint32_t aMaxLengthFactor
);
139 virtual ~nsBufferDecoderSupport();
141 //--------------------------------------------------------------------
142 // Interface nsIUnicodeDecoder [declaration]
144 NS_IMETHOD
Convert(const char * aSrc
, int32_t * aSrcLength
,
145 char16_t
* aDest
, int32_t * aDestLength
);
147 NS_IMETHOD
GetMaxLength(const char *aSrc
,
149 int32_t* aDestLength
);
152 //----------------------------------------------------------------------
153 // Class nsTableDecoderSupport [declaration]
156 * Support class for a single-table-driven Unicode decoder.
158 * @created 15/Mar/1999
159 * @author Catalin Rotaru [CATA]
161 class nsTableDecoderSupport
: public nsBufferDecoderSupport
168 nsTableDecoderSupport(uScanClassID aScanClass
, uShiftInTable
* aShiftInTable
,
169 uMappingTable
* aMappingTable
, uint32_t aMaxLengthFactor
);
174 virtual ~nsTableDecoderSupport();
178 uScanClassID mScanClass
;
179 uShiftInTable
* mShiftInTable
;
180 uMappingTable
* mMappingTable
;
182 //--------------------------------------------------------------------
183 // Subclassing of nsBufferDecoderSupport class [declaration]
185 NS_IMETHOD
ConvertNoBuff(const char * aSrc
, int32_t * aSrcLength
,
186 char16_t
* aDest
, int32_t * aDestLength
);
189 //----------------------------------------------------------------------
190 // Class nsMultiTableDecoderSupport [declaration]
193 * Support class for a multi-table-driven Unicode decoder.
195 * @created 24/Mar/1999
196 * @author Catalin Rotaru [CATA]
198 class nsMultiTableDecoderSupport
: public nsBufferDecoderSupport
205 nsMultiTableDecoderSupport(int32_t aTableCount
, const uRange
* aRangeArray
,
206 uScanClassID
* aScanClassArray
,
207 uMappingTable
** aMappingTable
,
208 uint32_t aMaxLengthFactor
);
213 virtual ~nsMultiTableDecoderSupport();
218 const uRange
* mRangeArray
;
219 uScanClassID
* mScanClassArray
;
220 uMappingTable
** mMappingTable
;
222 //--------------------------------------------------------------------
223 // Subclassing of nsBufferDecoderSupport class [declaration]
225 NS_IMETHOD
ConvertNoBuff(const char * aSrc
, int32_t * aSrcLength
,
226 char16_t
* aDest
, int32_t * aDestLength
);
229 //----------------------------------------------------------------------
230 // Class nsBufferDecoderSupport [declaration]
233 * Support class for a single-byte Unicode decoder.
235 * @created 19/Apr/1999
236 * @author Catalin Rotaru [CATA]
238 class nsOneByteDecoderSupport
: public nsBasicDecoderSupport
245 explicit nsOneByteDecoderSupport(uMappingTable
* aMappingTable
);
250 virtual ~nsOneByteDecoderSupport();
254 uMappingTable
* mMappingTable
;
255 char16_t mFastTable
[ONE_BYTE_TABLE_SIZE
];
256 bool mFastTableCreated
;
257 mozilla::Mutex mFastTableMutex
;
259 //--------------------------------------------------------------------
260 // Subclassing of nsBasicDecoderSupport class [declaration]
262 NS_IMETHOD
Convert(const char * aSrc
, int32_t * aSrcLength
,
263 char16_t
* aDest
, int32_t * aDestLength
);
264 NS_IMETHOD
GetMaxLength(const char * aSrc
, int32_t aSrcLength
,
265 int32_t * aDestLength
);
269 //----------------------------------------------------------------------
270 // Class nsBasicEncoder [declaration]
272 class nsBasicEncoder
: public nsIUnicodeEncoder
274 ,public nsIBasicEncoder
289 virtual ~nsBasicEncoder();
292 //----------------------------------------------------------------------
293 // Class nsEncoderSupport [declaration]
296 * Support class for the Unicode encoders.
298 * This class implements:
300 * - the buffer management
301 * - error handling procedure(s)
303 * @created 17/Feb/1999
304 * @author Catalin Rotaru [CATA]
306 class nsEncoderSupport
: public nsBasicEncoder
312 * Internal buffer for partial conversions.
315 int32_t mBufferCapacity
;
320 * Error handling stuff
322 int32_t mErrBehavior
;
323 nsCOMPtr
<nsIUnicharEncoder
> mErrEncoder
;
325 uint32_t mMaxLengthFactor
;
328 * Convert method but *without* the buffer management stuff and *with*
329 * error handling stuff.
331 NS_IMETHOD
ConvertNoBuff(const char16_t
* aSrc
, int32_t * aSrcLength
,
332 char * aDest
, int32_t * aDestLength
);
335 * Convert method but *without* the buffer management stuff and *without*
336 * error handling stuff.
338 NS_IMETHOD
ConvertNoBuffNoErr(const char16_t
* aSrc
, int32_t * aSrcLength
,
339 char * aDest
, int32_t * aDestLength
) = 0;
342 * Finish method but *without* the buffer management stuff.
344 NS_IMETHOD
FinishNoBuff(char * aDest
, int32_t * aDestLength
);
347 * Copy as much as possible from the internal buffer to the destination.
349 nsresult
FlushBuffer(char ** aDest
, const char * aDestEnd
);
356 explicit nsEncoderSupport(uint32_t aMaxLengthFactor
);
361 virtual ~nsEncoderSupport();
363 //--------------------------------------------------------------------
364 // Interface nsIUnicodeEncoder [declaration]
366 NS_IMETHOD
Convert(const char16_t
* aSrc
, int32_t * aSrcLength
,
367 char * aDest
, int32_t * aDestLength
);
368 NS_IMETHOD
Finish(char * aDest
, int32_t * aDestLength
);
370 NS_IMETHOD
SetOutputErrorBehavior(int32_t aBehavior
,
371 nsIUnicharEncoder
* aEncoder
, char16_t aChar
);
372 NS_IMETHOD
GetMaxLength(const char16_t
* aSrc
,
374 int32_t * aDestLength
);
377 //----------------------------------------------------------------------
378 // Class nsTableEncoderSupport [declaration]
381 * Support class for a single-table-driven Unicode encoder.
383 * @created 17/Feb/1999
384 * @author Catalin Rotaru [CATA]
386 class nsTableEncoderSupport
: public nsEncoderSupport
391 * Class constructors.
393 nsTableEncoderSupport(uScanClassID aScanClass
,
394 uShiftOutTable
* aShiftOutTable
,
395 uMappingTable
* aMappingTable
,
396 uint32_t aMaxLengthFactor
);
398 nsTableEncoderSupport(uScanClassID aScanClass
,
399 uMappingTable
* aMappingTable
,
400 uint32_t aMaxLengthFactor
);
405 virtual ~nsTableEncoderSupport();
409 uScanClassID mScanClass
;
410 uShiftOutTable
* mShiftOutTable
;
411 uMappingTable
* mMappingTable
;
413 //--------------------------------------------------------------------
414 // Subclassing of nsEncoderSupport class [declaration]
416 NS_IMETHOD
ConvertNoBuffNoErr(const char16_t
* aSrc
, int32_t * aSrcLength
,
417 char * aDest
, int32_t * aDestLength
);
420 //----------------------------------------------------------------------
421 // Class nsMultiTableEncoderSupport [declaration]
424 * Support class for a multi-table-driven Unicode encoder.
426 * @created 11/Mar/1999
427 * @author Catalin Rotaru [CATA]
429 class nsMultiTableEncoderSupport
: public nsEncoderSupport
436 nsMultiTableEncoderSupport(int32_t aTableCount
,
437 uScanClassID
* aScanClassArray
,
438 uShiftOutTable
** aShiftOutTable
,
439 uMappingTable
** aMappingTable
,
440 uint32_t aMaxLengthFactor
);
445 virtual ~nsMultiTableEncoderSupport();
450 uScanClassID
* mScanClassArray
;
451 uShiftOutTable
** mShiftOutTable
;
452 uMappingTable
** mMappingTable
;
454 //--------------------------------------------------------------------
455 // Subclassing of nsEncoderSupport class [declaration]
457 NS_IMETHOD
ConvertNoBuffNoErr(const char16_t
* aSrc
, int32_t * aSrcLength
,
458 char * aDest
, int32_t * aDestLength
);
462 #endif /* nsUCvJaSupport_h___ */