Skip to content

Commit

Permalink
Merge branch 'issue-Darkempire78#510' into bmg1919
Browse files Browse the repository at this point in the history
  • Loading branch information
bmg1919 committed Jan 16, 2025
2 parents 288aa0f + d35ce7b commit 14fb7cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ class MainActivity : AppCompatActivity() {

val calculation = binding.input.text.toString()

Expression().addParenthesis(calculation)

if (calculation != "") {

val resultString = calculationResult.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Expression {

}

private fun addParenthesis(calculation: String): String {
fun addParenthesis(calculation: String): String {
// Add ")" which lack
var cleanCalculation = calculation
var openParentheses = 0
Expand All @@ -121,6 +121,10 @@ class Expression {
cleanCalculation += ')'
}
}
// Trigger syntax error if missing '('
if (closeParentheses > openParentheses) {
syntax_error = true
}

return cleanCalculation
}
Expand Down

0 comments on commit 14fb7cb

Please sign in to comment.