From f0fd46daa4e5fef26f225c2ee22159fa0aff7914 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 28 Apr 2014 13:17:25 +0000 Subject: [PATCH] Core: Ini: Fixed C comment issue #768 git-svn-id: svn://ultimatepp.org/upp/trunk@7328 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Ini.cpp | 52 +++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/uppsrc/Core/Ini.cpp b/uppsrc/Core/Ini.cpp index 0876caff0..183c96fdd 100644 --- a/uppsrc/Core/Ini.cpp +++ b/uppsrc/Core/Ini.cpp @@ -2,27 +2,6 @@ namespace Upp { -String ReplaceEnvVars(CParser& p) { - const VectorMap& vars = Environment(); - String r; - const char* s = p.GetPtr(); - while (!p.IsEof()) { - if(p.Char2('$', '$')) { - r.Cat('$'); - } else if(p.Char('$') && p.IsId()) { - String id = p.ReadId(); - int q = vars.Find(id); - if(q >= 0) - r.Cat(vars[q]); - } else { - p.SkipTerm(); - r.Cat(s, p.GetPtr()); - } - s = p.GetPtr(); - } - return r; -} - static void LoadIniStream(Stream &sin, VectorMap& ret, const char *sfile); static void LoadIniFile(const char *filename, VectorMap& ret) @@ -39,8 +18,35 @@ static void LoadIniStream(Stream& in, VectorMap& key, const char CParser p(line); if(p.IsId()) { String k = p.ReadId(); - if(p.Char('=')) - key.Add(k, env ? ReplaceEnvVars(p) : (String)p.GetPtr()); + if(p.Char('=')) { + String h = TrimBoth((String)p.GetSpacePtr()); + if(env) { + String hh; + const char *s = ~h; + while(*s) { + if(*s == '$') { + s++; + if(*s == '$') { + hh.Cat('$'); + s++; + } + else { + while(*s == ' ') + s++; + String id; + while(iscid(*s)) + id.Cat(*s++); + hh.Cat(GetEnv(id)); + } + } + else + hh.Cat(*s++); + } + key.Add(k, hh); + } + else + key.Add(k, h); + } } else if(p.Char('@')) {