mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-25 01:19:06 +02: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;
|
||||||
|
}
|
@ -24,6 +24,7 @@ const char* Windows932Encoding::_names[] =
|
|||||||
"Windows-932",
|
"Windows-932",
|
||||||
"cp932",
|
"cp932",
|
||||||
"CP932",
|
"CP932",
|
||||||
|
"shift_jis",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ const char* Windows936Encoding::_names[] =
|
|||||||
"Windows-936",
|
"Windows-936",
|
||||||
"cp936",
|
"cp936",
|
||||||
"CP936",
|
"CP936",
|
||||||
|
"gb2312",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ const char* Windows949Encoding::_names[] =
|
|||||||
"Windows-949",
|
"Windows-949",
|
||||||
"cp949",
|
"cp949",
|
||||||
"CP949",
|
"CP949",
|
||||||
|
"ks_c_5601-1987",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ const char* Windows950Encoding::_names[] =
|
|||||||
"Windows-950",
|
"Windows-950",
|
||||||
"cp950",
|
"cp950",
|
||||||
"CP950",
|
"CP950",
|
||||||
|
"big5",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user