From 0d95290e23067a714731edac0be5575364c1f757 Mon Sep 17 00:00:00 2001 From: Tobias Thirolf Date: Fri, 10 Jan 2025 21:44:03 +0100 Subject: [PATCH] fix formatting of brackets --- .../core/check/comment/CommentedOutCodeCheck.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/autograder-core/src/main/java/de/firemage/autograder/core/check/comment/CommentedOutCodeCheck.java b/autograder-core/src/main/java/de/firemage/autograder/core/check/comment/CommentedOutCodeCheck.java index 5349b98c..fbae8797 100644 --- a/autograder-core/src/main/java/de/firemage/autograder/core/check/comment/CommentedOutCodeCheck.java +++ b/autograder-core/src/main/java/de/firemage/autograder/core/check/comment/CommentedOutCodeCheck.java @@ -112,19 +112,19 @@ private static List prepareCode(String content) { private static Collection getDifferentVersions(String original) { Set options = new HashSet<>(); options.add(original.endsWith(";") ? original : original + ";"); - options.add(formatClosedBlock(original)); + options.add(formatBrackets(formatBrackets(formatBrackets(original, '{', '}'), '(', ')'), '[', ']')); return options; } - private static String formatClosedBlock(String original) { - int differenceClosing = StringUtils.countMatches(original, '}') - StringUtils.countMatches(original, '{'); - if (differenceClosing == 0) { + private static String formatBrackets(String original, char opening, char closing) { + int difference = StringUtils.countMatches(original, closing) - StringUtils.countMatches(original, opening); + if (difference == 0) { return original; } - return differenceClosing > 0 - ? "{".repeat(differenceClosing) + original - : original + "}".repeat(-differenceClosing); + return difference > 0 + ? String.valueOf(opening).repeat(difference) + original + : original + String.valueOf(closing).repeat(-difference); } private static List wrapAsBlock(Collection differentVersions) {