#include #include #include #include #include #include "JLang/JString.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test JLANG::JString class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test string operations."); zap['d'] = make_field(debug) = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } { const JString buffer("% = %;", "key", 123); DEBUG(buffer << endl); ASSERT(buffer == "key = 123;", "Test formatting"); } { JString buffer("Hello world."); DEBUG(buffer << endl); buffer.toUpper(); DEBUG(buffer << endl); ASSERT(buffer == "HELLO WORLD.", "Test JString::toUpper()"); buffer.toLower(); DEBUG(buffer << endl); ASSERT(buffer == "hello world.", "Test JString::toLower()"); } { JString buffer("a = %1; b = %2; c = %3;"); buffer.replace("%1", 3.1415).replace("%2", "hello").replace("%3", 123); DEBUG(buffer << endl); ASSERT(buffer == "a = 3.1415; b = hello; c = 123;", "Test JString::replace()"); } { int i = JString::toValue("1234"); DEBUG(i << endl); ASSERT(i == 1234, "Test JString::toValue()"); } { JString buffer("1 3.1415 hello"); int i; double d; string w; buffer.assign(i).assign(d).assign(w); DEBUG(i << ' ' << d << ' ' << w << endl); ASSERT(i == 1 && d == 3.1415 && w == "hello", "Test JString::assign()"); } }