public ISet <ICookie> Decode(string header) { Contract.Requires(header != null); int headerLen = header.Length; if (headerLen == 0) { return(Empty); } var cookies = new SortedSet <ICookie>(); int i = 0; bool rfc2965Style = false; if (CharUtil.RegionMatchesIgnoreCase(header, 0, RFC2965Version, 0, RFC2965Version.Count)) { // RFC 2965 style cookie, move to after version value i = header.IndexOf(';') + 1; rfc2965Style = true; } // loop for (;;) { // Skip spaces and separators. for (;;) { if (i == headerLen) { goto loop; } char c = header[i]; if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; for (;;) { char curChar = header[i]; if (curChar == ';') { // NAME; (no value till ';') nameEnd = i; valueBegin = valueEnd = -1; break; } else if (curChar == '=') { // NAME=VALUE nameEnd = i; i++; if (i == headerLen) { // NAME= (empty value, i.e. nothing after '=') valueBegin = valueEnd = 0; break; } valueBegin = i; // NAME=VALUE; int semiPos = header.IndexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; break; } else { i++; } if (i == headerLen) { // NAME (no value till the end of string) nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } if (rfc2965Style && (CharUtil.RegionMatches(header, nameBegin, RFC2965Path, 0, RFC2965Path.Count) || CharUtil.RegionMatches(header, nameBegin, RFC2965Domain, 0, RFC2965Domain.Count) || CharUtil.RegionMatches(header, nameBegin, RFC2965Port, 0, RFC2965Port.Count))) { // skip obsolete RFC2965 fields continue; } DefaultCookie cookie = this.InitCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie != null) { cookies.Add(cookie); } } loop: return(cookies); }
private void Decode(string header, ICollection <ICookie> cookies) { int headerLen = header.Length; int i = 0; bool rfc2965Style = false; if (CharUtil.RegionMatchesIgnoreCase(header, 0, RFC2965Version, 0, RFC2965Version.Count)) { // RFC 2965 style cookie, move to after version value i = header.IndexOf(';') + 1; rfc2965Style = true; } // loop while (true) { // Skip spaces and separators. while (true) { if (i == headerLen) { goto loop; } char c = header[i]; if (IsSpace(c)) { i++; continue; } break; } int nameBegin = i; int nameEnd; int valueBegin; int valueEnd; while (true) { char curChar = header[i]; switch (curChar) { case HttpConstants.SemicolonChar: // NAME; (no value till ';') nameEnd = i; valueBegin = valueEnd = -1; goto loop0; case HttpConstants.EqualsSignChar: // NAME=VALUE nameEnd = i; i++; if (i == headerLen) { // NAME= (empty value, i.e. nothing after '=') valueBegin = valueEnd = 0; goto loop0; } valueBegin = i; // NAME=VALUE; int semiPos = header.IndexOf(';', i); valueEnd = i = semiPos > 0 ? semiPos : headerLen; goto loop0; default: i++; break; } if (i == headerLen) { // NAME (no value till the end of string) nameEnd = headerLen; valueBegin = valueEnd = -1; break; } } loop0: if (rfc2965Style && (CharUtil.RegionMatches(header, nameBegin, RFC2965Path, 0, RFC2965Path.Count) || CharUtil.RegionMatches(header, nameBegin, RFC2965Domain, 0, RFC2965Domain.Count) || CharUtil.RegionMatches(header, nameBegin, RFC2965Port, 0, RFC2965Port.Count))) { // skip obsolete RFC2965 fields continue; } DefaultCookie cookie = InitCookie(header, nameBegin, nameEnd, valueBegin, valueEnd); if (cookie is object) { cookies.Add(cookie); } } loop: return; }
public bool RegionMatches(int thisStart, ICharSequence seq, int start, int length) => CharUtil.RegionMatches(this, thisStart, seq, start, length);