public static void removeSpaces(ShortTermMemoryReader reader) throws IOException { char c = (char) reader.read(); while (Character.isSpaceChar(c)) { c = (char) reader.read(); } back(c, reader); }
public Double read(ShortTermMemoryReader reader) throws RowColumnReaderException { try { IntegerReadService.removeSpaces(reader); char c = (char) reader.read(); if (Character.isDigit(c) || c == '-' || c == '+') { StringBuilder sb = new StringBuilder(); sb.append(c); IntegerReadService.readDigitStar(reader, sb); c = (char) reader.read(); if (c == '.') { sb.append(c); IntegerReadService.readDigitStar(reader, sb); c = (char) reader.read(); } if (c == 'e' || c == 'E') { sb.append(c); c = (char) reader.read(); if (c == '-' || c == '+') { sb.append(c); } else { IntegerReadService.back(c, reader); } IntegerReadService.readDigitStar(reader, sb); } else { IntegerReadService.back(c, reader); } return Double.parseDouble(sb.toString()); } throw new Exception("Unexpected symbol " + c); } catch (Exception e) { throw reader.getException("Double Parser Error " + e.getMessage()); } }
public static void readDigitStar(ShortTermMemoryReader reader, StringBuilder sb) throws IOException { char c = (char) reader.read(); while (Character.isDigit(c)) { sb.append(c); c = (char) reader.read(); } back(c, reader); }
public Integer read(ShortTermMemoryReader reader) throws RowColumnReaderException { try { removeSpaces(reader); char c = (char) reader.read(); if (Character.isDigit(c) || c == '-' || c == '+') { StringBuilder sb = new StringBuilder(); sb.append(c); readDigitStar(reader, sb); return Integer.parseInt(sb.toString()); } throw new Exception("Unexpected symbol " + c); } catch (Exception e) { throw reader.getException("Integer Parser Error " + e.getMessage()); } }