Logo Search packages:      
Sourcecode: mailody-kde4 version File versions  Download package

QString Global::quote ( const QString &  text,
bool  stripSig = true 
) [static]

Alters text so it contains an extra > in front of each line;

Definition at line 138 of file global.cpp.

Referenced by Mailody::Composer::setMsgAndQuote().

{
    // We only quote untill we match a "-- ". After that the code will buffer
    // the rest. If after the "-- " a ^> is matched, then the code is added
    // again. This should quote a complete message, with a reply and sig at top.
    bool includeMore = false;
    QString result, extraResult;
    QStringList list1 = text.split( "\n" );
    QStringList::Iterator it;

    // Maybe not very fast, but pretty stable and straightforward, non?
    for ( it = list1.begin(); it != list1.end(); it++ ) {
        QString single = *it;
        while ( single.length() > 80 ) {
            QString piece = single.mid( 0,80 );
            int amount = 0;

            // find the space, dot and comma.
            int dot = piece.lastIndexOf( "." );
            int comma = piece.lastIndexOf( "," );
            int space = piece.lastIndexOf( " " );
            amount = qMax( dot,comma );
            amount = qMax( amount, space );

            // if no dot, comma or space is found, wrap hard.
            if ( amount < 1 )
                amount = 80;

            includeMore ? extraResult += "> " + single.mid( 0,amount ) + '\n'
                                         : result += "> " + single.mid( 0,amount ) + '\n';

            single = single.mid( amount+1 );
        }

        if ( stripSig && single == "-- " )
            includeMore = true;

        if ( includeMore && single.startsWith( '>' ) ) {
            includeMore = false;
            result += extraResult;
        }

        includeMore ? extraResult += "> " + single + '\n'
                                     :  result += "> " + single + '\n';
    }
    return result;
}


Generated by  Doxygen 1.6.0   Back to index