package com.mindprod.compactor;

/**
 * categorises HTML chars in order to remove excess whitespace.
 */
enum HTMLCharCategory
    {
        DASH,
        IGNORE,
        BEGIN,
        END,
        NL,
        QUOTE,
        SPACE,
        TEXT;

    // ------------------------------ FIELDS ------------------------------

    /**
     * true if we ignore \r characters, since in windows they come in pairs \r\n CrLf
     */
    private static final boolean ignoreCr =
            System.getProperty( "line.separator" ).equals( "\r\n" );

    // -------------------------- STATIC METHODS --------------------------

    /**
     * decide which category a char belongs to
     *
     * @param c character to categorise
     * @return the category of the character
     */
    static HTMLCharCategory categorise( char c )
        {
        switch ( c )
            {
            case ' ':
            case '\t':
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                // case 9: tab \t
                // case 10: lf
            case 11:
            case 12:
                // case 13: cr
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
                // don't include non-breaking space.
                return SPACE;
            case '\n':
                return NL;
            case '\r':
                return ignoreCr ? IGNORE : NL;
            case '<':
                return BEGIN;
            case '>':
                return END;
            case '\"':
                return QUOTE;
            case '-':
                return DASH;
            default:
                return TEXT;
            }
        }
    }