Comments (4)
Good catch.
Also I think the inline comment breaks something indeed...
from ini.
OK, just refactored the parser, please try it out.
The save result for
key1 = "value" ; comment
key2 = "one", "two", "three"
is now
; comment
key1 = value
key2 = "one", "two", "three"
from ini.
I dunno this still seems like it might not be that robust (though writing a truely robust INI parser is probably impossible).
I decided to modify your library fairly drastically, check it out:
https://github.com/Timmmm/ini/tree/master
You probably don't want to use that because I removed several features I don't need (e.g. variable substitution). But I think my parsing approach is probable better. Here's the approach:
-
Remove multi-line support as this makes it a lot easier (you can still do multiline strings with
"a\nb"
). -
Add a
modified
boolean to all the keys. This indicates whether they have been modified since loading from disk (or string) (TODO!) -
When parsing a key (or a section header), only try to split it into the key name, value and comment. In particular I don't try to parse the value. To split the comment I use made a couple of functions that find the first unquoted character in a string. So for example it you can do:
letters = "a; b; c" ; Semicolon separated list of letters.
Would that break in your parser? Currently the quoting model used is very basic (only double quotes for example). You could add support for
"""
and single quotes. -
Instead of parsing the values when you load the file, parse them when they are requested. This also has the benefit of allowing users to do their own custom parsing.
-
When writing back to the file, if the value was unmodified write it as-is (also TODO!)
I also added support for trailing comments. Feel free to take any code back!
from ini.
You probably don't want to use that because I removed several features I don't need (e.g. variable substitution). But I think my parsing approach is probable better. Here's the approach:
That's the best thing about open source ๐
Remove multi-line support as this makes it a lot easier (you can still do multiline strings with "a\nb").
Thought I agree it is not a commonly used feature, but as a public package remove a feature generally should not happen.
Add a modified boolean to all the keys. This indicates whether they have been modified since loading from disk (or string) (TODO!)
This is indeed a good thing, this allows you save the config file only for new additions but remain unchanged for everything else.
When parsing a key (or a section header), only try to split it into the key name, value and comment. In particular I don't try to parse the value. To split the comment I use made a couple of functions that find the first unquoted character in a string. So for example it you can do:
Quotes will be removed is documented explicitly in the README, so it causes break changes.
Instead of parsing the values when you load the file, parse them when they are requested. This also has the benefit of allowing users to do their own custom parsing.
It should work well in most of cases, but in my personal usages, it hurts big performance (maybe I should say unnecessary cost). For example, I use INI as I18N parse module, it is called so often in when rendering every page.
from ini.
Related Issues (20)
- Allow NonUniqueSections not working for Embedded Structs
- If the configuration item of my ini configuration file contains #, it will cause an error in reading the configuration. HOT 4
- Able to set incremental keys HOT 1
- ๆ ๆณๅๅปบไธไธชๆฐ็้ฎ๏ผ HOT 1
- "=" character not escaped properly HOT 1
- key prefixes
- Serialization for arrays of rune not a possibility?
- API Documentation link is not working
- Marshal and unmarshal functions
- same-key-with-multiple-values demo result is not correct
- DeleteKey not work
- Add line number and column output to error HOT 2
- Allow empty key values
- Fail to read file: key-value delimiter not found: }
- SaveTo without Indentation
- semicolon issue
- Error parse values
- using []string in a struct goes wrong if any of the strings contains a comma ','
- Question - Create nested INI file
- custom delimiter of comments
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 ini.