QString const & f = cc_->filter();
if (f.isEmpty())
return s;
-
- // step through data item and put "(x)" for every matching character
- QString r;
- int lastp = -1;
- for (int i = 0; i < f.length(); ++i) {
- int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
- if (p < 0)
- continue;
- if (lastp == p - 1 && lastp != -1) {
- // remove ")" and append "x)"
- r = r.left(r.length() - 4) + s[p] + "</u>";
- } else {
- // append "(x)"
- r += s.mid(lastp + 1, p - lastp - 1);
- r += QString("<u>") + s[p] + "</u>";
- }
- lastp = p;
- }
- r += s.mid(lastp + 1);
+ QString r(s);
+ QRegExp pattern(charFilterRegExpC(f));
+ r.replace(pattern, "<u>\\1</u>");
return r;
}
#include <QHeaderView>
#include <QItemDelegate>
#include <QPainter>
+#include <QRegExp>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTextFrame>
QString const & f = layout_->filter();
if (f.isEmpty())
return s;
-
- // step through data item and put "(x)" for every matching character
- QString r;
- int lastp = -1;
- for (int i = 0; i < f.length(); ++i) {
- int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
- if (p < 0)
- continue;
- if (lastp == p - 1 && lastp != -1) {
- // remove ")" and append "x)"
- r = r.left(r.length() - 4) + s[p] + "</u>";
- } else {
- // append "(x)"
- r += s.mid(lastp + 1, p - lastp - 1);
- r += QString("<u>") + s[p] + "</u>";
- }
- lastp = p;
- }
- r += s.mid(lastp + 1);
+ QString r(s);
+ QRegExp pattern(charFilterRegExpC(f));
+ r.replace(pattern, "<u>\\1</u>");
return r;
}
return re;
}
+QString charFilterRegExpC(QString const & filter)
+{
+ QString re = "(";
+ for (int i = 0; i < filter.length(); ++i) {
+ QChar c = filter[i];
+ if (c.isLower())
+ re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
+ else
+ re += QRegExp::escape(c);
+ }
+ return re + ")";
+}
+
+
+
} // namespace lyx
/**
* constructs a regex to filter on consecutive characters
+ * matches lower- and uppercase on lowercase characters,
+ * and just uppercase for uppercase
*/
QString charFilterRegExp(QString const & filter);
+/**
+ * as above, but constructs a capturing regex for a sequence of characters
+ */
+QString charFilterRegExpC(QString const & filter);
+
} // namespace lyx
#endif // QSTRING_HELPERS_H