Move files around to prepare for assimilation into core
[libs/core.git] / transcode.cpp
1 /* $Id$ */
2 #include <iostream>
3 #include <string>
4 #include <msp/strings/codec.h>
5
6 using namespace std;
7 using namespace Msp;
8
9 int main(int argc, char **argv)
10 {
11         if(argc<3)
12         {
13                 cerr<<"Usage: "<<argv[0]<<" <from-enc> <to-enc>\n";
14                 return 1;
15         }
16
17         Codecs::Codec *from = Codecs::create_codec(argv[1]);
18         Codecs::Codec *to = Codecs::create_codec(argv[2]);
19
20         Codecs::Decoder *from_dec = from->create_decoder(Codecs::TRANSLITERATE);
21         Codecs::Encoder *to_enc = to->create_encoder(Codecs::TRANSLITERATE);
22
23         string line;
24         while(getline(cin, line))
25         {
26                 line += '\n';
27                 Codecs::ustring ustr;
28                 from_dec->decode(line, ustr);
29                 string result;
30                 to_enc->encode(ustr, result);
31                 cout<<result;
32         }
33
34         string result;
35         to_enc->sync(result);
36         cout<<result;
37
38         delete from_dec;
39         delete to_enc;
40         delete from;
41         delete to;
42
43         return 0;
44 }