protected int getCharNWS() throws IOException { outWS.reset(); outer: for (;;) { int ch = getChar(); switch (ch) { case ' ' : case '\t' : case '\r' : case '\n' : outWS.write(ch); continue outer; case '#' : getNewlineComment(); continue outer; case '/' : getSlashComment(); continue outer; default: return ch; } } }
protected void getSlashComment() throws IOException { int ch = getChar(); if (ch != -1) outWS.write(ch); if (ch == '/') { getNewlineComment(); return; } if (ch != '*') { throw err("Invalid comment: expected //, /*, or #"); } ch = getChar(); if (ch != -1) outWS.write(ch); for (;;) { if (ch == '*') { ch = getChar(); if (ch != -1) outWS.write(ch); if (ch == '/') { return; } else if (ch == '*') { // handle cases of *******/ continue; } } if (ch == -1) { return; } ch = getChar(); if (ch != -1) outWS.write(ch); } }
protected void getNewlineComment() throws IOException { // read a # or a //, so go until newline for (;;) { int ch = getChar(); if (ch != -1) outWS.write(ch); // don't worry about DOS /r/n... we'll stop on the \r and let the rest of the whitespace // eater consume the \n if (ch == '\n' || ch == '\r' || ch == -1) { return; } } }
protected void getSlashComment() throws IOException { int ch = getChar(); if (ch != -1) outWS.write(ch); if (ch == '/') { getNewlineComment(); return; } if (ch != '*') { throw err("Invalid comment: expected //, /*, or #"); } ch = getChar(); if (ch != -1) outWS.write(ch); for (;;) { if (ch == '*') { ch = getChar(); if (ch != -1) outWS.write(ch); if (ch == '/') { return; } else if (ch == '*') { // handle cases of *******/ continue; } } if (ch == -1) { return; } ch = getChar(); if (ch != -1) outWS.write(ch); } }
protected void getNewlineComment() throws IOException { // read a # or a //, so go until newline for (;;) { int ch = getChar(); if (ch != -1) outWS.write(ch); // don't worry about DOS /r/n... we'll stop on the \r and let the rest of the whitespace // eater consume the \n if (ch == '\n' || ch == '\r' || ch == -1) { return; } } }
protected int getCharNWS() throws IOException { outWS.reset(); outer: for (;;) { int ch = getChar(); switch (ch) { case ' ' : case '\t' : case '\r' : case '\n' : outWS.write(ch); continue outer; case '#' : getNewlineComment(); continue outer; case '/' : getSlashComment(); continue outer; default: return ch; } } }