Commit e0f6a2f8 authored by Victor Zverovich's avatar Victor Zverovich

Add a formatter for folly::StringPiece

parent ae4a3945
......@@ -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)
......
// 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 <folly/Range.h>
#include "core.h"
FMT_BEGIN_NAMESPACE
template <typename Ctx>
inline internal::typed_value<Ctx, internal::string_type>
make_value(folly::StringPiece s) {
return string_view(s.data(), s.size());
}
FMT_END_NAMESPACE
#endif // FMT_FOLLY_H_
......@@ -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)
......
// 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 <fmt/folly.h>
#include "gtest.h"
TEST(FollyTest, FormatStringPiece) {
EXPECT_EQ(fmt::format("{}", "foo"), "foo");
EXPECT_EQ(fmt::format("{:>5}", "foo"), " foo");
}
// A folly::StringPiece stub.
#include <cstring>
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_;
};
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment