diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp index 7aed71f28853db046c9382cc2f2894dc7cc6f915..bed8e72d4103dff2ffac2b8b58c4145c203b505e 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp @@ -51,6 +51,7 @@ #include <projectexplorer/projectexplorer.h> #include <projectexplorer/project.h> #include <utils/fileutils.h> +#include <utils/hostosinfo.h> #include <QAction> #include <QMenu> @@ -148,6 +149,7 @@ void ArtisticStyle::formatFile() if (m_settings->version() > ArtisticStyleSettings::Version_2_03) { command.setProcessing(Command::PipeProcessing); command.setPipeAddsNewline(true); + command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost()); } else { command.addOption(QLatin1String("%file")); } diff --git a/src/plugins/beautifier/beautifierplugin.cpp b/src/plugins/beautifier/beautifierplugin.cpp index 5aae55778553f78884011bbad754be4cad1f0b2a..f0a21aa89ad865d7e6244c86cf63dc92b619f399 100644 --- a/src/plugins/beautifier/beautifierplugin.cpp +++ b/src/plugins/beautifier/beautifierplugin.cpp @@ -198,9 +198,14 @@ QString BeautifierPlugin::format(const QString &text, const Command &command, return QString(); } - if (command.pipeAddsNewline()) { + const bool addsNewline = command.pipeAddsNewline(); + const bool returnsCRLF = command.returnsCRLF(); + if (addsNewline || returnsCRLF) { QString formatted = QString::fromUtf8(process.readAllStandardOutput()); - formatted.remove(QRegExp(QLatin1String("(\\r\\n|\\n)$"))); + if (addsNewline) + formatted.remove(QRegExp(QLatin1String("(\\r\\n|\\n)$"))); + if (returnsCRLF) + formatted.replace(QLatin1String("\r\n"), QLatin1String("\n")); return formatted; } return QString::fromUtf8(process.readAllStandardOutput()); diff --git a/src/plugins/beautifier/command.cpp b/src/plugins/beautifier/command.cpp index 834f469a58c72ee00077994870755674c00ab355..55206c3b0f8256b7f2d8dc43ba31e4baa04d9da2 100644 --- a/src/plugins/beautifier/command.cpp +++ b/src/plugins/beautifier/command.cpp @@ -35,6 +35,7 @@ namespace Internal { Command::Command() : m_processing(FileProcessing) , m_pipeAddsNewline(false) + , m_returnsCRLF(false) { } @@ -78,5 +79,16 @@ void Command::setPipeAddsNewline(bool pipeAddsNewline) m_pipeAddsNewline = pipeAddsNewline; } +bool Command::returnsCRLF() const +{ + return m_returnsCRLF; +} + +void Command::setReturnsCRLF(bool returnsCRLF) +{ + m_returnsCRLF = returnsCRLF; +} + + } // namespace Internal } // namespace Beautifier diff --git a/src/plugins/beautifier/command.h b/src/plugins/beautifier/command.h index e6774f38fae6535074982b38392aa00c13bd9d1f..102e9f91c3fa26e835d4b23ef54b143b85d23dcd 100644 --- a/src/plugins/beautifier/command.h +++ b/src/plugins/beautifier/command.h @@ -58,11 +58,15 @@ public: bool pipeAddsNewline() const; void setPipeAddsNewline(bool pipeAddsNewline); + bool returnsCRLF() const; + void setReturnsCRLF(bool returnsCRLF); + private: QString m_executable; QStringList m_options; Processing m_processing; bool m_pipeAddsNewline; + bool m_returnsCRLF; }; } // namespace Internal