private static Map initVars() { Map vars = new Map(Sys.StrType, Sys.StrType); try { vars.caseInsensitive(true); // predefined vars.set("os.name", Environment.OSVersion.Platform.ToString()); vars.set("os.version", Environment.OSVersion.Version.ToString()); // environment variables IDictionary getenv = Environment.GetEnvironmentVariables(); foreach (DictionaryEntry de in getenv) { string key = (string)de.Key; string val = (string)de.Value; vars.set(key, val); } } catch (Exception e) { Err.dumpStack(e); } return((Map)vars.toImmutable()); }
internal override Map makeParams() { Map map = new Map(Sys.StrType, Sys.TypeType); for (int i = 0; i < m_params.Length; ++i) { map.set(FanStr.m_ascii['A' + i], m_params[i]); } return(map.set(FanStr.m_ascii['R'], m_ret).ro()); }
public Map map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) { r = Sys.ObjType.toNullable(); } Map acc = new Map(m_type.m_k, r); if (this.ordered()) { acc.ordered(true); } if (this.caseInsensitive()) { acc.caseInsensitive(true); } IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; acc.set(key, f.call(val, key)); } return(acc); }
public Map exclude(Func f) { Map acc = new Map(m_type); if (this.ordered()) { acc.ordered(true); } if (this.caseInsensitive()) { acc.caseInsensitive(true); } IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.False) { acc.set(key, val); } } return(acc); }
public static Map contents(ZipFile zipFile) { Map c = new Map(Sys.UriType, Sys.FileType); IEnumerator e = zipFile.GetEnumerator(); while (e.MoveNext()) { ZipEntry entry = (ZipEntry)e.Current; ZipEntryFile f = new ZipEntryFile(zipFile, entry); c.set(f.m_uri, f); } return c; }
public static Map contents(ZipFile zipFile) { Map c = new Map(Sys.UriType, Sys.FileType); IEnumerator e = zipFile.GetEnumerator(); while (e.MoveNext()) { ZipEntry entry = (ZipEntry)e.Current; ZipEntryFile f = new ZipEntryFile(zipFile, entry); c.set(f.m_uri, f); } return(c); }
public Map env() { if (m_env == null) { m_env = new Map(Sys.StrType, Sys.StrType); IDictionaryEnumerator en = (IDictionaryEnumerator) new System.Diagnostics.Process(). StartInfo.EnvironmentVariables.GetEnumerator(); while (en.MoveNext()) { string key = (string)en.Key; string val = (string)en.Value; m_env.set(key, val); } } return(m_env); }
public Map map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) r = Sys.ObjType.toNullable(); Map acc = new Map(m_type.m_k, r); if (this.ordered()) acc.ordered(true); if (this.caseInsensitive()) acc.caseInsensitive(true); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; acc.set(key, f.call(val, key)); } return acc; }
public Map findAll(Func f) { Map acc = new Map(m_type); if (this.ordered()) acc.ordered(true); if (this.caseInsensitive()) acc.caseInsensitive(true); IDictionaryEnumerator en = m_map.GetEnumerator(); while (en.MoveNext()) { object key = en.Key; object val = en.Value; if (f.call(val, key) == Boolean.True) acc.set(key, val); } return acc; }
private static Map initVars() { Map vars = new Map(Sys.StrType, Sys.StrType); try { vars.caseInsensitive(true); // predefined vars.set("os.name", Environment.OSVersion.Platform.ToString()); vars.set("os.version", Environment.OSVersion.Version.ToString()); // environment variables IDictionary getenv = Environment.GetEnvironmentVariables(); foreach (DictionaryEntry de in getenv) { string key = (string)de.Key; string val = (string)de.Value; vars.set(key, val); } } catch (Exception e) { Err.dumpStack(e); } return (Map)vars.toImmutable(); }
private void addQueryParam(Map map, string q, int start, int eq, int end, bool escaped) { string key, val; if (start == eq && q[start] != '=') { key = toQueryStr(q, start, end, escaped); val = "true"; } else { key = toQueryStr(q, start, eq, escaped); val = toQueryStr(q, eq+1, end, escaped); } string dup = (string)map.get(key); if (dup != null) val = dup + "," + val; map.set(key, val); }
public Map env() { if (m_env == null) { m_env = new Map(Sys.StrType, Sys.StrType); IDictionaryEnumerator en = (IDictionaryEnumerator)new System.Diagnostics.Process(). StartInfo.EnvironmentVariables.GetEnumerator(); while (en.MoveNext()) { string key = (string)en.Key; string val = (string)en.Value; m_env.set(key, val); } } return m_env; }
private static Map doParseParams(string s, int offset) { Map pars = new Map(Sys.StrType, Sys.StrType); pars.caseInsensitive(true); bool inQuotes = false; int keyStart = offset; int valStart = -1; int valEnd = -1; int eq = -1; bool hasEsc = false; for (int i = keyStart; i<s.Length; ++i) { int c = s[i]; // let parens slide since sometimes they occur in cookies // if (c == '(' && !inQuotes) // throw ParseErr.make("MimeType", s, "comments not supported"); if (c == '=' && !inQuotes && valStart < 0) { eq = i++; while (FanInt.isSpace(s[i])) ++i; if (s[i] == '"') { inQuotes = true; ++i; c=s[i]; } else inQuotes = false; valStart = i; } if (eq < 0) continue; if (c == '\\' && inQuotes) { ++i; hasEsc = true; continue; } if (c == '"' && inQuotes) { valEnd = i-1; inQuotes = false; } if (c == ';' && !inQuotes) { if (valEnd < 0) valEnd = i-1; string key = s.Substring(keyStart, eq-keyStart).Trim(); string val = s.Substring(valStart, valEnd+1-valStart).Trim(); if (hasEsc) val = unescape(val); pars.set(key, val); keyStart = i+1; eq = valStart = valEnd = -1; hasEsc = false; } } if (keyStart < s.Length) { if (valEnd < 0) valEnd = s.Length-1; string key = s.Substring(keyStart, eq-keyStart).Trim(); string val = s.Substring(valStart, valEnd+1-valStart).Trim(); if (hasEsc) val = unescape(val); pars.set(key, val); } return pars; }
void readComplexSet(Type t, int line, string name, Map toSet) { // resolve field Field field = t.field(name, false); if (field == null) throw err("Field not found: " + t.qname() + "." + name, line); // parse value object val = readObj(field, null, false); try { // if const field, then make val immutable if (field.isConst()) val = OpUtil.toImmutable(val); } catch (System.Exception ex) { throw err("Cannot make object const for " + field.qname() + ": " + ex, line, ex); } // add to map toSet.set(field, val); }
private static Map doParseParams(string s, int offset) { Map pars = new Map(Sys.StrType, Sys.StrType); pars.caseInsensitive(true); bool inQuotes = false; int keyStart = offset; int valStart = -1; int valEnd = -1; int eq = -1; bool hasEsc = false; for (int i = keyStart; i < s.Length; ++i) { int c = s[i]; // let parens slide since sometimes they occur in cookies // if (c == '(' && !inQuotes) // throw ParseErr.make("MimeType", s, "comments not supported"); if (c == '=' && !inQuotes && valStart < 0) { eq = i++; while (FanInt.isSpace(s[i])) { ++i; } if (s[i] == '"') { inQuotes = true; ++i; c = s[i]; } else { inQuotes = false; } valStart = i; } if (eq < 0) { continue; } if (c == '\\' && inQuotes) { ++i; hasEsc = true; continue; } if (c == '"' && inQuotes) { valEnd = i - 1; inQuotes = false; } if (c == ';' && !inQuotes) { if (valEnd < 0) { valEnd = i - 1; } string key = s.Substring(keyStart, eq - keyStart).Trim(); string val = s.Substring(valStart, valEnd + 1 - valStart).Trim(); if (hasEsc) { val = unescape(val); } pars.set(key, val); keyStart = i + 1; eq = valStart = valEnd = -1; hasEsc = false; } } if (keyStart < s.Length) { if (valEnd < 0) { valEnd = s.Length - 1; } string key = s.Substring(keyStart, eq - keyStart).Trim(); string val = s.Substring(valStart, valEnd + 1 - valStart).Trim(); if (hasEsc) { val = unescape(val); } pars.set(key, val); } return(pars); }
internal override Map makeParams() { Map map = new Map(Sys.StrType, Sys.TypeType); for (int i=0; i<m_params.Length; ++i) map.set(FanStr.m_ascii['A'+i], m_params[i]); return map.set(FanStr.m_ascii['R'], m_ret).ro(); }