Home » U++ Library support » U++ Core » Little .ini reading request
Little .ini reading request [message #24273] |
Fri, 08 January 2010 13:49  |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
The current Ini file reading util function is very handy, but it is unable to cope with sections that some people put in .Ini files. These are usually deliminated by [SECTION_NAME], but people have nasty habit of just making it up as they go along 
I have a requirement to read such a file and wondered whether the following minor change could be committed for me so that I don't have to duplicate code:
Util.cpp:
VectorMap<String, String> LoadIniFile(const char *filename) {
FileIn in(filename);
if(!in) return VectorMap<String, String>();
return LoadIniStream(in);
}
VectorMap<String, String> LoadIniStream(Stream &in) {
VectorMap<String, String> key;
int c;
if((c = in.Get()) < 0) return key;
for(;;) {
String k, v;
for(;;) {
if(IsAlNum(c) || c == '_')
k.Cat(c);
else
break;
if((c = in.Get()) < 0) return key;
}
for(;;) {
if(c != '=' && c != ' ') break;
if((c = in.Get()) < 0) return key;
}
for(;;) {
if(c < ' ') break;
v.Cat(c);
if((c = in.Get()) < 0) break;
}
if(!k.IsEmpty())
key.Add(k, v);
if(k == "LINK") {
in.Close();
if(!in.Open(v) || (c = in.Get()) < 0) return key;
}
else
for(;;) {
if(IsAlNum(c) || c == '_') break;
if((c = in.Get()) < 0) return key;
}
}
}
Util.h:
VectorMap<String, String> LoadIniFile(const char *filename);
VectorMap<String, String> LoadIniStream(Stream &in);
This means that I can just read .Ini file to correct section myself and then call LoadIniStream.
Cheers!
[Updated on: Fri, 08 January 2010 13:51] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed Apr 30 14:57:14 CEST 2025
Total time taken to generate the page: 0.03927 seconds
|