Fan.Sys.MimeType.doParseParams C# (CSharp) Method

doParseParams() private static method

private static doParseParams ( string s, int offset ) : Map
s string
offset int
return Map
        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;
        }