private void fillCookie(ArrayList<WebCookie> cookies,CharSegment rawCookie){
  char[] buf=rawCookie.buffer();
  int j=rawCookie.offset();
  int end=j + rawCookie.length();
  int version=0;
  WebCookie cookie=null;
  while (j < end) {
    char ch=0;
    CharBuffer cbName=_cbName;
    CharBuffer cbValue=_cbValue;
    cbName.clear();
    cbValue.clear();
    for (; j < end && ((ch=buf[j]) == ' ' || ch == ';' || ch == ','); j++) {
    }
    if (end <= j)     break;
    boolean isSpecial=false;
    if (buf[j] == '$') {
      isSpecial=true;
      j++;
    }
    for (; j < end; j++) {
      ch=buf[j];
      if (ch < 128 && TOKEN[ch])       cbName.append(ch);
 else       break;
    }
    for (; j < end && (ch=buf[j]) == ' '; j++) {
    }
    if (end <= j)     break;
 else     if (ch == ';' || ch == ',') {
      try {
        cookie=new WebCookie(cbName.toString(),"");
        cookie.setVersion(version);
        _cookies.add(cookie);
      }
 catch (      Exception e) {
        log.log(Level.FINE,e.toString(),e);
      }
      continue;
    }
 else     if (ch != '=') {
      for (; j < end && (ch=buf[j]) != ';'; j++) {
      }
      continue;
    }
    j++;
    for (; j < end && (ch=buf[j]) == ' '; j++) {
    }
    if (ch == '"') {
      for (j++; j < end; j++) {
        ch=buf[j];
        if (ch == '"')         break;
        cbValue.append(ch);
      }
      j++;
    }
 else {
      int head=j;
      int tail=j;
      for (; j < end; j++) {
        ch=buf[j];
        if (ch < 128 && VALUE[ch]) {
          cbValue.append(ch);
          tail=j + 1;
        }
 else         if (ch == ' ') {
          cbValue.append(ch);
        }
 else {
          break;
        }
      }
      cbValue.length(tail - head);
    }
    if (!isSpecial) {
      if (cbName.length() == 0)       log.warning("bad cookie: " + rawCookie);
 else {
        cookie=new WebCookie(toName(cbName),cbValue.toString());
        cookie.setVersion(version);
        _cookies.add(cookie);
      }
    }
 else     if (cookie == null) {
      if (cbName.matchesIgnoreCase("Version"))       version=cbValue.charAt(0) - '0';
    }
 else     if (cbName.matchesIgnoreCase("Version"))     cookie.setVersion(cbValue.charAt(0) - '0');
 else     if (cbName.matchesIgnoreCase("Domain"))     cookie.setDomain(cbValue.toString());
 else     if (cbName.matchesIgnoreCase("Path"))     cookie.setPath(cbValue.toString());
  }
}

private void fillCookie ( ArrayList < WebCookie > cookies , CharSegment rawCookie ) { char [ ] buf = rawCookie . buffer ( ) ; int j = rawCookie . offset ( ) ; int end = j + rawCookie . length ( ) ; int version = 0 ; WebCookie cookie = null ; while ( j < end ) { char ch = 0 ; CharBuffer cbName = _cbName ; CharBuffer cbValue = _cbValue ; cbName . clear ( ) ; cbValue . clear ( ) ; for ( ; j < end && ( ( ch = buf [ j ] ) == ' ' || ch == ';' || ch == ',' ) ; j ++ ) { } if ( end <= j ) break ; boolean isSpecial = false ; if ( buf [ j ] == '$' ) { isSpecial = true ; j ++ ; } for ( ; j < end ; j ++ ) { ch = buf [ j ] ; if ( ch < 128 && TOKEN [ ch ] ) cbName . append ( ch ) ; else break ; } for ( ; j < end && ( ch = buf [ j ] ) == ' ' ; j ++ ) { } if ( end <= j ) break ; else if ( ch == ';' || ch == ',' ) { try { cookie = new WebCookie ( cbName . toString ( ) , "" ) ; cookie . setVersion ( version ) ; _cookies . add ( cookie ) ; } catch ( Exception e ) { log . log ( Level . FINE , e . toString ( ) , e ) ; } continue ; } else if ( ch != '=' ) { for ( ; j < end && ( ch = buf [ j ] ) != ';' ; j ++ ) { } continue ; } j ++ ; for ( ; j < end && ( ch = buf [ j ] ) == ' ' ; j ++ ) { } if ( ch == '"' ) { for ( j ++ ; j < end ; j ++ ) { ch = buf [ j ] ; if ( ch == '"' ) break ; cbValue . append ( ch ) ; } j ++ ; } else { int head = j ; int tail = j ; for ( ; j < end ; j ++ ) { ch = buf [ j ] ; if ( ch < 128 && VALUE [ ch ] ) { cbValue . append ( ch ) ; tail = j + 1 ; } else if ( ch == ' ' ) { cbValue . append ( ch ) ; } else { break ; } } cbValue . length ( tail - head ) ; } if ( ! isSpecial ) { if ( cbName . length ( ) == 0 ) log . warning ( "bad cookie: " + rawCookie ) ; else { cookie = new WebCookie ( toName ( cbName ) , cbValue . toString ( ) ) ; cookie . setVersion ( version ) ; _cookies . add ( cookie ) ; } } else if ( cookie == null ) { if ( cbName . matchesIgnoreCase ( "Version" ) ) version = cbValue . charAt ( 0 ) - '0' ; } else if ( cbName . matchesIgnoreCase ( "Version" ) ) cookie . setVersion ( cbValue . charAt ( 0 ) - '0' ) ; else if ( cbName . matchesIgnoreCase ( "Domain" ) ) cookie . setDomain ( cbValue . toString ( ) ) ; else if ( cbName . matchesIgnoreCase ( "Path" ) ) cookie . setPath ( cbValue . toString ( ) ) ; } }
parses a single cookie
