Fixed up the DocBuffer a bit and added a basic XML writer.
[jsvc.git] / src / dolda / jsvc / next / ColumnWriter.java
diff --git a/src/dolda/jsvc/next/ColumnWriter.java b/src/dolda/jsvc/next/ColumnWriter.java
new file mode 100644 (file)
index 0000000..0ea5b77
--- /dev/null
@@ -0,0 +1,51 @@
+package dolda.jsvc.next;
+
+import java.io.*;
+
+public class ColumnWriter extends FilterWriter {
+    public int line, col;
+    public boolean start = true;
+    
+    public ColumnWriter(Writer out) {
+       super(out);
+       line = col = 0;
+    }
+    
+    private void hc(int c) {
+       if(c == '\n') {
+           col = 0;
+           line++;
+           start = true;
+       } else if(c == '\t') {
+           col = (col - (col % 8)) + 8;
+       } else {
+           col++;
+       }
+       if(!Character.isWhitespace(c))
+           start = false;
+    }
+
+    public void write(int c) throws IOException {
+       super.write(c);
+       hc(c);
+    }
+    
+    public void write(String s, int off, int len) throws IOException {
+       super.write(s, off, len);
+       for(int i = 0; i < s.length(); i++)
+           hc(s.charAt(i));
+    }
+    
+    public void write(char[] b, int off, int len) throws IOException {
+       super.write(b, off, len);
+       for(int i = 0; i < len; i++, off++)
+           hc(b[off]);
+    }
+    
+    public void indent(int level) throws IOException {
+       if(!start)
+           write('\n');
+       while(col < level)
+           write(' ');
+    }
+}