1 18 package org.apache.batik.util.io; 19 20 import java.io.IOException ; 21 22 28 public class StringNormalizingReader extends NormalizingReader { 29 30 33 protected String string; 34 35 38 protected int length; 39 40 43 protected int next; 44 45 48 protected int line = 1; 49 50 53 protected int column; 54 55 59 public StringNormalizingReader(String s) { 60 string = s; 61 length = s.length(); 62 } 63 64 69 public int read() throws IOException { 70 int result = (length == next) ? -1 : string.charAt(next++); 71 if (result <= 13) { 72 switch (result) { 73 case 13: 74 column = 0; 75 line++; 76 int c = (length == next) ? -1 : string.charAt(next); 77 if (c == 10) { 78 next++; 79 } 80 return 10; 81 82 case 10: 83 column = 0; 84 line++; 85 } 86 } 87 return result; 88 } 89 90 93 public int getLine() { 94 return line; 95 } 96 97 100 public int getColumn() { 101 return column; 102 } 103 104 107 public void close() throws IOException { 108 string = null; 109 } 110 } 111 | Popular Tags |