Skip to content

Commit 92cbbd7

Browse files
committed
Add some functions, and change a feature.
1. Update doccomments in reiconv.hpp.in. 2. Add function 'int iconv_string(const iconv_t& cd, const char *start, const char *end, char **resultp, size_t *lengthp)' 3. Add function 'int iconv_string(int tocode_cp, int fromcode_cp, const char* start, const char* end, char** resultp, size_t* lengthp, bool strict=true)' 4. Update function 'encode' definion. 5. Fix some warnings in Clang. 6. Change the 'autodetect' feature of 'iconv_string' to a non extra feature. 修改: ChangeLog 修改: NEWS.md 修改: README.md 修改: include/cppp/reiconv.hpp.in 修改: lib/hkscs2001.h 修改: lib/hkscs2008.h 修改: lib/iconv.cpp
1 parent ffca294 commit 92cbbd7

File tree

7 files changed

+166
-101
lines changed

7 files changed

+166
-101
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2023-09-09 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
2+
3+
Version 2.1.0 compile failed (release failed).
4+
Update doccomments in reiconv.hpp.in.
5+
Add function 'int iconv_string(const iconv_t& cd, const char *start, const char *end, char **resultp, size_t *lengthp)'
6+
Add function 'int iconv_string(int tocode_cp, int fromcode_cp, const char* start, const char* end, char** resultp, size_t* lengthp, bool strict=true)'
7+
Update function 'encode' definion.
8+
Fix some warnings in Clang.
9+
Change the 'autodetect' feature of 'iconv_string' to a non extra feature.
10+
111
2023-09-02 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
212

313
Optimize 'iconv_open(int, int)'.

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
New in 2.1.0:
22
* Add a new function `iconv_t iconv_open(int tocode_cp, int fromcode_cp, bool strict = true);` and codepage definitions.
3+
* Add new function `int iconv_string(const iconv_t& cd, const char *start, const char *end, char **resultp, size_t *lengthp)`
4+
* Add new function `int iconv_string(int tocode_cp, int fromcode_cp, const char* start, const char* end, char** resultp, size_t* lengthp, bool strict=true)`
5+
* Update function 'encode' definion.
36
* Add CTest on Windows support.
47
* Remove 'iconv_allocation_t';
58
* Fully remove wchar support.
69
* Fix some bugs.
710
* Add header comments NLS support.
811
* Add Doxygen comments for 'cppp/reiconv.hpp'.
12+
* Change the 'autodetect' feature of 'iconv_string' to a non extra feature.
913

1014
New in 2.0.0:
1115
* Redist 'GNU LIBICONV' to 'cppp-reiconv'.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ cmake --build . --config=Release
117117
cmake --install .
118118
```
119119

120-
When use full build, extra encodings and features will be enabled.
121-
iconv string will suport autodetect input encoding.
120+
When use full build, extra encodings will be enabled.
122121

123122
+ Build with test suite
124123
```shell

include/cppp/reiconv.hpp.in

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file cppp/reiconv.hpp
33
* @author ChenPi11
4-
* @brief C++ Plus base definitions
4+
* @brief C++ Plus cppp-reiconv package.
55
* @version 2.1.0
66
* @date 2023-7-28
77
* @copyright Copyright (C) 1999-2023 Free Software Foundation, Inc.
@@ -28,14 +28,14 @@
2828
#ifndef _CPPP_REICONV_HPP
2929
#define _CPPP_REICONV_HPP
3030

31-
#ifdef _MSC_VER
31+
#if _MSC_VER >= 1600
3232
/* Use UTF-8 to decode this file. */
3333
#pragma execution_character_set("utf-8")
3434
#endif
3535

36-
#include <errno.h>
3736
#include <exception>
3837
#include <iostream>
38+
#include <errno.h>
3939
#include <time.h>
4040
#include <vector>
4141
#include <wchar.h>
@@ -216,7 +216,20 @@ extern "C++"
216216
void *data);
217217

218218
/**
219-
* @brief Converts an entire string from one encoding to another, using iconv. Easier to use than iconv() itself,
219+
* @brief Converts an entire string from one encoding to another, using iconv. Easier to use than iconv() itself.
220+
* @note This function does not treat zero characters specially.
221+
* @param cd Conversion descriptor.
222+
* @param start Source string start pointer.
223+
* @param end Source string end pointer.
224+
* @param resultp Result memory pointer.
225+
* @param lengthp Pointer to a variable that stores the length of the result.
226+
* @return Return 0 if successful, otherwise return errno and errno set. Particular errno values are EILSEQ and ENOMEM.
227+
*/
228+
extern @DLL_VARIABLE@ int iconv_string(const iconv_t& cd, const char *start,
229+
const char *end, char **resultp, size_t *lengthp);
230+
231+
/**
232+
* @brief Converts an entire string from one encoding to another,
220233
* and supports autodetect encodings on input when extra features enabled.
221234
*
222235
* @note Converts a memory region given in encoding FROMCODE to a new memory
@@ -231,25 +244,47 @@ extern "C++"
231244
* *resultp; malloc/realloc is used to allocate the result.
232245
*
233246
* @note This function does not treat zero characters specially.
234-
*
235247
* @param tocode Target encoding.
236248
* @param fromcode From encoding.
237249
* @param start Source string start pointer.
238250
* @param end Source string end pointer.
239251
* @param resultp Result memory pointer.
240252
* @param lengthp Pointer to a variable that stores the length of the result.
241-
* @return Return 0 if successful, otherwise -1 and errno set. Particular errno values: EILSEQ and ENOMEM.
253+
* @return Return 0 if successful, otherwise return errno and errno set. Particular errno values: EILSEQ and ENOMEM.
242254
*
243255
* @example
244256
* const char* s = ...;
245257
* char* result = NULL;
246258
* if (iconv_string("UCS-4-INTERNAL", "GBK",
247-
* s, s+strlen(s)+1, &result, NULL) < 0)
259+
* s, s+strlen(s)+1, &result, NULL) != 0)
248260
* perror("iconv_string");
249261
*
250262
*/
251-
extern @DLL_VARIABLE@ int iconv_string(const char *tocode, const char *fromcode, const char *start,
252-
const char *end, char **resultp, size_t *lengthp);
263+
extern @DLL_VARIABLE@ int iconv_string(const char* tocode, const char* fromcode, const char* start,
264+
const char* end, char** resultp, size_t* lengthp);
265+
266+
/**
267+
* @brief Converts an entire string from one encoding to another.
268+
* @note This function does not treat zero characters specially.
269+
* @param tocode_cp Target encoding codepage.
270+
* @param fromcode_cp From encoding codepage.
271+
* @param start Source string start pointer.
272+
* @param end Source string end pointer.
273+
* @param resultp Result memory pointer.
274+
* @param lengthp Pointer to a variable that stores the length of the result.
275+
* @param strict Strict mode, if false, will ignore the invalid characters.
276+
* @return Return 0 if successful, otherwise return errno and errno set. Particular errno values: EILSEQ and ENOMEM.
277+
*
278+
* @example
279+
* const char* s = ...;
280+
* char* result = NULL;
281+
* if (iconv_string(65001, 936,
282+
* s, s+strlen(s)+1, &result, NULL) != 0)
283+
* perror("iconv_string");
284+
*
285+
*/
286+
extern @DLL_VARIABLE@ int iconv_string(int tocode_cp, int fromcode_cp, const char* start,
287+
const char* end, char** resultp, size_t* lengthp, bool strict=true);
253288

254289
/**
255290
* @brief Encode source string to another encoding.
@@ -259,7 +294,7 @@ extern "C++"
259294
* @param ignore Ignore invalid characters.
260295
* @throw int: when conversation error, throw the 'errno', you can catch the errno for more infomation.
261296
*/
262-
inline std::vector<char> encode(std::string from, std::string to, const std::vector<char> &data,
297+
inline std::vector<char> encode(const std::string& from, const std::string& to, const std::vector<char>& data,
263298
bool ignore = false)
264299
{
265300
char *result = NULL;

lib/hkscs2001.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int
5959
hkscs2001_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
6060
{
6161
unsigned char c1 = s[0];
62-
if ((c1 == (unsigned char)0x8c)) {
62+
if (c1 == (unsigned char)0x8c) {
6363
if (n >= 2) {
6464
unsigned char c2 = s[1];
6565
if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {

lib/hkscs2008.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int
5555
hkscs2008_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, size_t n)
5656
{
5757
unsigned char c1 = s[0];
58-
if ((c1 == (unsigned char)0x87)) {
58+
if (c1 == (unsigned char)0x87) {
5959
if (n >= 2) {
6060
unsigned char c2 = s[1];
6161
if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {

0 commit comments

Comments
 (0)