mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-27 03:36:00 -05:00
Move compareIgnoringLineEnding() to utility.hpp
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <unordered_map>
|
||||
@@ -182,3 +183,24 @@ placeWidgets(std::string text, QBoxLayout *layout,
|
||||
layout->addStretch();
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool compareIgnoringLineEnding(QString &s1, QString &s2)
|
||||
{
|
||||
// Let QT deal with different types of lineendings
|
||||
QTextStream s1stream(&s1);
|
||||
QTextStream s2stream(&s2);
|
||||
|
||||
while (!s1stream.atEnd() || !s2stream.atEnd()) {
|
||||
QString s1s = s1stream.readLine();
|
||||
QString s2s = s2stream.readLine();
|
||||
if (s1s != s2s) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s1stream.atEnd() && !s2stream.atEnd()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -175,32 +175,6 @@ std::string getRemoteData(std::string &url)
|
||||
return readBuffer;
|
||||
}
|
||||
|
||||
bool compareIgnoringLineEnding(QString &s1, QString &s2)
|
||||
{
|
||||
/*
|
||||
Im using QTextStream here so the conversion between different lineendings is done by QT.
|
||||
QT itself uses only the linefeed internally so the input by the user is always using that,
|
||||
but the files selected by the user might use different line endings.
|
||||
If you are reading this and know of a cleaner way to do this, please let me know :)
|
||||
*/
|
||||
QTextStream s1stream(&s1);
|
||||
QTextStream s2stream(&s2);
|
||||
|
||||
while (!s1stream.atEnd() || !s2stream.atEnd()) {
|
||||
QString s1s = s1stream.readLine();
|
||||
QString s2s = s2stream.readLine();
|
||||
if (s1s != s2s) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s1stream.atEnd() && !s2stream.atEnd()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool matchFileContent(QString &filedata, FileSwitch &s)
|
||||
{
|
||||
if (s.onlyMatchIfChanged) {
|
||||
|
||||
Reference in New Issue
Block a user