Parsing KeyValue File
Is there any way to properly parse a key value structure such as the following? The amount of Key/Value lines per section will be varying, so I cannot simply call GetValueString() a set number of times. I cannot find anyway to loop through as it doesn't seem I can iterate over each key/value line. I have also tried just turning the values into sub-sections and reading them that way, but I would like to avoid forcing the user to place {} after every line. I would also like to avoid having to write an XML extension if possible.
In this case, the 'key' is irrelevant. I simply need to get the values, but to do so I must be able to iterate over each line in some manner. Code:
"ROOT" |
Re: Parsing KeyValue File
You coud use default properties for finding out if the value existed or not?
PHP Code:
But if they're not, you'll need to use http://wiki.alliedmods.net/KeyValues...erative_Lookup (Unless that's what you tried already, ofcourse) |
Re: Parsing KeyValue File
I thought that was going to work, but ran into the same issue since the Section names are not uniform. Before posting I was looking at doing while(KvGetString()) but that didn't return a value. The KvJumpToKey() looked like a solid approach, but since my Section names aren't (and can't be) uniform, that won't work either.
The actual file looks like this... Code:
"MapGroups" |
Re: Parsing KeyValue File
Actually, after thinking about it a bit more, I figured out another way to do it. I figured I would post it incase someone stumbles across this in the future and needs to do the same thing. It is not exactly optimal, but I rarely call this function so it isn't an issue.
I am still having a problem where it doesn't iterate the sections properly. It handles the first Section, gets all of the key/value pairs, then just ends. I am still trying to hunt that issue down, so don't use the code directly. PHP Code:
|
Re: Parsing KeyValue File
Why not just use the SMC parser? It already reads iteratively and tells you all the section names and key names as it reads them rather than you having to know them.
|
Re: Parsing KeyValue File
Oh, my bad. I linked to the wrong section.
Fully traversal should cover it all. But you're best of using a hybrid suited for your ends. Here's how I would do it (not garanteed to be the most efficient, but it should work, I guess) with a file like yours: PHP Code:
Edit2: But aha! I know how to fix your issue, I believe :p Remove the KvGoBack(kv); I do believe KvGoToNextKey already covers that. |
Re: Parsing KeyValue File
Quote:
*Edit* Okay, To be honest, I forgot about the SMC parser as well. |
Re: Parsing KeyValue File
Quote:
|
Re: Parsing KeyValue File
Does the SMC parser catch syntax errors like missing quotes or braces? That would really help, because Valve's parser just crash the server in some cases. :P
|
| All times are GMT -4. The time now is 05:27. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.