forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
@@ -39,7 +39,7 @@ class UtilsJsExtension : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UtilsJsExtension(QObject *parent = 0) : QObject(parent) { }
|
||||
UtilsJsExtension(QObject *parent = nullptr) : QObject(parent) { }
|
||||
|
||||
// File name conversions:
|
||||
Q_INVOKABLE QString toNativeSeparators(const QString &in) const;
|
||||
@@ -69,6 +69,9 @@ public:
|
||||
|
||||
// Generate temporary file:
|
||||
Q_INVOKABLE QString mktemp(const QString &pattern) const;
|
||||
|
||||
// Generate a ascii-only string:
|
||||
Q_INVOKABLE QString asciify(const QString &input) const;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user