Comments (9)
There's been a lot of discussion over commenting in INI files, some of it here: https://stackoverflow.com/questions/1378219/do-standard-windows-ini-files-allow-comments. The best spec for INI file comments is here: https://en.wikipedia.org/wiki/INI_file#Comments (and this doesn't even suggest lines with trailing comments, though I've seen the windows ini parser deal with this before).
These all suggest that the correct commenting character for INI is the semi-colon (;
). However, semi-colons may be put into quoted strings: https://en.wikipedia.org/wiki/INI_file#Quoted_values
Is there any reason why your INI file can't look like the following?
[PATHS]
; The line below contains the SQL connection string to customer DB
DBPATH="Driver={SQL Server};Server=192.168.85.130\SQLEXPRESS02;DATABASE=OneSQL;UID=sa;PWD=pazzword;TRUSTED_CONECTION=NO;CONNECTION TIMEOUT=60;"
I've proven that this is already supported with
PeanutButter/source/INI/PeanutButter.INI.Tests/TestINIFile.cs
Lines 431 to 455 in 29c8388
This is not to tell you that the solution to your problem is simply to do it "my way" - part of the reason for ubiquitous formats like INI is that so many things understand how to read them. If you try to read the INI file as described in this issue with another tool, it will exhibit the same result - making your INI file no longer portable
If there is no way around this behavior for you, I'm willing to expose a protected field on BestEffortLineParser, CommentDelimiter
which you can use to set the comment delimiter in a derived class (much as you are doing now, and it will also cope with lines commented by whatever you please).
However, I would heartily discourage such usage as, at the expense of repeating myself, it means that your INI files wouldn't be portable - they would only be readable by your code.
from peanutbutter.
"Is there any reason why your INI file can't look like the following?"
It's about legacy code and legacy files, which I have to live with.
About portability, that's not really a requirement.
from peanutbutter.
Ah, fair enough - so I'll commit the changes I've made - you're already having to do custom work to parse these files, and hopefully this makes your custom work a little easier:
- inherit from BestEffortLineParser
- set the protected CommentDelimiter field in your derived class
Changes are pushed to 7a6752c - I hope it helps (: I'll push packages now (should be version 2.0.62).
I'd also suggest, if possible, adding a "red bin" item somewhere in your worklog to fix up these ini files if it won't affect other parts of your system - you could use PeanutButter.INI to do so: load with your custom parser and write back out again (INIFile always writes out consistent formatting). Perhaps I'm being too pedantic about portability tho
from peanutbutter.
Is it possible that I cannot inherit from BestEffortLineParser because it is internal?
from peanutbutter.
It should be public in 2.0.62. It used to be internal to reduce the noise of exported types. Have you updated?
from peanutbutter.
I can confirm that, in a brand new project targeting 2.0.62, I can derive from BestEffortLineParser
:
from peanutbutter.
Yes, it works, thank you!
Do you think that is a good idea that in case of
base.CommentDelimiter = "";
the comments are never stripped out of the line, so the whole line is returned?
Use cases:
[DESCRIPTION]
MESG-32=Industrie de l'emballage et fabrication d'autres matΓ©riaux
PWD-ENCRIPTED=xLvA'M3%^GKSV
from peanutbutter.
hm, wow, you have some really gnarly "ini" files to deal with! if you're trying to prevent any comment parsing whatsoever, I'd probably put some non-printable character in there, like char 0 or something like that? You'd want to not match on anything, so any character which isn't in your input file will do the trick - if you have a real null in your ini file, that would be Bad :D so yeah, perhaps
CommentDelimiter = "\0";
from peanutbutter.
again, I'd suggest processing these ini files to standard formats - perhaps your systems could (once-off) load up with the derivative line parser, with CommentDelimiter set to "\0" and rewrite the files, then open again? You'd want to record somewhere that you did this work so it's not done every time. I'm just thinking about the next poor person who has to deal with these files and doesn't have a PeanutButter to help
from peanutbutter.
Related Issues (20)
- Add Option (or default) for Section Gaps HOT 3
- Adding some README and documentations to explain INI HOT 1
- Servicepath can not be set // any documentation? HOT 3
- Feature: maintain order of sections and settings within file
- Quotes HOT 2
- CORS policy HOT 3
- semi-colon ini text value causes truncation HOT 21
- IniFile should not use ordinal Dictionary HOT 4
- ini Remove method leaves the key behind HOT 3
- Per-project documentation
- Switch build, pack & push to use `dotnet` HOT 1
- Project restructuring to simplify dev, especially multi-platform dev
- SetValue return value HOT 1
- How to set encoding? HOT 1
- PeanutButter.INI: CommentDelimiter not respected when saving HOT 2
- PeanutButter.INI exception HOT 6
- [PeanutButter.INI] How can I add an empty line at the last line? HOT 6
- PeanutButter.DuckTyping: Parameter count error when trying to invoke overloaded method HOT 7
- Update PeanutButter.EasyArgs to be AOT-friendly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peanutbutter.