mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 18:28:20 +00:00
Add a path formatter
This commit is contained in:
parent
8833f386e4
commit
f0903ad9df
29
include/fmt/std.h
Normal file
29
include/fmt/std.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Formatting library for C++ - formatters for standard library types
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 - present, Victor Zverovich
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
|
#ifndef FMT_STD_H_
|
||||||
|
#define FMT_STD_H_
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_filesystem
|
||||||
|
# include <filesystem>
|
||||||
|
|
||||||
|
namespace fmt {
|
||||||
|
|
||||||
|
template <> struct formatter<std::filesystem::path> : formatter<string_view> {
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const path& p, FormatContext& ctx) const ->
|
||||||
|
typename FormatContext::iterator {
|
||||||
|
return formatter<string_view>::format(p.string(), ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace fmt
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // FMT_STD_H_
|
16
test/std-test.cc
Normal file
16
test/std-test.cc
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Formatting library for C++ - tests of formatters for standard library types
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 - present, Victor Zverovich
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
|
#include "fmt/std.h"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
TEST(std_test, path) {
|
||||||
|
#ifdef __cpp_lib_filesystem
|
||||||
|
EXPECT_EQ(fmt::format("{:8}", std::filesystem::path("foo")), "foo ");
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user