| 4 | #include <stdio.h> |
| 5 | |
| 6 | static 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 |
no test coverage detected
searching dependent graphs…