// -*- c++ -*- /* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: EncodingTest.jlc,v 1.15 2003/09/26 15:55:26 florian Exp $ */ #include "Test.h" #include #include #include using namespace jakelib::lang; using namespace jakelib::text::enc; using namespace jakelib::io; using namespace jakelib::util; char* encoderNames[] = {"ISO8859_1", "latin1", "l2", "ISO-8859-20", null}; String& operator+ (String& a, Object& b) { String* n = &a; n = n->plus(&b); return *n; } String& operator+ (String* a, Object& b); String& operator+ (String& a, Object* b) { String* n = &a; n = n->plus(b); return *n; } void toUnicode(String* encoding, jbyte* input) { String str(input, encoding); printf("toUnicode(\"%s\", \"%s\"):\n", encoding->latin1(), input); System::out->println(&str); // int len = strlen(input); // ByteToCharConverter* conv = ByteToCharConverter::getConverter(encoding); // jchar* converted = (jchar*) malloc(sizeof(jchar) * len); // conv->convert((jbyte*) str, 0, len, converted, 0, len); // for (int idx = 0; idx < len; idx++) // System::out->println(String(" ").plus(Integer::toHexString(input[idx] & 0xff))->plus(" -> ") // ->plus(Integer::toHexString(str.charAt(idx)))->plus(", ")); System::out->println(); } // void fromUnicode(String* encoding, String* input) // { // printf("fromUnicode(\"%s\", \"%s\"):\n", encoding->latin1(), input->latin1()); // CharToByteConverter* conv = CharToByteConverter::getConverter(encoding); // ByteArray ba; // conv->convert(input->getChars(), 0, input->length(), &ba); // printf(" => \""); // for (int idx = 0; idx < ba.size(); idx++) // printf("%c", ba.get(idx)); // printf("\"\n"); // } void encodingTest() { char* str_001 = "0123 abcdef äÄöÖüÜß"; try { ByteToCharConverter* conv = ByteToCharConverter::getDefault(); System::out->println(`"conv = ByteToCharConverter::getDefault(): "`->plus(conv)); for (int idx = 0; encoderNames[idx] != null; idx++) { try { System::out->println(`"ByteToCharConverter::getConverter(\""` ->plus(encoderNames[idx])->plus(`"\"): "`) ->plus(ByteToCharConverter::getConverter(encoderNames[idx]))); } catch (Exception *e) { System::out->println(e); } } toUnicode(`"ISO8859_2"`, "0123 abcdef §ÛÝ"); toUnicode(`"ISO8859_2"`, "0123 abcdef äÄöÖüÜß"); toUnicode(`"latin3"`, "0123 abcdef äÄöÖüÜß"); toUnicode(`"cyrillic"`, "0123 abcdef äÄöÖüÜß"); toUnicode(`"latin1"`, "0123 abcdef äÄöÖüÜß"); toUnicode(`"ASCII"`, "0123 abcdef äÄöÖüÜß"); toUnicode(`"utf8"`, "Interessieren Sie sich für die optimale Gestaltung des Außenbereiches rund um Ihr Eigenheim? Ob Möbel, Fensterrahmen oder ganze Räume - hier finden Sie nützliche Tipps und Ideen zur Renovierung alter Gegenstände, "); //fromUnicode(`"utf8"`, new String("0123 abcdef äÄöÖüÜß", "latin1")); //fromUnicode(`"ascii"`, new String("0123 abcdef äÄöÖüÜß", "latin1")); } catch (Exception *e) { System::out->println(e); } }