Skip to content

Make line endings of saved files consistent across platforms - #774

Draft
CoffeeFlux wants to merge 1 commit into
TypesettingTools:masterfrom
CoffeeFlux:consistent-line-endings
Draft

CoffeeFlux wants to merge 1 commit into
TypesettingTools:masterfrom
CoffeeFlux:consistent-line-endings

Conversation

@CoffeeFlux

Copy link
Copy Markdown
Member

Previously TextFileWriter wrote \r\n on Windows and \n everywhere else, so the same script saved on different platforms produced spurious version-control diffs.

Always write \n for newly created files on every platform. When overwriting an existing file, detect the line endings it already uses (in the target charset, so UTF-16 files are handled too) and keep them, so files already committed with \r\n don't churn when resaved.

Also drop the platform-dependent LINEBREAK macro from the ASS writer's format lines, which bypassed TextFileWriter's newline handling.

Fixes #757.

Requested-by: Ryan Lucia

Previously TextFileWriter wrote \r\n on Windows and \n everywhere else,
so the same script saved on different platforms produced spurious
version-control diffs.

Always write \n for newly created files on every platform. When
overwriting an existing file, detect the line endings it already uses
(in the target charset, so UTF-16 files are handled too) and keep them,
so files already committed with \r\n don't churn when resaved.

Also drop the platform-dependent LINEBREAK macro from the ASS writer's
format lines, which bypassed TextFileWriter's newline handling.

Fixes TypesettingTools#757.

Requested-by: Ryan Lucia

@rcombs rcombs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a couple nits.

Comment thread src/text_file_writer.cpp
Comment on lines +33 to +37
std::string cr("\r"), lf("\n");
if (conv) {
cr = conv->Convert(cr);
lf = conv->Convert(lf);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this just exists to handle UTF-16? Kinda awkward that it gets searched byte-wise, but eh, probably good enough.

Comment thread src/text_file_writer.cpp
Comment on lines +46 to +53
return "\r\n";
}
}
catch (agi::Exception const&) {
// The file doesn't exist or can't be read, so just use the default
}

return "\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just return cr + lf and lf here, and then drop the newline = conv->Convert(newline) in the ctor.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make line-ending behavior consistent across platforms

2 participants