Skip to content

Commit

Permalink
Check max output size before displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
duy committed Oct 29, 2024
1 parent cce1de2 commit c2ac634
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package com.symja.evaluator;

import org.matheclipse.core.basic.Config;
import org.matheclipse.core.form.output.OutputFormFactory;
import org.matheclipse.core.form.tex.TeXFormFactory;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.parser.client.ParserConfig;

public class OutputForm {

public static String toString(IExpr result) {
if (result == null) {
return "";
}
try {
OutputFormFactory outputFormFactory = OutputFormFactory.get(true, false);
return outputFormFactory.toString(result);
OutputFormFactory outputFormFactory = OutputFormFactory.get(ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS, false);
String string = outputFormFactory.toString(result);

if (string.length() > Config.MAX_OUTPUT_SIZE) {
return "Max output size " + Config.MAX_OUTPUT_SIZE + " characters exceeded";
}

return string;
} catch (Exception e) {
return "Error";
return "Error: " + e.getMessage();
}
}

Expand All @@ -27,9 +36,14 @@ public static String toLatex(IExpr expr) {
if (teXFormFactory.convert(buffer, expr)) {
return buffer.toString();
}

if (buffer.length() > Config.MAX_OUTPUT_SIZE) {
return "Max output size " + Config.MAX_OUTPUT_SIZE + " characters exceeded";
}

return "Error";
} catch (Exception e) {
return "Error";
return "Error: " + e.getMessage();
}
}
}

0 comments on commit c2ac634

Please sign in to comment.