Skip to content

Commit

Permalink
Allow -> as placeholder separator
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Feb 2, 2025
1 parent 13688dd commit b5907dd
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.google.common.base.CharMatcher.whitespace;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.mu.util.Optionals.optionally;
import static com.google.mu.util.Substring.before;
import static com.google.mu.util.Substring.consecutive;
import static com.google.mu.util.Substring.first;
import static com.google.mu.util.Substring.firstOccurrence;
Expand Down Expand Up @@ -33,17 +34,16 @@
final class FormatStringUtils {
static final Substring.Pattern PLACEHOLDER_PATTERN =
consecutive(CharMatcher.noneOf("{}")::matches).immediatelyBetween("{", INCLUSIVE, "}", INCLUSIVE);
private static final Substring.Pattern PLACEHOLDER_SEPARATOR =
private static final Substring.Pattern PLACEHOLDER_NAME_END =
Stream.of("=", "->").map(Substring::first).collect(firstOccurrence());
static final Substring.RepeatingPattern PLACEHOLDER_NAMES_PATTERN =
consecutive(CharMatcher.noneOf("{}")::matches).immediatelyBetween("{", "}").repeatedly();

static ImmutableList<String> placeholderVariableNames(String formatString) {
Substring.Pattern beforeSeparator = Substring.before(PLACEHOLDER_SEPARATOR);
return PLACEHOLDER_NAMES_PATTERN
.from(formatString)
// for Cloud resource name syntax
.map(n -> beforeSeparator.from(n).map(whitespace()::trimTrailingFrom).orElse(n))
.map(n -> before(PLACEHOLDER_NAME_END).from(n).map(whitespace()::trimTrailingFrom).orElse(n))
.collect(toImmutableList());
}

Expand Down

0 comments on commit b5907dd

Please # to comment.