/***************************************************************************** file : $Id: test_unicode.cpp,v 1.7 2006/10/02 15:24:40 nils Exp $ description : ------------------------------------------------------------------------ copyright : (C) 2006 by Nils Springob, Aachen, GERMANY email : nils.springob@nicai-systems.de project : nicai-systems library *****************************************************************************/ //#define WITH_ENCODINGS #include "unicode.h" #include #include #ifdef WITH_ENCODINGS # include "encodings.h" #endif using namespace nicai; template void test() { UNISTR a; a = utf8_string("German umlauts: "); a += 0x00E4; // a umlaut a += ','; a += 0x00F6; // o umlaut a += ','; a += 0x00FC; // u umlaut utf8_string u8(a); utf16_string u16(a); utf32_string u32(a); UNISTR b; b = u8; b = u16; b = u32; assert(b==u8); assert(b==u16); assert(b==u32); std::copy(a.begin(), a.end(), std::ostream_iterator(std::cout, ", ")); std::cout << std::endl; a+=b; assert(a==b+b); std::cout << "utf8: "; std::cout << unicode_string(b).raw() << std::endl; #ifdef WITH_ENCODINGS std::cout << "windows_1252: "; std::cout << unicode_string(b).raw() << std::endl; std::cout << "cp437: "; std::cout << unicode_string(b).raw() << std::endl; #endif // find and replace: a=utf8_string("a simple test!"); typename UNISTR::iterator it = a.find(utf8_string("simple")); a.replace(it, 6, utf8_string("nice")); std::cout << utf8_string(a).raw() << std::endl; // sorting: std::vector data; data.push_back(utf8_string("alpha")); data.push_back(utf8_string("betha")); data.push_back(utf8_string("alef")); data.push_back(utf8_string("alphabet")); std::sort(data.begin(), data.end()); assert(data[0]==utf8_string("alef")); assert(data[1]==utf8_string("alpha")); assert(data[2]==utf8_string("alphabet")); assert(data[3]==utf8_string("betha")); } int main (int argc, char * argv []) { std::cout << "testing utf8:" << std::endl; test(); std::cout << std::endl << "testing utf16:" << std::endl; test(); std::cout << std::endl << "testing utf32:" << std::endl; test(); #ifdef WITH_ENCODINGS typedef unicode_string latin1_string; std::cout << std::endl << "testing latin1:" << std::endl; test(); typedef unicode_string windows_1252_string; std::cout << std::endl << "testing windows_1252:" << std::endl; test(); typedef unicode_string cp437_string; std::cout << std::endl << "testing cp437:" << std::endl; test(); #endif }