protected static function parseCookieElement ($elm) {
    $cookie = array();
    // eat whitespace outside of quotes
    // each part ends with a semi-colon outside of quotes
    $i = 0;
    $from = 0;
    $len = mb_strlen($elm, 'latin1');
    $quoted = false;
    while ($i < $len) {
      if ('"' === $elm[$i] && '\\' !== $elm[$i - 1]) {
        $quoted = !$quoted;
      }
      $chunk = null;
      if (!$quoted && ';' === $elm[$i]) {
        $chunk = mb_substr($elm, $from, $i - $from, 'latin1');
        $from = $i + 1;
      } else if ($i === $len - 1) {
        $chunk = mb_substr($elm, $from, $len - $from, 'latin1');
      }
      if (null !== $chunk) {
        $parts = explode('=', $chunk, 2);
        if (count($parts) == 1) {
          // we found a flag of some sort
          $name = trim($parts[0]);
          $cookie[$name] = true;

        } else {
          $name = trim($parts[0]);
          $val = trim($parts[1]);
          // remove quotes
          $val = trim($val, '"');
          if (empty($cookie)) {
            // first key=value pair is the cookie name and value
            $cookie[self::COOKIE_NAME] = $name;
            $cookie[self::COOKIE_VALUE] = $val;

          } else {
            $cookie[$name] = $val;
          }
        } //end if/else
      } //end if
      $i += 1;
    } //end while

    return $cookie;
  }