2001-09-26 04:40:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-07 04:23:22 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-01-07 04:23:22 +03:00
|
|
|
*
|
2001-09-26 04:40:45 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-07 04:23:22 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 04:40:45 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-26 04:40:45 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-26 04:40:45 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 04:40:45 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 04:40:45 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-07 04:23:22 +03:00
|
|
|
|
|
|
|
#ifndef nsIUnicodeDecoder_h___
|
|
|
|
#define nsIUnicodeDecoder_h___
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
|
|
|
|
// Interface ID for our Unicode Decoder interface
|
2009-02-16 15:22:47 +03:00
|
|
|
// {25359602-FC70-4d13-A9AB-8086D3827C0D}
|
2000-03-11 06:08:04 +03:00
|
|
|
//NS_DECLARE_ID(kIUnicodeDecoderIID,
|
2009-02-16 15:22:47 +03:00
|
|
|
// 0x25359602, 0xfc70, 0x4d13, 0xa9, 0xab, 0x80, 0x86, 0xd3, 0x82, 0x7c, 0xd);
|
1999-01-07 04:23:22 +03:00
|
|
|
|
1999-07-26 21:01:11 +04:00
|
|
|
#define NS_IUNICODEDECODER_IID \
|
2009-02-16 15:22:47 +03:00
|
|
|
{ 0x25359602, 0xfc70, 0x4d13, \
|
|
|
|
{ 0xa9, 0xab, 0x80, 0x86, 0xd3, 0x82, 0x7c, 0xd }}
|
1999-07-26 21:01:11 +04:00
|
|
|
|
1999-03-19 01:27:11 +03:00
|
|
|
// XXX deprecated
|
|
|
|
/*---------- BEGIN DEPRECATED */
|
1999-01-07 04:23:22 +03:00
|
|
|
#define NS_EXACT_LENGTH \
|
1999-01-27 21:02:58 +03:00
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 11)
|
|
|
|
|
1999-01-07 04:23:22 +03:00
|
|
|
#define NS_PARTIAL_MORE_INPUT \
|
1999-01-27 21:02:58 +03:00
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 12)
|
|
|
|
|
1999-01-07 04:23:22 +03:00
|
|
|
#define NS_PARTIAL_MORE_OUTPUT \
|
1999-01-27 21:02:58 +03:00
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 13)
|
|
|
|
|
1999-01-07 04:23:22 +03:00
|
|
|
#define NS_ERROR_ILLEGAL_INPUT \
|
1999-01-27 21:02:58 +03:00
|
|
|
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 14)
|
1999-03-19 01:27:11 +03:00
|
|
|
/*---------- END DEPRECATED */
|
|
|
|
|
|
|
|
// XXX make us hex! (same digits though)
|
|
|
|
#define NS_OK_UDEC_EXACTLENGTH \
|
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 11)
|
|
|
|
|
|
|
|
#define NS_OK_UDEC_MOREINPUT \
|
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 12)
|
|
|
|
|
|
|
|
#define NS_OK_UDEC_MOREOUTPUT \
|
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 13)
|
|
|
|
|
|
|
|
#define NS_ERROR_UDEC_ILLEGALINPUT \
|
|
|
|
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 14)
|
1999-01-07 04:23:22 +03:00
|
|
|
|
2004-04-13 05:12:18 +04:00
|
|
|
#define NS_OK_UDEC_NOBOMFOUND \
|
|
|
|
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 14)
|
|
|
|
|
1999-05-11 02:22:01 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
#define NS_UNICODEDECODER_CONTRACTID_BASE "@mozilla.org/intl/unicode/decoder;1?charset="
|
1999-05-11 02:22:01 +04:00
|
|
|
|
1999-01-07 04:23:22 +03:00
|
|
|
/**
|
|
|
|
* Interface for a Converter from a Charset into Unicode.
|
|
|
|
*
|
|
|
|
* @created 23/Nov/1998
|
|
|
|
* @author Catalin Rotaru [CATA]
|
|
|
|
*/
|
|
|
|
class nsIUnicodeDecoder : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IUNICODEDECODER_IID)
|
1999-01-07 04:23:22 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kOnError_Recover, // on an error, recover and continue
|
1999-02-04 01:57:36 +03:00
|
|
|
kOnError_Signal // on an error, stop and signal
|
1999-01-07 04:23:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
1999-01-27 21:02:58 +03:00
|
|
|
* Converts the data from one Charset to Unicode.
|
1999-01-07 04:23:22 +03:00
|
|
|
*
|
1999-01-27 21:02:58 +03:00
|
|
|
* About the byte ordering:
|
|
|
|
* - For input, if the converter cares (that depends of the charset, for
|
|
|
|
* example a singlebyte will ignore the byte ordering) it should assume
|
|
|
|
* network order. If necessary and requested, we can add a method
|
|
|
|
* SetInputByteOrder() so that the reverse order can be used, too. That
|
|
|
|
* method would have as default the assumed network order.
|
1999-01-07 04:23:22 +03:00
|
|
|
* - The output stream is Unicode, having the byte order which is internal
|
1999-01-27 21:02:58 +03:00
|
|
|
* for the machine on which the converter is running on.
|
|
|
|
*
|
|
|
|
* Unless there is not enough output space, this method must consume all the
|
|
|
|
* available input data! The eventual incomplete final character data will be
|
|
|
|
* stored internally in the converter and used when the method is called
|
|
|
|
* again for continuing the conversion. This way, the caller will not have to
|
|
|
|
* worry about managing incomplete input data by mergeing it with the next
|
|
|
|
* buffer.
|
1999-01-07 04:23:22 +03:00
|
|
|
*
|
1999-09-02 01:44:39 +04:00
|
|
|
* Error conditions:
|
|
|
|
* If the read value does not belong to this character set, one should
|
|
|
|
* replace it with the Unicode special 0xFFFD. When an actual input error is
|
|
|
|
* encountered, like a format error, the converter stop and return error.
|
2010-04-16 14:52:06 +04:00
|
|
|
* However, we should keep in mind that we need to be lax in decoding. When
|
|
|
|
* a decoding error is returned to the caller, it is the caller's
|
2010-07-26 23:11:09 +04:00
|
|
|
* responsibility to advance over the bad byte (unless aSrcLength is -1 in
|
|
|
|
* which case the caller should call the decoder with 0 offset again) and
|
|
|
|
* reset the decoder before trying to call the decoder again.
|
1999-02-12 22:24:08 +03:00
|
|
|
*
|
1999-09-02 01:44:39 +04:00
|
|
|
* Converter required behavior:
|
|
|
|
* In this order: when output space is full - return right away. When input
|
|
|
|
* data is wrong, return input pointer right after the wrong byte. When
|
|
|
|
* partial input, it will be consumed and cached. All the time input pointer
|
|
|
|
* will show how much was actually consumed and how much was actually
|
|
|
|
* written.
|
1999-02-12 22:24:08 +03:00
|
|
|
*
|
1999-09-02 01:44:39 +04:00
|
|
|
* @param aSrc [IN] the source data buffer
|
|
|
|
* @param aSrcLength [IN/OUT] the length of source data buffer; after
|
2010-07-26 23:11:09 +04:00
|
|
|
* conversion will contain the number of bytes read or
|
|
|
|
* -1 on error to indicate that the caller should re-push
|
|
|
|
* the same buffer after resetting the decoder
|
1999-01-27 21:02:58 +03:00
|
|
|
* @param aDest [OUT] the destination data buffer
|
|
|
|
* @param aDestLength [IN/OUT] the length of the destination data buffer;
|
|
|
|
* after conversion will contain the number of Unicode
|
|
|
|
* characters written
|
1999-01-07 04:23:22 +03:00
|
|
|
* @return NS_PARTIAL_MORE_INPUT if only a partial conversion was
|
|
|
|
* done; more input is needed to continue
|
|
|
|
* NS_PARTIAL_MORE_OUTPUT if only a partial conversion
|
|
|
|
* was done; more output space is needed to continue
|
|
|
|
* NS_ERROR_ILLEGAL_INPUT if an illegal input sequence
|
2010-04-16 14:52:06 +04:00
|
|
|
* was encountered and the behavior was set to "signal";
|
|
|
|
* the caller must skip over one byte, reset the decoder
|
|
|
|
* and retry.
|
1999-01-07 04:23:22 +03:00
|
|
|
*/
|
1999-09-02 01:44:39 +04:00
|
|
|
NS_IMETHOD Convert(const char * aSrc, PRInt32 * aSrcLength,
|
|
|
|
PRUnichar * aDest, PRInt32 * aDestLength) = 0;
|
1999-01-07 04:23:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a quick estimation of the size of the buffer needed to hold the
|
1999-02-12 22:24:08 +03:00
|
|
|
* converted data. Remember: this estimation is >= with the actual size of
|
|
|
|
* the buffer needed. It will be computed for the "worst case"
|
|
|
|
*
|
1999-01-07 04:23:22 +03:00
|
|
|
* @param aSrc [IN] the source data buffer
|
|
|
|
* @param aSrcLength [IN] the length of source data buffer
|
1999-01-27 21:02:58 +03:00
|
|
|
* @param aDestLength [OUT] the needed size of the destination buffer
|
1999-01-07 04:23:22 +03:00
|
|
|
* @return NS_EXACT_LENGTH if an exact length was computed
|
1999-02-12 22:24:08 +03:00
|
|
|
* NS_OK is all we have is an approximation
|
1999-01-07 04:23:22 +03:00
|
|
|
*/
|
1999-09-02 01:44:39 +04:00
|
|
|
NS_IMETHOD GetMaxLength(const char * aSrc, PRInt32 aSrcLength,
|
|
|
|
PRInt32 * aDestLength) = 0;
|
1999-01-07 04:23:22 +03:00
|
|
|
|
|
|
|
/**
|
1999-01-27 21:02:58 +03:00
|
|
|
* Resets the charset converter so it may be recycled for a completely
|
|
|
|
* different and urelated buffer of data.
|
1999-01-07 04:23:22 +03:00
|
|
|
*/
|
|
|
|
NS_IMETHOD Reset() = 0;
|
2009-02-16 15:22:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify what to do when a character cannot be mapped into unicode
|
|
|
|
*
|
|
|
|
* @param aBehavior [IN] the desired behavior
|
|
|
|
* @see kOnError_Recover
|
|
|
|
* @see kOnError_Signal
|
|
|
|
*/
|
|
|
|
virtual void SetInputErrorBehavior(PRInt32 aBehavior) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return the UNICODE character for unmapped character
|
|
|
|
*/
|
|
|
|
virtual PRUnichar GetCharacterForUnMapped() = 0;
|
1999-01-07 04:23:22 +03:00
|
|
|
};
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIUnicodeDecoder, NS_IUNICODEDECODER_IID)
|
|
|
|
|
1999-01-07 04:23:22 +03:00
|
|
|
#endif /* nsIUnicodeDecoder_h___ */
|