From 3f492f468a7c9d1de0ce584448a66c5f056120e2 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Fri, 30 Apr 2021 23:38:32 +0200 Subject: [PATCH] Move compareIgnoringLineEnding() to utility.hpp --- src/headers/utility.hpp | 22 ++++++++++++++++++++++ src/switch-file.cpp | 26 -------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/headers/utility.hpp b/src/headers/utility.hpp index fcc1525e..242cd9ed 100644 --- a/src/headers/utility.hpp +++ b/src/headers/utility.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -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; +} diff --git a/src/switch-file.cpp b/src/switch-file.cpp index 1505793e..17ca0197 100644 --- a/src/switch-file.cpp +++ b/src/switch-file.cpp @@ -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) {