]> git.tdb.fi Git - libs/core.git/blob - transcode.cpp
maputils.h: add insert_unique function
[libs/core.git] / transcode.cpp
1 /* $Id$ */
2 #include <iostream>
3 #include <string>
4 #include <msp/stringcodec/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         StringCodec::Codec *from = StringCodec::create_codec(argv[1]);
18         StringCodec::Codec *to = StringCodec::create_codec(argv[2]);
19
20         StringCodec::Decoder *from_dec = from->create_decoder();
21         StringCodec::Encoder *to_enc = to->create_encoder();
22
23         string line;
24         while(getline(cin, line))
25         {
26                 line += '\n';
27                 StringCodec::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 }