When parsing a file, if a section line contains some leading or trailing spaces (outside the square brackets), it is not recognized. A sample ini file reproducing the error would be (please note the extra trailing in the section line: "[General] "):
[General]
key=value
key2=value2
# Before patch
package require inifile
set fh [::ini::open sample.ini]
puts [llength [ini::sections $fh]]
0
# After applying the attached patch
package require inifile
set fh [::ini::open sample.ini]
puts [llength [ini::sections $fh]]
1
Ignore leading and trailing spaces in sections
Why stop halfway ? Comments and settings line would benefit from the same tolerance.
The simpler patch below does that.
--- ini.tcl~ 2013-05-02 18:24:50.000000000 +0200
+++ ini.tcl 2013-05-02 18:25:24.000000000 +0200
@@ -113,6 +113,7 @@
seek $channel 0 start
foreach line [split [read $channel] "\n"] {
+ set line [string trim $line]
if { [string match "$char*" $line] } {
lappend com [string trim [string range $line [string length $char] end]]
} elseif { [string match {\[*\]} $line] } {
For the record, I know how Stupid SF eats any indentation, which makes any inlined patch nearly unusable, but the same Stupid SF won't allow me to attach anything...