forked from qt-creator/qt-creator
Beautifier: Handle CRLF for Artistic Style on Windows correctly
Artistic Style will return CRLF on Windows if you are using a pipe. Thus we have to convert it. Change-Id: Id24cac2f35cc3c1978d709fb6c66cee8c8814e34 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user