Marcos: Make Utils.asciify(...) avialable to MarcoExpander

The Util.asciify(...) method takes a string and returns an
ASCII only string for the input. All ASCII characters are kept as
is, anything non-ASCII is replaced by 'u' followed by the hex
encoded unicode value of the character.

Change-Id: I90b0adeb809bc2f6eb4374ce48851396861d4673
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2017-01-20 16:30:45 +01:00
parent 5762182e23
commit b5730af461
2 changed files with 16 additions and 1 deletions

View File

@@ -142,5 +142,17 @@ QString UtilsJsExtension::mktemp(const QString &pattern) const
return file.fileName();
}
QString UtilsJsExtension::asciify(const QString &input) const
{
QString result;
for (const QChar c : input) {
if (c.isPrint() && c.unicode() < 128)
result.append(c);
else
result.append(QString::fromLatin1("u%1").arg(c.unicode(), 4, 16, QChar('0')));
}
return result;
}
} // namespace Internal
} // namespace Core