if (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP || whitespace == IdentValue.PRE) { text = linefeed_space_collapse.matcher(text).replaceAll(EOL); }
text = collapseWhitespace(whitespace, text, collapseLeading);
    static boolean stripWhitespace(CalculatedStyle style, boolean collapseLeading, TextContent tc) {        IdentValue whitespace = style.getIdent(CSSName.WHITE_SPACE);        String text = tc.getText();        // do step 1        if (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP || whitespace == IdentValue.PRE) {            text = linefeed_space_collapse.matcher(text).replaceAll(EOL);        }        // do step 2        // pull out pre's for breaking        // OK: any spaces in a pre or pre-wrap are considered to be non-breaking        // resolve that later, the space-sequence may only be broken at the end!        // do step 3        // convert line feeds to spaces        if (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP) {            text = linefeed_to_space.matcher(text).replaceAll(SPACE);        }        // do step 4        if (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP || whitespace == IdentValue.PRE) {            text = tab_to_space.matcher(text).replaceAll(SPACE);            text = space_collapse.matcher(text).replaceAll(SPACE);            // collapse first space against prev inline            if (text.startsWith(SPACE) &&                    collapseLeading) {                text = text.substring(1, text.length());            }        }        boolean collapseNext = (text.endsWith(SPACE) &&                (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP || whitespace == IdentValue.PRE));        tc.setText(text);        if (text.trim().equals("")) {            if (whitespace == IdentValue.NORMAL || whitespace == IdentValue.NOWRAP) {                tc.setRemovableWhitespace(true);            } else if (whitespace == IdentValue.PRE) {                tc.setRemovableWhitespace(false);//actually unnecessary, is set to this by default            } else if (text.indexOf(EOL) < 0) {//and whitespace.equals("pre-line"), the only one left                tc.setRemovableWhitespace(true);            }        }        return collapseNext;    }