Comments (8)
Hi @chienhsinlin, there's no special provision for this in inih itself, but you can definitely parse comma-separated values in the handler yourself -- use something like strchr
or strtok
to find the ','
(comma) separators.
If the values for one key are spread across multiple lines, you'll also want to set INI_ALLOW_MULTILINE
to 1
. This works like Python's configparser
multi-line values -- subsequent values have to be indented with whitespace. For example:
[section]
lut_table = 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16
Then you'll receive two separate calls to your handler function with the same section and key name, and you'll need to save the last lut_table
array index in a global or something like that.
Hope that helps!
from inih.
Thanks a lot, It works now after using strtok in the handler to parse each line and tokenize strings with delimiter.
from inih.
Something like that. as you said idx is global variable.
idx = 0; // as global variable.
tok = strtok((char *)value,",");
pconfig.lut[idx] = atoi(tok);
while(tok!=NULL) {
idx++;
tok =strtok(NULL," ,");
if(tok!= NULL)
pconfig.lut[idx] = atoi(tok);
}
from inih.
Hi @chienhsinlin, there's no special provision for this in inih itself, but you can definitely parse comma-separated values in the handler yourself -- use something like
strchr
orstrtok
to find the','
(comma) separators.If the values for one key are spread across multiple lines, you'll also want to set
INI_ALLOW_MULTILINE
to1
. This works like Python'sconfigparser
multi-line values -- subsequent values have to be indented with whitespace. For example:[section] lut_table = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
Then you'll receive two separate calls to your handler function with the same section and key name, and you'll need to save the last
lut_table
array index in a global or something like that.Hope that helps!
hi, @benhoyt,
for multiple lines like this, seems it's no longer possible to add comments after the value, and the comments either with # or ; are treated as part of value. I feel it's not right. Is this an issue? Thanks.
from inih.
Hi @silly2020, do you have INI_ALLOW_INLINE_COMMENTS
turned off? See ini.h
for a complete list of settings.
from inih.
Hi, @benhoyt , thanks for prompt reply.
I didn't turned off INI_ALLOW_INLINE_COMMENTS, it is 1 and INI_ALLOW_INLINE_COMMENTS is ";".
Comments start with ";" in subsequent lines are treated as part of value, comments in the line with name is OK.
Thanks again.
P.S.
I tested with dump in example as below:
ini file content:
[test]
MyName = value part 1 ; comments OK
value part 2 ; expect ignore this as comments
what I got with dump:
[test]
MyName = value part 1
MyName = value part 2 ; expect ignore this as comments
from inih.
@silly2020 Thanks for the report. This is an oversight (bug!) in inih, and differs from how Python's ConfigParser
works. Does the latest master
version work for you? If so, I'll release this in r56
.
from inih.
@benhoyt Yes. I tested again with master
version and it works for me. Thank you so much!
from inih.
Related Issues (20)
- pkg-config files have version `undefined` HOT 3
- possible NULL pointer dereference HOT 2
- unittest.sh doesn' report that tests succeeded? HOT 1
- Emit ini file HOT 1
- Error attempting to link against libinih HOT 3
- Expected key/section missing error HOT 3
- Do you have plan to support write feature ? HOT 1
- Do you plan support buid with cmake HOT 3
- how to get all the sections, key-value pairs HOT 3
- Seems to not discard the rest of a long line? HOT 4
- meason.build distro_install option HOT 5
- Duplicate keys cause a trailing \n to be appended? HOT 1
- inih v57 fails to build using GCC 4.8.5 on CentOS 7 HOT 3
- Add support for UTF-16 HOT 5
- Add Cflags.private to support static linking on Windows
- strncpy0 should be in ini_ namespace HOT 8
- Undefined symbol when linking with LLD HOT 3
- undefined reference to `INIReader
- undefined reference to 'ini_parse'
- When loading the ini file,, all the spaces in the value will be deleted HOT 1
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 inih.