|
4 | 4 | import static com.google.common.base.CharMatcher.whitespace; |
5 | 5 | import static com.google.common.collect.ImmutableList.toImmutableList; |
6 | 6 | import static com.google.mu.util.Optionals.optionally; |
| 7 | +import static com.google.mu.util.Substring.before; |
7 | 8 | import static com.google.mu.util.Substring.consecutive; |
8 | 9 | import static com.google.mu.util.Substring.first; |
9 | 10 | import static com.google.mu.util.Substring.firstOccurrence; |
|
33 | 34 | final class FormatStringUtils { |
34 | 35 | static final Substring.Pattern PLACEHOLDER_PATTERN = |
35 | 36 | consecutive(CharMatcher.noneOf("{}")::matches).immediatelyBetween("{", INCLUSIVE, "}", INCLUSIVE); |
36 | | - private static final Substring.Pattern PLACEHOLDER_SEPARATOR = |
| 37 | + private static final Substring.Pattern PLACEHOLDER_NAME_END = |
37 | 38 | Stream.of("=", "->").map(Substring::first).collect(firstOccurrence()); |
38 | 39 | static final Substring.RepeatingPattern PLACEHOLDER_NAMES_PATTERN = |
39 | 40 | consecutive(CharMatcher.noneOf("{}")::matches).immediatelyBetween("{", "}").repeatedly(); |
40 | 41 |
|
41 | 42 | static ImmutableList<String> placeholderVariableNames(String formatString) { |
42 | | - Substring.Pattern beforeSeparator = Substring.before(PLACEHOLDER_SEPARATOR); |
43 | 43 | return PLACEHOLDER_NAMES_PATTERN |
44 | 44 | .from(formatString) |
45 | 45 | // for Cloud resource name syntax |
46 | | - .map(n -> beforeSeparator.from(n).map(whitespace()::trimTrailingFrom).orElse(n)) |
| 46 | + .map(n -> before(PLACEHOLDER_NAME_END).from(n).map(whitespace()::trimTrailingFrom).orElse(n)) |
47 | 47 | .collect(toImmutableList()); |
48 | 48 | } |
49 | 49 |
|
|
0 commit comments