Skip to content

Commit 67525ed

Browse files
committed
Finish NLS Translate language maps.
修改: CMakeLists.txt 修改: ChangeLog 修改: include/cppp/reiconv.hpp.in 新文件: lang/en_US.langmap 新文件: lang/zh_CN.langmap
1 parent 1fbf56f commit 67525ed

File tree

5 files changed

+950
-83
lines changed

5 files changed

+950
-83
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ else()
6262
set(DLL_VARIABLE "")
6363
endif()
6464
configure_file("${srcdir}/include/cppp/reiconv.hpp.in" "${output_includedir}/cppp/reiconv.hpp.inst")
65+
cppp_nls_autotranslate("${output_includedir}/cppp/reiconv.hpp.inst" "${srcdir}/lang")
6566

6667
# Add includes
6768
include_directories("${srcdir}/lib")

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2023-07-28 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
2+
3+
Finish NLS Translate language maps (en_US, zh_CN).
4+
Add Doxygen notes for 'cppp/reiconv.hpp'.
5+
16
2023-07-19 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
27

38
Fix encode()'s EILSEQ bug.

include/cppp/reiconv.hpp.in

Lines changed: 177 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* @file cppp/reiconv.hpp
3+
* @author ChenPi11
4+
* @brief C++ Plus base definitions
5+
* @version 2.0.1
6+
* @date 2023-7-28
7+
* @copyright Copyright (C) 1999-2023 Free Software Foundation, Inc.
8+
*/
19
/* Copyright (C) 1999-2023 Free Software Foundation, Inc.
210
This file is part of the cppp-reiconv library.
311

@@ -36,29 +44,50 @@ extern "C++"
3644
{
3745
namespace cppp{namespace base{namespace reiconv
3846
{
39-
extern @DLL_VARIABLE@ int reiconv_version; /* Version info */
47+
/**
48+
* @brief Version infomation. (major<<8) + minor
49+
*/
50+
extern @DLL_VARIABLE@ int reiconv_version;
4051

4152
#undef iconv_t
42-
/* Identifier for conversion method from one codeset to another. */
53+
/**
54+
* @typedef void*
55+
* @brief Identifier for conversion method from one codeset to another.
56+
*/
4357
typedef void* iconv_t;
4458

4559
#undef iconv_open
46-
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
47-
encoding ‘tocode’. */
60+
/**
61+
* @brief Allocates descriptor for code conversion from encoding 'fromcode' to encoding 'tocode'.
62+
* @param tocode Target encoding.
63+
* @param fromcode From encoding.
64+
* @return Allocated iconv conversation buffer's pointer.
65+
*/
4866
extern @DLL_VARIABLE@ iconv_t iconv_open (const char* tocode, const char* fromcode);
4967

5068
#undef iconv
51-
/* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
52-
starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
53-
‘*outbuf’.
54-
Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
55-
Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
56-
extern @DLL_VARIABLE@ size_t iconv (iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
69+
/**
70+
* @brief Converts, using conversion descriptor 'cd', at most '*inbytesleft' bytes starting at '*inbuf', writing at most '*outbytesleft' bytes starting at '*outbuf'.
71+
* @attention Decrements '*inbytesleft' and increments '*inbuf' by the same amount.
72+
* @attention Decrements '*outbytesleft' and increments '*outbuf' by the same amount.
73+
* @param cd Conversion descriptor.
74+
* @param inbuf Input buffer.
75+
* @param inbytesleft Input bytes left.
76+
* @param outbuf Output buffer.
77+
* @param outbytesleft Output bytes left.
78+
* @return Number of converted characters (excluding terminators, -1 means error).
79+
*/
80+
extern @DLL_VARIABLE@ size_t iconv (iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft);
5781

5882
#undef iconv_close
59-
/* Frees resources allocated for conversion descriptor ‘cd’. */
83+
/**
84+
* @brief Frees resources allocated for conversion descriptor 'cd'.
85+
* @param cd Conversion descriptor you want to close.
86+
* @return Operation status. (-1 means error, 0 means success).
87+
*/
6088
extern @DLL_VARIABLE@ int iconv_close (iconv_t cd);
6189

90+
// We will remove this typedef in the next commit, because function 'iconv_open_into was removed'.
6291
/* A type that holds all memory needed by a conversion descriptor.
6392
A pointer to such an object can be used as an iconv_t. */
6493
typedef struct
@@ -67,66 +96,90 @@ extern "C++"
6796
mbstate_t dummy2;
6897
} iconv_allocation_t;
6998

70-
/* Control of attributes. */
99+
/**
100+
* @brief Control of attributes.
101+
* @param cd Conversion descriptor.
102+
* @param request Attribute request id.
103+
* @param argument Attribute argument.
104+
* @return Operation status (>=0 means success, <0 means error).
105+
*/
71106
extern @DLL_VARIABLE@ int iconvctl (iconv_t cd, int request, void* argument);
72107

73-
/* Hook performed after every successful conversion of a Unicode character. */
108+
/**
109+
* @typedef void (*) (unsigned int, void*)
110+
* @brief Hook performed after every successful conversion of a Unicode character.
111+
*/
74112
typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
75-
/* Hook performed after every successful conversion of a wide character. */
113+
/**
114+
* @typedef void (*) (wchar_t, void*)
115+
* @brief Hook performed after every successful conversion of a wide character.
116+
*/
76117
typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
77-
/* Set of hooks. */
118+
/**
119+
* @brief Set of hooks.
120+
*/
78121
struct iconv_hooks
79122
{
80123
iconv_unicode_char_hook uc_hook;
81124
iconv_wide_char_hook wc_hook;
82125
void* data;
83126
};
84127

85-
/* Fallback function. Invoked when a small number of bytes could not be
86-
converted to a Unicode character. This function should process all
87-
bytes from inbuf and may produce replacement Unicode characters by calling
88-
the write_replacement callback repeatedly. */
128+
/**
129+
* @brief Fallback function. Invoked when a small number of bytes could not be
130+
* converted to a Unicode character. This function should process all
131+
* bytes from inbuf and may produce replacement Unicode characters by calling
132+
* the write_replacement callback repeatedly.
133+
*/
89134
typedef void (*iconv_unicode_mb_to_uc_fallback)
90135
(const char* inbuf, size_t inbufsize,
91136
void (*write_replacement) (const unsigned int *buf, size_t buflen,
92137
void* callback_arg),
93138
void* callback_arg,
94139
void* data);
95140

96-
/* Fallback function. Invoked when a Unicode character could not be converted
97-
to the target encoding. This function should process the character and
98-
may produce replacement bytes (in the target encoding) by calling the
99-
write_replacement callback repeatedly. */
141+
/**
142+
* @brief Fallback function. Invoked when a Unicode character could not be converted
143+
* to the target encoding. This function should process the character and
144+
* may produce replacement bytes (in the target encoding) by calling the
145+
* write_replacement callback repeatedly.
146+
*/
100147
typedef void (*iconv_unicode_uc_to_mb_fallback)
101148
(unsigned int code,
102149
void (*write_replacement) (const char *buf, size_t buflen,
103150
void* callback_arg),
104151
void* callback_arg,
105152
void* data);
106153

107-
/* Fallback function. Invoked when a number of bytes could not be converted to
108-
a wide character. This function should process all bytes from inbuf and may
109-
produce replacement wide characters by calling the write_replacement
110-
callback repeatedly. */
154+
/**
155+
* @brief Fallback function. Invoked when a number of bytes could not be converted to
156+
* a wide character. This function should process all bytes from inbuf and may
157+
* produce replacement wide characters by calling the write_replacement
158+
* callback repeatedly.
159+
*/
111160
typedef void (*iconv_wchar_mb_to_wc_fallback)
112161
(const char* inbuf, size_t inbufsize,
113162
void (*write_replacement) (const wchar_t *buf, size_t buflen,
114163
void* callback_arg),
115164
void* callback_arg,
116165
void* data);
117166

118-
/* Fallback function. Invoked when a wide character could not be converted to
119-
the target encoding. This function should process the character and may
120-
produce replacement bytes (in the target encoding) by calling the
121-
write_replacement callback repeatedly. */
167+
/**
168+
* @brief Fallback function. Invoked when a wide character could not be converted to
169+
* the target encoding. This function should process the character and may
170+
* produce replacement bytes (in the target encoding) by calling the
171+
* write_replacement callback repeatedly.
172+
*/
122173
typedef void (*iconv_wchar_wc_to_mb_fallback)
123174
(wchar_t code,
124175
void (*write_replacement) (const char *buf, size_t buflen,
125176
void* callback_arg),
126177
void* callback_arg,
127178
void* data);
128179

129-
/* Set of fallbacks. */
180+
/**
181+
* @brief Set of fallbacks.
182+
*/
130183
struct iconv_fallbacks
131184
{
132185
iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
@@ -136,65 +189,106 @@ extern "C++"
136189
void* data;
137190
};
138191

139-
/* Surfaces.
140-
The concept of surfaces is described in the 'recode' manual. */
192+
/**
193+
* @brief Surfaces. The concept of surfaces is described in the 'recode' manual.
194+
*/
141195
constexpr int ICONV_SURFACE_NONE = 0;
142-
/* In EBCDIC encodings, 0x15 (which encodes the "newline function", see the
143-
Unicode standard, chapter 5) maps to U+000A instead of U+0085. This is
144-
for interoperability with C programs and Unix environments on z/OS. */
145-
constexpr int ICONV_SURFACE_EBCDIC_ZOS_UNIX = 1;////////////
146-
147-
/* Requests for iconvctl. */
148-
constexpr int ICONV_TRIVIALP = 0; /* int *argument */
149-
constexpr int ICONV_GET_DISCARD_ILSEQ = 3; /* int *argument */
150-
constexpr int ICONV_SET_DISCARD_ILSEQ = 4; /* const int *argument */
151-
constexpr int ICONV_SET_HOOKS = 5; /* const struct iconv_hooks *argument */
152-
constexpr int ICONV_SET_FALLBACKS = 6; /* const struct iconv_fallbacks *argument */
153-
constexpr int ICONV_GET_FROM_SURFACE = 7; /* unsigned int *argument */
154-
constexpr int ICONV_SET_FROM_SURFACE = 8; /* const unsigned int *argument */
155-
constexpr int ICONV_GET_TO_SURFACE = 9; /* unsigned int *argument */
156-
constexpr int ICONV_SET_TO_SURFACE = 10; /* const unsigned int *argument */
157-
158-
/* Listing of locale independent encodings. */
196+
/**
197+
* @brief In EBCDIC encodings, 0x15 (which encodes the "newline function", see the
198+
* Unicode standard, chapter 5) maps to U+000A instead of U+0085. This is
199+
* for interoperability with C programs and Unix environments on z/OS.
200+
*/
201+
constexpr int ICONV_SURFACE_EBCDIC_ZOS_UNIX = 1;
202+
203+
/**
204+
* @brief Request for iconvctl.
205+
*/
206+
constexpr int ICONV_TRIVIALP = 0; /* int *argument */
207+
/**
208+
* @brief Request for iconvctl.
209+
*/
210+
constexpr int ICONV_GET_DISCARD_ILSEQ = 3; /* int *argument */
211+
/**
212+
* @brief Request for iconvctl.
213+
*/
214+
constexpr int ICONV_SET_DISCARD_ILSEQ = 4; /* const int *argument */
215+
/**
216+
* @brief Request for iconvctl.
217+
*/
218+
constexpr int ICONV_SET_HOOKS = 5; /* const struct iconv_hooks *argument */
219+
/**
220+
* @brief Request for iconvctl.
221+
*/
222+
constexpr int ICONV_SET_FALLBACKS = 6; /* const struct iconv_fallbacks *argument */
223+
/**
224+
* @brief Request for iconvctl.
225+
*/
226+
constexpr int ICONV_GET_FROM_SURFACE = 7; /* unsigned int *argument */
227+
/**
228+
* @brief Request for iconvctl.
229+
*/
230+
constexpr int ICONV_SET_FROM_SURFACE = 8; /* const unsigned int *argument */
231+
/**
232+
* @brief Request for iconvctl.
233+
*/
234+
constexpr int ICONV_GET_TO_SURFACE = 9; /* unsigned int *argument */
235+
/**
236+
* @brief Request for iconvctl.
237+
*/
238+
constexpr int ICONV_SET_TO_SURFACE = 10; /* const unsigned int *argument */
239+
240+
/**
241+
* @brief Listing of locale independent encodings.
242+
* @param do_one One encoding fallback function.
243+
* @param data Data.
244+
*/
159245
extern @DLL_VARIABLE@ void iconvlist (int (*do_one) (unsigned int namescount,
160246
const char * const * names,
161247
void* data),
162248
void* data);
163249

164-
/*
165-
* This C function converts an entire string from one encoding to another,
166-
* using iconv. Easier to use than iconv() itself, and supports autodetect
167-
* encodings on input.
168-
*
169-
* int iconv_string (const char* tocode, const char* fromcode,
170-
* const char* start, const char* end,
171-
* char** resultp, size_t* lengthp)
172-
*
173-
* Converts a memory region given in encoding FROMCODE to a new memory
174-
* region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
175-
* except that FROMCODE may be one of the values when enabled extra features
176-
* "autodetect_utf8" supports ISO-8859-1 and UTF-8
177-
* "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
178-
* "autodetect_kr" supports EUC-KR and ISO-2022-KR
179-
* The input is in the memory region between start (inclusive) and end
180-
* (exclusive). If resultp is not NULL, the output string is stored in
181-
* *resultp; malloc/realloc is used to allocate the result.
182-
*
183-
* This function does not treat zero characters specially.
184-
*
185-
* Return value: 0 if successful, otherwise -1 and errno set. Particular
186-
* errno values: EILSEQ and ENOMEM.
187-
*
188-
* Example:
189-
* const char* s = ...;
190-
* char* result = NULL;
191-
* if (iconv_string("UCS-4-INTERNAL", "GBK",
192-
* s, s+strlen(s)+1, &result, NULL) < 0)
193-
* perror("iconv_string");
194-
*
195-
*/
250+
/**
251+
* @brief Converts an entire string from one encoding to another, using iconv. Easier to use than iconv() itself, and supports autodetect encodings on input when extra features enabled.
252+
*
253+
* @note Converts a memory region given in encoding FROMCODE to a new memory
254+
* region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
255+
* except that FROMCODE may be one of the values when enabled extra features.
256+
*
257+
* @note "autodetect_utf8" supports ISO-8859-1 and UTF-8
258+
* @note "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
259+
* @note "autodetect_kr" supports EUC-KR and ISO-2022-KR
260+
* @note The input is in the memory region between start (inclusive) and end
261+
* (exclusive). If resultp is not NULL, the output string is stored in
262+
* *resultp; malloc/realloc is used to allocate the result.
263+
*
264+
* @note This function does not treat zero characters specially.
265+
*
266+
* @param tocode Target encoding.
267+
* @param fromcode From encoding.
268+
* @param start Source string start pointer.
269+
* @param end Source string end pointer.
270+
* @param resultp Result memory pointer.
271+
* @param lengthp Pointer to a variable that stores the length of the result.
272+
* @return Return 0 if successful, otherwise -1 and errno set. Particular errno values: EILSEQ and ENOMEM.
273+
*
274+
* @example
275+
* const char* s = ...;
276+
* char* result = NULL;
277+
* if (iconv_string("UCS-4-INTERNAL", "GBK",
278+
* s, s+strlen(s)+1, &result, NULL) < 0)
279+
* perror("iconv_string");
280+
*
281+
*/
196282
extern @DLL_VARIABLE@ int iconv_string (const char* tocode, const char* fromcode, const char* start, const char* end, char** resultp, size_t* lengthp);
197283

284+
/**
285+
* @brief Encode source string to another encoding.
286+
* @param from From encoding.
287+
* @param to Target encoding.
288+
* @param data Input string data.
289+
* @param ignore Ignore invalid characters.
290+
* @throw int: when conversation error, throw the 'errno', you can catch the errno for more infomation.
291+
*/
198292
inline std::vector<char> encode (std::string from, std::string to,
199293
const std::vector<char>& data, bool ignore = false)
200294
{

0 commit comments

Comments
 (0)