Exemple #1
0
void tst_Q3CString::leftJustify()
{
    Q3CString a;
    a="ABC";
    QCOMPARE(a.leftJustify(5,'-'),(Q3CString)"ABC--");
    QCOMPARE(a.leftJustify(4,'-'),(Q3CString)"ABC-");
    QCOMPARE(a.leftJustify(4),(Q3CString)"ABC ");
    QCOMPARE(a.leftJustify(3),(Q3CString)"ABC");
    QCOMPARE(a.leftJustify(2),(Q3CString)"ABC");
    QCOMPARE(a.leftJustify(1),(Q3CString)"ABC");
    QCOMPARE(a.leftJustify(0),(Q3CString)"ABC");

    Q3CString n;
    QVERIFY(!n.leftJustify(3).isNull());    // I expected TRUE
    QCOMPARE(a.leftJustify(4,' ',TRUE),(Q3CString)"ABC ");
    QCOMPARE(a.leftJustify(3,' ',TRUE),(Q3CString)"ABC");
    QCOMPARE(a.leftJustify(2,' ',TRUE),(Q3CString)"AB");
    QCOMPARE(a.leftJustify(1,' ',TRUE),(Q3CString)"A");
    QCOMPARE(a.leftJustify(0,' ',TRUE),(Q3CString)"");
}
b.isNull();                // false because b.data() == ""
b.isEmpty();        // true  because b.length() == 0
//! [1]


//! [2]
Q3CString s = "truncate this string";
s.truncate(5);                      // s == "trunc"
//! [2]


//! [3]
Q3CString s;
s.sprintf("%d - %s", 1, "first");                // result < 256 chars

Q3CString big(25000);                        // very long string
big.sprintf("%d - %s", 2, longString);        // result < 25000 chars
//! [3]


//! [4]
Q3CString s("apple");
Q3CString t = s.leftJustify(8, '.');  // t == "apple..."
//! [4]


//! [5]
Q3CString s("pie");
Q3CString t = s.rightJustify(8, '.');  // t == ".....pie"
//! [5]