Fixed debug output with special chars

This commit is contained in:
Andrea Cavalli 2018-03-21 16:45:20 +01:00
parent c58bc6c9e0
commit 19083a380a
3 changed files with 48 additions and 15 deletions

View File

@ -9,6 +9,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean; import java.lang.management.OperatingSystemMXBean;
@ -43,6 +44,7 @@ import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.math.Function; import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Expression; import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Multiplication;
@ -81,17 +83,50 @@ public class Utils {
public static final class AdvancedOutputStream extends StringWriter { public static final class AdvancedOutputStream extends StringWriter {
private void print(PrintStream stream, String str) {
stream.print(fixString(str));
}
private void println(PrintStream stream, String str) {
stream.println(fixString(str));
}
private void println(PrintStream stream) {
stream.println();
}
private String fixString(String str) {
return str
.replace(""+MathematicalSymbols.NTH_ROOT, "root")
.replace(""+MathematicalSymbols.SQUARE_ROOT, "sqrt")
.replace(""+MathematicalSymbols.POWER, "powerOf")
.replace(""+MathematicalSymbols.POWER_OF_TWO, "powerOfTwo")
.replace(""+MathematicalSymbols.SINE, "sine")
.replace(""+MathematicalSymbols.COSINE, "cosine")
.replace(""+MathematicalSymbols.TANGENT, "tangent")
.replace(""+MathematicalSymbols.ARC_SINE, "asin")
.replace(""+MathematicalSymbols.ARC_COSINE, "acos")
.replace(""+MathematicalSymbols.ARC_TANGENT, "atan")
.replace(""+MathematicalSymbols.UNDEFINED, "undefined")
.replace(""+MathematicalSymbols.PI, "PI")
.replace(""+MathematicalSymbols.X, "X")
.replace(""+MathematicalSymbols.Y, "Y")
;
}
public void println(String str) { public void println(String str) {
println(0, str); println(0, str);
} }
public void println(int level) { public void println(int level) {
if (StaticVars.outputLevel >= level) { if (StaticVars.outputLevel >= level) {
final String time = getTimeString(); final String time = getTimeString();
if (StaticVars.outputLevel == 0) { if (StaticVars.outputLevel == 0) {
System.out.println(); println(System.out);
} else { } else {
System.err.println(); println(System.err);
} }
} }
} }
@ -100,9 +135,9 @@ public class Utils {
if (StaticVars.outputLevel >= level) { if (StaticVars.outputLevel >= level) {
final String time = getTimeString(); final String time = getTimeString();
if (StaticVars.outputLevel == 0) { if (StaticVars.outputLevel == 0) {
System.out.println("[" + time + "]"+str); println(System.out, "[" + time + "]"+str);
} else { } else {
System.err.println("[" + time + "]"+str); println(System.err, "[" + time + "]"+str);
} }
} }
} }
@ -110,9 +145,9 @@ public class Utils {
public void print(int level, String str) { public void print(int level, String str) {
if (StaticVars.outputLevel >= level) { if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) { if (StaticVars.outputLevel == 0) {
System.out.print(str); print(System.out, str);
} else { } else {
System.err.print(str); print(System.err, str);
} }
} }
} }
@ -121,9 +156,9 @@ public class Utils {
if (StaticVars.outputLevel >= level) { if (StaticVars.outputLevel >= level) {
final String time = getTimeString(); final String time = getTimeString();
if (StaticVars.outputLevel == 0) { if (StaticVars.outputLevel == 0) {
System.out.println("[" + time + "][" + prefix + "]" + str); println(System.out, "[" + time + "][" + prefix + "]" + str);
} else { } else {
System.err.println("[" + time + "][" + prefix + "]" + str); println(System.err, "[" + time + "][" + prefix + "]" + str);
} }
} }
} }
@ -140,10 +175,9 @@ public class Utils {
} }
} }
if (StaticVars.outputLevel == 0) { if (StaticVars.outputLevel == 0) {
System.out.println("[" + time + "]" + output); println(System.out, "[" + time + "]" + output);
} else { } else {
println(System.err, "[" + time + "]" + output);
System.err.println("[" + time + "]" + output);
} }
} }
} }

View File

@ -27,6 +27,8 @@ public class MathematicalSymbols {
public static final char ARC_TANGENT = 'Ⓗ'; public static final char ARC_TANGENT = 'Ⓗ';
public static final char UNDEFINED = '∅'; public static final char UNDEFINED = '∅';
public static final char PI = 'π'; public static final char PI = 'π';
public static final char X = 'ⓧ';
public static final char Y = 'Ⓨ';
public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER }; public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER };
@ -49,7 +51,7 @@ public class MathematicalSymbols {
public static final char[] parentheses = new char[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE }; public static final char[] parentheses = new char[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE };
public static final char[] variables = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'ⓧ', 'Ⓨ', 'Z', PI, UNDEFINED }; public static final char[] variables = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', X, Y, 'Z', PI, UNDEFINED };
public static final char[] genericSyntax = new char[] { SYSTEM, EQUATION }; public static final char[] genericSyntax = new char[] { SYSTEM, EQUATION };

View File

@ -48,9 +48,6 @@ public class Variable implements Function {
@Override @Override
public String toString() { public String toString() {
if (getChar() > 0x2000) {
return "0x" + String.format("%04x", (int) getChar());
}
return "" + getChar(); return "" + getChar();
} }