fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
814 stars 288 forks source link

Preserving linefeed style #1481

Closed arialdomartini closed 1 year ago

arialdomartini commented 1 year ago

I'm using the CVS Type Provider to parse a CSV file, make some modifications, and writing it back.

In Windows, Save() and SaveToString() always output a file with CRLF style, even when the original file was using the Unix linefeed style.

It would be nice if there was a way to preserve the line feed style. Is there any way to do so?

bonjune commented 1 year ago

Save () and SaveToString () depends on TextWriter's WriteLine () method to write line terminate at the end of each line.

TextWriter outputs the line terminator which defaults to the system's default. But it can be changed via setting NewLine property of TextWriter.

Loot at: https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.newline?view=net-7.0

I think we can add a optional parameter to the Save () and SaveToString () methods.

cc @cartermp

References

arialdomartini commented 1 year ago

Yes, that would be useful. Please, consider that as per the RFC 4180 rule 2.1

| 1. Each record is located on a separate line, delimited by a line break (CRLF)

regardless the hosting OS.

cartermp commented 1 year ago

So I guess this was technically a breaking change, but I think "correctly adhering to the standard" is fine, so this is in, and it'll be a minor version bump because versioning is whatever we want it to be.