mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-29 13:21:05 +00:00
Add a formatter for folly::StringPiece
This commit is contained in:
parent
ae4a3945f5
commit
e0f6a2f8be
@ -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)
|
||||
|
22
include/fmt/folly.h
Normal file
22
include/fmt/folly.h
Normal file
@ -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 <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)
|
||||
|
14
test/folly-test.cc
Normal file
14
test/folly-test.cc
Normal file
@ -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 <fmt/folly.h>
|
||||
#include "gtest.h"
|
||||
|
||||
TEST(FollyTest, FormatStringPiece) {
|
||||
EXPECT_EQ(fmt::format("{}", "foo"), "foo");
|
||||
EXPECT_EQ(fmt::format("{:>5}", "foo"), " foo");
|
||||
}
|
17
test/folly/Range.h
Normal file
17
test/folly/Range.h
Normal file
@ -0,0 +1,17 @@
|
||||
// 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_;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user