added antlr comparison test

This commit is contained in:
2018-09-09 21:45:58 +01:00
parent 1f7261bca8
commit 135c56151c
9 changed files with 245 additions and 36 deletions

View File

@@ -0,0 +1,25 @@
package org.oggio88.worth.buffer;
import java.io.IOException;
import java.io.InputStream;
public class LookAheadInputStream extends InputStream {
private final InputStream stream;
private int currentByte;
LookAheadInputStream(InputStream stream) {
this.stream = stream;
}
@Override
public int read() throws IOException {
int result = currentByte;
currentByte = stream.read();
return result;
}
public int getCurrentByte(){
return currentByte;
}
}

View File

@@ -23,6 +23,37 @@ public class JSONDumper extends ValueDumper {
protected Writer writer;
private String escapeString(String value){
StringBuilder sb = new StringBuilder();
for (char c : value.toCharArray()) {
switch (c) {
case '"':
sb.append("\\\"");
break;
case '\r':
sb.append("\\r");
break;
case '\n':
sb.append("\\n");
break;
case '\t':
sb.append("\\t");
break;
case '\\':
sb.append("\\\\");
break;
default: {
if (c < 128)
sb.append(c);
else {
sb.append("\\u").append(String.format("%04X", (int) c));
}
}
}
}
return sb.toString();
}
@Override
public void dump(Value value, OutputStream stream) {
dump(value, new OutputStreamWriter(stream));
@@ -121,40 +152,13 @@ public class JSONDumper extends ValueDumper {
@Override
@SneakyThrows
protected void objectKey(String key) {
this.writer.write("\"" + key + "\"");
this.writer.write("\"" + escapeString(key) + "\"");
}
@Override
@SneakyThrows
protected void stringValue(String value) {
StringBuilder sb = new StringBuilder();
for (char c : value.toCharArray()) {
switch (c) {
case '"':
sb.append("\\\"");
break;
case '\r':
sb.append("\\r");
break;
case '\n':
sb.append("\\n");
break;
case '\t':
sb.append("\\t");
break;
case '\\':
sb.append("\\\\");
break;
default: {
if (c < 128)
sb.append(c);
else {
sb.append("\\u").append(String.format("%04X", (int) c));
}
}
}
}
this.writer.write("\"" + sb.toString() + "\"");
this.writer.write("\"" + escapeString(value) + "\"");
}
@Override

View File

@@ -1,7 +1,10 @@
package org.oggio88.worth.utils;
import lombok.SneakyThrows;
import org.oggio88.worth.buffer.CircularBuffer;
import org.oggio88.worth.exception.ParseException;
import java.io.InputStream;
import java.util.concurrent.Callable;
public class WorthUtils {