Ini.diff

Jan DolinĂ¡r, 10/13/2013 04:45 PM

Download (1.38 KB)

View differences:

uppsrc/Core/Ini.cpp (working copy)
2 2

  
3 3
namespace Upp {
4 4

  
5
String ReplaceEnvVars(CParser& p) {
6
	const VectorMap<String, String>& vars = Environment();
7
	String r;
8
	const char* s = p.GetPtr();
9
	while (!p.IsEof()) {
10
		if(p.Char2('$', '$')) {
11
			r.Cat('$');
12
		} else if(p.Char('$') && p.IsId()) {
13
			String id = p.ReadId();
14
			int q = vars.Find(id);
15
			if(q >= 0)
16
				r.Cat(vars[q]);
17
		} else {
18
			p.SkipTerm();
19
			r.Cat(s, p.GetPtr());
20
		}
21
		s = p.GetPtr();
22
	}
23
	return r;
24
}
25

  
5 26
static void LoadIniStream(Stream &sin, VectorMap<String, String>& ret, const char *sfile);
6 27

  
7 28
static void LoadIniFile(const char *filename, VectorMap<String, String>& ret)
......
12 33

  
13 34
static void LoadIniStream(Stream& in, VectorMap<String, String>& key, const char *sfile)
14 35
{
36
	bool env = false;
15 37
	while(!in.IsEof()) {
16 38
		String line = in.GetLine();
17 39
		CParser p(line);
18 40
		if(p.IsId()) {
19 41
			String k = p.ReadId();
20 42
			if(p.Char('='))
21
				key.Add(k, p.GetPtr());
43
				key.Add(k, env ? ReplaceEnvVars(p) : (String)p.GetPtr());
22 44
		}
23 45
		else
24 46
		if(p.Char('@')) {
......
31 53
			else
32 54
			if(p.Id("end"))
33 55
				return;
56
			else
57
			if(p.Id("replace-env"))
58
				env = true;
59
			else
60
			if(p.Id("ignore-env"))
61
				env = false;
34 62
		}
35 63
	}
36 64
}