Extract the entity parsing code to a static function
This way we can use it from qtdeclarative to parse styled text Change-Id: Ic888a75a9700558e97b3e743d6d42fda121ddcba Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
eab0bb73a5
commit
c3102b1f76
@ -800,28 +800,13 @@ void QTextHtmlParser::parseExclamationTag()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parses an entity after "&", and returns it
|
QString QTextHtmlParser::parseEntity(QStringView entity)
|
||||||
QString QTextHtmlParser::parseEntity()
|
|
||||||
{
|
{
|
||||||
const int recover = pos;
|
|
||||||
int entityLen = 0;
|
|
||||||
QStringView entity;
|
|
||||||
while (pos < len) {
|
|
||||||
QChar c = txt.at(pos++);
|
|
||||||
if (c.isSpace() || pos - recover > 9) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (c == QLatin1Char(';'))
|
|
||||||
break;
|
|
||||||
++entityLen;
|
|
||||||
}
|
|
||||||
if (entityLen) {
|
|
||||||
entity = QStringView(txt).mid(recover, entityLen);
|
|
||||||
QChar resolved = resolveEntity(entity);
|
QChar resolved = resolveEntity(entity);
|
||||||
if (!resolved.isNull())
|
if (!resolved.isNull())
|
||||||
return QString(resolved);
|
return QString(resolved);
|
||||||
|
|
||||||
if (entityLen > 1 && entity.at(0) == QLatin1Char('#')) {
|
if (entity.length() > 1 && entity.at(0) == QLatin1Char('#')) {
|
||||||
entity = entity.mid(1); // removing leading #
|
entity = entity.mid(1); // removing leading #
|
||||||
|
|
||||||
int base = 10;
|
int base = 10;
|
||||||
@ -839,6 +824,29 @@ QString QTextHtmlParser::parseEntity()
|
|||||||
return QStringView{QChar::fromUcs4(uc)}.toString();
|
return QStringView{QChar::fromUcs4(uc)}.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// parses an entity after "&", and returns it
|
||||||
|
QString QTextHtmlParser::parseEntity()
|
||||||
|
{
|
||||||
|
const int recover = pos;
|
||||||
|
int entityLen = 0;
|
||||||
|
while (pos < len) {
|
||||||
|
QChar c = txt.at(pos++);
|
||||||
|
if (c.isSpace() || pos - recover > 9) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (c == QLatin1Char(';'))
|
||||||
|
break;
|
||||||
|
++entityLen;
|
||||||
|
}
|
||||||
|
if (entityLen) {
|
||||||
|
const QStringView entity = QStringView(txt).mid(recover, entityLen);
|
||||||
|
const QString parsedEntity = parseEntity(entity);
|
||||||
|
if (!parsedEntity.isNull()) {
|
||||||
|
return parsedEntity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
error:
|
error:
|
||||||
pos = recover;
|
pos = recover;
|
||||||
|
@ -310,6 +310,9 @@ public:
|
|||||||
void parse(const QString &text, const QTextDocument *resourceProvider);
|
void parse(const QString &text, const QTextDocument *resourceProvider);
|
||||||
|
|
||||||
static int lookupElement(const QString &element);
|
static int lookupElement(const QString &element);
|
||||||
|
|
||||||
|
Q_GUI_EXPORT static QString parseEntity(QStringView entity);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTextHtmlParserNode *newNode(int parent);
|
QTextHtmlParserNode *newNode(int parent);
|
||||||
QList<QTextHtmlParserNode *> nodes;
|
QList<QTextHtmlParserNode *> nodes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user