概要
| プロトタイプ宣言 | 動作説明 |
|---|---|
| std::string base64_encode(const char* str, size_t strLen); | |
| std::string base64_encode(const char* str); | |
| std::string base64_encode(std::string& str); | |
| std::string base64_decode(const char* str, size_t strLen); | when it was error, return 0 size std::string. |
| std::string base64_decode(const char* str); | when it was error, return 0 size std::string. |
| std::string base64_decode(std::string& str); | when it was error, return 0 size std::string. |
| const char bin2str_table[256][3]; | |
| const uchar str2bin_table[256]; | |
| std::string url_encode(const char* str, size_t strLen); | |
| std::string url_encode(const char* str); | |
| std::string url_encode(std::string& str); | |
| std::string url_decode(const char* str, size_t strLen); | when it was error, return 0 size std::string. |
| std::string url_decode(const char* str); | when it was error, return 0 size std::string. |
| std::string url_decode(std::string& str); | when it was error, return 0 size std::string. |
| std::u32string utf16_to_utf32(const std::u16string& str); | when it was error, return 0 size of std::u32string. |
| std::u16string utf32_to_utf16(const std::u32string& str); | when it was error, return 0 size of std::u16string. |
| std:: string utf32_to_utf8 (const std::u32string& str); | when it was error, return 0 size of std::string. |
| std::u32string utf8_to_utf32(const std:: string& str); | when it was error, return 0 size of std::u32string. |
| std::u16string utf8_to_utf16(const std:: string& str); | when it was error, return 0 size of std::u16string. |
| std:: string utf16_to_utf8 (const std::u16string& str); | when it was error, return 0 size of std::string. |
| std::string unicodeEscape_encode(const std::u16string& str); | |
| std::u16string unicodeEscape_decode(const char* str, size_t strLen); | |
| std::u16string unicodeEscape_decode(const char* str); | |
| std::u16string unicodeEscape_decode(const std::string& str); |
使用例
#include <sstd/sstd.hpp> int main(){ printf("■ encode_decode\n"); printf("□ base64_encode\n"); std::string str_b64 = "#include \"./sstd/sstd.hpp\".+=ABCD"; printf("%s ->[base64 encode]-> %s\n", str_b64.c_str(), sstd::base64_encode(str_b64.c_str(), str_b64.size()).c_str()); printf("%s ->[base64 encode]-> %s\n", str_b64.c_str(), sstd::base64_encode(str_b64.c_str()).c_str()); printf("%s ->[base64 encode]-> %s\n", str_b64.c_str(), sstd::base64_encode(str_b64).c_str()); printf("□ base64_decode\n"); std::string str_b64e = sstd::base64_encode(str_b64); printf("%s ->[base64 decode]-> %s\n", str_b64e.c_str(), sstd::base64_decode(str_b64e.c_str(), str_b64e.size()).c_str()); printf("%s ->[base64 decode]-> %s\n", str_b64e.c_str(), sstd::base64_decode(str_b64e.c_str()).c_str()); printf("%s ->[base64 decode]-> %s\n", str_b64e.c_str(), sstd::base64_decode(str_b64e).c_str()); printf("□ make_base64_decode_table\n"); sstd::print_base64_decode_table(); // for developers printf("\n"); //=== printf("□ url_encode\n"); std::string str_url(256, 0); for(uint i=0; i<str_url.size(); i++){ str_url[i]=i; } printf("[url encode]-> %s\n", sstd::url_encode(str_url.c_str(), str_url.size()).c_str()); printf("[url encode]-> %s\n", sstd::url_encode(str_url.c_str()).c_str()); // 先頭が 0 なので、終端だと判断されている。 printf("[url encode]-> %s\n", sstd::url_encode(str_url).c_str()); printf("\n"); sstd::url_encode_compare_speed(); // for developers printf("\n"); printf("□ url_decode\n"); std::string str_url_d = sstd::url_encode("#include \"./sstd/sstd.hpp\".+=ABCD"); printf("%s ->[url encode]-> %s\n", "#include \"./sstd/sstd.hpp\".+=ABCD", str_url_d.c_str()); printf("%s ->[url decode]-> %s\n", str_url_d.c_str(), sstd::url_decode(str_url_d.c_str(), str_url_d.size()).c_str()); printf("%s ->[url decode]-> %s\n", str_url_d.c_str(), sstd::url_decode(str_url_d.c_str()).c_str()); printf("%s ->[url decode]-> %s\n", str_url_d.c_str(), sstd::url_decode(str_url_d).c_str()); printf("\n"); printf("□ make_url_decode_table\n"); sstd::print_url_decode_table(); printf("\n"); //=== printf("■ utf8 <-> utf16\n"); printf("□ unicode escape (utf16) -> utf16 (binary)\n"); std::string escaped_utf16 = R"(\u30e6\u30cb\u30b3\u30fc\u30c9)"; // "ユニコード" // std::string escaped_utf16 = R"(abcd_\u30e6\u30cb\u30b3\u30fc\u30c9)"; // "abcd_ユニコード" // <- これがバグる。 issue std::u16string utf16_bin = sstd::unicodeEscape_decode(escaped_utf16); for(uint i=0; i<utf16_bin.size(); i++){ printf("%X\n", utf16_bin[i]); } printf("□ utf16 (binary) -> utf8\n"); std::string utf8 = sstd::utf16_to_utf8(utf16_bin); printf("%s\n", utf8.c_str()); std::u32string utf32_bin = sstd::utf8_to_utf32(utf8); std::u16string utf16_bin2 = sstd::utf32_to_utf16(utf32_bin); printf("□ utf16 (binary) -> unicode escape (utf16)\n"); printf("%s\n", sstd::unicodeEscape_encode(utf16_bin2).c_str()); sstd::unicodeEscape_compare_speed(); // for developers printf("\n"); printf("□ make_unicodeEscape_decode_table\n"); sstd::print_unicodeEscape_decode_table(); printf("\n"); }
実行結果
$ ./exe.exe ■ encode_decode □ base64_encode #include "./sstd/sstd.hpp".+=ABCD ->[base64 encode]-> I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE #include "./sstd/sstd.hpp".+=ABCD ->[base64 encode]-> I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE #include "./sstd/sstd.hpp".+=ABCD ->[base64 encode]-> I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE □ base64_decode I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE ->[base64 decode]-> #include "./sstd/sstd.hpp".+=ABCD I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE ->[base64 decode]-> #include "./sstd/sstd.hpp".+=ABCD I2luY2x1ZGUgIi4vc3N0ZC9zc3RkLmhwcCIuKz1BQkNE ->[base64 decode]-> #include "./sstd/sstd.hpp".+=ABCD □ make_base64_decode_table 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0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F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, □ url_encode [url encode]-> %01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF [url encode]-> [url encode]-> %01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF sstd::url_encode -------------------------------- Execution time: 0. 102 sec -------------------------------- sstd::url_encode_type2 -------------------------------- Execution time: 0. 386 sec -------------------------------- □ url_decode #include "./sstd/sstd.hpp".+=ABCD ->[url encode]-> %23include%20%22.%2Fsstd%2Fsstd.hpp%22.%2B%3DABCD %23include%20%22.%2Fsstd%2Fsstd.hpp%22.%2B%3DABCD ->[url decode]-> #include "./sstd/sstd.hpp".+=ABCD %23include%20%22.%2Fsstd%2Fsstd.hpp%22.%2B%3DABCD ->[url decode]-> #include "./sstd/sstd.hpp".+=ABCD %23include%20%22.%2Fsstd%2Fsstd.hpp%22.%2B%3DABCD ->[url decode]-> #include "./sstd/sstd.hpp".+=ABCD □ make_url_decode_table 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ■ utf8 <-> utf16 □ unicode escape (utf16) -> utf16 (binary) 30E6 30CB 30B3 30FC 30C9 □ utf16 (binary) -> utf8 ユニコード □ utf16 (binary) -> unicode escape (utf16) \u30E6\u30CB\u30B3\u30FC\u30C9 sstd::url_encode -------------------------------- Execution time: 0. 108 sec -------------------------------- sstd::url_encode_type2 -------------------------------- Execution time: 0. 364 sec -------------------------------- □ make_unicodeEscape_decode_table 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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