Skip to content

Commit

Permalink
Properly set CRLF line ending.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 24, 2016
1 parent 44eb332 commit 56794bf
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -3613,26 +3613,31 @@ bool LibraryWidget::saveFile(QString fileName, QString contents)
bom = false;
break;
}
// set the line ending format
QString newContents;
QComboBox *pLineEndingComboBox = mpMainWindow->getOptionsDialog()->getTextEditorPage()->getLineEndingComboBox();
Utilities::LineEndingMode lineEndingMode = (Utilities::LineEndingMode)pLineEndingComboBox->itemData(pLineEndingComboBox->currentIndex()).toInt();
QTextStream crlfTextStream(&contents);
switch (lineEndingMode) {
case Utilities::CRLFLineEnding:
while (!crlfTextStream.atEnd()) {
newContents += crlfTextStream.readLine() + "\r\n";
}
break;
case Utilities::LFLineEnding:
newContents = contents;
newContents.replace(QLatin1String("\r\n"), QLatin1String("\n"));
default:
break;
}
// open the file for writing
QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream textStream(&file);
// set to UTF-8
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(bom);
// set the line ending format
QComboBox *pLineEndingComboBox = mpMainWindow->getOptionsDialog()->getTextEditorPage()->getLineEndingComboBox();
Utilities::LineEndingMode lineEndingMode = (Utilities::LineEndingMode)pLineEndingComboBox->itemData(pLineEndingComboBox->currentIndex()).toInt();
switch (lineEndingMode) {
case Utilities::CRLFLineEnding:
contents.replace(QLatin1String("\n"), QLatin1String("\r\n"));
break;
case Utilities::LFLineEnding:
contents.replace(QLatin1String("\r\n"), QLatin1String("\n"));
default:
break;
}
textStream << contents;
textStream << newContents;
file.close();
return true;
} else {
Expand Down

0 comments on commit 56794bf

Please sign in to comment.