Skip to content

Commit 9f1d350

Browse files
committed
Move to C++.
修改: .gitignore 修改: CMakeLists.txt 修改: README 删除: config.h.in 新文件: include/cppp/reiconv.hpp.in 删除: include/iconv.h.in 删除: lib/iconv.c 新文件: lib/iconv.cpp 删除: lib/iconv_string.c 修改: tests/Makefile.in 重命名: tests/cmp.c -> tests/cmp.cpp 重命名: tests/gengb18030z.c -> tests/gengb18030z.cpp 重命名: tests/genutf8.c -> tests/genutf8.cpp 删除: tests/is-native.c 修改: tests/reiconv-test.cpp 重命名: tests/table-from.c -> tests/table-from.cpp 重命名: tests/table-to.c -> tests/table-to.cpp 重命名: tests/test-shiftseq.c -> tests/test-shiftseq.cpp 重命名: tests/test-to-wchar.c -> tests/test-to-wchar.cpp 新文件: tests/tests.cmake 重命名: tests/uniq-u.c -> tests/uniq-u.cpp
1 parent 096e806 commit 9f1d350

21 files changed

+1236
-1391
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ build/
1414
# Autopull modules
1515
/build-aux/
1616

17+
# Temp tests files.
18+
/tests/data/UTF-8.TXT

CMakeLists.txt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
cmake_minimum_required(VERSION 3.1)
2-
project(cppp-reiconv)
1+
cmake_minimum_required(VERSION 3.12)
2+
project(cppp-reiconv VERSION 2.0.0)
3+
4+
set(CMAKE_CXX_STANDARD 11)
35

46
include("${CMAKE_SOURCE_DIR}/build-aux/cmake/cppp.cmake")
57

68
check_have_visibility()
79

8-
include(TestBigEndian)
9-
10-
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
10+
set(DLL_VARIABLE "__attribute__((__visibility__(\"default\")))")
1111

12-
if(IS_BIG_ENDIAN)
13-
set(WORDS_BIGENDIAN 1)
14-
else()
15-
set(WORDS_LITTLEENDIAN 1)
16-
endif()
12+
configure_file("${srcdir}/include/cppp/reiconv.hpp.in" "${output_includedir}/cppp/reiconv.hpp")
1713

14+
# Clear DLL_VARIABLE
1815
set(DLL_VARIABLE "")
19-
20-
configure_file("${srcdir}/config.h.in" "${output_includedir}/config.h")
21-
configure_file("${srcdir}/include/iconv.h.in" "${output_includedir}/iconv.h")
16+
configure_file("${srcdir}/include/cppp/reiconv.hpp.in" "${output_includedir}/cppp/reiconv.hpp.inst")
2217

2318
include_directories("${srcdir}/lib")
2419
include_directories("${srcdir}/lib/generated")
2520
include_directories("${output_includedir}")
2621

27-
add_library(cppp-reiconv STATIC "${srcdir}/lib/iconv.c")
22+
# Add definitions
23+
add_compile_definitions(ENABLE_EXTRA=1)
24+
25+
# Add library
26+
add_library(libcppp-reiconv.shared SHARED "${srcdir}/lib/iconv.cpp")
27+
28+
# Set properties
29+
set_target_properties(libcppp-reiconv.shared PROPERTIES
30+
OUTPUT_NAME ${PROJECT_NAME}
31+
LIBRARY_OUTPUT_DIRECTORY "${output_shareddir}"
32+
ARCHIVE_OUTPUT_DIRECTORY "${output_staticddir}"
33+
VERSION ${PROJECT_VERSION} )
34+
35+
include("tests/tests.cmake")

README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ Recall that before building a package for the second time, you need to erase
128128
the traces of the first build by running "make distclean".
129129

130130
This library installs:
131-
- a library 'libiconv.so',
132-
- a header file '<iconv.h>'.
131+
- a library 'libcppp-reiconv.so',
132+
- a header file '<cppp/reiconv.hpp>'.
133133

134-
To use it, simply #include <iconv.h> and use the functions.
134+
To use it, simply #include <cppp/reiconv.hpp> and use the functions.
135135

136136
To use it in a package that uses GNU autoconf and GNU automake:
137137
- Use gnulib-tool to import the Gnulib module 'iconv'. It consists

config.h.in

Lines changed: 0 additions & 82 deletions
This file was deleted.

include/cppp/reiconv.hpp.in

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/* Copyright (C) 1999-2023 Free Software Foundation, Inc.
2+
This file is part of the cppp-reiconv library.
3+
4+
The cppp-reiconv library is free software; you can redistribute it
5+
and/or modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either version 2.1
7+
of the License, or (at your option) any later version.
8+
9+
The cppp-reiconv library is distributed in the hope that it will be
10+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with the cppp-reiconv library; see the file COPYING.
16+
If not, see <https://www.gnu.org/licenses/>. */
17+
18+
/* When installed, this file is called "cppp/reiconv.hpp". */
19+
20+
#ifndef _CPPP_REICONV_HPP
21+
#define _CPPP_REICONV_HPP
22+
23+
#include <stddef.h>
24+
#include <stdio.h>
25+
#include <time.h>
26+
#include <stddef.h>
27+
#include <errno.h>
28+
#include <wchar.h>
29+
30+
extern "C++"
31+
{
32+
namespace cppp{namespace base{namespace reiconv
33+
{
34+
extern @DLL_VARIABLE@ int reiconv_version; /* Likewise */
35+
36+
/* Define iconv_t ourselves. */
37+
#undef iconv_t
38+
typedef void* iconv_t;
39+
40+
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
41+
encoding ‘tocode’. */
42+
extern @DLL_VARIABLE@ iconv_t iconv_open (const char* tocode, const char* fromcode);
43+
44+
/* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
45+
starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
46+
‘*outbuf’.
47+
Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
48+
Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
49+
extern @DLL_VARIABLE@ size_t iconv (iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
50+
51+
/* Frees resources allocated for conversion descriptor ‘cd’. */
52+
extern @DLL_VARIABLE@ int iconv_close (iconv_t cd);
53+
54+
/* A type that holds all memory needed by a conversion descriptor.
55+
A pointer to such an object can be used as an iconv_t. */
56+
typedef struct
57+
{
58+
void* dummy1[28];
59+
mbstate_t dummy2;
60+
} iconv_allocation_t;
61+
62+
/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
63+
encoding ‘tocode’ into preallocated memory. Returns an error indicator
64+
(0 or -1 with errno set). */
65+
extern @DLL_VARIABLE@ int iconv_open_into (const char* tocode, const char* fromcode,
66+
iconv_allocation_t* resultp);
67+
68+
/* Control of attributes. */
69+
extern @DLL_VARIABLE@ int iconvctl (iconv_t cd, int request, void* argument);
70+
71+
/* Hook performed after every successful conversion of a Unicode character. */
72+
typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
73+
/* Hook performed after every successful conversion of a wide character. */
74+
typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
75+
/* Set of hooks. */
76+
struct iconv_hooks
77+
{
78+
iconv_unicode_char_hook uc_hook;
79+
iconv_wide_char_hook wc_hook;
80+
void* data;
81+
};
82+
83+
/* Fallback function. Invoked when a small number of bytes could not be
84+
converted to a Unicode character. This function should process all
85+
bytes from inbuf and may produce replacement Unicode characters by calling
86+
the write_replacement callback repeatedly. */
87+
typedef void (*iconv_unicode_mb_to_uc_fallback)
88+
(const char* inbuf, size_t inbufsize,
89+
void (*write_replacement) (const unsigned int *buf, size_t buflen,
90+
void* callback_arg),
91+
void* callback_arg,
92+
void* data);
93+
94+
/* Fallback function. Invoked when a Unicode character could not be converted
95+
to the target encoding. This function should process the character and
96+
may produce replacement bytes (in the target encoding) by calling the
97+
write_replacement callback repeatedly. */
98+
typedef void (*iconv_unicode_uc_to_mb_fallback)
99+
(unsigned int code,
100+
void (*write_replacement) (const char *buf, size_t buflen,
101+
void* callback_arg),
102+
void* callback_arg,
103+
void* data);
104+
105+
/* Fallback function. Invoked when a number of bytes could not be converted to
106+
a wide character. This function should process all bytes from inbuf and may
107+
produce replacement wide characters by calling the write_replacement
108+
callback repeatedly. */
109+
typedef void (*iconv_wchar_mb_to_wc_fallback)
110+
(const char* inbuf, size_t inbufsize,
111+
void (*write_replacement) (const wchar_t *buf, size_t buflen,
112+
void* callback_arg),
113+
void* callback_arg,
114+
void* data);
115+
116+
/* Fallback function. Invoked when a wide character could not be converted to
117+
the target encoding. This function should process the character and may
118+
produce replacement bytes (in the target encoding) by calling the
119+
write_replacement callback repeatedly. */
120+
typedef void (*iconv_wchar_wc_to_mb_fallback)
121+
(wchar_t code,
122+
void (*write_replacement) (const char *buf, size_t buflen,
123+
void* callback_arg),
124+
void* callback_arg,
125+
void* data);
126+
127+
/* Set of fallbacks. */
128+
struct iconv_fallbacks
129+
{
130+
iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
131+
iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
132+
iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
133+
iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
134+
void* data;
135+
};
136+
137+
/* Surfaces.
138+
The concept of surfaces is described in the 'recode' manual. */
139+
#define ICONV_SURFACE_NONE 0
140+
/* In EBCDIC encodings, 0x15 (which encodes the "newline function", see the
141+
Unicode standard, chapter 5) maps to U+000A instead of U+0085. This is
142+
for interoperability with C programs and Unix environments on z/OS. */
143+
#define ICONV_SURFACE_EBCDIC_ZOS_UNIX 1
144+
145+
/* Requests for iconvctl. */
146+
#define ICONV_TRIVIALP 0 /* int *argument */
147+
#define ICONV_GET_TRANSLITERATE 1 /* int *argument */
148+
#define ICONV_SET_TRANSLITERATE 2 /* const int *argument */
149+
#define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */
150+
#define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */
151+
#define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */
152+
#define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */
153+
#define ICONV_GET_FROM_SURFACE 7 /* unsigned int *argument */
154+
#define ICONV_SET_FROM_SURFACE 8 /* const unsigned int *argument */
155+
#define ICONV_GET_TO_SURFACE 9 /* unsigned int *argument */
156+
#define ICONV_SET_TO_SURFACE 10 /* const unsigned int *argument */
157+
158+
/* Listing of locale independent encodings. */
159+
extern @DLL_VARIABLE@ void iconvlist (int (*do_one) (unsigned int namescount,
160+
const char * const * names,
161+
void* data),
162+
void* data);
163+
164+
/* Canonicalize an encoding name.
165+
The result is either a canonical encoding name, or name itself. */
166+
extern @DLL_VARIABLE@ const char * iconv_canonicalize (const char * name);
167+
168+
/*
169+
* This C function converts an entire string from one encoding to another,
170+
* using iconv. Easier to use than iconv() itself, and supports autodetect
171+
* encodings on input.
172+
*
173+
* int iconv_string (const char* tocode, const char* fromcode,
174+
* const char* start, const char* end,
175+
* char** resultp, size_t* lengthp)
176+
*
177+
* Converts a memory region given in encoding FROMCODE to a new memory
178+
* region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
179+
* except that FROMCODE may be one of the values
180+
* "autodetect_utf8" supports ISO-8859-1 and UTF-8
181+
* "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
182+
* "autodetect_kr" supports EUC-KR and ISO-2022-KR
183+
* The input is in the memory region between start (inclusive) and end
184+
* (exclusive). If resultp is not NULL, the output string is stored in
185+
* *resultp; malloc/realloc is used to allocate the result.
186+
*
187+
* This function does not treat zero characters specially.
188+
*
189+
* Return value: 0 if successful, otherwise -1 and errno set. Particular
190+
* errno values: EILSEQ and ENOMEM.
191+
*
192+
* Example:
193+
* const char* s = ...;
194+
* char* result = NULL;
195+
* if (iconv_string("UCS-4-INTERNAL", "autodetect_utf8",
196+
* s, s+strlen(s)+1, &result, NULL) < 0)
197+
* perror("iconv_string");
198+
*
199+
*/
200+
extern @DLL_VARIABLE@ int iconv_string (const char* tocode, const char* fromcode, const char* start, const char* end, char** resultp, size_t* lengthp);
201+
202+
}}}
203+
}
204+
205+
#endif /* _CPPP_REICONV_HPP */

0 commit comments

Comments
 (0)