Skip to content

Commit

Permalink
Fixed #283, #284
Browse files Browse the repository at this point in the history
1. Fixed: Unnecessary newline at the end in getErrorMessage() #283
2. Fixed: Unnecessary space in function expression string returned by getErrorMessage() #284
  • Loading branch information
mariuszgromada committed Nov 18, 2022
1 parent 355b89d commit b053e16
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 33 deletions.
28 changes: 17 additions & 11 deletions CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/Expression.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.cs 5.1.0 2022-11-11
* @(#)Expression.cs 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace org.mariuszgromada.math.mxparser {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.1.0
* @version 5.1.1
*
* @see Argument
* @see RecursiveArgument
Expand Down Expand Up @@ -508,7 +508,13 @@ internal void showRelatedExpressions() {
* @return Error message as string.
*/
public String getErrorMessage() {
return errorMessage;
int length = errorMessage.Length;

if (length > 0)
if (errorMessage[length - 1] == '\n')
return errorMessage.Substring(0, length - 1);

return errorMessage;
}
/**
* Gets syntax status of the expression.
Expand Down Expand Up @@ -5414,9 +5420,9 @@ private bool checkSyntax(String level, bool functionWithBodyExt) {
} else if (arg.getArgumentBodyType() == Argument.BODY_RUNTIME) {
if ( arg.getArgumentType() == Argument.DEPENDENT_ARGUMENT ) {
if ((arg.argumentExpression != this) && !arg.argumentExpression.recursionCallPending) {
bool syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.getExpressionString() + "] ", false);
bool syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.expressionString + "] ", false);
syntax = syntax && syntaxRec;
errorMessage = errorMessage + level + tokenStr + "checking dependent argument ...\n" + arg.argumentExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking dependent argument ...\n" + arg.argumentExpression.errorMessage;
}
}
} else {
Expand All @@ -5433,9 +5439,9 @@ private bool checkSyntax(String level, bool functionWithBodyExt) {
errorMessage = errorMessage + level + tokenStr + "<RECURSIVE_ARGUMENT> expecting 1 parameter.\n";
} else
if ((arg.argumentExpression != this) && !arg.argumentExpression.recursionCallPending) {
bool syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.getExpressionString() + "] ", false);
bool syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.expressionString + "] ", false);
syntax = syntax && syntaxRec;
errorMessage = errorMessage + level + tokenStr + "checking recursive argument ...\n" + arg.argumentExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking recursive argument ...\n" + arg.argumentExpression.errorMessage;
}
}
/*
Expand Down Expand Up @@ -5469,14 +5475,14 @@ private bool checkSyntax(String level, bool functionWithBodyExt) {
if ((fun.functionExpression != this) && !fun.functionExpression.recursionCallPending) {
bool syntaxRec;
if (fun.getFunctionBodyType() == Function.BODY_RUNTIME)
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.getExpressionString() + "] ", false);
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.expressionString + "] ", false);
else
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.getExpressionString() + "] ", true);
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.expressionString + "] ", true);
syntax = syntax && syntaxRec;
if (fun.isVariadic)
errorMessage = errorMessage + level + tokenStr + "checking variadic user defined function ...\n" + fun.functionExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking variadic user defined function ...\n" + fun.functionExpression.errorMessage;
else
errorMessage = errorMessage + level + tokenStr + "checking user defined function ...\n" + fun.functionExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking user defined function ...\n" + fun.functionExpression.errorMessage;
}
}
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Miscellaneous.cs 5.1.0 2022-11-11
* @(#)Miscellaneous.cs 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -386,8 +386,8 @@ internal HeadEqBody(String definitionString) {
else eqPos++;
} while ((eqPos < definitionString.Length) && (matchStatus == mXparser.NOT_FOUND));
if ((matchStatus == mXparser.FOUND) && (eqPos > 0) && (eqPos <= definitionString.Length - 2)) {
headStr = definitionString.Substring(0, eqPos);
bodyStr = definitionString.Substring(eqPos + 1);
headStr = definitionString.Substring(0, eqPos).Trim();
bodyStr = definitionString.Substring(eqPos + 1).Trim();
Expression headExpression = new Expression(headStr, ONLY_PARSER_KEYWORDS);
headExpression.disableImpliedMultiplicationMode();
headTokens = headExpression.getCopyOfInitialTokens();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)mXparser.cs 5.1.0 2022-11-12
* @(#)mXparser.cs 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace org.mariuszgromada.math.mxparser {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.1.0
* @version 5.1.1
*
* @see RecursiveArgument
* @see Expression
Expand All @@ -216,7 +216,7 @@ public sealed class mXparser {
*/
public const int VERSION_MAJOR = 5;
public const int VERSION_MINOR = 1;
public const int VERSION_PATCH = 0;
public const int VERSION_PATCH = 1;
public static readonly String VERSION = VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH;
public const String VERSION_CODE_NAME = "Libris";
public static readonly String VERSION_NAME = VERSION + " " + VERSION_CODE_NAME;
Expand Down
26 changes: 16 additions & 10 deletions CURRENT/java/src/org/mariuszgromada/math/mxparser/Expression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.java 5.1.0 2022-11-11
* @(#)Expression.java 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -237,7 +237,7 @@
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.1.0
* @version 5.1.1
*
* @see Argument
* @see RecursiveArgument
Expand Down Expand Up @@ -533,6 +533,12 @@ void showRelatedExpressions() {
* @return Error message as string.
*/
public String getErrorMessage() {
int length = errorMessage.length();

if (length > 0)
if (errorMessage.charAt(length - 1) == '\n')
return errorMessage.substring(0, length - 1);

return errorMessage;
}
/**
Expand Down Expand Up @@ -5449,9 +5455,9 @@ private boolean checkSyntax(String level, boolean functionWithBodyExt) {
} else if (arg.getArgumentBodyType() == Argument.BODY_RUNTIME) {
if ( arg.getArgumentType() == Argument.DEPENDENT_ARGUMENT ) {
if ( (arg.argumentExpression != this) && (!arg.argumentExpression.recursionCallPending) ) {
boolean syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.getExpressionString() + "] ", false);
boolean syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.expressionString + "] ", false);
syntax = syntax && syntaxRec;
errorMessage = errorMessage + level + tokenStr + "checking dependent argument ...\n" + arg.argumentExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking dependent argument ...\n" + arg.argumentExpression.errorMessage;
}
}
} else {
Expand All @@ -5468,9 +5474,9 @@ private boolean checkSyntax(String level, boolean functionWithBodyExt) {
errorMessage = errorMessage + level + tokenStr + "<RECURSIVE_ARGUMENT> expecting 1 parameter.\n";
} else
if ( (arg.argumentExpression != this) && (arg.argumentExpression.recursionCallPending == false) ) {
boolean syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.getExpressionString() + "] ", false);
boolean syntaxRec = arg.argumentExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + arg.argumentExpression.expressionString + "] ", false);
syntax = syntax && syntaxRec;
errorMessage = errorMessage + level + tokenStr + "checking recursive argument ...\n" + arg.argumentExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking recursive argument ...\n" + arg.argumentExpression.errorMessage;
}
}
/*
Expand Down Expand Up @@ -5504,14 +5510,14 @@ private boolean checkSyntax(String level, boolean functionWithBodyExt) {
if ( (fun.functionExpression != this) && (!fun.functionExpression.recursionCallPending) ) {
boolean syntaxRec;
if (fun.getFunctionBodyType() == Function.BODY_RUNTIME)
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.getExpressionString() + "] ", false);
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.expressionString + "] ", false);
else
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.getExpressionString() + "] ", true);
syntaxRec = fun.functionExpression.checkSyntax(level + "-> " + "[" + t.tokenStr + "] = [" + fun.functionExpression.expressionString + "] ", true);
syntax = syntax && syntaxRec;
if (fun.isVariadic)
errorMessage = errorMessage + level + tokenStr + "checking variadic user defined function ...\n" + fun.functionExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking variadic user defined function ...\n" + fun.functionExpression.errorMessage;
else
errorMessage = errorMessage + level + tokenStr + "checking user defined function ...\n" + fun.functionExpression.getErrorMessage();
errorMessage = errorMessage + level + tokenStr + "checking user defined function ...\n" + fun.functionExpression.errorMessage;
}
}
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Miscellaneous.java 5.1.0 2022-11-11
* @(#)Miscellaneous.java 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -398,8 +398,8 @@ class HeadEqBody implements Serializable {
else eqPos++;
} while ( (eqPos < definitionString.length()) && (matchStatus == mXparser.NOT_FOUND) );
if ( (matchStatus == mXparser.FOUND) && (eqPos > 0) && (eqPos <= definitionString.length()-2) ) {
headStr = definitionString.substring(0, eqPos);
bodyStr = definitionString.substring(eqPos+1);
headStr = definitionString.substring(0, eqPos).trim();
bodyStr = definitionString.substring(eqPos+1).trim();
Expression headExpression = new Expression(headStr, ONLY_PARSER_KEYWORDS);
headExpression.disableImpliedMultiplicationMode();
headTokens = headExpression.getCopyOfInitialTokens();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)mXparser.java 5.1.0 2022-11-12
* @(#)mXparser.java 5.1.1 2022-11-18
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -218,7 +218,7 @@
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.1.0
* @version 5.1.1
*
* @see RecursiveArgument
* @see Expression
Expand All @@ -231,7 +231,7 @@ public final class mXparser {
*/
public static final int VERSION_MAJOR = 5;
public static final int VERSION_MINOR = 1;
public static final int VERSION_PATCH = 0;
public static final int VERSION_PATCH = 1;
public static final String VERSION = VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH;
public static final String VERSION_CODE_NAME = "Libris";
public static final String VERSION_NAME = VERSION + " " + VERSION_CODE_NAME;
Expand Down

0 comments on commit b053e16

Please sign in to comment.