Read the comments of each group from an INI file

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
lionking
Earned a small fee
Earned a small fee
Posts: 17
Joined: Sun Apr 07, 2019 6:07 pm

Read the comments of each group from an INI file

Post by lionking » Tue May 21, 2019 12:49 pm

I am using wxFileConfig to read an INI file, but there is no way to read the comments of each group.

An example of an INI file:

Code: Select all

[sdl]
#	 sensitivity: Mouse sensitivity.
# 	 waitonerror: Wait before closing the console if has an error.
#       mapperfile: File used to load/save the key/event mappings from. Resetmapper only works with the default value.

sensitivity=100
waitonerror=false
mapperfile=mapper.map
As you saw, [sdl] is a group, the next three lines are comments, the last three lines are the items and its values.

How to read the comments of a group for instance [sdl] group?

Kvaz1r
I live to help wx-kind
I live to help wx-kind
Posts: 184
Joined: Tue Jun 07, 2016 1:07 pm

Re: Read the comments of each group from an INI file

Post by Kvaz1r » Tue May 21, 2019 1:49 pm

You can't since comments are skipping when file parse. So just use another parser or do it manually.

If you think it's a common problem you can open ticket - trac.wxwidgets.org

alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Tue Oct 18, 2016 2:31 pm

Re: Read the comments of each group from an INI file

Post by alys666 » Tue May 21, 2019 4:22 pm

comments are widely used to skip unneeded items, so there could be a mess of useful comments and just omitted parts of a file.
to get group comment just now, you could add a legal item to a group.

Code: Select all

[my_group]
group_comment= "this is my comment to this group"
...
and use its value.
ps. i don't use ini files, and do not know an actual format of this file.
ubuntu 16.04, wxWidgets 3.0.4

Post Reply