]> git.tdb.fi Git - libs/core.git/blobdiff - transcode.cpp
Rework the codec API completely to remove the internal buffering
[libs/core.git] / transcode.cpp
diff --git a/transcode.cpp b/transcode.cpp
new file mode 100644 (file)
index 0000000..675f368
--- /dev/null
@@ -0,0 +1,44 @@
+/* $Id$ */
+#include <iostream>
+#include <string>
+#include "codec.h"
+
+using namespace std;
+using namespace Msp;
+
+int main(int argc, char **argv)
+{
+       if(argc<3)
+       {
+               cerr<<"Usage: "<<argv[0]<<" <from-enc> <to-enc>\n";
+               return 1;
+       }
+
+       Codecs::Codec *from=Codecs::create_codec(argv[1]);
+       Codecs::Codec *to=Codecs::create_codec(argv[2]);
+
+       Codecs::Decoder *from_dec=from->create_decoder();
+       Codecs::Encoder *to_enc=to->create_encoder();
+
+       string line;
+       while(getline(cin, line))
+       {
+               line+='\n';
+               Codecs::ustring ustr;
+               from_dec->decode(line, ustr);
+               string result;
+               to_enc->encode(ustr, result);
+               cout<<result;
+       }
+
+       string result;
+       to_enc->sync(result);
+       cout<<result;
+
+       delete from_dec;
+       delete to_enc;
+       delete from;
+       delete to;
+
+       return 0;
+}