| 1 | #include <iostream> |
|---|
| 2 | #include <string> |
|---|
| 3 | #include <boost/regex.hpp> |
|---|
| 4 | |
|---|
| 5 | #include "EncodeString.hpp" |
|---|
| 6 | |
|---|
| 7 | using namespace std; |
|---|
| 8 | using namespace boost; |
|---|
| 9 | |
|---|
| 10 | char const *const TestLiteral = |
|---|
| 11 | "昔々、あるところに、くまさんがいました。クマー。\n" |
|---|
| 12 | "ある日、くまさんは、川でお魚を捕っていました。バシャッ!! とれたー。\n" |
|---|
| 13 | "そこへ、一匹のきつねがやってきて、言いました。「お、なかなか立派な魚じゃねーか。」\n" |
|---|
| 14 | "くまさんはそれを聞いて、得意げにしていたのですが…"; |
|---|
| 15 | |
|---|
| 16 | int main(int argc, char const* argv[]) |
|---|
| 17 | { |
|---|
| 18 | if (argc < 2) { |
|---|
| 19 | cerr << "Usage: " << argv[0] << " CHARSET" << endl; |
|---|
| 20 | cerr << "example of CHARSET: UTF-8, EUC-JP, CP932, etc..." << endl; |
|---|
| 21 | return 1; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | try { |
|---|
| 25 | EncodeString encode(TestLiteral, argv[1]); |
|---|
| 26 | cout << "<< original >>\n" << encode.getCharArray() << endl; |
|---|
| 27 | |
|---|
| 28 | string text(TestLiteral); |
|---|
| 29 | string modified_text; |
|---|
| 30 | regex reg("くま|川|(お)?魚"); |
|---|
| 31 | smatch match; |
|---|
| 32 | while (regex_search(text, match, reg)) { |
|---|
| 33 | modified_text += match.prefix().str(); |
|---|
| 34 | modified_text += |
|---|
| 35 | match.str() == "くま" ? "ぱんだ" : |
|---|
| 36 | match.str() == "川" ? "森" : |
|---|
| 37 | match.str() == "魚" || match.str() == "お魚" ? "笹の葉" : ""; |
|---|
| 38 | text = match.suffix().str(); |
|---|
| 39 | } |
|---|
| 40 | modified_text += text; |
|---|
| 41 | cout << "<< modified >>\n" << EncodeString(modified_text, argv[1]).getCharArray() << endl; |
|---|
| 42 | } |
|---|
| 43 | catch (EncodeStringException &ex) { |
|---|
| 44 | cerr << argv[0] << ": " << ex.what() << endl; |
|---|
| 45 | return 2; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | return 0; |
|---|
| 49 | } |
|---|