Added kerrigan29a's patch to allow name:value style lines as per Python's ConfigParser.
Added tests for the above and updated baselines.
diff --git a/ini.c b/ini.c
index 1a77ba9..a1ef32a 100644
--- a/ini.c
+++ b/ini.c
@@ -108,9 +108,12 @@
}
}
else if (*start && *start != ';') {
- /* Not a comment, must be a name=value pair */
+ /* Not a comment, must be a name[=:]value pair */
end = find_char_or_comment(start, '=');
- if (*end == '=') {
+ if (*end != '=') {
+ end = find_char_or_comment(start, ':');
+ }
+ if (*end == '=' || *end == ':') {
*end = '\0';
name = rstrip(start);
value = lskip(end + 1);
@@ -119,13 +122,13 @@
*end = '\0';
rstrip(value);
- /* Valid name=value pair found, call handler */
+ /* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name));
if (!handler(user, section, name, value) && !error)
error = lineno;
}
else if (!error) {
- /* No '=' found on name=value line */
+ /* No '=' or ':' found on name[=:]value line */
error = lineno;
}
}
diff --git a/ini.h b/ini.h
index 18f6850..0bfccd6 100644
--- a/ini.h
+++ b/ini.h
@@ -17,7 +17,8 @@
/* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section
- is "" if name=value pair parsed before any section heading.
+ is "" if name=value pair parsed before any section heading. name:value
+ pairs are also supported as a concession to Python's ConfigParser.
For each name=value pair parsed, call handler function with given user
pointer as well as section, name, and value (data only valid for duration
diff --git a/tests/baseline_multi.txt b/tests/baseline_multi.txt
index 9901e70..dc20043 100644
--- a/tests/baseline_multi.txt
+++ b/tests/baseline_multi.txt
@@ -11,6 +11,10 @@
... test;3=345;
... test4=4#5#6;
... test4=# test6 = 678 ; entire line commented, except in MULTILINE mode;
+... [colon_tests]
+... Content-Type=text/html;
+... foo=bar;
+... adams=42;
normal.ini: e=0 user=101
... [section1]
... name1=value1;
@@ -31,5 +35,9 @@
... multi=a;
... multi=b;
... multi=c;
+... [section3]
+... single=ghi;
+... multi=the quick;
+... multi=brown fox;
multi_line.ini: e=0 user=105
bad_multi.ini: e=1 user=105
diff --git a/tests/baseline_single.txt b/tests/baseline_single.txt
index 2af61e2..025ecdc 100644
--- a/tests/baseline_single.txt
+++ b/tests/baseline_single.txt
@@ -10,6 +10,10 @@
... test2=2;3;4;this won't be a comment, needs whitespace before ';';
... test;3=345;
... test4=4#5#6;
+... [colon_tests]
+... Content-Type=text/html;
+... foo=bar;
+... adams=42;
normal.ini: e=0 user=101
... [section1]
... name1=value1;
@@ -27,5 +31,8 @@
... single2=xyz;
... [section2]
... multi=a;
+... [section3]
+... single=ghi;
+... multi=the quick;
multi_line.ini: e=4 user=105
bad_multi.ini: e=1 user=105
diff --git a/tests/multi_line.ini b/tests/multi_line.ini
index 4f75ed4..f08acf0 100644
--- a/tests/multi_line.ini
+++ b/tests/multi_line.ini
@@ -7,3 +7,7 @@
multi = a
b
c
+[section3]
+single: ghi
+multi: the quick
+ brown fox
diff --git a/tests/normal.ini b/tests/normal.ini
index 44597b2..787ff81 100644
--- a/tests/normal.ini
+++ b/tests/normal.ini
@@ -18,3 +18,8 @@
test4 = 4#5#6 ; '#' only starts a comment at start of line
#test5 = 567 ; entire line commented
# test6 = 678 ; entire line commented, except in MULTILINE mode
+
+[colon_tests]
+Content-Type: text/html
+foo:bar
+adams : 42