Skip to content

Commit 2d9defb

Browse files
committed
Update documents.
1 parent 6f8a1ba commit 2d9defb

File tree

8 files changed

+1111
-13
lines changed

8 files changed

+1111
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See [docs/](docs/README.md) for full requirements list.
1414

1515
**We are planning to use [Rubisco](https://github.com/cppp-project/rubisco) to manage submodules. But it is not ready yet. So we don not use git submodule for now. Please clone them manually.**
1616

17-
Use the following command to fetch source code:
17+
Use the following command to fetch source code, or download source package:
1818

1919
```shell
2020
git clone https://github.com/cppp-project/cppp-reiconv
@@ -175,7 +175,7 @@ This library installs:
175175

176176
+ A shared library `libcppp-reiconv`.
177177
+ A static library `libcppp-reiconv.static`.
178-
+ Header files
178+
+ Header files.
179179

180180
```text
181181
include

README.zh_CN.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# cppp-reiconv
2+
3+
<img alt="C+++" src="https://avatars.githubusercontent.com/u/130828670" width="10%">
4+
5+
一个基于 GNU LIBICONV 的字符集转换库。**支持 C 和 C++20。**
6+
7+
如果你的 C++ 标准低于 C++20,需要修改一些代码。
8+
9+
## 构建
10+
11+
此库需要 `build-aux``cppp-platform` 两个子模块用于构建。
12+
13+
参见 [docs/](docs/zh_CN/README.md) 获取完整依赖列表。
14+
15+
**我们正在使用 [Rubisco](https://github.com/cppp-project/rubisco) 管理子模块。但它还没有准备好。所以我们现在不使用 git submodule。请手动克隆它们。**
16+
17+
使用以下命令克隆源代码,或者直接下载源码包:
18+
19+
```shell
20+
git clone https://github.com/cppp-project/cppp-reiconv
21+
cd cppp-reiconv
22+
git clone https://github.com/cppp-project/build-aux --depth 1
23+
git clone https://github.com/cppp-project/rubisco --depth 1
24+
```
25+
26+
使用以下命令构建和安装:
27+
28+
```shell
29+
mkdir build
30+
cd build
31+
cmake .. -DCMAKE_BUILD_TYPE=[[BUILD_TYPE]] -DCMAKE_INSTALL_PREFIX=[[PREFIX]]
32+
cmake --build . --config=[[BUILD_TYPE]]
33+
cmake --install . --config=[[BUILD_TYPE]]
34+
```
35+
36+
## 简单的用法
37+
38+
```cpp
39+
#include <cppp/reiconv.hpp>
40+
41+
#include <cstdlib>
42+
#include <iostream>
43+
44+
int main()
45+
{
46+
const std::string_view src = "\xb8\xfc\xcf\xb2\xe1\xba\xc9\xbd\xc7\xa7\xc0\xef\xd1\xa9\xa3\xac\xc8\xfd\xbe\xfc\xb9\xfd\xba\xf3\xbe\xa1\xbf\xaa\xd1\xd5\xa3\xa1";
47+
48+
std::string result = reiconv::convert("GB18030", "UTF-8", src);
49+
50+
std::cout << result << std::endl;
51+
52+
const std::string_view correct_result = "\u66f4\u559c\u5cb7\u5c71\u5343\u91cc\u96ea\uff0c\u4e09\u519b\u8fc7\u540e\u5c3d\u5f00\u989c\uff01";
53+
54+
if (result == correct_result)
55+
{
56+
std::cout << "正确!" << std::endl;
57+
}
58+
else
59+
{
60+
// 如果发生了这个,请提 issue!
61+
std::cout << "错误!" << std::endl;
62+
}
63+
64+
return EXIT_SUCCESS;
65+
}
66+
```
67+
68+
完整文档参见 [docs/](docs/zh_CN/README.md)
69+
70+
## 支持的编码
71+
72+
和 GNU LIBICONV 一样,它提供了以下编码的支持:
73+
74+
+ 欧洲语言
75+
+ ASCII, ISO-8859-{1,2,3,4,5,7,9,10,13,14,15,16},
76+
+ KOI8-R, KOI8-U, KOI8-RU,
77+
+ CP{1250,1251,1252,1253,1254,1257}, CP{850,866,1131},
78+
+ Mac{Roman,CentralEurope,Iceland,Croatian,Romania},
79+
+ Mac{Cyrillic,Ukraine,Greek,Turkish},
80+
+ Macintosh
81+
+ 闪米特诸族语言
82+
+ ISO-8859-{6,8}, CP{1255,1256}, CP862, Mac{Hebrew,Arabic}
83+
+ 日本语
84+
+ EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP, ISO-2022-JP-2, ISO-2022-JP-1,
85+
+ ISO-2022-JP-MS
86+
+ 中文
87+
+ EUC-CN, HZ, GBK, CP936, GB18030, GB18030:2022, EUC-TW, BIG5, CP950,
88+
+ BIG5-HKSCS, BIG5-HKSCS:2004, BIG5-HKSCS:2001, BIG5-HKSCS:1999,
89+
+ ISO-2022-CN, ISO-2022-CN-EXT
90+
+ 韩语
91+
+ EUC-KR, CP949, ISO-2022-KR, JOHAB
92+
+ 亚美尼亚语
93+
+ ARMSCII-8
94+
+ 格鲁吉亚语
95+
+ Georgian-Academy, Georgian-PS
96+
+ 塔吉克语
97+
+ KOI8-T
98+
+ 哈萨克语
99+
+ PT154, RK1048
100+
+ 泰语
101+
+ ISO-8859-11, TIS-620, CP874, MacThai
102+
+ 老挝语
103+
+ MuleLao-1, CP1133
104+
+ 越南语
105+
+ VISCII, TCVN, CP1258
106+
+ 平台特定
107+
+ HP-ROMAN8, NEXTSTEP
108+
+ 完整的 Unicode
109+
+ UTF-8
110+
+ UCS-2, UCS-2BE, UCS-2LE
111+
+ UCS-4, UCS-4BE, UCS-4LE
112+
+ UTF-16, UTF-16BE, UTF-16LE
113+
+ UTF-32, UTF-32BE, UTF-32LE
114+
+ UTF-7
115+
+ C99, JAVA
116+
+ 完整的 Unicode,以 'uint16_t' 或 'uint32_t' 表示
117+
+ UCS-2-INTERNAL, UCS-4-INTERNAL (具有设备依赖的字节序和对齐)
118+
119+
一些额外的编码。这些编码是 GNU LIBICONV 的额外编码。
120+
121+
+ 欧洲语言
122+
+ CP{437,737,775,852,853,855,857,858,860,861,863,865,869,1125}
123+
+ 闪米特诸族语言
124+
+ CP864
125+
+ 日本语
126+
+ EUC-JISX0213, Shift_JISX0213, ISO-2022-JP-3
127+
+ 中文
128+
+ BIG5-2003 (experimental)
129+
+ 土库曼语
130+
+ TDS565
131+
+ 平台特定
132+
+ ATARIST, RISCOS-LATIN1
133+
+ EBCDIC 兼容编码(不兼容ASCII,几乎不使用)
134+
+ 欧洲语言
135+
+ IBM-{037,273,277,278,280,282,284,285,297,423,500,870,871,875,880},
136+
+ IBM-{905,924,1025,1026,1047,1112,1122,1123,1140,1141,1142,1143},
137+
+ IBM-{1144,1145,1146,1147,1148,1149,1153,1154,1155,1156,1157,1158},
138+
+ IBM-{1165,1166,4971}
139+
+ 闪米特诸族语言
140+
+ IBM-{424,425,12712,16804}
141+
+ 波斯语
142+
+ IBM-1097
143+
+ 泰语
144+
+ IBM-{838,1160}
145+
+ 老挝语
146+
+ IBM-1132
147+
+ 越南语
148+
+ IBM-{1130,1164}
149+
+ 印度语
150+
+ IBM-1137
151+
152+
它可以通过 Unicode 从这些编码中的任何一种转换为任何其他编码
153+
转换。
154+
155+
## 编译选项
156+
157+
使用 CMake 进行构建
158+
159+
+ `BUILD_TESTING`: 编译测试工具。默认为 `ON`.
160+
161+
```shell
162+
cmake .. -DBUILD_TESTING=ON
163+
cmake --build . --config=RelWithDebInfo
164+
ctest -C RelWithDebInfo --output-on-failure
165+
```
166+
167+
+ `ICONV_COMPAT`: 启用 iconv 兼容。默认为 `OFF`.
168+
169+
如果 `ICONV_COMPAT` 开启,会安装 `iconv.h` 和基本的函数。
170+
但是我们不支持 POSIX:2024 的所有功能。参见 [TODO](TODO).
171+
172+
## 安装
173+
174+
此库安装:
175+
176+
+ 动态库 `libcppp-reiconv`
177+
+ 静态库 `libcppp-reiconv.static`
178+
+ 头文件。
179+
180+
```text
181+
include
182+
├── cppp
183+
│ ├── cppp-platform.h
184+
│ ├── encodings
185+
│ │ ├── reiconv.h
186+
│ │ └── reiconv.hpp
187+
│ ├── reiconv.h
188+
│ └── reiconv.hpp
189+
└── iconv.h # 仅当 ICONV_COMPAT 开启才存在
190+
```
191+
192+
## 版权
193+
194+
cppp-reiconv 使用 LGPLv3,参见 [LICENSE](./LICENSE).
195+
196+
## 下载
197+
198+
参见 <https://github.com/cppp-project/cppp-reiconv/releases>
199+
200+
## 主页
201+
202+
<https://github.com/cppp-project/cppp-reiconv>
203+
204+
## Bug 反馈
205+
206+
+ 请在 GitHub 创建 issue [来一个](https://github.com/cppp-project/cppp-reiconv/issues/new/)

docs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# cppp-reiconv documentation
22

3+
[[Simplified Chinese]](zh_CN/README.md)
4+
35
## Introduction
46

57
These docs is for `cppp-reiconv 3.0.0`.
@@ -18,7 +20,7 @@ encodings and locale charset detection.
1820

1921
### Runtime
2022

21-
- C runtime
23+
- C runtime.
2224
- C++ runtime with C++20 support.
2325

2426
### Build with data generation

docs/c-api.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Although we have C API, we still require C++20 runtime.
44

5-
header file `cppp/reiconv.h` contains all C API.
5+
Header file `cppp/reiconv.h` contains all C API.
66

77
## Version Information API
88

@@ -42,12 +42,12 @@ extern _CPPP_API size_t reiconv_name_canonicalize(const char *name, char *outbuf
4242

4343
#### Description
4444

45-
Canonicalize an encoding name. the `canonical` means the internal name of
45+
Canonicalize an encoding name. The `canonical` means the internal name of
4646
encoding. Not the canonical name of IANA.
4747
We will ignore '-' and '_', and uppercase all characters.
4848

4949
Segment fault if `name` or `outbuf` is `nullptr`. We will not check the
50-
length of `outbuf`
50+
length of `outbuf`.
5151

5252
**This function is not recommended to use.**
5353

@@ -343,7 +343,7 @@ Get the size of converted string.
343343
344344
#### Return
345345
346-
The size of converted string. If the conversion failed, returns `(size_t)(-1)`
346+
The size of converted string. If the conversion failed, returns `(size_t)(-1)`.
347347
348348
**It's don't support flags now, so `flags` is always `REICONV_NO_FLAGS`. We will**
349349
**support it in the next version. So this API will change in the next version.**
@@ -378,7 +378,7 @@ If the output buffer is too small, -1 is returned.
378378
If the output buffer is too big, the rest of the buffer will not change.
379379
380380
This function is useful when you want to convert a string to a fixed size buffer
381-
like stack buffer. It's faster than `reiconv_convert`
381+
like stack buffer. It's faster than `reiconv_convert`.
382382
383383
#### Parameters
384384
@@ -441,7 +441,7 @@ Bruno Haible put this file into the public domain.
441441
we will allocate memory for you and set it to the result buffer. If pointed but
442442
not `NULL`, we will use it as the output buffer but reallocate it. So it must be
443443
a pointer that can be modified.
444-
**But don't let it value to `NULL`!**
444+
**But don't let output_data_ptr's value to `NULL`!**
445445
- `output_length_ptr`: The length of output buffer. If NULL, error will be occured.
446446
447447
#### Return
@@ -550,8 +550,6 @@ printf("Your locale charset is: %s\n", charset);
550550
Iconv compatibility is disabled by default. You can enable it by defining
551551
`-DICONV_COMPAT=ON` when you configure cppp-reiconv.
552552
553-
See "Iconv support" section below.
554-
555553
### `iconv_t`, aka `reiconv_t` in `cppp/reiconv.h`
556554
557555
#### Definition

docs/cpp-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ memory for the output string.
199199
200200
#### Throws
201201
202-
std::system_error if the conversion failed. Use it because it's has errno set.
202+
- `std::system_error` If the conversion failed. Use it because it's has errno set.
203203
204204
#### Example
205205
@@ -233,7 +233,7 @@ The current locale's character encoding.
233233

234234
#### Example
235235

236-
```c
236+
```cpp
237237
std::setlocale(LC_ALL, "");
238238
std::string_view charset = reiconv::locale_charset();
239239
std::cout <<"Your locale charset is: " << charset << std::endl;

docs/zh_CN/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# cppp-reiconv 文档
2+
3+
## 介绍
4+
5+
这是 `cppp-reiconv 3.0.0` 文档。不稳定版本。
6+
7+
cppp-reiconv 是一个可移植的 C/C++ 库,用于字符编码之间的转换和字符集检测。
8+
9+
## 依赖
10+
11+
### 构建
12+
13+
- 一个支持 C++20 的 C++ 编译器。
14+
- CMake 3.12 或更高版本.
15+
16+
### 运行时
17+
18+
- C 运行时。
19+
- 支持 C++20 的 C++ 运行时。
20+
21+
### 生成数据
22+
23+
我们需要为编码生成索引,它们存储在 `lib/generated` 中。
24+
25+
**如果你不感兴趣,你可以跳过这步骤。**
26+
**我们已经在 Git 仓库和源码包提供了相关数据。**
27+
28+
- GNU Make.
29+
- GNU Gperf.
30+
- 一个 POSIX 操作系统.
31+
32+
安装以上工具以后,你可以用下面的命令生成数据:
33+
34+
```shell
35+
make -f Makefile.devel -B
36+
```
37+
38+
## API 参考
39+
40+
- [C API 和 iconv 兼容 API 参考](c-api.md)
41+
- [C++ API 参考](cpp-api.md)

0 commit comments

Comments
 (0)