/*
TODO: allow a Set-Cookie string to be parsed into multiple cookies
328806
function parseCookie($cookie_str) {
		$cookie_str = str_replace('; ', ';', $cookie_str) . ';';
		$data = preg_split('/;/', $cookie_str);
		$value_str = $data[0];

		$cookie_param = 'domain=';
		$start = strpos($cookie_str, $cookie_param);
		if ($start > 0) {
			$domain = substr($cookie_str, $start + strlen($cookie_param));
			$domain = substr($domain, 0, strpos($domain, ';'));
		} else {
			$domain = '';
		}

		$cookie_param = 'expires=';
		$start = strpos($cookie_str, $cookie_param);
		if ($start > 0) {
			$expires = substr($cookie_str, $start + strlen($cookie_param));
			$expires = substr($expires, 0, strpos($expires, ';'));
		} else {
			$expires = '';
		}

		$cookie_param = 'path=';
		$start = strpos($cookie_str, $cookie_param);
		if ( $start > 0 ) {
			$path = substr($cookie_str, $start + strlen($cookie_param));
			$path = substr($path, 0, strpos($path, ';'));
		} else {
			$path = '/';
		}
						
		$cookie_param = ';secure;';
		if (strpos($cookie_str, $cookie_param) !== FALSE) {
			$secure = true;
		} else {
			$secure = false;
		}

		$sep_pos = strpos($value_str, '=');

		if ($sep_pos) {
			$name = substr($value_str, 0, $sep_pos);
			$value = substr($value_str, $sep_pos + 1);
			$cookie= array(	'name' => $name,
			                'value' => $value,
							'domain' => $domain,
							'path' => $path,
							'expires' => $expires,
							'secure' => $secure
							);		
			return $cookie;
		}
		return false;
	}
1153720
function(_name){
            var _cookie = document.cookie,
                _search = '\\b'+_name+'=',
                _index1 = _cookie.search(_search);
            if (_index1<0) return '';
            _index1 += _search.length-2;
            var _index2 = _cookie.indexOf(';',_index1);
            if (_index2<0) _index2 = _cookie.length;
            return _cookie.substring(_index1,_index2)||'';
        }
1122735
function(name) {
    var c = document.cookie.split(';');
    
    for (var i = 0, cookie; i < c.length; i++) {
      cookie = c[i].split('=');
      if (cookie[0].strip() === name)
        return cookie[1].strip();
    }
    
    return null;
  }
79840
def parse_cookie(self, string):
        '''
        
        '''
        results = re.findall('([^=]+)=([^\;]+);?\s?', string)
        my_dict = {}
        for item in results:
            my_dict[item[0]] = item[1]

        return my_dict
673374
protected function setCookieFromString($string)
    {
        $cookieParams = explode('; ', $string);
        $cookieValue = array_shift($cookieParams);
        $sep = strpos($cookieValue, '=');
        $cookie = [
            'Name' => substr($cookieValue, 0, $sep),
            'Value' => substr($cookieValue, $sep + 1),
        ];

        foreach ($cookieParams as $cookieParam) {
            if ('secure' === strtolower($cookieParam)) {
                $cookie['Secure'] = true;
                continue;
            }

            if ('httponly' === strtolower($cookieParam)) {
                $cookie['HttpOnly'] = true;
                continue;
            }

            $sep = strpos($cookieParam, '=');
            $key = substr($cookieParam, 0, $sep);
            $key = strtolower($key);

            if (in_array($key, ['domain', 'path', 'max-age', 'expires'], true)) {
                $key = 'max-age' === $key ? 'Max-Age' : ucfirst($key);
                $cookie[$key] = substr($cookieParam, $sep + 1);
            }
        }

        $this->getCookieJar()->setCookie(new SetCookie($cookie));

        return $this;
    }
1037958
protected Cookie decodeCookie(String cookieString) {
        byte[] bytes = hexStringToByteArray(cookieString);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        Cookie cookie = null;
        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
        } catch (IOException e) {
            Util.log("IOException in decodeCookie", e);
        } catch (ClassNotFoundException e) {
            Util.log("ClassNotFoundException in decodeCookie", e);
        }

        return cookie;
    }
469767
function set(name, value) {

        // if no value then remove
        if (!value) {
            remove(name);
            return;
        }

        if (localStorage) {
            try {
                localStorage.setItem(name, value);
            }
            catch (ex) {}
        }

        _.isFunction($cookies.put) ?
            $cookies.put(name, value, { domain: cookieDomain }) :
            $cookies[name] = value;

    }
733073
@Nullable
    public static Cookie parseCookie(String cookieStr, String host, String defaultPath) {
        String[] items = cookieStr.split(";");
        Parameter<String> param = parseCookieNameValue(items[0]);
        if (param == null) {
            return null;
        }

        String domain = "";
        String path = "";
        long expiry = 0;
        boolean secure = false;
        for (String item : items) {
            item = item.trim();
            if (item.isEmpty()) {
                continue;
            }
            Parameter<String> attribute = parseCookieAttribute(item);
            switch (attribute.name().toLowerCase()) {
                case "domain":
                    domain = normalizeDomain(attribute.value());
                    break;
                case "path":
                    path = normalizePath(attribute.value());
                    break;
                case "expires":
                    // If a cookie has both the Max-Age and the Expires attribute, the Max-Age attribute has precedence
                    // and controls the expiration date of the cookie.
                    if (expiry == 0) {
                        Date date = CookieDateUtil.parseDate(attribute.value());
                        if (date != null) {
                            expiry = date.getTime();
                            if (expiry == 0) {
                                expiry = 1;
                            }
                        }
                    }
                    break;
                case "max-age":
                    try {
                        int seconds = Integer.parseInt(attribute.value());
                        expiry = System.currentTimeMillis() + seconds * 1000;
                        if (expiry == 0) {
                            expiry = 1;
                        }
                    } catch (NumberFormatException ignore) {
                    }
                    break;
                case "secure":
                    secure = true;
                    break;
                case "httponly":
                    // ignore http only now
                    break;
                default:
            }
        }

        if (path.isEmpty()) {
            path = defaultPath;
        }
        boolean hostOnly;
        if (domain.isEmpty()) {
            domain = host;
            hostOnly = true;
        } else {
            if (isIP(host)) {
                // should not set
                return null;
            }
            if (!isDomainSuffix(host, domain)) {
                return null;
            }
            hostOnly = false;
        }

        return new Cookie(domain, path, param.name(), param.value(), expiry, secure, hostOnly);
    }
1041769
function parseCookie(str) {
  var obj = {},
    pairs = str.split(/[;,] */);

  for (var pair,eqlIndex,key,val,i=0; i < pairs.length; i++) {
    pair = pairs[i];
    eqlIndex = pair.indexOf('=');
    key = pair.substr(0, eqlIndex).trim().toLowerCase();
    val = pair.substr(++eqlIndex, pair.length).trim();
    if ('"' === val[0]) val = val.slice(1, -1);
    if (obj[key] === undefined) {
      val = val.replace(/\+/g, ' ');
      try {
        obj[key] = decodeURIComponent(val);
      } catch (err) {
        if (err instanceof URIError) {
          obj[key] = val;
        } else {
          throw err;
        }
      }
    }
  }
  return obj;
}
284453
private function updateCookieHeader()
	{
		$strings = array();

		foreach ($this->cookies as $key => $value) {
			$strings[] = "{$key}={$value}";
		}

		$this->setHeader('cookie', implode('; ', $strings));
	}
529319
String getCookieString(Cookie cookie) {
        StringBuilder builder = new StringBuilder();

        builder.append(cookie.getName());
        builder.append("=");
        builder.append(cookie.getValue());

        if (cookie.getVersion() > 0) {
            builder.append(";" + VERSION + "=").append(cookie.getVersion());
        }

        if (StringUtils.hasText(cookie.getPath())) {
            builder.append(";" + PATH + "=").append(cookie.getPath());
        }

        if (StringUtils.hasText(cookie.getDomain())) {
            builder.append(";" + DOMAIN + "=").append(cookie.getDomain());
        }

        if (cookie.getMaxAge() > 0) {
            builder.append(";" + MAX_AGE + "=").append(cookie.getMaxAge());
        }

        if (StringUtils.hasText(cookie.getComment())) {
            builder.append(";" + COMMENT + "=").append(cookie.getComment());
        }

        if (cookie.getSecure()) {
            builder.append(";" + SECURE);
        }

        if (cookie.isHttpOnly()) {
            builder.append(";" + HTTP_ONLY);
        }

        return builder.toString();
    }
528810
function extractHeaderCookies(headerSet) {
    var cookie = headerSet.cookie;
    var cookies = cookie ? cookie.split(';') : [];
    delete headerSet.cookie;
    return cookies;
}
229241
function() {
            var cookieString = "";

            utils.forEach(this._cookieStore, function (cookieValue, cookieKey) {
                cookieString += cookieKey;
                cookieString += '=';
                cookieString += cookieValue;
                cookieString += '; ';
            });

            return cookieString;

        }
218392
function setcookie($name, $value = null, $expire = null, $path = '/', $domain = null, $secure = null, $httponly = null)
    {
        if ($value == null)
        {
            $value = 'deleted';
        }
        $cookie = "$name=$value";
        if ($expire)
        {
            $cookie .= "; expires=" . date("D, d-M-Y H:i:s T", $expire);
        }
        if ($path)
        {
            $cookie .= "; path=$path";
        }
        if ($secure)
        {
            $cookie .= "; secure";
        }
        if ($domain)
        {
            $cookie .= "; domain=$domain";
        }
        if ($httponly)
        {
            $cookie .= '; httponly';
        }
        $this->cookie[] = $cookie;
    }
446594
function getCookie(cookieName) {
  if (typeof window === 'undefined' || typeof document === 'undefined') {
    return '';
  }
  var name = cookieName + '=';
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) === ' ') {
      c = c.substring(1);
    }
    try {
      if ((0, _includes2.default)(c, name)) {
        return c.substring(name.length, c.length);
      }
    } catch (error) {
      _logger2.default.warn({
        description: 'Cookie cannot be loaded.', cookieName: cookieName,
        error: error, func: 'getCookie', obj: 'cookiesUtil'
      });
      return '';
    }
  }
  return '';
}
167518
def parse_cookies(self, req, name, field):
        """"""
        cookie = req.cookies.get(name)

        if cookie is not None:
            return [cookie.value] if core.is_multiple(field) else cookie.value
        else:
            return [] if core.is_multiple(field) else None
876204
function rewriteCookies(rawCookie) {
    var objCookie = (function() {
        // simple parse function (does not remove quotes)
        var obj = {};
        var pairs = rawCookie.split(/; */);

        pairs.forEach(function(pair) {
            var eqIndex = pair.indexOf("=");

            // skip things that don't look like key=value
            if (eqIndex < 0) {
                return;
            }

            var key = pair.substr(0, eqIndex).trim();
            obj[key] = pair.substr(eqIndex + 1, pair.length).trim();
        });

        return obj;
    })();

    var pairs = Object.keys(objCookie)
        .filter(function(item) {
            return item.toLowerCase() !== "domain";
        })
        .map(function(key) {
            return key + "=" + objCookie[key];
        });

    if (rawCookie.match(/httponly/i)) {
        pairs.push("HttpOnly");
    }

    return pairs.join("; ");
}