quote:
Originally posted by Shunter
2, If character is "]", clear collision array
3, If character is linebreak:
3a, Check next character
3b, If next character is linebreak, clear collision array
I didn't test this, but this explaination seems a bit dodgy if it realy happens like I read it...
A) you're only test for a new topic is "]" somewhere in a line?
B) linebreaks? you shouldn't let the code depend on linebreaks at all...
EDIT: I tested it with this file, and my assumptions are correct...
code:
[topic1]
key11=h&ello world
key12=[test]
key13=mor&e text
[topic2]
key21=yep th&is is topic number 2
key22=and mambo number f&ive
This is a valid INI file... As you can see your program doesn't reconize double apersands in both topics...
First, A new topic is ALWAYS started at a new line not in the middle of a line. For example, the value from key12 ([test]) isn't a new topic, it is a valid value for a key....
Also, remember that spaces in front of keys and spaces in front and behind a topic should be ignored. The following file is exact the same INI-file, and should be handled just the same (note I replaced the spaces with points so you can see them clearly):
code:
......................
............[topic1].................
.......key11=h&ello world
key12=[test]
............key13=mor&e text..........
.......
...[topic2]
...........................key21=yep th&is is topic number 2
...............................
........key22=and mambo number f&ive
(also note that the value of key13 is "mor&e text.........." in this case and not "mor&e text")
Second, linebreaks in a INI-file can occur everywhere, key21 and key22 are still part of topic2... checking on linebreaks to check topics is a big no-no...
So,
How to detect a new topic (without the use of API's):
in pseudocode:
TRIM(readline) == "[?*]"
-
readline is the variable which holds the new textline read from the ini-file.
-
TRIM is to strip the line from leading and trailing spaces
-
[?*] means: starting with "[", then some text (at least 1 character), ending with "]"
This is the ONLY valid way. If the above function returns true, then, and only then, you have a new topic...
PS: Lines you should ignore (AFTER removing leading and trailing spaces!): empty lines and lines starting with ";"