mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
refactor: Remove Qt5 compatibility layer
This commit is contained in:
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -108,7 +108,7 @@ jobs:
|
|||||||
uses: jurplel/install-qt-action@v4
|
uses: jurplel/install-qt-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.qt_version }}
|
version: ${{ env.qt_version }}
|
||||||
modules: 'qtmultimedia qt5compat'
|
modules: 'qtmultimedia'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Cache InstallBuilder
|
- name: Cache InstallBuilder
|
||||||
id: cache-bitrock
|
id: cache-bitrock
|
||||||
@@ -201,7 +201,7 @@ jobs:
|
|||||||
uses: jurplel/install-qt-action@v4
|
uses: jurplel/install-qt-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.qt_version }}
|
version: ${{ env.qt_version }}
|
||||||
modules: 'qtmultimedia qt5compat'
|
modules: 'qtmultimedia'
|
||||||
arch: win64_msvc2022_64
|
arch: win64_msvc2022_64
|
||||||
cache: true
|
cache: true
|
||||||
- name: Install Qt debug info
|
- name: Install Qt debug info
|
||||||
@@ -299,7 +299,7 @@ jobs:
|
|||||||
uses: jurplel/install-qt-action@v4
|
uses: jurplel/install-qt-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.qt_version }}
|
version: ${{ env.qt_version }}
|
||||||
modules: 'qtmultimedia qt5compat'
|
modules: 'qtmultimedia'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Cache InstallBuilder
|
- name: Cache InstallBuilder
|
||||||
id: cache-bitrock
|
id: cache-bitrock
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Find dependencies
|
# Find dependencies
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui Multimedia Network OpenGL Concurrent Xml Qml Widgets Svg Test Core5Compat)
|
find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui Multimedia Network OpenGL Concurrent Xml Qml Widgets Svg Test)
|
||||||
|
|
||||||
# Global compiler options
|
# Global compiler options
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ if(UNIX AND NOT APPLE)
|
|||||||
|
|
||||||
|
|
||||||
installLib(${QT_INSTALL_LIBS} libQt6Core.so.6)
|
installLib(${QT_INSTALL_LIBS} libQt6Core.so.6)
|
||||||
installLib(${QT_INSTALL_LIBS} libQt6Core5Compat.so.6)
|
|
||||||
installLib(${QT_INSTALL_LIBS} libQt6DBus.so.6)
|
installLib(${QT_INSTALL_LIBS} libQt6DBus.so.6)
|
||||||
installLib(${QT_INSTALL_LIBS} libQt6Gui.so.6)
|
installLib(${QT_INSTALL_LIBS} libQt6Gui.so.6)
|
||||||
installLib(${QT_INSTALL_LIBS} libQt6Multimedia.so.6)
|
installLib(${QT_INSTALL_LIBS} libQt6Multimedia.so.6)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ set(SWIFT_MISC_PCH
|
|||||||
<QString>
|
<QString>
|
||||||
<QStringBuilder>
|
<QStringBuilder>
|
||||||
<QStringList>
|
<QStringList>
|
||||||
<QStringRef>
|
<QStringView>
|
||||||
<QThread>
|
<QThread>
|
||||||
<QTime>
|
<QTime>
|
||||||
<QTimer>
|
<QTimer>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ endfunction()
|
|||||||
|
|
||||||
copy_framework(QtConcurrent)
|
copy_framework(QtConcurrent)
|
||||||
copy_framework(QtCore)
|
copy_framework(QtCore)
|
||||||
copy_framework(QtCore5Compat)
|
|
||||||
copy_framework(QtDBus)
|
copy_framework(QtDBus)
|
||||||
copy_framework(QtGui)
|
copy_framework(QtGui)
|
||||||
copy_framework(QtMultimedia)
|
copy_framework(QtMultimedia)
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
<distributionFile>
|
<distributionFile>
|
||||||
<origin>../../dist/bin/Qt6Core.dll</origin>
|
<origin>../../dist/bin/Qt6Core.dll</origin>
|
||||||
</distributionFile>
|
</distributionFile>
|
||||||
<distributionFile>
|
|
||||||
<origin>../../dist/bin/Qt6Core5Compat.dll</origin>
|
|
||||||
</distributionFile>
|
|
||||||
<distributionFile>
|
<distributionFile>
|
||||||
<origin>../../dist/bin/Qt6DBus.dll</origin>
|
<origin>../../dist/bin/Qt6DBus.dll</origin>
|
||||||
</distributionFile>
|
</distributionFile>
|
||||||
@@ -75,9 +72,6 @@
|
|||||||
<distributionFile>
|
<distributionFile>
|
||||||
<origin>../../dist/lib/libQt6Core.so.6</origin>
|
<origin>../../dist/lib/libQt6Core.so.6</origin>
|
||||||
</distributionFile>
|
</distributionFile>
|
||||||
<distributionFile>
|
|
||||||
<origin>../../dist/lib/libQt6Core5Compat.so.6</origin>
|
|
||||||
</distributionFile>
|
|
||||||
<distributionFile>
|
<distributionFile>
|
||||||
<origin>../../dist/lib/libQt6DBus.so.6</origin>
|
<origin>../../dist/lib/libQt6DBus.so.6</origin>
|
||||||
</distributionFile>
|
</distributionFile>
|
||||||
@@ -128,9 +122,6 @@
|
|||||||
<distributionDirectory>
|
<distributionDirectory>
|
||||||
<origin>../../dist/lib/QtCore.framework</origin>
|
<origin>../../dist/lib/QtCore.framework</origin>
|
||||||
</distributionDirectory>
|
</distributionDirectory>
|
||||||
<distributionDirectory>
|
|
||||||
<origin>../../dist/lib/QtCore5Compat.framework</origin>
|
|
||||||
</distributionDirectory>
|
|
||||||
<distributionDirectory>
|
<distributionDirectory>
|
||||||
<origin>../../dist/lib/QtDBus.framework</origin>
|
<origin>../../dist/lib/QtDBus.framework</origin>
|
||||||
</distributionDirectory>
|
</distributionDirectory>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -155,8 +154,7 @@ namespace swift::sample
|
|||||||
std::generate_n(std::back_inserter(strList3), 100000, generator);
|
std::generate_n(std::back_inserter(strList3), 100000, generator);
|
||||||
std::generate_n(std::back_inserter(strList4), 100000, generator);
|
std::generate_n(std::back_inserter(strList4), 100000, generator);
|
||||||
QRegularExpression newRegex("^.*aaa.*$", QRegularExpression::CaseInsensitiveOption);
|
QRegularExpression newRegex("^.*aaa.*$", QRegularExpression::CaseInsensitiveOption);
|
||||||
QRegExp fullRegex(".*aaa.*", Qt::CaseInsensitive);
|
QRegularExpression fullRegex(".*aaa.*", QRegularExpression::CaseInsensitiveOption);
|
||||||
QRegExp wildcardRegex("*aaa*", Qt::CaseInsensitive, QRegExp::Wildcard);
|
|
||||||
QString containsStr("aaa");
|
QString containsStr("aaa");
|
||||||
number = 0;
|
number = 0;
|
||||||
timer.start();
|
timer.start();
|
||||||
@@ -170,20 +168,12 @@ namespace swift::sample
|
|||||||
timer.start();
|
timer.start();
|
||||||
for (const auto &str : std::as_const(strList2))
|
for (const auto &str : std::as_const(strList2))
|
||||||
{
|
{
|
||||||
if (fullRegex.exactMatch(str)) number++;
|
if (fullRegex.match(str).hasMatch()) number++;
|
||||||
}
|
}
|
||||||
ms = timer.elapsed();
|
ms = timer.elapsed();
|
||||||
out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << Qt::endl;
|
out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << Qt::endl;
|
||||||
number = 0;
|
number = 0;
|
||||||
timer.start();
|
timer.start();
|
||||||
for (const auto &str : std::as_const(strList3))
|
|
||||||
{
|
|
||||||
if (wildcardRegex.exactMatch(str)) number++;
|
|
||||||
}
|
|
||||||
ms = timer.elapsed();
|
|
||||||
out << "wildcard matched " << number << " of " << strList3.size() << " strings in " << ms << "ms" << Qt::endl;
|
|
||||||
number = 0;
|
|
||||||
timer.start();
|
|
||||||
for (const auto &str : std::as_const(strList4))
|
for (const auto &str : std::as_const(strList4))
|
||||||
{
|
{
|
||||||
if (str.contains(containsStr)) number++;
|
if (str.contains(containsStr)) number++;
|
||||||
@@ -441,7 +431,7 @@ namespace swift::sample
|
|||||||
auto lines = splitLinesRefs(bigString);
|
auto lines = splitLinesRefs(bigString);
|
||||||
Q_UNUSED(lines);
|
Q_UNUSED(lines);
|
||||||
}
|
}
|
||||||
out << "Split 100,000 line string into list of lines: (QList<QStringRef>) " << timer.elapsed() << "ms"
|
out << "Split 100,000 line string into list of lines: (QList<QStringView>) " << timer.elapsed() << "ms"
|
||||||
<< Qt::endl;
|
<< Qt::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ namespace swift::core::fsd
|
|||||||
"Can't change server details while still connected");
|
"Can't change server details while still connected");
|
||||||
|
|
||||||
const QString codecName(server.getFsdSetup().getTextCodec());
|
const QString codecName(server.getFsdSetup().getTextCodec());
|
||||||
QTextCodec *textCodec = QTextCodec::codecForName(codecName.toLocal8Bit());
|
auto codec = QStringDecoder::encodingForName(codecName);
|
||||||
if (!textCodec) { textCodec = QTextCodec::codecForName("utf-8"); }
|
if (!codec.has_value()) { codec = QStringConverter::Utf8; }
|
||||||
const int protocolRev = (server.getServerType() == CServer::FSDServerVatsim) ?
|
const int protocolRev = (server.getServerType() == CServer::FSDServerVatsim) ?
|
||||||
PROTOCOL_REVISION_VATSIM_VELOCITY :
|
PROTOCOL_REVISION_VATSIM_VELOCITY :
|
||||||
PROTOCOL_REVISION_CLASSIC;
|
PROTOCOL_REVISION_CLASSIC;
|
||||||
@@ -150,7 +150,8 @@ namespace swift::core::fsd
|
|||||||
QWriteLocker l(&m_lockUserClientBuffered);
|
QWriteLocker l(&m_lockUserClientBuffered);
|
||||||
m_server = server;
|
m_server = server;
|
||||||
m_protocolRevision = protocolRev;
|
m_protocolRevision = protocolRev;
|
||||||
m_fsdTextCodec = textCodec;
|
m_encoder = QStringEncoder(codec.value_or(QStringConverter::Utf8));
|
||||||
|
m_decoder = QStringDecoder(codec.value_or(QStringConverter::Utf8));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFSDClient::setCallsign(const CCallsign &callsign)
|
void CFSDClient::setCallsign(const CCallsign &callsign)
|
||||||
@@ -781,7 +782,7 @@ namespace swift::core::fsd
|
|||||||
void CFSDClient::sendMessageString(const QString &message)
|
void CFSDClient::sendMessageString(const QString &message)
|
||||||
{
|
{
|
||||||
if (message.isEmpty()) { return; }
|
if (message.isEmpty()) { return; }
|
||||||
const QByteArray bufferEncoded = m_fsdTextCodec->fromUnicode(message);
|
const QByteArray bufferEncoded = m_encoder(message);
|
||||||
if (m_printToConsole) { qDebug() << "FSD Sent=>" << bufferEncoded; }
|
if (m_printToConsole) { qDebug() << "FSD Sent=>" << bufferEncoded; }
|
||||||
if (!m_unitTestMode) { m_socket->write(bufferEncoded); }
|
if (!m_unitTestMode) { m_socket->write(bufferEncoded); }
|
||||||
|
|
||||||
@@ -2199,7 +2200,7 @@ namespace swift::core::fsd
|
|||||||
{
|
{
|
||||||
const QByteArray dataEncoded = m_socket->readLine();
|
const QByteArray dataEncoded = m_socket->readLine();
|
||||||
if (dataEncoded.isEmpty()) { continue; }
|
if (dataEncoded.isEmpty()) { continue; }
|
||||||
const QString data = m_fsdTextCodec->toUnicode(dataEncoded);
|
const QString data = m_decoder(dataEncoded);
|
||||||
this->parseMessage(data);
|
this->parseMessage(data);
|
||||||
lines++;
|
lines++;
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QTextCodec>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
@@ -651,7 +650,8 @@ namespace swift::core::fsd
|
|||||||
// User data
|
// User data
|
||||||
swift::misc::network::CServer m_server;
|
swift::misc::network::CServer m_server;
|
||||||
swift::misc::network::CLoginMode m_loginMode;
|
swift::misc::network::CLoginMode m_loginMode;
|
||||||
QTextCodec *m_fsdTextCodec = nullptr;
|
QStringEncoder m_encoder;
|
||||||
|
QStringDecoder m_decoder;
|
||||||
SimType m_simType = SimType::Unknown;
|
SimType m_simType = SimType::Unknown;
|
||||||
PilotRating m_pilotRating = PilotRating::Unknown;
|
PilotRating m_pilotRating = PilotRating::Unknown;
|
||||||
AtcRating m_atcRating = AtcRating::Unknown;
|
AtcRating m_atcRating = AtcRating::Unknown;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace swift::gui::editors
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->resetToDefaultValues();
|
this->resetToDefaultValues();
|
||||||
ui->cb_Override->setChecked(true);
|
ui->cb_Override->setChecked(true);
|
||||||
ui->le_TextCodec->setCompleter(new QCompleter(textCodecNames(true, true), this));
|
ui->le_TextCodec->setCompleter(new QCompleter(QStringDecoder::availableCodecs(), this));
|
||||||
connect(ui->cb_Override, &QCheckBox::toggled, this, &CFsdSetupForm::enabledToggled, Qt::QueuedConnection);
|
connect(ui->cb_Override, &QCheckBox::toggled, this, &CFsdSetupForm::enabledToggled, Qt::QueuedConnection);
|
||||||
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CFsdSetupForm::resetToDefaultValues);
|
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CFsdSetupForm::resetToDefaultValues);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -698,7 +698,6 @@ target_link_libraries(misc
|
|||||||
Qt::Network
|
Qt::Network
|
||||||
Qt::Multimedia
|
Qt::Multimedia
|
||||||
nlohmann_json::nlohmann_json
|
nlohmann_json::nlohmann_json
|
||||||
Qt::Core5Compat # for QStringRef
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
Qt::Xml
|
Qt::Xml
|
||||||
SimpleCrypt
|
SimpleCrypt
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringRef>
|
|
||||||
#include <QStringView>
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace swift::misc::network
|
|||||||
{
|
{
|
||||||
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"No codec"));
|
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"No codec"));
|
||||||
}
|
}
|
||||||
if (!textCodecNames(true, true).contains(this->getTextCodec()))
|
if (!QStringDecoder::availableCodecs().contains(this->getTextCodec()))
|
||||||
{
|
{
|
||||||
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"Unrecognized codec name"));
|
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"Unrecognized codec name"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -657,13 +657,13 @@ namespace swift::misc::simulation::fscommon
|
|||||||
// manually parsing because QSettings did not work properly
|
// manually parsing because QSettings did not work properly
|
||||||
const QString fileContent = CFileUtils::readFileToString(configFile);
|
const QString fileContent = CFileUtils::readFileToString(configFile);
|
||||||
if (fileContent.isEmpty()) { continue; }
|
if (fileContent.isEmpty()) { continue; }
|
||||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||||
static const QString p("Path=");
|
static const QString p("Path=");
|
||||||
for (const QStringRef &line : lines)
|
for (const QStringView &line : lines)
|
||||||
{
|
{
|
||||||
const int i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
const int i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||||
if (i < 0 || line.endsWith('=')) { continue; }
|
if (i < 0 || line.endsWith('=')) { continue; }
|
||||||
const QStringRef path = line.mid(i + p.length());
|
const QStringView path = line.mid(i + p.length());
|
||||||
const QDir dir(QDir::fromNativeSeparators(
|
const QDir dir(QDir::fromNativeSeparators(
|
||||||
pathPrefix.isEmpty() ? path.toString() :
|
pathPrefix.isEmpty() ? path.toString() :
|
||||||
CFileUtils::appendFilePathsAndFixUnc(pathPrefix, path.toString())));
|
CFileUtils::appendFilePathsAndFixUnc(pathPrefix, path.toString())));
|
||||||
@@ -785,20 +785,20 @@ namespace swift::misc::simulation::fscommon
|
|||||||
{
|
{
|
||||||
const QString fileContent = CFileUtils::readFileToString(fsxFile);
|
const QString fileContent = CFileUtils::readFileToString(fsxFile);
|
||||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||||
static const QString p("SimObjectPaths.");
|
static const QString p("SimObjectPaths.");
|
||||||
|
|
||||||
const QFileInfo fsxFileInfo(fsxFile);
|
const QFileInfo fsxFileInfo(fsxFile);
|
||||||
const QString relPath = fsxFileInfo.absolutePath();
|
const QString relPath = fsxFileInfo.absolutePath();
|
||||||
|
|
||||||
QSet<QString> paths;
|
QSet<QString> paths;
|
||||||
for (const QStringRef &line : lines)
|
for (const QStringView &line : lines)
|
||||||
{
|
{
|
||||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||||
if (i1 < 0) { continue; }
|
if (i1 < 0) { continue; }
|
||||||
const int i2 = line.lastIndexOf('=');
|
const int i2 = line.lastIndexOf('=');
|
||||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||||
const QStringRef path = line.mid(i2 + 1);
|
const QStringView path = line.mid(i2 + 1);
|
||||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||||
if (logConfigPathReading())
|
if (logConfigPathReading())
|
||||||
{
|
{
|
||||||
@@ -857,20 +857,20 @@ namespace swift::misc::simulation::fscommon
|
|||||||
{
|
{
|
||||||
const QString fileContent = CFileUtils::readFileToString(msfsFile);
|
const QString fileContent = CFileUtils::readFileToString(msfsFile);
|
||||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||||
static const QString p("SimObjectPaths.");
|
static const QString p("SimObjectPaths.");
|
||||||
|
|
||||||
const QFileInfo fsxFileInfo(msfsFile);
|
const QFileInfo fsxFileInfo(msfsFile);
|
||||||
const QString relPath = fsxFileInfo.absolutePath();
|
const QString relPath = fsxFileInfo.absolutePath();
|
||||||
|
|
||||||
QSet<QString> paths;
|
QSet<QString> paths;
|
||||||
for (const QStringRef &line : lines)
|
for (const QStringView &line : lines)
|
||||||
{
|
{
|
||||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||||
if (i1 < 0) { continue; }
|
if (i1 < 0) { continue; }
|
||||||
const int i2 = line.lastIndexOf('=');
|
const int i2 = line.lastIndexOf('=');
|
||||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||||
const QStringRef path = line.mid(i2 + 1);
|
const QStringView path = line.mid(i2 + 1);
|
||||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||||
if (logConfigPathReading())
|
if (logConfigPathReading())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <QChar>
|
#include <QChar>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QTextCodec>
|
|
||||||
|
|
||||||
namespace swift::misc
|
namespace swift::misc
|
||||||
{
|
{
|
||||||
@@ -17,7 +16,7 @@ namespace swift::misc
|
|||||||
return removeChars(s, [](QChar c) { return c == u' ' || c == u':' || c == u'_' || c == u'-' || c == u'.'; });
|
return removeChars(s, [](QChar c) { return c == u' ' || c == u':' || c == u'_' || c == u'-' || c == u'.'; });
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringRef> splitLinesRefs(const QString &s)
|
QList<QStringView> splitLinesRefs(const QString &s)
|
||||||
{
|
{
|
||||||
return splitStringRefs(s, [](QChar c) { return c == '\n' || c == '\r'; });
|
return splitStringRefs(s, [](QChar c) { return c == '\n' || c == '\r'; });
|
||||||
}
|
}
|
||||||
@@ -210,44 +209,6 @@ namespace swift::misc
|
|||||||
return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
|
return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList simpleTextCodecNamesImpl()
|
|
||||||
{
|
|
||||||
QStringList codecs;
|
|
||||||
for (const QByteArray &ba : QTextCodec::availableCodecs())
|
|
||||||
{
|
|
||||||
const QString c(QString::fromLocal8Bit(ba));
|
|
||||||
codecs << c;
|
|
||||||
}
|
|
||||||
return codecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList mibTextCodecNamesImpl()
|
|
||||||
{
|
|
||||||
QStringList codecs;
|
|
||||||
for (int mib : QTextCodec::availableMibs())
|
|
||||||
{
|
|
||||||
const QByteArray ba(QTextCodec::codecForMib(mib)->name());
|
|
||||||
const QString c(QString::fromLocal8Bit(ba));
|
|
||||||
codecs << c;
|
|
||||||
}
|
|
||||||
return codecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList textCodecNames(bool simpleNames, bool mibNames)
|
|
||||||
{
|
|
||||||
static const QStringList simple(simpleTextCodecNamesImpl());
|
|
||||||
static const QStringList mib(mibTextCodecNamesImpl());
|
|
||||||
if (simpleNames && mibNames)
|
|
||||||
{
|
|
||||||
QStringList s(simple);
|
|
||||||
s.append(mib);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
if (simpleNames) { return simple; }
|
|
||||||
if (mibNames) { return mib; }
|
|
||||||
return QStringList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// http://www.codegur.online/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
// http://www.codegur.online/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
||||||
// https://stackoverflow.com/questions/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
// https://stackoverflow.com/questions/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
||||||
// https://german.stackexchange.com/questions/4992/conversion-table-for-diacritics-e-g-%C3%BC-%E2%86%92-ue
|
// https://german.stackexchange.com/questions/4992/conversion-table-for-diacritics-e-g-%C3%BC-%E2%86%92-ue
|
||||||
@@ -458,11 +419,11 @@ namespace swift::misc
|
|||||||
QMap<QString, QString> parseIniValues(const QString &data)
|
QMap<QString, QString> parseIniValues(const QString &data)
|
||||||
{
|
{
|
||||||
QMap<QString, QString> map;
|
QMap<QString, QString> map;
|
||||||
QList<QStringRef> lines = splitLinesRefs(data);
|
QList<QStringView> lines = splitLinesRefs(data);
|
||||||
for (const QStringRef &l : lines)
|
for (const QStringView &l : lines)
|
||||||
{
|
{
|
||||||
if (l.isEmpty()) { continue; }
|
if (l.isEmpty()) { continue; }
|
||||||
const int i = l.indexOf("=");
|
const int i = l.indexOf('=');
|
||||||
if (i < 0 || i >= l.length() + 1) { continue; }
|
if (i < 0 || i >= l.length() + 1) { continue; }
|
||||||
|
|
||||||
const QString key = l.left(i).trimmed().toString();
|
const QString key = l.left(i).trimmed().toString();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <QMapIterator>
|
#include <QMapIterator>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringRef>
|
|
||||||
#include <QStringView>
|
#include <QStringView>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
@@ -89,9 +88,9 @@ namespace swift::misc
|
|||||||
//! Split a string into multiple strings, using a predicate function to identify the split points.
|
//! Split a string into multiple strings, using a predicate function to identify the split points.
|
||||||
//! \warning The returned refs are only valid during the lifetime of the original string.
|
//! \warning The returned refs are only valid during the lifetime of the original string.
|
||||||
template <class F>
|
template <class F>
|
||||||
QList<QStringRef> splitStringRefs(const QString &s, F predicate)
|
QList<QStringView> splitStringRefs(const QString &s, F predicate)
|
||||||
{
|
{
|
||||||
QList<QStringRef> result;
|
QList<QStringView> result;
|
||||||
auto notPredicate = [=](auto c) { return !predicate(c); };
|
auto notPredicate = [=](auto c) { return !predicate(c); };
|
||||||
auto begin = s.begin();
|
auto begin = s.begin();
|
||||||
while (true)
|
while (true)
|
||||||
@@ -99,14 +98,14 @@ namespace swift::misc
|
|||||||
begin = std::find_if(begin, s.end(), notPredicate);
|
begin = std::find_if(begin, s.end(), notPredicate);
|
||||||
if (begin == s.end()) { return result; }
|
if (begin == s.end()) { return result; }
|
||||||
auto end = std::find_if(begin, s.end(), predicate);
|
auto end = std::find_if(begin, s.end(), predicate);
|
||||||
result.push_back(QStringRef(&s, std::distance(s.begin(), begin), std::distance(begin, end)));
|
result.push_back(QStringView(s).slice(std::distance(s.begin(), begin), std::distance(begin, end)));
|
||||||
begin = end;
|
begin = end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Split a string into multiple lines. Blank lines are skipped.
|
//! Split a string into multiple lines. Blank lines are skipped.
|
||||||
//! \warning The returned refs are only valid during the lifetime of the original string.
|
//! \warning The returned refs are only valid during the lifetime of the original string.
|
||||||
SWIFT_MISC_EXPORT QList<QStringRef> splitLinesRefs(const QString &s);
|
SWIFT_MISC_EXPORT QList<QStringView> splitLinesRefs(const QString &s);
|
||||||
|
|
||||||
//! It would be risky to call splitStringRefs with an rvalue, so forbid it.
|
//! It would be risky to call splitStringRefs with an rvalue, so forbid it.
|
||||||
template <class F>
|
template <class F>
|
||||||
@@ -119,7 +118,7 @@ namespace swift::misc
|
|||||||
template <class F>
|
template <class F>
|
||||||
QStringList splitString(const QString &s, F predicate)
|
QStringList splitString(const QString &s, F predicate)
|
||||||
{
|
{
|
||||||
return makeRange(splitStringRefs(s, predicate)).transform([](QStringRef sr) { return sr.toString(); });
|
return makeRange(splitStringRefs(s, predicate)).transform([](QStringView sv) { return sv.toString(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Split a string into multiple lines. Blank lines are skipped.
|
//! Split a string into multiple lines. Blank lines are skipped.
|
||||||
@@ -256,9 +255,6 @@ namespace swift::misc
|
|||||||
//! Strip a designator from a combined string
|
//! Strip a designator from a combined string
|
||||||
SWIFT_MISC_EXPORT QString stripDesignatorFromCompleterString(const QString &candidate);
|
SWIFT_MISC_EXPORT QString stripDesignatorFromCompleterString(const QString &candidate);
|
||||||
|
|
||||||
//! Strip a designator from a combined string
|
|
||||||
SWIFT_MISC_EXPORT QStringList textCodecNames(bool simpleNames, bool mibNames);
|
|
||||||
|
|
||||||
//! Remove accents / diacritic marks from a string
|
//! Remove accents / diacritic marks from a string
|
||||||
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate);
|
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate);
|
||||||
|
|
||||||
@@ -333,11 +329,6 @@ namespace swift::misc
|
|||||||
static QString toQString(const QString &s) { return s; }
|
static QString toQString(const QString &s) { return s; }
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
struct TString<QStringRef>
|
|
||||||
{
|
|
||||||
static QString toQString(const QStringRef &sr) { return sr.toString(); }
|
|
||||||
};
|
|
||||||
template <>
|
|
||||||
struct TString<QStringView>
|
struct TString<QStringView>
|
||||||
{
|
{
|
||||||
static QString toQString(QStringView sv) { return sv.toString(); }
|
static QString toQString(QStringView sv) { return sv.toString(); }
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QTextCodec>
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
@@ -130,18 +129,21 @@ namespace MiscTest
|
|||||||
|
|
||||||
void CTestStringUtils::testCodecs()
|
void CTestStringUtils::testCodecs()
|
||||||
{
|
{
|
||||||
QTextCodec *latin1 = QTextCodec::codecForName("latin1");
|
const QStringConverter::Encoding latin1_enc = QStringDecoder::encodingForName("latin1").value();
|
||||||
QTextCodec *cp1251 = QTextCodec::codecForName("windows-1251");
|
const QStringConverter::Encoding utf8_enc = QStringDecoder::encodingForName("UTF-8").value();
|
||||||
QTextCodec *utf8 = QTextCodec::codecForName("UTF-8");
|
|
||||||
|
QStringDecoder latin1_decoder = QStringDecoder(latin1_enc);
|
||||||
|
QStringEncoder latin1_encoder = QStringEncoder(latin1_enc);
|
||||||
|
QStringDecoder utf8_decoder = QStringDecoder(utf8_enc);
|
||||||
|
QStringEncoder utf8_encoder = QStringEncoder(utf8_enc);
|
||||||
|
|
||||||
const QString testEnglish = QStringLiteral(u"test");
|
const QString testEnglish = QStringLiteral(u"test");
|
||||||
const QString testRussian = QStringLiteral(u"тест");
|
const QString testRussian = QStringLiteral(u"тест");
|
||||||
bool okEn1 = latin1->toUnicode(latin1->fromUnicode(testEnglish)) == testEnglish;
|
bool okEn1 = latin1_decoder(latin1_encoder(testEnglish)) == testEnglish;
|
||||||
bool okEn2 = utf8->toUnicode(utf8->fromUnicode(testEnglish)) == testEnglish;
|
bool okEn2 = utf8_decoder(utf8_encoder(testEnglish)) == testEnglish;
|
||||||
bool okRu1 = cp1251->toUnicode(cp1251->fromUnicode(testRussian)) == testRussian;
|
bool okRu2 = utf8_decoder(utf8_encoder(testRussian)) == testRussian;
|
||||||
bool okRu2 = utf8->toUnicode(utf8->fromUnicode(testRussian)) == testRussian;
|
|
||||||
QVERIFY2(okEn1, "English \"test\" equal after round-trip with latin1");
|
QVERIFY2(okEn1, "English \"test\" equal after round-trip with latin1");
|
||||||
QVERIFY2(okEn2, "English \"test\" equal after round-trip with utf8");
|
QVERIFY2(okEn2, "English \"test\" equal after round-trip with utf8");
|
||||||
QVERIFY2(okRu1, "Russian \"test\" equal after round-trip with cp1251");
|
|
||||||
QVERIFY2(okRu2, "Russian \"test\" equal after round-trip with utf8");
|
QVERIFY2(okRu2, "Russian \"test\" equal after round-trip with utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user