Repository navigation
Make line endings of saved files consistent across platforms - #774
Draft
CoffeeFlux wants to merge 1 commit into
Draft
CoffeeFlux wants to merge 1 commit into
CoffeeFlux wants to merge 1 commit into
Conversation
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
approved these changes
Nov 7, 2026
rcombs
left a comment
Contributor
There was a problem hiding this comment.
LGTM, with a couple nits.
Comment on lines
+33
to
+37
| std::string cr("\r"), lf("\n"); | ||
| if (conv) { | ||
| cr = conv->Convert(cr); | ||
| lf = conv->Convert(lf); | ||
| } |
Contributor
There was a problem hiding this comment.
I guess this just exists to handle UTF-16? Kinda awkward that it gets searched byte-wise, but eh, probably good enough.
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"; |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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