MCPcopy Create free account
hub / github.com/acl-dev/acl / test1

Function test1

lib_acl_cpp/samples/charset/main.cpp:6–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <stdio.h>
5
6static int test1(void)
7{
8 const char* s = "�й����񹲺͹�";
9 acl::charset_conv conv;
10 acl::string out, out2, out3;
11 acl::fstream out_fp;
12 acl::mime_base64 encoder;
13
14 /////////////////////////////////////////////////////////////////////
15
16
17 if (conv.convert("gb2312", "utf-8", s, strlen(s), &out) == false)
18 {
19 printf("convert from gb2312 to utf-8 error\n");
20 getchar();
21 return (1);
22 }
23 printf("ok, gb2312 to utf-8(%d): %s\n\n", (int) out.length(), out.c_str());
24
25 if (out_fp.open_trunc("gbutf8_1.txt"))
26 {
27 out_fp << out.c_str();
28 out_fp.close();
29 }
30
31 ///
32
33 encoder.encode_update(out.c_str(), out.length(), &out3);
34 encoder.encode_finish(&out3);
35 printf("ok, utf-8's base64: %s\n", out3.c_str());
36
37 if (out_fp.open_trunc("gbutf8.txt"))
38 {
39 out_fp << (char) 0xef << (char) 0xbb << (char) 0xbf
40 << out.c_str() << "\r\n";
41 out_fp << out.c_str();
42 out_fp.close();
43 }
44
45 if (conv.convert("utf-8", "gb2312", out, out.length(), &out2) == false)
46 {
47 printf("convert from utf-8 to gb2312 error\n");
48 getchar();
49 return (1);
50 }
51 printf("ok, utf-8 to gb2312: %s\n", out2.c_str());
52
53 /////////////////////////////////////////////////////////////////////
54
55 out.clear();
56 if (conv.convert("gb2312", "big5", s, strlen(s), &out) == false)
57 {
58 printf("convert from gb2312 to big5 error\n");
59 getchar();
60 return (1);
61 }
62 printf("ok, gb2312 to big5: %s\n", out.c_str());
63

Callers 1

mainFunction · 0.70

Calls 11

convertMethod · 0.80
update_finishMethod · 0.80
lengthMethod · 0.45
c_strMethod · 0.45
open_truncMethod · 0.45
closeMethod · 0.45
encode_updateMethod · 0.45
encode_finishMethod · 0.45
clearMethod · 0.45
update_beginMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…