class HttpField {

    public boolean contains(String search) {
        if (search == null)
            return value == null;
        if (search.length() == 0)
            return false;
        if (value == null)
            return false;
        if (search.equals(value))
            return true;

        search = StringUtils.asciiToLowerCase(search);

        int state = 0;
        int match = 0;
        int param = 0;

        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            switch (state) {
                case 0: // initial white space
                    switch (c) {
                        case '"': // open quote
                            match = 0;
                            state = 2;
                            break;

                        case ',': // ignore leading empty field
                            break;

                        case ';': // ignore leading empty field parameter
                            param = -1;
                            match = -1;
                            state = 5;
                            break;

                        case ' ': // more white space
                        case '\t':
                            break;

                        default: // character
                            match = Character.toLowerCase(c) == search.charAt(0) ? 1 : -1;
                            state = 1;
                            break;
                    }
                    break;

                case 1: // In token
                    switch (c) {
                        case ',': // next field
                            // Have we matched the token?
                            if (match == search.length())
                                return true;
                            state = 0;
                            break;

                        case ';':
                            param = match >= 0 ? 0 : -1;
                            state = 5; // parameter
                            break;

                        default:
                            if (match > 0) {
                                if (match < search.length())
                                    match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1;
                                else if (c != ' ' && c != '\t')
                                    match = -1;
                            }
                            break;

                    }
                    break;

                case 2: // In Quoted token
                    switch (c) {
                        case '\\': // quoted character
                            state = 3;
                            break;

                        case '"': // end quote
                            state = 4;
                            break;

                        default:
                            if (match >= 0) {
                                if (match < search.length())
                                    match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1;
                                else
                                    match = -1;
                            }
                    }
                    break;

                case 3: // In Quoted character in quoted token
                    if (match >= 0) {
                        if (match < search.length())
                            match = Character.toLowerCase(c) == search.charAt(match) ? (match + 1) : -1;
                        else
                            match = -1;
                    }
                    state = 2;
                    break;

                case 4: // WS after end quote
                    switch (c) {
                        case ' ': // white space
                        case '\t': // white space
                            break;

                        case ';':
                            state = 5; // parameter
                            break;

                        case ',': // end token
                            // Have we matched the token?
                            if (match == search.length())
                                return true;
                            state = 0;
                            break;

                        default:
                            // This is an illegal token, just ignore
                            match = -1;
                    }
                    break;

                case 5:  // parameter
                    switch (c) {
                        case ',': // end token
                            // Have we matched the token and not q=0?
                            if (param != ZERO_QUALITY.length() && match == search.length())
                                return true;
                            param = 0;
                            state = 0;
                            break;

                        case ' ': // white space
                        case '\t': // white space
                            break;

                        default:
                            if (param >= 0) {
                                if (param < ZERO_QUALITY.length())
                                    param = Character.toLowerCase(c) == ZERO_QUALITY.charAt(param) ? (param + 1) : -1;
                                else if (c != '0' && c != '.')
                                    param = -1;
                            }

                    }
                    break;

                default:
                    throw new IllegalStateException();
            }
        }

        return param != ZERO_QUALITY.length() && match == search.length();
    }

    public  HttpField(HttpHeader header, String name, String value);
    public  HttpField(HttpHeader header, String value);
    public  HttpField(HttpHeader header, HttpHeaderValue value);
    public  HttpField(String name, String value);

}