Bumping manifests a=b2g-bump
[gecko.git] / intl / uconv / nsIUnicodeDecoder.h
blob0d2864e3633aed9b934cdad77cabfc788d0889fd
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 nsIUnicodeDecoder_h___
7 #define nsIUnicodeDecoder_h___
9 #include "nscore.h"
10 #include "nsISupports.h"
12 // Interface ID for our Unicode Decoder interface
13 // {25359602-FC70-4d13-A9AB-8086D3827C0D}
14 //NS_DECLARE_ID(kIUnicodeDecoderIID,
15 // 0x25359602, 0xfc70, 0x4d13, 0xa9, 0xab, 0x80, 0x86, 0xd3, 0x82, 0x7c, 0xd);
17 #define NS_IUNICODEDECODER_IID \
18 { 0x25359602, 0xfc70, 0x4d13, \
19 { 0xa9, 0xab, 0x80, 0x86, 0xd3, 0x82, 0x7c, 0xd }}
22 #define NS_UNICODEDECODER_CONTRACTID_BASE "@mozilla.org/intl/unicode/decoder;1?charset="
24 /**
25 * Interface for a Converter from a Charset into Unicode.
27 * @created 23/Nov/1998
28 * @author Catalin Rotaru [CATA]
30 class nsIUnicodeDecoder : public nsISupports
32 public:
33 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IUNICODEDECODER_IID)
35 enum {
36 kOnError_Recover, // on an error, recover and continue
37 kOnError_Signal // on an error, stop and signal
40 /**
41 * Converts the data from one Charset to Unicode.
43 * About the byte ordering:
44 * - For input, if the converter cares (that depends of the charset, for
45 * example a singlebyte will ignore the byte ordering) it should assume
46 * network order. If necessary and requested, we can add a method
47 * SetInputByteOrder() so that the reverse order can be used, too. That
48 * method would have as default the assumed network order.
49 * - The output stream is Unicode, having the byte order which is internal
50 * for the machine on which the converter is running on.
52 * Unless there is not enough output space, this method must consume all the
53 * available input data! The eventual incomplete final character data will be
54 * stored internally in the converter and used when the method is called
55 * again for continuing the conversion. This way, the caller will not have to
56 * worry about managing incomplete input data by mergeing it with the next
57 * buffer.
59 * Error conditions:
60 * If the read value does not belong to this character set, one should
61 * replace it with the Unicode special 0xFFFD. When an actual input error is
62 * encountered, like a format error, the converter stop and return error.
63 * However, we should keep in mind that we need to be lax in decoding. When
64 * a decoding error is returned to the caller, it is the caller's
65 * responsibility to advance over the bad byte (unless aSrcLength is -1 in
66 * which case the caller should call the decoder with 0 offset again) and
67 * reset the decoder before trying to call the decoder again.
69 * Converter required behavior:
70 * In this order: when output space is full - return right away. When input
71 * data is wrong, return input pointer right after the wrong byte. When
72 * partial input, it will be consumed and cached. All the time input pointer
73 * will show how much was actually consumed and how much was actually
74 * written.
76 * @param aSrc [IN] the source data buffer
77 * @param aSrcLength [IN/OUT] the length of source data buffer; after
78 * conversion will contain the number of bytes read or
79 * -1 on error to indicate that the caller should re-push
80 * the same buffer after resetting the decoder
81 * @param aDest [OUT] the destination data buffer
82 * @param aDestLength [IN/OUT] the length of the destination data buffer;
83 * after conversion will contain the number of Unicode
84 * characters written
85 * @return NS_PARTIAL_MORE_INPUT if only a partial conversion was
86 * done; more input is needed to continue
87 * NS_PARTIAL_MORE_OUTPUT if only a partial conversion
88 * was done; more output space is needed to continue
89 * NS_ERROR_ILLEGAL_INPUT if an illegal input sequence
90 * was encountered and the behavior was set to "signal";
91 * the caller must skip over one byte, reset the decoder
92 * and retry.
94 NS_IMETHOD Convert(const char * aSrc, int32_t * aSrcLength,
95 char16_t * aDest, int32_t * aDestLength) = 0;
97 /**
98 * Returns a quick estimation of the size of the buffer needed to hold the
99 * converted data. Remember: this estimation is >= with the actual size of
100 * the buffer needed. It will be computed for the "worst case"
102 * @param aSrc [IN] the source data buffer
103 * @param aSrcLength [IN] the length of source data buffer
104 * @param aDestLength [OUT] the needed size of the destination buffer
105 * @return NS_EXACT_LENGTH if an exact length was computed
106 * NS_OK is all we have is an approximation
108 NS_IMETHOD GetMaxLength(const char * aSrc, int32_t aSrcLength,
109 int32_t * aDestLength) = 0;
112 * Resets the charset converter so it may be recycled for a completely
113 * different and urelated buffer of data.
115 NS_IMETHOD Reset() = 0;
118 * Specify what to do when a character cannot be mapped into unicode
120 * @param aBehavior [IN] the desired behavior
121 * @see kOnError_Recover
122 * @see kOnError_Signal
124 virtual void SetInputErrorBehavior(int32_t aBehavior) = 0;
127 * return the UNICODE character for unmapped character
129 virtual char16_t GetCharacterForUnMapped() = 0;
132 NS_DEFINE_STATIC_IID_ACCESSOR(nsIUnicodeDecoder, NS_IUNICODEDECODER_IID)
134 #endif /* nsIUnicodeDecoder_h___ */