Browse Source

Change splitToViews() return type to QVector

adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
ff707ea5af
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 4
      src/base/http/requestparser.cpp
  2. 5
      src/base/search/searchpluginmanager.cpp
  3. 10
      src/base/utils/bytearray.cpp
  4. 8
      src/base/utils/bytearray.h
  5. 3
      src/base/utils/foreignapps.cpp
  6. 3
      src/base/utils/password.cpp

4
src/base/http/requestparser.cpp

@ -253,7 +253,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
// split data by "dash-boundary" // split data by "dash-boundary"
const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF; const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF;
QList<QByteArray> multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); QVector<QByteArray> multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts);
if (multipart.isEmpty()) { if (multipart.isEmpty()) {
qWarning() << Q_FUNC_INFO << "multipart empty"; qWarning() << Q_FUNC_INFO << "multipart empty";
return false; return false;
@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
bool RequestParser::parseFormData(const QByteArray &data) bool RequestParser::parseFormData(const QByteArray &data)
{ {
const QList<QByteArray> list = splitToViews(data, EOH, QString::KeepEmptyParts); const QVector<QByteArray> list = splitToViews(data, EOH, QString::KeepEmptyParts);
if (list.size() != 2) { if (list.size() != 2) {
qWarning() << Q_FUNC_INFO << "multipart/form-data format error"; qWarning() << Q_FUNC_INFO << "multipart/form-data format error";

5
src/base/search/searchpluginmanager.cpp

@ -37,7 +37,6 @@
#include <QDomDocument> #include <QDomDocument>
#include <QDomElement> #include <QDomElement>
#include <QDomNode> #include <QDomNode>
#include <QList>
#include <QPointer> #include <QPointer>
#include <QProcess> #include <QProcess>
@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info)
QHash<QString, PluginVersion> updateInfo; QHash<QString, PluginVersion> updateInfo;
int numCorrectData = 0; int numCorrectData = 0;
const QList<QByteArray> lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); const QVector<QByteArray> lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts);
for (QByteArray line : lines) { for (QByteArray line : lines) {
line = line.trimmed(); line = line.trimmed();
if (line.isEmpty()) continue; if (line.isEmpty()) continue;
if (line.startsWith('#')) continue; if (line.startsWith('#')) continue;
const QList<QByteArray> list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); const QVector<QByteArray> list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts);
if (list.size() != 2) continue; if (list.size() != 2) continue;
const QString pluginName = list.first().trimmed(); const QString pluginName = list.first().trimmed();

10
src/base/utils/bytearray.cpp

@ -28,15 +28,17 @@
#include "bytearray.h" #include "bytearray.h"
#include <QList> #include <QByteArray>
QList<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) QVector<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior)
{ {
if (sep.isEmpty()) if (sep.isEmpty())
return {in}; return {in};
QList<QByteArray> ret; QVector<QByteArray> ret;
ret.reserve((behavior == QString::KeepEmptyParts)
? (1 + (in.size() / sep.size()))
: (1 + (in.size() / (sep.size() + 1))));
int head = 0; int head = 0;
while (head < in.size()) { while (head < in.size()) {
int end = in.indexOf(sep, head); int end = in.indexOf(sep, head);

8
src/base/utils/bytearray.h

@ -28,15 +28,17 @@
#pragma once #pragma once
#include <QByteArray>
#include <QString> #include <QString>
#include <QVector>
class QByteArray;
namespace Utils namespace Utils
{ {
namespace ByteArray namespace ByteArray
{ {
// Mimic QString::split(sep, behavior) // Mimic QString::splitRef(sep, behavior)
QList<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); QVector<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts);
// Mimic QByteArray::mid(pos, len) but instead of returning a full-copy, // Mimic QByteArray::mid(pos, len) but instead of returning a full-copy,
// we only return a partial view // we only return a partial view

3
src/base/utils/foreignapps.cpp

@ -43,6 +43,7 @@
#endif #endif
#include "base/logger.h" #include "base/logger.h"
#include "base/utils/bytearray.h"
using namespace Utils::ForeignApps; using namespace Utils::ForeignApps;
@ -61,7 +62,7 @@ namespace
// Software 'Anaconda' installs its own python interpreter // Software 'Anaconda' installs its own python interpreter
// and `python --version` returns a string like this: // and `python --version` returns a string like this:
// "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)" // "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)"
const QList<QByteArray> outputSplit = procOutput.split(' '); const QVector<QByteArray> outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", QString::SkipEmptyParts);
if (outputSplit.size() <= 1) if (outputSplit.size() <= 1)
return false; return false;

3
src/base/utils/password.cpp

@ -33,7 +33,6 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <QByteArray> #include <QByteArray>
#include <QList>
#include <QString> #include <QString>
#include "bytearray.h" #include "bytearray.h"
@ -99,7 +98,7 @@ bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QString &pa
bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password) bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password)
{ {
const QList<QByteArray> list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); const QVector<QByteArray> list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts);
if (list.size() != 2) if (list.size() != 2)
return false; return false;

Loading…
Cancel
Save