mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-10 15:22:30 +01:00
Added text escaping methods.
This commit is contained in:
parent
215b99689f
commit
3f33529bfd
@ -49,3 +49,44 @@ QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
|||||||
QString TextFactory::stripTags(QString text) {
|
QString TextFactory::stripTags(QString text) {
|
||||||
return text.remove(QRegExp("<[^>]*>"));
|
return text.remove(QRegExp("<[^>]*>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TextFactory::escapeHtml(const QString &html) {
|
||||||
|
QMap<QString, QString> sequences;
|
||||||
|
|
||||||
|
sequences["<"] = "<";
|
||||||
|
sequences[">"] = ">";
|
||||||
|
sequences["&"] = "&";
|
||||||
|
sequences["""] = "\"";
|
||||||
|
sequences[" "] = " ";
|
||||||
|
sequences["±"] = "±";
|
||||||
|
sequences["×"] = "×";
|
||||||
|
|
||||||
|
QList<QString> keys = sequences.uniqueKeys();
|
||||||
|
QString output = html;
|
||||||
|
|
||||||
|
foreach (const QString &key, keys) {
|
||||||
|
output.replace(key, sequences.value(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TextFactory::deEscapeHtrml(const QString &text) {
|
||||||
|
QMap<QString, QString> sequences;
|
||||||
|
|
||||||
|
sequences["<"] = "<";
|
||||||
|
sequences[">"] = ">";
|
||||||
|
sequences["&"] = "&";
|
||||||
|
sequences["\""] = """;
|
||||||
|
sequences["±"] = "±";
|
||||||
|
sequences["×"] = "×";
|
||||||
|
|
||||||
|
QList<QString> keys = sequences.uniqueKeys();
|
||||||
|
QString output = text;
|
||||||
|
|
||||||
|
foreach (const QString &key, keys) {
|
||||||
|
output.replace(key, sequences.value(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
@ -19,6 +19,11 @@ class TextFactory {
|
|||||||
// Strips "<....>" (HTML, XML) tags from given text.
|
// Strips "<....>" (HTML, XML) tags from given text.
|
||||||
static QString stripTags(QString text);
|
static QString stripTags(QString text);
|
||||||
|
|
||||||
|
// HTML entity escaping.
|
||||||
|
// TODO: Optimize these methods.
|
||||||
|
static QString escapeHtml(const QString &html);
|
||||||
|
static QString deEscapeHtrml(const QString &text);
|
||||||
|
|
||||||
// Shortens input string according to given length limit.
|
// Shortens input string according to given length limit.
|
||||||
static QString shorten(const QString &input, int text_length_limit = TEXT_TITLE_LIMIT);
|
static QString shorten(const QString &input, int text_length_limit = TEXT_TITLE_LIMIT);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user