File indexing completed on 2024-06-16 04:32:44
0001 /* ***** BEGIN LICENSE BLOCK ***** 0002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 0003 * 0004 * The contents of this file are subject to the Mozilla Public License Version 0005 * 1.1 (the "License"); you may not use this file except in compliance with 0006 * the License. You may obtain a copy of the License at 0007 * http://www.mozilla.org/MPL/ 0008 * 0009 * Software distributed under the License is distributed on an "AS IS" basis, 0010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 0011 * for the specific language governing rights and limitations under the 0012 * License. 0013 * 0014 * The Original Code is Mozilla Universal charset detector code. 0015 * 0016 * The Initial Developer of the Original Code is 0017 * Netscape Communications Corporation. 0018 * Portions created by the Initial Developer are Copyright (C) 2001 0019 * the Initial Developer. All Rights Reserved. 0020 * 0021 * Contributor(s): 0022 * Kohei TAKETA <k-tak@void.in> 0023 * Jim Huang <jserv.tw@gmail.com> 0024 * 0025 * Alternatively, the contents of this file may be used under the terms of 0026 * either the GNU General Public License Version 2 or later (the "GPL"), or 0027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 0028 * in which case the provisions of the GPL or the LGPL are applicable instead 0029 * of those above. If you wish to allow use of your version of this file only 0030 * under the terms of either the GPL or the LGPL, and not to allow others to 0031 * use your version of this file under the terms of the MPL, indicate your 0032 * decision by deleting the provisions above and replace them with the notice 0033 * and other provisions required by the GPL or the LGPL. If you do not delete 0034 * the provisions above, a recipient may use your version of this file under 0035 * the terms of any one of the MPL, the GPL or the LGPL. 0036 * 0037 * ***** END LICENSE BLOCK ***** */ 0038 #ifndef ___CHARDET_H___ 0039 #define ___CHARDET_H___ 0040 0041 #include <stddef.h> 0042 0043 #define CHARDET_RESULT_OK 0 0044 #define CHARDET_RESULT_NOMEMORY (-1) 0045 #define CHARDET_RESULT_INVALID_DETECTOR (-2) 0046 0047 #define CHARDET_MAX_ENCODING_NAME 64 0048 0049 0050 typedef void* chardet_t; 0051 0052 #ifdef __cplusplus 0053 extern "C" { 0054 #endif 0055 0056 /** 0057 * Create an encoding detector. 0058 * @param pdet [out] pointer to a chardet_t variable that receives 0059 * the encoding detector handle. 0060 * @return CHARDET_RESULT_OK if succeeded. CHARDET_RESULT_NOMEMORY otherwise. 0061 */ 0062 int chardet_create(chardet_t* pdet); 0063 0064 /** 0065 * Destroy an encoding detector. 0066 * @param det [in] the encoding detector handle to be destroyed. 0067 */ 0068 void chardet_destroy(chardet_t det); 0069 0070 /** 0071 * Feed data to an encoding detector. 0072 * @param det [in] the encoding detector handle 0073 * @param data [in] data 0074 * @param len [in] length of data in bytes. 0075 * @return CHARDET_RESULT_OK if succeeded. 0076 * CHARSET_RESULT_NOMEMORY if running out of memory. 0077 * CHARDET_RESULT_INVALID_DETECTOR if det was invalid. 0078 */ 0079 int chardet_handle_data(chardet_t det, const char* data, unsigned int len); 0080 0081 /** 0082 * Notify an end of data to an encoding detector. 0083 * @param det [in] the encoding detector handle 0084 * @return CHARDET_RESULT_OK if succeeded. 0085 * CHARDET_RESULT_INVALID_DETECTOR if det was invalid. 0086 */ 0087 int chardet_data_end(chardet_t det); 0088 0089 /** 0090 * Reset an encoding detector. 0091 * @param det [in] the encoding detector handle 0092 * @return CHARDET_RESULT_OK if succeeded. 0093 * CHARDET_RESULT_INVALID_DETECTOR if det was invalid. 0094 */ 0095 int chardet_reset(chardet_t det); 0096 0097 /** 0098 * Get the name of encoding that was detected. 0099 * @param det [in] the encoding detector handle 0100 * @param namebuf [in/out] pointer to a buffer that receives the name of 0101 * detected encoding. A valid encoding name or an empty string 0102 * will be written to namebuf. If an empty strng was written, 0103 * the detector could not detect any encoding. 0104 * Written strings will always be NULL-terminated. 0105 * @param buflen [in] length of namebuf 0106 * @return CHARDET_RESULT_OK if succeeded. 0107 * CHARDET_RESULT_NOMEMORY if namebuf was too small to store 0108 * the entire encoding name. 0109 * CHARDET_RESULT_INVALID_DETECTOR if det was invalid. 0110 */ 0111 int chardet_get_charset(chardet_t det, char* namebuf, unsigned int buflen); 0112 0113 0114 #ifdef __cplusplus 0115 } 0116 #endif 0117 0118 #endif