From d3ec9a13167ea2919ff05a63a948590b304bbe63 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 8 Nov 2013 09:53:50 -0700 Subject: [PATCH] Add support for StringRef in BasicFormatter. --- format.h | 5 +++++ format_test.cc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/format.h b/format.h index e75bced1..8dda2130 100644 --- a/format.h +++ b/format.h @@ -862,6 +862,11 @@ class BasicFormatter { string.size = value.size(); } + Arg(StringRef value) : type(STRING), formatter(0) { + string.value = value.c_str(); + string.size = value.size(); + } + template Arg(const T &value) : type(CUSTOM), formatter(0) { custom.value = &value; diff --git a/format_test.cc b/format_test.cc index 6f5b8e09..2f428915 100644 --- a/format_test.cc +++ b/format_test.cc @@ -1091,6 +1091,10 @@ TEST(FormatterTest, FormatString) { EXPECT_EQ("test", str(Format("{0}") << std::string("test"))); } +TEST(FormatterTest, FormatStringRef) { + EXPECT_EQ("test", str(Format("{0}") << StringRef("test"))); +} + TEST(FormatterTest, FormatUsingIOStreams) { EXPECT_EQ("a string", str(Format("{0}") << TestString("a string"))); std::string s = str(fmt::Format("The date is {0}") << Date(2012, 12, 9));