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 e2a0902 commit 9514b7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@
final class FormatStringUtils {
static final Substring.Pattern PLACEHOLDER_PATTERN =
consecutive(CharMatcher.noneOf("{}")::matches).immediatelyBetween("{", INCLUSIVE, "}", INCLUSIVE);
static final Substring.Pattern PLACEHOLDER_SEPARATOR =
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 beforeEqualSign = Substring.before(first('='));
Substring.Pattern beforeSeparator = Substring.before(PLACEHOLDER_SEPARATOR);
return PLACEHOLDER_NAMES_PATTERN
.from(formatString)
// for Cloud resource name syntax
.map(n -> beforeEqualSign.from(n).map(whitespace()::trimTrailingFrom).orElse(n))
.map(n -> beforeSeparator.from(n).map(whitespace()::trimTrailingFrom).orElse(n))
.collect(toImmutableList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ public void trailingSpacesBeforeEqualSignIgnored() {
.doTest();
}

@Test
public void trailingSpacesBeforeArrowIgnored() {
helper
.addSourceLines(
"Test.java",
"import com.google.mu.util.StringFormat;",
"class Test {",
" private static final StringFormat FORMAT =",
" new StringFormat(\"{shows_id -> id,}\");",
"}")
.doTest();
}

@Ignore
@Test
public void squareBracketedPlaceholdersChecked() {
Expand Down

0 comments on commit 9514b7d

Please # to comment.