31 #include <terralib_buildconfig.h> 38 int main(
int argc,
char *argv[])
41 std::cout <<
"===> Handling character encoding CP1252 <===" << std::endl;
42 std::ifstream input_file(TERRALIB_DATA_DIR
"/encoding/arq_cp1252.txt");
44 std::string text_in_cp1252((std::istreambuf_iterator<char>(input_file)),
45 std::istreambuf_iterator<char>());
47 std::cout <<
"Original text size in CP1252: " << text_in_cp1252.size() << std::endl;
48 std::cout <<
"Original text in CP1252:\n" << text_in_cp1252 << std::endl << std::endl;
52 std::cout <<
"Text size when converted from CP1252 to UTF-8: " << text_in_utf8.size() << std::endl;
53 std::cout <<
"Text converted from CP1252 to UTF-8:\n" << text_in_utf8 << std::endl << std::endl ;
57 std::cout <<
"===> Handling character encoding LATIN1 <===" << std::endl;
59 std::ifstream input_file(TERRALIB_DATA_DIR
"/encoding/arq_latin1.txt");
61 std::string text_in_latin1((std::istreambuf_iterator<char>(input_file)),
62 std::istreambuf_iterator<char>());
64 std::cout <<
"Original text size in LATIN1: " << text_in_latin1.size() << std::endl;
65 std::cout <<
"Original text in LATIN1:\n" << text_in_latin1 << std::endl << std::endl;
69 std::cout <<
"Text size when converted from LATIN1 to UTF-8: " << text_in_utf8.size() << std::endl;
70 std::cout <<
"Text converted from LATIN1 to UTF-8:\n" << text_in_utf8 << std::endl << std::endl ;
74 std::cout <<
"===> // Handling character encoding UTF8 <===" << std::endl;
76 std::ifstream input_file(TERRALIB_DATA_DIR
"/encoding/arq_utf8.txt");
78 std::string text_in_utf8((std::istreambuf_iterator<char>(input_file)),
79 std::istreambuf_iterator<char>());
81 std::cout <<
"Original text size in UTF8: " << text_in_utf8.size() << std::endl;
82 std::cout <<
"Original text in UTF8:\n" << text_in_utf8 << std::endl << std::endl;
86 std::cout <<
"Text size when converted from UTF8 to LATIN1: " << text_in_latin1.size() << std::endl;
87 std::cout <<
"Text converted from UTF8 to LATIN1:\n" << text_in_latin1 << std::endl << std::endl;
91 std::cout <<
"Text size when converted from UTF8 to CP1252: " << text_in_cp1252.size() << std::endl;
92 std::cout <<
"Text converted from UTF8 to CP1252:\n" << text_in_cp1252 << std::endl ;
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
int main(int argc, char *argv[])
A class for handling character enconding/decoding.
static std::string toUTF8(const std::string &src)
Convert a string from a current locale encoding to UTF-8.