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) @@ -253,7 +253,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
// split data by "dash-boundary"
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()) {
qWarning() << Q_FUNC_INFO << "multipart empty";
return false;
@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) @@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(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) {
qWarning() << Q_FUNC_INFO << "multipart/form-data format error";

5
src/base/search/searchpluginmanager.cpp

@ -37,7 +37,6 @@ @@ -37,7 +37,6 @@
#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include <QList>
#include <QPointer>
#include <QProcess>
@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info) @@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info)
QHash<QString, PluginVersion> updateInfo;
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) {
line = line.trimmed();
if (line.isEmpty()) 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;
const QString pluginName = list.first().trimmed();

10
src/base/utils/bytearray.cpp

@ -28,15 +28,17 @@ @@ -28,15 +28,17 @@
#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())
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;
while (head < in.size()) {
int end = in.indexOf(sep, head);

8
src/base/utils/bytearray.h

@ -28,15 +28,17 @@ @@ -28,15 +28,17 @@
#pragma once
#include <QByteArray>
#include <QString>
#include <QVector>
class QByteArray;
namespace Utils
{
namespace ByteArray
{
// Mimic QString::split(sep, behavior)
QList<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts);
// Mimic QString::splitRef(sep, behavior)
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,
// we only return a partial view

3
src/base/utils/foreignapps.cpp

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
#endif
#include "base/logger.h"
#include "base/utils/bytearray.h"
using namespace Utils::ForeignApps;
@ -61,7 +62,7 @@ namespace @@ -61,7 +62,7 @@ namespace
// Software 'Anaconda' installs its own python interpreter
// and `python --version` returns a string like this:
// "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)
return false;

3
src/base/utils/password.cpp

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

Loading…
Cancel
Save