package com.github.sormuras.bach.internal;

import java.util.List;
import java.util.stream.Collectors;

public interface StringSupport {
  static String join(List<String> strings) {
    return strings.stream().map(StringSupport::firstLine).collect(Collectors.joining(" "));
  }

  static String firstLine(String string) {
    var lines = string.lines().toList();
    var size = lines.size();
    return size <= 1 ? string : lines.get(0) + "[...%d lines]".formatted(size);
  }

  record Property(String key, String value) {}

  static Property parseProperty(String string) {
    return StringSupport.parseProperty(string, '=');
  }

  static Property parseProperty(String string, char separator) {
    int index = string.indexOf(separator);
    if (index < 0) {
      var message = "Expected a `KEY%sVALUE` string, but got: %s".formatted(separator, string);
      throw new IllegalArgumentException(message);
    }
    var key = string.substring(0, index);
    var value = string.substring(index + 1);
    return new Property(key, value);
  }
}

@@ -37,16 +37,64 @@
 ernal;%0A%0A
+import java.net.URI;%0Aimport java.nio.file.Path;%0A
 import j
@@ -518,16 +518,199 @@
 );%0A  %7D%0A%0A
+  static String parseFileName(String string) %7B%0A    var path = string.indexOf(':') %3E 0 ? URI.create(string).getPath() : string;%0A    return Path.of(path).getFileName().toString();%0A  %7D%0A%0A
   record

Add file name parsing helper