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

mercurial