/*
 * @(#)HTMLCharCategory.java
 *
 * Summary: categorises HTML chars for the finite state automaton parse in order to remove excess whitespace.
 *
 * Copyright: (c) 2009-2010 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.6+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * Version History:
 *  2.8 2009-04-04 - no longer correct missing entities. Just issue warning messages.
 */
package com.mindprod.compactor;

/**
 * categorises HTML chars for the finite state automaton parse in order to remove excess whitespace.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 2.8 2009-04-04 - no longer correct missing entities. Just issue warning messages.
 * @since 2009
 */
enum HTMLCharCategory
    {
        DASH,
        IGNORE,
        BEGIN,
        END,
        NL,
        QUOTE,
        SPACE,
        TEXT;

    // ------------------------------ CONSTANTS ------------------------------

    /**
     * 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;
            }
        }
    }
