diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp index 7aed71f2885..bed8e72d410 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -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 5aae5577855..f0a21aa89ad 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 834f469a58c..55206c3b0f8 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 e6774f38fae..102e9f91c3f 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