### Question:
StringUtil { @SuppressWarnings({ "squid:S135", "squid:S3776" }) public static String format(String template, Object... array) { if (template == null) { return null; } if (template.indexOf('{') < 0) { return template; } final StringBuilder result = new StringBuilder(template.length()); final int len = template.length(); final int arrayLen = array != null ? array.length : 0; int i = 0; int currentIndex = 0; int index; while (i < len) { int ndx = template.indexOf('{', i); if (ndx == -1) { result.append(i == 0 ? template : template.substring(i)); break; } int j = ndx - 1; while (j >= 0 && template.charAt(j) == '\\') { j--; } int escapeCharCount = ndx - 1 - j; result.append(template, i, escapeCharCount > 0 ? ndx - ((escapeCharCount + 1) >> 1) : ndx); if ((escapeCharCount & 1) == 1) { result.append('{'); i = ndx + 1; continue; } ndx += 1; int ndxEnd = template.indexOf('}', ndx); if (ndxEnd == -1) { throw new IllegalArgumentException("Invalid message, unclosed macro at: " + (ndx - 1)); } index = ndx == ndxEnd ? currentIndex++ : Integer.parseInt(template.substring(ndx, ndxEnd)); if (index < arrayLen && index >= 0 && array[index] != null) { result.append(array[index].toString()); } i = ndxEnd + 1; } return result.toString(); }  static String join(List<?> list, char separator); static String[] toArray(String src); @SuppressWarnings({ "squid:S135", // Loops should not contain more than a single "break" or "continue" statement "squid:S3776" // Cognitive Complexity of methods should not be too high }) static String format(String template, Object... array);  }### Answer:
@Test void format() { assertEquals("\\abcd", StringUtil.format("\\ab{}cd{1}")); assertEquals("ab-123-cd-456|ab-456-cd-123|ab-{1}-cd-123|ab-\\456-cd-123|\\\\123", StringUtil.format("ab-{}-cd-{}|ab-{1}-cd-{0}|ab-\\{1}-cd-{0}|ab-\\\\{1}-cd-{0}|\\\\\\\\{0}", 123, 456)); }