Logo Search packages:      
Sourcecode: cb2bib version File versions

QString EQRegExp::escape ( const QString &  str  )  [static]

Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, \,], ^, {, | and }.

Example:

        s1 = EQRegExp::escape("bingo");   // s1 == "bingo"
        s2 = EQRegExp::escape("f(x)");    // s2 == "f\\(x\\)"

This function is useful to construct regexp patterns dynamically:

        EQRegExp rx("(" + EQRegExp::escape(name) +
                   "|" + EQRegExp::escape(alias) + ")");

See also:
setPatternSyntax()

Definition at line 4011 of file eqregexp.cpp.

{
    static const char meta[] = "$()*+.?[\\]^{|}";
    QString quoted = str;
    int i = 0;

    while (i < quoted.length()) {
        if (strchr(meta, quoted.at(i).toLatin1()) != 0)
            quoted.insert(i++, QLatin1Char('\\'));
        ++i;
    }
    return quoted;
}


Generated by  Doxygen 1.6.0   Back to index