1 // 2 // TextConverter.cpp 3 // 4 // This sample demonstrates the text encodings support in POCO. 5 // 6 // Copyright (c) 2018, Applied Informatics Software Engineering GmbH. 7 // and Contributors. 8 // 9 // SPDX-License-Identifier: BSL-1.0 10 // 11 12 13 #include "Poco/StreamConverter.h" 14 #include "Poco/StreamCopier.h" 15 #include "Poco/TextEncoding.h" 16 #include "Poco/Encodings.h" 17 #include <iostream> 18 19 usage()20inline int usage() 21 { 22 std::cout << "Usage: TextConverter <inEncoding> <outEncoding>" << std::endl; 23 return 1; 24 } 25 26 main(int argc,char ** argv)27int main(int argc, char** argv) 28 { 29 if (argc < 3) return usage(); 30 31 try 32 { 33 Poco::registerExtraEncodings(); // register encodings from the PocoEncodings library 34 35 std::string inEncodingName(argv[1]); 36 std::string outEncodingName(argv[2]); 37 38 Poco::TextEncoding& inEncoding = Poco::TextEncoding::byName(inEncodingName); 39 Poco::TextEncoding& outEncoding = Poco::TextEncoding::byName(outEncodingName); 40 41 Poco::OutputStreamConverter conv(std::cout, inEncoding, outEncoding); 42 Poco::StreamCopier::copyStream(std::cin, conv); 43 } 44 catch (Poco::Exception& exc) 45 { 46 std::cerr << exc.displayText() << std::endl; 47 return 2; 48 } 49 50 return 0; 51 } 52