]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java
Filter out CR in resource files generated by graph compiler.
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / resourceFiles / FilterCRWriter.java
diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/FilterCRWriter.java
new file mode 100644 (file)
index 0000000..2e96675
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.graph.compiler.internal.resourceFiles;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+public class FilterCRWriter extends FilterWriter {
+
+    public FilterCRWriter(Writer out) {
+        super(out);
+    }
+    
+    @Override
+    public void write(int c) throws IOException {
+        if(c != '\r')
+            out.write(c);
+    }
+    
+    @Override
+    public void write(char[] cbuf, int off, int len) throws IOException {
+        int begin = 0;
+        for(int i=0;i<len;++i) {
+            if(cbuf[off+i] == '\r') {
+                if(i > begin)
+                    write(cbuf, off+begin, i-begin);
+                begin = i+1;
+            }
+        }
+        if(len > begin)
+            write(cbuf, off+begin, len-begin);
+    }
+    
+    @Override
+    public void write(String str, int off, int len) throws IOException {
+        int begin = 0;
+        for(int i=0;i<len;++i) {
+            if(str.charAt(off+i) == '\r') {
+                if(i > begin)
+                    write(str, off+begin, i-begin);
+                begin = i+1;
+            }
+        }
+        if(len > begin)
+            write(str, off+begin, len-begin);
+    }
+
+}