forked from qt-creator/qt-creator
QmlDesigner: Fix the bug for regexp and encoding of csv in ModelEditor
Fixes: QDS-11667 Change-Id: I2399f1a8689634f92595624f4da781f27290fb57 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -54,9 +54,8 @@ public:
|
|||||||
|
|
||||||
inline static bool isValidColorName(const QString &colorName)
|
inline static bool isValidColorName(const QString &colorName)
|
||||||
{
|
{
|
||||||
constexpr QStringView colorPattern(
|
static const QRegularExpression colorRegex{
|
||||||
u"(?<color>^(?:#(?:(?:[0-9a-fA-F]{2}){3,4}|(?:[0-9a-fA-F]){3,4}))$)");
|
"(?<color>^(?:#(?:(?:[0-9a-fA-F]{2}){3,4}|(?:[0-9a-fA-F]){3,4}))$)"};
|
||||||
static const QRegularExpression colorRegex(colorPattern.toString());
|
|
||||||
return colorRegex.match(colorName).hasMatch();
|
return colorRegex.match(colorName).hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,19 +78,19 @@ inline static bool getCustomUrl(const QString &value,
|
|||||||
QUrl *urlResult = nullptr,
|
QUrl *urlResult = nullptr,
|
||||||
QString *subType = nullptr)
|
QString *subType = nullptr)
|
||||||
{
|
{
|
||||||
constexpr QStringView urlPattern(
|
static const QRegularExpression urlRegex{
|
||||||
u"^(?<MimeType>"
|
"^(?<MimeType>"
|
||||||
u"(?<MainType>image)\\/"
|
"(?<MainType>image)\\/"
|
||||||
u"(?<SubType>apng|avif|gif|jpeg|png|(?:svg\\+xml)|webp|xyz)\\:)?" // end of MimeType
|
"(?<SubType>apng|avif|gif|jpeg|png|(?:svg\\+xml)|webp|xyz)\\:)?" // end of MimeType
|
||||||
u"(?<Address>"
|
"(?<Address>"
|
||||||
u"(?<Url>https?:\\/\\/"
|
"(?<Url>https?:\\/\\/"
|
||||||
u"(?:www\\.|(?!www))[A-z0-9][A-z0-9-]+[A-z0-9]\\.[^\\s]{2,}|www\\.[A-z0-9][A-z0-9-]+"
|
"(?:www\\.|(?!www))[A-z0-9][A-z0-9-]+[A-z0-9]\\.[^\\s]{2,}|www\\.[A-z0-9][A-z0-9-]+"
|
||||||
u"[A-z0-9]\\.[^\\s]{2,}|https?:\\/\\/"
|
"[A-z0-9]\\.[^\\s]{2,}|https?:\\/\\/"
|
||||||
u"(?:www\\.|(?!www))[A-z0-9]+\\.[^\\s]{2,}|www\\.[A-z0-9]+\\.[^\\s]{2,})|" // end of Url
|
"(?:www\\.|(?!www))[A-z0-9]+\\.[^\\s]{2,}|www\\.[A-z0-9]+\\.[^\\s]{2,})|" // end of Url
|
||||||
u"(?<LocalFile>("
|
"(?<LocalFile>("
|
||||||
u"?:(?:[A-z]:)|(?:(?:\\\\|\\/){1,2}\\w+)\\$?)(?:(?:\\\\|\\/)(?:\\w[\\w ]*.*))+)" // end of LocalFile
|
"?:(?:[A-z]:)|(?:(?:\\\\|\\/){1,2}\\w+)\\$?)(?:(?:\\\\|\\/)(?:\\w[\\w ]*.*))+)" // end of LocalFile
|
||||||
u"){1}$"); // end of Address
|
"){1}$" // end of Address
|
||||||
static const QRegularExpression urlRegex(urlPattern.toString());
|
};
|
||||||
|
|
||||||
const QRegularExpressionMatch match = urlRegex.match(value);
|
const QRegularExpressionMatch match = urlRegex.match(value);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
@@ -267,10 +266,9 @@ inline static bool isEmptyJsonValue(const QJsonValue &value)
|
|||||||
|
|
||||||
QStringList csvReadLine(const QString &line)
|
QStringList csvReadLine(const QString &line)
|
||||||
{
|
{
|
||||||
constexpr QStringView linePattern = u"(?:,\"|^\")(?<value>\"\"|[\\w\\W]*?)(?=\",|\"$)"
|
static const QRegularExpression lineRegex{
|
||||||
u"|(?:,(?!\")|^(?!\"))(?<quote>[^,]*?)(?=$|,)|(\\r\\n|\\n)";
|
"(?:,\\\"|^\\\")(?<value>\\\"\\\"|[\\w\\W]*?)(?=\\\",|\\\"$)"
|
||||||
|
"|(?:,(?!\\\")|^(?!\\\"))(?<quote>[^,]*?)(?=$|,)|(\\\\r\\\\n|\\\\n)"};
|
||||||
static const QRegularExpression lineRegex(linePattern.toString());
|
|
||||||
static const int valueIndex = lineRegex.namedCaptureGroups().indexOf("value");
|
static const int valueIndex = lineRegex.namedCaptureGroups().indexOf("value");
|
||||||
static const int quoteIndex = lineRegex.namedCaptureGroups().indexOf("quote");
|
static const int quoteIndex = lineRegex.namedCaptureGroups().indexOf("quote");
|
||||||
Q_ASSERT(valueIndex > 0 && quoteIndex > 0);
|
Q_ASSERT(valueIndex > 0 && quoteIndex > 0);
|
||||||
@@ -281,7 +279,7 @@ QStringList csvReadLine(const QString &line)
|
|||||||
const QRegularExpressionMatch match = iterator.next();
|
const QRegularExpressionMatch match = iterator.next();
|
||||||
|
|
||||||
if (match.hasCaptured(valueIndex))
|
if (match.hasCaptured(valueIndex))
|
||||||
result.append(match.captured(2));
|
result.append(match.captured(valueIndex));
|
||||||
else if (match.hasCaptured(quoteIndex))
|
else if (match.hasCaptured(quoteIndex))
|
||||||
result.append(match.captured(quoteIndex));
|
result.append(match.captured(quoteIndex));
|
||||||
}
|
}
|
||||||
@@ -737,6 +735,7 @@ CollectionDetails CollectionDetails::fromImportedCsv(const QByteArray &document,
|
|||||||
QJsonArray importedArray;
|
QJsonArray importedArray;
|
||||||
|
|
||||||
QTextStream stream(document);
|
QTextStream stream(document);
|
||||||
|
stream.setEncoding(QStringConverter::Latin1);
|
||||||
|
|
||||||
if (firstRowIsHeader && !stream.atEnd()) {
|
if (firstRowIsHeader && !stream.atEnd()) {
|
||||||
headers = Utils::transform(csvReadLine(stream.readLine()),
|
headers = Utils::transform(csvReadLine(stream.readLine()),
|
||||||
|
Reference in New Issue
Block a user