(String template, @Nullable Object... args)
| 1348 | // Note that this is somewhat-improperly used from Verify.java as well. |
| 1349 | |
| 1350 | static String format(String template, @Nullable Object... args) { |
| 1351 | template = String.valueOf(template); // null -> "null" |
| 1352 | |
| 1353 | // start substituting the arguments into the '%s' placeholders |
| 1354 | StringBuilder builder = new StringBuilder(template.length() + 16 * args.length); |
| 1355 | int templateStart = 0; |
| 1356 | int i = 0; |
| 1357 | while (i < args.length) { |
| 1358 | int placeholderStart = template.indexOf("%s", templateStart); |
| 1359 | if (placeholderStart == -1) { |
| 1360 | break; |
| 1361 | } |
| 1362 | builder.append(template, templateStart, placeholderStart); |
| 1363 | builder.append(args[i++]); |
| 1364 | templateStart = placeholderStart + 2; |
| 1365 | } |
| 1366 | builder.append(template, templateStart, template.length()); |
| 1367 | |
| 1368 | // if we run out of placeholders, append the extra args in square braces |
| 1369 | if (i < args.length) { |
| 1370 | builder.append(" ["); |
| 1371 | builder.append(args[i++]); |
| 1372 | while (i < args.length) { |
| 1373 | builder.append(", "); |
| 1374 | builder.append(args[i++]); |
| 1375 | } |
| 1376 | builder.append(']'); |
| 1377 | } |
| 1378 | return builder.toString(); |
| 1379 | } |
| 1380 | } |
no test coverage detected