⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixcrlffilter.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        numEOL = 2;                        push(c2);                    } else if (c1 == '\n') {                        // EOL was "\r\n"                        push(c2);                    } else {                        // EOL was "\r"                        push(c2);                        push(c1);                    }                default:                    // Fall tru                }                if (numEOL > 0) {                    while (numEOL-- > 0) {                        push(eol);                        normalizedEOL += eol.length;                    }                    previousWasEOL = true;                    thisChar = read();                } else if (!atEnd) {                    previousWasEOL = false;                }            } else {                normalizedEOL--;            }            return thisChar;        }    }    private static class AddEofFilter extends SimpleFilterReader {        private int lastChar = -1;        public AddEofFilter(Reader in) {            super(in);        }        public int read() throws IOException {            int thisChar = super.read();            // if source is EOF but last character was NOT ctrl-z, return ctrl-z            if (thisChar == -1) {                if (lastChar != CTRLZ) {                    lastChar = CTRLZ;                    return lastChar;                }            } else {                lastChar = thisChar;            }            return thisChar;        }    }    private static class RemoveEofFilter extends SimpleFilterReader {        private int lookAhead = -1;        public RemoveEofFilter(Reader in) {            super(in);            try {                lookAhead = in.read();            } catch (IOException e) {                lookAhead = -1;            }        }        public int read() throws IOException {            int lookAhead2 = super.read();            // If source at EOF and lookAhead is ctrl-z, return EOF (NOT ctrl-z)            if (lookAhead2 == -1 && lookAhead == CTRLZ) {                return -1;            }            // Return current look-ahead            int i = lookAhead;            lookAhead = lookAhead2;            return i;        }    }    private static class AddTabFilter extends SimpleFilterReader {        private int columnNumber = 0;        private int tabLength = 0;        public AddTabFilter(Reader in, int tabLength) {            super(in);            this.tabLength = tabLength;        }        public int read() throws IOException {            int c = super.read();            switch (c) {            case '\r':            case '\n':                columnNumber = 0;                break;            case ' ':                columnNumber++;                if (!editsBlocked()) {                    int colNextTab = ((columnNumber + tabLength - 1) / tabLength) * tabLength;                    int countSpaces = 1;                    int numTabs = 0;                    scanWhitespace: while ((c = super.read()) != -1) {                        switch (c) {                        case ' ':                            if (++columnNumber == colNextTab) {                                numTabs++;                                countSpaces = 0;                                colNextTab += tabLength;                            } else {                                countSpaces++;                            }                            break;                        case '\t':                            columnNumber = colNextTab;                            numTabs++;                            countSpaces = 0;                            colNextTab += tabLength;                            break;                        default:                            push(c);                            break scanWhitespace;                        }                    }                    while (countSpaces-- > 0) {                        push(' ');                        columnNumber--;                    }                    while (numTabs-- > 0) {                        push('\t');                        columnNumber -= tabLength;                    }                    c = super.read();                    switch (c) {                    case ' ':                        columnNumber++;                        break;                    case '\t':                        columnNumber += tabLength;                        break;                    default:                        // Fall tru                    }                }                break;            case '\t':                columnNumber = ((columnNumber + tabLength - 1) / tabLength) * tabLength;                break;            default:                columnNumber++;            }            return c;        }    }    private static class RemoveTabFilter extends SimpleFilterReader {        private int columnNumber = 0;        private int tabLength = 0;        public RemoveTabFilter(Reader in, int tabLength) {            super(in);            this.tabLength = tabLength;        }        public int read() throws IOException {            int c = super.read();            switch (c) {            case '\r':            case '\n':                columnNumber = 0;                break;            case '\t':                int width = tabLength - columnNumber % tabLength;                if (!editsBlocked()) {                    for (; width > 1; width--) {                        push(' ');                    }                    c = ' ';                }                columnNumber += width;                break;            default:                columnNumber++;            }            return c;        }    }    /**     * Enumerated attribute with the values "asis", "add" and "remove".     */    public static class AddAsisRemove extends EnumeratedAttribute {        private static final AddAsisRemove ASIS = newInstance("asis");        private static final AddAsisRemove ADD = newInstance("add");        private static final AddAsisRemove REMOVE = newInstance("remove");        /** {@inheritDoc}. */        public String[] getValues() {            return new String[] {"add", "asis", "remove"};        }        /**         * Equality depending in the index.         * @param other the object to test equality against.         * @return true if the object has the same index as this.         */        public boolean equals(Object other) {            return other instanceof AddAsisRemove                    && getIndex() == ((AddAsisRemove) other).getIndex();        }        /**         * Hashcode depending on the index.         * @return the index as the hashcode.         */        public int hashCode() {            return getIndex();        }        AddAsisRemove resolve() throws IllegalStateException {            if (this.equals(ASIS)) {                return ASIS;            }            if (this.equals(ADD)) {                return ADD;            }            if (this.equals(REMOVE)) {                return REMOVE;            }            throw new IllegalStateException("No replacement for " + this);        }        // Works like clone() but doesn't show up in the Javadocs        private AddAsisRemove newInstance() {            return newInstance(getValue());        }        /**         * Create an instance of this enumerated value based on the string value.         * @param value the value to use.         * @return an enumerated instance.         */        public static AddAsisRemove newInstance(String value) {            AddAsisRemove a = new AddAsisRemove();            a.setValue(value);            return a;        }    }    /**     * Enumerated attribute with the values "asis", "cr", "lf" and "crlf".     */    public static class CrLf extends EnumeratedAttribute {        private static final CrLf ASIS = newInstance("asis");        private static final CrLf CR = newInstance("cr");        private static final CrLf CRLF = newInstance("crlf");        private static final CrLf DOS = newInstance("dos");        private static final CrLf LF = newInstance("lf");        private static final CrLf MAC = newInstance("mac");        private static final CrLf UNIX = newInstance("unix");        /**         * @see EnumeratedAttribute#getValues         */        /** {@inheritDoc}. */        public String[] getValues() {            return new String[] {"asis", "cr", "lf", "crlf", "mac", "unix", "dos"};        }        /**         * Equality depending in the index.         * @param other the object to test equality against.         * @return true if the object has the same index as this.         */        public boolean equals(Object other) {            return other instanceof CrLf && getIndex() == ((CrLf) other).getIndex();        }        /**         * Hashcode depending on the index.         * @return the index as the hashcode.         */        public int hashCode() {            return getIndex();        }        CrLf resolve() {            if (this.equals(ASIS)) {                return ASIS;            }            if (this.equals(CR) || this.equals(MAC)) {                return CR;            }            if (this.equals(CRLF) || this.equals(DOS)) {                return CRLF;            }            if (this.equals(LF) || this.equals(UNIX)) {                return LF;            }            throw new IllegalStateException("No replacement for " + this);        }        // Works like clone() but doesn't show up in the Javadocs        private CrLf newInstance() {            return newInstance(getValue());        }        /**         * Create an instance of this enumerated value based on the string value.         * @param value the value to use.         * @return an enumerated instance.         */        public static CrLf newInstance(String value) {            CrLf c = new CrLf();            c.setValue(value);            return c;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -