mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 16:55:36 +08:00
Partially revert "Remove unused stringutils methods"
This partially reverts commit 0c1a5a5c97.
This commit is contained in:
@@ -569,7 +569,7 @@ namespace BlackMisc::Simulation::XPlane
|
||||
{
|
||||
++lineNum;
|
||||
QString line = in.readLine();
|
||||
auto tokens = line.split(' ');
|
||||
auto tokens = splitString(line, [](QChar c) { return c.isSpace(); });
|
||||
if (!tokens.empty())
|
||||
{
|
||||
auto it = commands.find(tokens[0]);
|
||||
@@ -615,7 +615,7 @@ namespace BlackMisc::Simulation::XPlane
|
||||
++lineNum;
|
||||
QString line = in.readLine();
|
||||
if (line.isEmpty() || line[0] == '#') continue;
|
||||
auto tokens = line.split(' ');
|
||||
auto tokens = splitString(line, [](QChar c) { return c.isSpace(); });
|
||||
if (!tokens.empty())
|
||||
{
|
||||
auto it = commands.find(tokens[0]);
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace BlackMisc
|
||||
return splitStringRefs(s, [](QChar c) { return c == '\n' || c == '\r'; });
|
||||
}
|
||||
|
||||
QStringList splitLines(const QString &s)
|
||||
{
|
||||
return splitString(s, [](QChar c) { return c == '\n' || c == '\r'; });
|
||||
}
|
||||
|
||||
QByteArray utfToPercentEncoding(const QString& s, const QByteArray &allow, char percent)
|
||||
{
|
||||
QByteArray result;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define BLACKMISC_STRINGUTILS_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/range.h"
|
||||
#include "blackmisc/typetraits.h"
|
||||
|
||||
#include <QByteArray>
|
||||
@@ -116,6 +117,15 @@ namespace BlackMisc
|
||||
//! It would be risky to call splitLinesRefs with an rvalue, so forbid it.
|
||||
void splitLinesRefs(const QString &&) = delete;
|
||||
|
||||
//! Split a string into multiple strings, using a predicate function to identify the split points.
|
||||
template <class F> QStringList splitString(const QString &s, F predicate)
|
||||
{
|
||||
return makeRange(splitStringRefs(s, predicate)).transform([](QStringRef sr) { return sr.toString(); });
|
||||
}
|
||||
|
||||
//! Split a string into multiple lines. Blank lines are skipped.
|
||||
BLACKMISC_EXPORT QStringList splitLines(const QString &s);
|
||||
|
||||
//! Extended percent encoding supporting UTF-16
|
||||
BLACKMISC_EXPORT QByteArray utfToPercentEncoding(const QString &s, const QByteArray &allow = {}, char percent = '%');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user