mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
add sample and alternative encoding names
This commit is contained in:
parent
37b0c377a9
commit
11d91b663d
1
Encodings/samples/CMakeLists.txt
Normal file
1
Encodings/samples/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(TextConverter)
|
10
Encodings/samples/Makefile
Normal file
10
Encodings/samples/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# Makefile for Poco Encodings Samples
|
||||
#
|
||||
|
||||
.PHONY: projects
|
||||
clean all: projects
|
||||
projects:
|
||||
$(MAKE) -C TextConverter $(MAKECMDGOALS)
|
7
Encodings/samples/TextConverter/CMakeLists.txt
Normal file
7
Encodings/samples/TextConverter/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
set(SAMPLE_NAME "TextConverter")
|
||||
|
||||
set(LOCAL_SRCS "")
|
||||
aux_source_directory(src LOCAL_SRCS)
|
||||
|
||||
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
|
||||
target_link_libraries( ${SAMPLE_NAME} PocoEncodings PocoFoundation )
|
15
Encodings/samples/TextConverter/Makefile
Normal file
15
Encodings/samples/TextConverter/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# Makefile for Poco TextConverter
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = TextConverter
|
||||
|
||||
target = TextConverter
|
||||
target_version = 1
|
||||
target_libs = PocoEncodings PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
51
Encodings/samples/TextConverter/src/TextConverter.cpp
Normal file
51
Encodings/samples/TextConverter/src/TextConverter.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// TextConverter.cpp
|
||||
//
|
||||
// This sample demonstrates the text encodings support in POCO.
|
||||
//
|
||||
// Copyright (c) 2018, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/StreamConverter.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/TextEncoding.h"
|
||||
#include "Poco/Encodings.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
inline int usage()
|
||||
{
|
||||
std::cout << "Usage: TextConverter <inEncoding> <outEncoding>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 3) return usage();
|
||||
|
||||
try
|
||||
{
|
||||
Poco::registerExtraEncodings(); // register encodings from the PocoEncodings library
|
||||
|
||||
std::string inEncodingName(argv[1]);
|
||||
std::string outEncodingName(argv[2]);
|
||||
|
||||
Poco::TextEncoding& inEncoding = Poco::TextEncoding::byName(inEncodingName);
|
||||
Poco::TextEncoding& outEncoding = Poco::TextEncoding::byName(outEncodingName);
|
||||
|
||||
Poco::OutputStreamConverter conv(std::cout, inEncoding, outEncoding);
|
||||
Poco::StreamCopier::copyStream(std::cin, conv);
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << exc.displayText() << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user