00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as 00002 * applicable. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_XLATE_H 00018 #define APR_XLATE_H 00019 00020 #include "apu.h" 00021 #include "apr_pools.h" 00022 #include "apr_errno.h" 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif /* __cplusplus */ 00027 00028 /** 00029 * @file apr_xlate.h 00030 * @brief APR I18N translation library 00031 */ 00032 00033 /** 00034 * @defgroup APR_XLATE I18N translation library 00035 * @ingroup APR 00036 * @{ 00037 */ 00038 /** Opaque translation buffer */ 00039 typedef struct apr_xlate_t apr_xlate_t; 00040 00041 /** 00042 * Set up for converting text from one charset to another. 00043 * @param convset The handle to be filled in by this function 00044 * @param topage The name of the target charset 00045 * @param frompage The name of the source charset 00046 * @param pool The pool to use 00047 * @remark 00048 * Specify APR_DEFAULT_CHARSET for one of the charset 00049 * names to indicate the charset of the source code at 00050 * compile time. This is useful if there are literal 00051 * strings in the source code which must be translated 00052 * according to the charset of the source code. 00053 * APR_DEFAULT_CHARSET is not useful if the source code 00054 * of the caller was not encoded in the same charset as 00055 * APR at compile time. 00056 * 00057 * @remark 00058 * Specify APR_LOCALE_CHARSET for one of the charset 00059 * names to indicate the charset of the current locale. 00060 * 00061 * @remark 00062 * Return APR_EINVAL if unable to procure a convset, or APR_ENOTIMPL 00063 * if charset transcoding is not available in this instance of 00064 * apr-util at all (i.e., APR_HAS_XLATE is undefined). 00065 */ 00066 APU_DECLARE(apr_status_t) apr_xlate_open(apr_xlate_t **convset, 00067 const char *topage, 00068 const char *frompage, 00069 apr_pool_t *pool); 00070 00071 /** 00072 * This is to indicate the charset of the sourcecode at compile time 00073 * names to indicate the charset of the source code at 00074 * compile time. This is useful if there are literal 00075 * strings in the source code which must be translated 00076 * according to the charset of the source code. 00077 */ 00078 #define APR_DEFAULT_CHARSET (const char *)0 00079 /** 00080 * To indicate charset names of the current locale 00081 */ 00082 #define APR_LOCALE_CHARSET (const char *)1 00083 00084 /** 00085 * Find out whether or not the specified conversion is single-byte-only. 00086 * @param convset The handle allocated by apr_xlate_open, specifying the 00087 * parameters of conversion 00088 * @param onoff Output: whether or not the conversion is single-byte-only 00089 * @remark 00090 * Return APR_ENOTIMPL if charset transcoding is not available 00091 * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined). 00092 */ 00093 APU_DECLARE(apr_status_t) apr_xlate_sb_get(apr_xlate_t *convset, int *onoff); 00094 00095 /** @deprecated @see apr_xlate_sb_get */ 00096 APU_DECLARE(apr_status_t) apr_xlate_get_sb(apr_xlate_t *convset, int *onoff); 00097 00098 /** 00099 * Convert a buffer of text from one codepage to another. 00100 * @param convset The handle allocated by apr_xlate_open, specifying 00101 * the parameters of conversion 00102 * @param inbuf The address of the source buffer 00103 * @param inbytes_left Input: the amount of input data to be translated 00104 * Output: the amount of input data not yet translated 00105 * @param outbuf The address of the destination buffer 00106 * @param outbytes_left Input: the size of the output buffer 00107 * Output: the amount of the output buffer not yet used 00108 * @remark 00109 * Return APR_ENOTIMPL if charset transcoding is not available 00110 * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined). 00111 */ 00112 APU_DECLARE(apr_status_t) apr_xlate_conv_buffer(apr_xlate_t *convset, 00113 const char *inbuf, 00114 apr_size_t *inbytes_left, 00115 char *outbuf, 00116 apr_size_t *outbytes_left); 00117 00118 /* @see apr_file_io.h the comment in apr_file_io.h about this hack */ 00119 #ifdef APR_NOT_DONE_YET 00120 /** 00121 * The purpose of apr_xlate_conv_char is to translate one character 00122 * at a time. This needs to be written carefully so that it works 00123 * with double-byte character sets. 00124 * @param convset The handle allocated by apr_xlate_open, specifying the 00125 * parameters of conversion 00126 * @param inchar The character to convert 00127 * @param outchar The converted character 00128 */ 00129 APU_DECLARE(apr_status_t) apr_xlate_conv_char(apr_xlate_t *convset, 00130 char inchar, char outchar); 00131 #endif 00132 00133 /** 00134 * Convert a single-byte character from one charset to another. 00135 * @param convset The handle allocated by apr_xlate_open, specifying the 00136 * parameters of conversion 00137 * @param inchar The single-byte character to convert. 00138 * @warning This only works when converting between single-byte character sets. 00139 * -1 will be returned if the conversion can't be performed. 00140 */ 00141 APU_DECLARE(apr_int32_t) apr_xlate_conv_byte(apr_xlate_t *convset, 00142 unsigned char inchar); 00143 00144 /** 00145 * Close a codepage translation handle. 00146 * @param convset The codepage translation handle to close 00147 * @remark 00148 * Return APR_ENOTIMPL if charset transcoding is not available 00149 * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined). 00150 */ 00151 APU_DECLARE(apr_status_t) apr_xlate_close(apr_xlate_t *convset); 00152 00153 /** @} */ 00154 #ifdef __cplusplus 00155 } 00156 #endif 00157 00158 #endif /* ! APR_XLATE_H */