forked from qt-creator/qt-creator
Utils: Turn "Util.asciify" into a plain macro
This monves the asciify function to stringutils and makes it directly available as "asciify:" prefix macro, so that the generation of a default build path does not go through JavaScript. "Util.asciify" remains available as core JavaScript extension for the case that it is used by third party code/wizards. This change also adds a test to tst_stringutils Change-Id: Iba2f20c0415ee8fe757c2f0058a90629b3fbeff0 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -346,6 +346,18 @@ QString quoteAmpersands(const QString &text)
|
|||||||
return result.replace("&", "&&");
|
return result.replace("&", "&&");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString asciify(const QString &input)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
QString formatElapsedTime(qint64 elapsed)
|
QString formatElapsedTime(qint64 elapsed)
|
||||||
{
|
{
|
||||||
elapsed += 500; // round up
|
elapsed += 500; // round up
|
||||||
|
@@ -32,6 +32,8 @@ QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings);
|
|||||||
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
|
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
|
||||||
// Quotes all ampersands
|
// Quotes all ampersands
|
||||||
QTCREATOR_UTILS_EXPORT QString quoteAmpersands(const QString &text);
|
QTCREATOR_UTILS_EXPORT QString quoteAmpersands(const QString &text);
|
||||||
|
// Convert non-ascii characters into foobar
|
||||||
|
QTCREATOR_UTILS_EXPORT QString asciify(const QString &input);
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out);
|
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out);
|
||||||
|
|
||||||
|
@@ -139,14 +139,7 @@ QString UtilsJsExtension::mktemp(const QString &pattern) const
|
|||||||
|
|
||||||
QString UtilsJsExtension::asciify(const QString &input) const
|
QString UtilsJsExtension::asciify(const QString &input) const
|
||||||
{
|
{
|
||||||
QString result;
|
return Utils::asciify(input);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UtilsJsExtension::qtQuickVersion(const QString &filePath) const
|
QString UtilsJsExtension::qtQuickVersion(const QString &filePath) const
|
||||||
|
@@ -232,6 +232,9 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|||||||
[] { return QUuid::createUuid().toString(); });
|
[] { return QUuid::createUuid().toString(); });
|
||||||
|
|
||||||
expander->registerPrefix("#:", Tr::tr("A comment."), [](const QString &) { return QString(); });
|
expander->registerPrefix("#:", Tr::tr("A comment."), [](const QString &) { return QString(); });
|
||||||
|
expander->registerPrefix("asciify:", Tr::tr("Convert string into pure ascii."),
|
||||||
|
[expander] (const QString &s) {
|
||||||
|
return asciify(expander->expand(s)); });
|
||||||
|
|
||||||
Utils::PathChooser::setAboutToShowContextMenuHandler(&CorePlugin::addToPathChooserContextMenu);
|
Utils::PathChooser::setAboutToShowContextMenuHandler(&CorePlugin::addToPathChooserContextMenu);
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ namespace ProjectExplorer {
|
|||||||
|
|
||||||
static QString defaultBuildDirectoryTemplate()
|
static QString defaultBuildDirectoryTemplate()
|
||||||
{
|
{
|
||||||
return "../%{JS: Util.asciify(\"build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}\")}";
|
return "../%{asciify:build-%{Project:Name}-%{Kit:FileSystemName}-%{BuildConfig:Name}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildPropertiesSettings &buildPropertiesSettings()
|
BuildPropertiesSettings &buildPropertiesSettings()
|
||||||
|
@@ -81,6 +81,8 @@ private slots:
|
|||||||
void testWildcardToRegularExpression();
|
void testWildcardToRegularExpression();
|
||||||
void testSplitAtFirst_data();
|
void testSplitAtFirst_data();
|
||||||
void testSplitAtFirst();
|
void testSplitAtFirst();
|
||||||
|
void testAsciify_data();
|
||||||
|
void testAsciify();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestMacroExpander mx;
|
TestMacroExpander mx;
|
||||||
@@ -438,6 +440,26 @@ void tst_StringUtils::testSplitAtFirst()
|
|||||||
QCOMPARE(r, right);
|
QCOMPARE(r, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_StringUtils::testAsciify_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("input");
|
||||||
|
QTest::addColumn<QString>("expected");
|
||||||
|
|
||||||
|
QTest::newRow("Basic Latin") << QString("Basic text") << QString("Basic text");
|
||||||
|
QTest::newRow("Control character") << QString("\x07 text") << QString("u0007 text");
|
||||||
|
QTest::newRow("Miscellaneous Technical") << QString("\u23F0 text") << QString("u23f0 text");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_StringUtils::testAsciify()
|
||||||
|
{
|
||||||
|
QFETCH(QString, input);
|
||||||
|
QFETCH(QString, expected);
|
||||||
|
|
||||||
|
const QString asciified = Utils::asciify(input);
|
||||||
|
|
||||||
|
QCOMPARE(asciified, expected);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(tst_StringUtils)
|
QTEST_GUILESS_MAIN(tst_StringUtils)
|
||||||
|
|
||||||
#include "tst_stringutils.moc"
|
#include "tst_stringutils.moc"
|
||||||
|
Reference in New Issue
Block a user