// -*- 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: StringTest.jlc,v 1.1 2003/09/14 15:53:16 florian Exp $ */ #include "Test.h" #include #include using namespace jakelib::lang; using namespace jakelib::util; void stringTest() { String* s1 = null; System::out->println(String("s1 = '").plus(JAKELIB_ONDEMAND(s1, new String(" This is a string with trailing spaces.")))->plus("'")); s1 = s1->trim(); System::out->println(String(" s1->trim() => '").plus(s1)->plus("'")); s1 = new String("This is a string with preceeding spaces. "); System::out->println(String("s2 = '").plus(s1)->plus("'")); s1 = s1->trim(); System::out->println(String(" s2->trim() => '").plus(s1)->plus("'")); s1 = new String("This is a string without trailing/preceeding spaces."); System::out->println(String("s3 = '").plus(s1)->plus("'")); s1 = s1->trim(); System::out->println(String(" s3->trim() => '").plus(s1)->plus("'")); s1 = new String(" "); System::out->println(String("s4 = '").plus(s1)->plus("'")); s1 = s1->trim(); System::out->println(String(" s4->trim() => '").plus(s1)->plus("'")); s1 = new String(""); System::out->println(String("s5 = '").plus(s1)->plus("'")); s1 = s1->trim(); System::out->println(String(" s5->trim() => '").plus(s1)->plus("'")); System::out->println(); // .indexOf s1 = `"It''s raining cats and dogs."`; String* s2 = `"dogs"`; System::out->println(String("s1 = \"").plus(s1)->plus("\"; s2 = \"")->plus(s2) ->plus("\"")); System::out->println(String(" s1->indexOf(s2) => ").plus((jlong) s1->indexOf(s2))); s2 = new String(""); System::out->println(String("s1 = \"").plus(s1)->plus("\"; s2 = \"")->plus(s2) ->plus("\"")); System::out->println(String(" s1->indexOf(s2) => ").plus((jlong) s1->indexOf(s2))); s2 = new String("."); System::out->println(String("s1 = \"").plus(s1)->plus("\"; s2 = \"")->plus(s2) ->plus("\"")); System::out->println(String(" s1->indexOf(s2) => ").plus((jlong) s1->indexOf(s2))); s2 = new String(":"); System::out->println(String("s1 = \"").plus(s1)->plus("\"; s2 = \"")->plus(s2) ->plus("\"")); System::out->println(String(" s1->indexOf(s2) => ").plus((jlong) s1->indexOf(s2))); System::out->println(); // .toUpperCase s1 = `"This is a String with lower and upper case LETTERS"`; System::out->println(`" \""`->plus(s1)->plus(`"\"->toUpperCase()\n => \""`)->plus(s1->toUpperCase())->plus(`"\""`)); s1 = `"¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"`; System::out->println(`" \""`->plus(s1)->plus(`"\"->toLowerCase()\n => \""`)->plus(s1->toLowerCase())->plus(`"\""`)); System::out->println(`" \""`->plus(s1)->plus(`"\"->toUpperCase()\n => \""`)->plus(s1->toUpperCase())->plus(`"\""`)); s1 = `"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"`; System::out->println(`" \""`->plus(s1)->plus(`"\"->toLowerCase()\n => \""`)->plus(s1->toLowerCase())->plus(`"\""`)); System::out->println(`" \""`->plus(s1)->plus(`"\"->toUpperCase()\n => \""`)->plus(s1->toUpperCase())->plus(`"\""`)); s1 = `"A few Unicode characters: \u0048\u0045\u004c\u004c\u004f\u0021 \u20ac"`; System::out->println(`" \""`->plus(s1)->plus(`"\"->toLowerCase()\n => \""`)->plus(s1->toLowerCase())->plus(`"\""`)); System::out->println(); s1 = `"This string is to be tokenized! "`; StringTokenizer* st = new StringTokenizer(s1); System::out->print(`"StringTokenizer(\""` .. s1 .. `"\")\n => "`); while (st->hasMoreTokens()) { System::out->print(`"\""` .. st->nextToken() .. `"\", "`); } System::out->println(); System::out->println(`"String::valueOf(12345467) => "` .. String::valueOf(12345467)); System::out->println(`"String::valueOf(-98765) => "` .. String::valueOf(-98765)); jchar aChar = 'A'; System::out->println(`"String::valueOf('A') => "` .. String::valueOf(aChar)); System::out->println(`"String::valueOf(789.990001) => "` .. String::valueOf(789.990001)); // .arg() System::out->println(); s1 = `"The first name is '%1' and the last name is '%2'"`; System::out->println(`"\""` .. s1 .. `"\"->arg(1, \"Dummy\")->arg(2, \"User\")"`); System::out->println(`" => \""` .. s1->arg(1, `"Dummy"`)->arg(2, `"User"`)); System::out->println(`" => \""` .. s1->arg(1, 85)->arg(2, "User")); System::out->println(`" => \""` .. s1->arg(1, 8575.99991)->arg(2, 'E')); System::out->println(`" => \""` .. s1->arg(1, (jchar)65)->arg(2, (char)65)); // +++ AlFa 01/29/2003 .getChars() System::out->println(`"++++++++++++++++String::getChars()+++++++++++"`); jint chrpos = 4; const jint chrcount = 10; jchars chrs(chrcount); System::out->println(s1); System::out->println(`"^123456789^123456789^1234567890^"`); System::out->println(); StringBuffer buf("Hello World: "); System::out->println(buf); buf.append("This is a StringBuffer"); buf.append('.'); System::out->println(buf); }