2323 * If not, see <https://www.gnu.org/licenses/>.
2424 */
2525
26- /* When installed, this file is called "cppp/reiconv.h". */
27-
2826#pragma once
29-
3027#ifndef _CPPP_REICONV_H_
3128#define _CPPP_REICONV_H_
3229
33- #include <cppp/ encodings/reiconv.h>
30+ #include " encodings/reiconv.h"
3431
35- #include <stdbool.h>
3632#include <stddef.h>
3733
38- #define _CPPP_API
39-
4034#ifndef _CPPP_API
4135#define _CPPP_API @CPPP_API@
42- #endif
36+ #endif /* _CPPP_API */
4337
4438#if _MSC_VER >= 1600
4539#pragma execution_character_set("utf-8")
46- #endif
40+ #endif /* _MSC_VER >= 1600 */
4741
4842#ifdef __cplusplus
49- extern "C" {
50- #endif
43+ extern "C"
44+ {
45+ #endif /* __cplusplus */
5146
5247/**
5348 * @brief Version information.
@@ -86,7 +81,7 @@ extern _CPPP_API size_t reiconv_name_canonicalize(const char *name, char *outbuf
8681
8782/**
8883 * @brief Lookup an encoding by it's name.
89- * @note The return value is an encoding index that can be used with `reiconv_open_from_codepage `.
84+ * @note The return value is an encoding index that can be used with `reiconv_open_from_index `.
9085 * @note We will ignore '-' and '_', and uppercase all characters.
9186 * @param encoding The encoding name.
9287 * @return The encoding index. If the it is not found, -1 is returned.
@@ -95,7 +90,7 @@ extern _CPPP_API int reiconv_lookup_from_name(const char *encoding);
9590
9691/**
9792 * @brief Lookup an encoding by it's codepage.
98- * @note The return value is an encoding index that can be used with `reiconv_open_from_codepage `.
93+ * @note The return value is an encoding index that can be used with `reiconv_open_from_index `.
9994 * @param codepage The codepage.
10095 * @return The encoding index. If the it is not found, -1 is returned.
10196 */
@@ -106,36 +101,52 @@ extern _CPPP_API int reiconv_lookup_from_codepage(int codepage);
106101 */
107102typedef void * reiconv_t ;
108103
104+ /**
105+ * @brief Convert flags. Used for open conversion descriptor.
106+ */
107+ enum ConvertFlag
108+ {
109+ /**
110+ * @brief No flags.
111+ */
112+ REICONV_NO_FLAGS = 0 ,
113+
114+ /**
115+ * @brief Discard illegal sequences. Same as iconv(3) '//IGNORE'.
116+ */
117+ REICONV_DISCARD_ILSEQ = 1 ,
118+ };
119+
109120/**
110121 * @brief Open a conversion descriptor from encoding index.
111122 * @note The return value is a conversion descriptor.
112123 * @param fromcode The input buffer encoding's index.
113124 * @param tocode The output buffer encoding's index.
114- * @param discard_ilseq If true, we will ignore conversion errors. Same as iconv(3) '//IGNORE' .
125+ * @param flags The convert flags .
115126 * @return The conversion descriptor. Indexes MUST BE VALID or the behavior is undefined.
116127 * @note If the conversion descriptor cannot be created, returns (reiconv_t)(-1) and errno is set to ENOMEM.
117128 */
118- extern _CPPP_API reiconv_t reiconv_open_from_index (int fromcode , int tocode , bool discard_ilseq );
129+ extern _CPPP_API reiconv_t reiconv_open_from_index (int fromcode , int tocode , enum ConvertFlag flags );
119130
120131/**
121132 * @brief Open a conversion descriptor from codepage.
122133 * @note The return value is a conversion descriptor.
123134 * @param fromcode The input buffer encoding's codepage.
124135 * @param tocode The output buffer encoding's codepage.
125- * @param discard_ilseq If true, we will ignore conversion errors. Same as iconv(3) '//IGNORE' .
136+ * @param flags The convert flags .
126137 * @return The conversion descriptor. (reiconv_t)(-1) is returned if error occured with errno set.
127138 */
128- extern _CPPP_API reiconv_t reiconv_open_from_codepage (int fromcode , int tocode , bool discard_ilseq );
139+ extern _CPPP_API reiconv_t reiconv_open_from_codepage (int fromcode , int tocode , enum ConvertFlag flags );
129140
130141/**
131142 * @brief Open a conversion descriptor from encoding name.
132143 * @note The return value is a conversion descriptor.
133144 * @param fromcode The input buffer encoding's name.
134145 * @param tocode The output buffer encoding's name.
135- * @param discard_ilseq If true, we will ignore conversion errors. Same as iconv(3) '//IGNORE' .
146+ * @param flags The convert flags .
136147 * @return The conversion descriptor. (reiconv_t)(-1) is returned if error occured with errno set.
137148 */
138- extern _CPPP_API reiconv_t reiconv_open_from_name (const char * fromcode , const char * tocode , bool discard_ilseq );
149+ extern _CPPP_API reiconv_t reiconv_open_from_name (const char * fromcode , const char * tocode , enum ConvertFlag flags );
139150
140151/**
141152 * @brief Get the size of the result. -1 on error with errno set.
@@ -159,7 +170,8 @@ extern _CPPP_API size_t reiconv_result_size(reiconv_t cd, const char *start, siz
159170 * @note If the output buffer is too big, the rest of the buffer is filled with zero.
160171 * @return 0 on success, -1 on error with errno set.
161172 */
162- extern _CPPP_API int reiconv_convert_static_size (reiconv_t cd , const char * input_data , size_t input_length , char * output_data , size_t output_length );
173+ extern _CPPP_API int reiconv_convert_static_size (reiconv_t cd , const char * input_data , size_t input_length ,
174+ char * output_data , size_t output_length );
163175
164176/**
165177 * @brief Converts an string from one encoding to another.
@@ -175,7 +187,8 @@ extern _CPPP_API int reiconv_convert_static_size(reiconv_t cd, const char* input
175187 * @note The length of the result is stored in `*output_length_ptr`.
176188 * @return 0 on success, -1 on error with errno set.
177189 */
178- extern _CPPP_API int reiconv_convert (reiconv_t cd , const char * input_data , size_t input_length , char * * output_data_ptr , size_t * output_length_ptr );
190+ extern _CPPP_API int reiconv_convert (reiconv_t cd , const char * input_data , size_t input_length , char * * output_data_ptr ,
191+ size_t * output_length_ptr );
179192
180193/**
181194 * @brief Open a conversion descriptor. For iconv compatibility.
@@ -192,7 +205,8 @@ extern _CPPP_API reiconv_t reiconv_open(const char *tocode, const char *fromcode
192205 * @note Decrements `*inbytesleft` and increments `*inbuf` by the same amount.
193206 * @note Decrements `*outbytesleft` and increments `*outbuf` by the same amount.
194207 */
195- extern _CPPP_API size_t reiconv_iconv (reiconv_t cd , char * * inbuf , size_t * inbytesleft , char * * outbuf , size_t * outbytesleft );
208+ extern _CPPP_API size_t reiconv_iconv (reiconv_t cd , char * * inbuf , size_t * inbytesleft , char * * outbuf ,
209+ size_t * outbytesleft );
196210
197211/**
198212 * @brief Close a conversion descriptor. For iconv compatibility.
@@ -210,6 +224,6 @@ extern _CPPP_API const char *locale_charset();
210224
211225#ifdef __cplusplus
212226}
213- #endif
227+ #endif /* __cplusplus */
214228
215229#endif /* _CPPP_REICONV_H_ */
0 commit comments