Skip to content

Commit e432e3d

Browse files
committed
Normalize CRLF in comments to avoid double spacing some input.
Fixes apple#1107
1 parent e1904bf commit e432e3d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/SwiftProtobufPluginLibrary/Google_Protobuf_SourceCodeInfo+Extensions.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ extension Google_Protobuf_SourceCodeInfo.Location {
3434

3535
func prefixLines(text: String, prefix: String) -> String {
3636
var result = String()
37-
var lines = text.components(separatedBy: .newlines)
37+
// Protoc doesn't normalize newlines in the comments, make sure CRLF
38+
// doesn't insert blank lines and the generated file is hopefully then
39+
// consistent in using '\n'.
40+
var lines =
41+
text.replacingOccurrences(of: "\r\n", with: "\n").components(separatedBy: .newlines)
3842
// Trim any blank lines off the end.
3943
while !lines.isEmpty && lines.last!.trimmingCharacters(in: .whitespaces).isEmpty {
4044
lines.removeLast()

0 commit comments

Comments
 (0)