diff --git a/CMakeLists.txt b/CMakeLists.txt index 78016a98..265f8e8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,8 +148,8 @@ function(add_headers VAR) endfunction() # Define the fmt library, its includes and the needed defines. -add_headers(FMT_HEADERS core.h format.h format-inl.h ostream.h printf.h time.h - ranges.h) +add_headers(FMT_HEADERS core.h folly.h format.h format-inl.h ostream.h printf.h + time.h ranges.h) set(FMT_SOURCES src/format.cc) if (HAVE_OPEN) add_headers(FMT_HEADERS posix.h) diff --git a/include/fmt/folly.h b/include/fmt/folly.h new file mode 100644 index 00000000..b9ffd3e7 --- /dev/null +++ b/include/fmt/folly.h @@ -0,0 +1,22 @@ +// Formatting library for C++ - folly::StringPiece formatter +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. + +#ifndef FMT_FOLLY_H_ +#define FMT_FOLLY_H_ + +#include +#include "core.h" + +FMT_BEGIN_NAMESPACE +template +inline internal::typed_value + make_value(folly::StringPiece s) { + return string_view(s.data(), s.size()); +} +FMT_END_NAMESPACE + +#endif // FMT_FOLLY_H_ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1a8c900a..0fcff9f9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -86,6 +86,7 @@ endfunction() add_fmt_test(assert-test) add_fmt_test(gtest-extra-test) +add_fmt_test(folly-test) add_fmt_test(format-test) add_fmt_test(format-impl-test) add_fmt_test(ostream-test) diff --git a/test/folly-test.cc b/test/folly-test.cc new file mode 100644 index 00000000..c3b1579c --- /dev/null +++ b/test/folly-test.cc @@ -0,0 +1,14 @@ +// Formatting library for C++ - folly::StringPiece formatter tests +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. + +#include +#include "gtest.h" + +TEST(FollyTest, FormatStringPiece) { + EXPECT_EQ(fmt::format("{}", "foo"), "foo"); + EXPECT_EQ(fmt::format("{:>5}", "foo"), " foo"); +} diff --git a/test/folly/Range.h b/test/folly/Range.h new file mode 100644 index 00000000..f794019f --- /dev/null +++ b/test/folly/Range.h @@ -0,0 +1,17 @@ +// A folly::StringPiece stub. + +#include + +namespace folly { +class StringPiece { + public: + explicit StringPiece(const char *s) : data_(s), size_(std::strlen(s)) {} + + const char* data() const { return "foo"; } + size_t size() const { return 3; } + + private: + const char *data_; + size_t size_; +}; +}