Skip to content

Commit

Permalink
[LLVM] Update formatv() documentation to clarify no escape for }
Browse files Browse the repository at this point in the history
- Update documentation to clarify that `}` does not need to be doubled up.
- Update `EscapedBrace` test case to test this behavior

Differential Revision: https://reviews.llvm.org/D83888
  • Loading branch information
jurahul committed Jul 22, 2020
1 parent f773d37 commit e6ea5b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/FormatVariadic.h
Expand Up @@ -205,10 +205,10 @@ template <typename Tuple> class formatv_object : public formatv_object_base {
//
// The characters '{' and '}' are reserved and cannot appear anywhere within a
// replacement sequence. Outside of a replacement sequence, in order to print
// a literal '{' or '}' it must be doubled -- "{{" to print a literal '{' and
// "}}" to print a literal '}'.
// a literal '{' it must be doubled as "{{".
//
// ===Parameter Indexing===
//
// `index` specifies the index of the parameter in the parameter pack to format
// into the output. Note that it is possible to refer to the same parameter
// index multiple times in a given format string. This makes it possible to
Expand Down
12 changes: 12 additions & 0 deletions llvm/unittests/Support/FormatVariadicTest.cpp
Expand Up @@ -60,6 +60,18 @@ TEST(FormatVariadicTest, EscapedBrace) {
ASSERT_EQ(1u, Replacements.size());
EXPECT_EQ("{{{", Replacements[0].Spec);
EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);

// } does not require doubling up.
Replacements = formatv_object_base::parseFormatString("}");
ASSERT_EQ(1u, Replacements.size());
EXPECT_EQ("}", Replacements[0].Spec);
EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);

// } does not require doubling up.
Replacements = formatv_object_base::parseFormatString("}}}");
ASSERT_EQ(1u, Replacements.size());
EXPECT_EQ("}}}", Replacements[0].Spec);
EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);
}

TEST(FormatVariadicTest, ValidReplacementSequence) {
Expand Down

0 comments on commit e6ea5b3

Please sign in to comment.