Coder Social home page Coder Social logo

Comments (8)

QEDK avatar QEDK commented on July 23, 2024

Hello,

Currently, when serializing, configparser-rs always uses unix line endings ('\n', lf). On the python side, configparser will use the appropriate line ending depending on the platform it's currently running on (crlf on windows, lf everywhere else).

I think it'd be nice if configparser would allow configuring the line endings being used, e.g. add an enum to IniDefaults to let the user chose between Lf and Crlf line endings.

Good point, I will look into this a bit more and make a decision.

from configparser-rs.

QEDK avatar QEDK commented on July 23, 2024

Hello,

Currently, when serializing, configparser-rs always uses unix line endings ('\n', lf). On the python side, configparser will use the appropriate line ending depending on the platform it's currently running on (crlf on windows, lf everywhere else).

I think it'd be nice if configparser would allow configuring the line endings being used, e.g. add an enum to IniDefaults to let the user chose between Lf and Crlf line endings.

Thought about this a bit more and I'm honestly not sure how useful this would be. Rust does not support optional parameters like other languages, so the only way would be an Option that would break compat with the current API - or extending IniDefault which is already quite encompassing of features.

from configparser-rs.

vthib avatar vthib commented on July 23, 2024

For us this is a needed feature, on windows we want to use CRLF line endings.

I see several possibilities for this feature:

  • do not expose any options, but change behavior to use CRLF on windows, LF anywhere else. This is a breaking change, but aligns on python's behavior afaict
  • expose a new option in IniDefault to configure the line endings. Yes it adds yet another parameters in this object, but since #22, this is not a breaking change, and adding more fields to this object does not impact the end user.
  • do both: expose an option, but by default decide depending on the platform
  • last option if you do not want to add more fields to IniDefault would be to add a set_line_endings to Ini, though it looked like you designed all parameters to be settable through the IniDefault struct.

Also, #22 was done to allow adding more parameters to IniDefault without breaking the API, so not wanting to bloat IniDefault more goes a bit in another direction design-wise

from configparser-rs.

QEDK avatar QEDK commented on July 23, 2024

For us this is a needed feature, on windows we want to use CRLF line endings.

I see several possibilities for this feature:

* do not expose any options, but change behavior to use CRLF on windows, LF anywhere else. This is a breaking change, but aligns on python's behavior afaict

* expose a new option in IniDefault to configure the line endings. Yes it adds yet another parameters in this object, but since [Non exhaustive IniDefault #22](https://github.com/QEDK/configparser-rs/pull/22), this is not a breaking change, and adding more fields to this object does not impact the end user.

* do both: expose an option, but by default decide depending on the platform

* last option if you do not want to add more fields to IniDefault would be to add a `set_line_endings` to `Ini`, though it looked like you designed all parameters to be settable through the IniDefault struct.

Also, #22 was done to allow adding more parameters to IniDefault without breaking the API, so not wanting to bloat IniDefault more goes a bit in another direction design-wise

I agree but line endings are low on the list of things that will cause things to break (on a modern version of Windows atleast). I think we can add something like this, similar to your first suggested option:

#[cfg(windows)]
const LINE_ENDING: &'static str = "\r\n";
#[cfg(not(windows))]
const LINE_ENDING: &'static str = "\n";

Edit: Upon further thought and research, most of the Windows ecosystem (i.e. VSCode really) have all adapted to using LF (including Notepad in 2018). Unless, I have an example of this breaking something somewhere, we don't really need this.

from configparser-rs.

roblabla avatar roblabla commented on July 23, 2024

Edit: Upon further thought and research, most of the Windows ecosystem (i.e. VSCode really) have all adapted to using LF (including Notepad in 2018). Unless, I have an example of this breaking something somewhere, we don't really need this.

This is not true in my case. At least on my product, I have lots of users on versions of windows that don't universally support CRLF line endings. For instance, I have clients using Windows Server 2016 and Windows 10 Enterprise LTSC 2016, and various versions of windows 8-8.1 (all of which still supported by microsoft). VSCode does not have the issue, but my users are very unlikely to be using VSCode to edit the ini files (and much more likely to use whatever notepad comes preinstalled on their windows machines).

Setting the line endings based on cfg would work for me. If this is OK with you, I can submit a PR with the change.

from configparser-rs.

QEDK avatar QEDK commented on July 23, 2024

@roblabla @vthib alright, any one of you feel free to pick this up. thanks a lot for your patience and work 😄

from configparser-rs.

vthib avatar vthib commented on July 23, 2024

Thanks for coming back to this :) . However I see you have released 3.0.0 and marked this for 3.0.1, and the cfg solution that I pushed is a breaking change. I'm not sure how you prefer to tackle this

from configparser-rs.

QEDK avatar QEDK commented on July 23, 2024

Thanks for coming back to this :) . However I see you have released 3.0.0 and marked this for 3.0.1, and the cfg solution that I pushed is a breaking change. I'm not sure how you prefer to tackle this

We'll go with the Pythonic approach of setting the ending per platform, it shouldn't be a breaking change as Rust fs treats CRLF as LF when ingesting it.

from configparser-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.