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

    Q3CString n;
    QVERIFY(!n.rightJustify(3).isNull());  // I expected TRUE
    QCOMPARE(a.rightJustify(4,'-',TRUE),(Q3CString)"-ABC");
    QCOMPARE(a.rightJustify(4,' ',TRUE),(Q3CString)" ABC");
    QCOMPARE(a.rightJustify(3,' ',TRUE),(Q3CString)"ABC");
    QCOMPARE(a.rightJustify(2,' ',TRUE),(Q3CString)"AB");
    QCOMPARE(a.rightJustify(1,' ',TRUE),(Q3CString)"A");
    QCOMPARE(a.rightJustify(0,' ',TRUE),(Q3CString)"");
    QCOMPARE(a,(Q3CString)"ABC");
}
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]