From f0903ad9df429f3a610da45de5161c076cf2d268 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 16 May 2022 17:32:25 -0700 Subject: [PATCH] Add a path formatter --- include/fmt/std.h | 29 +++++++++++++++++++++++++++++ test/std-test.cc | 16 ++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 include/fmt/std.h create mode 100644 test/std-test.cc diff --git a/include/fmt/std.h b/include/fmt/std.h new file mode 100644 index 00000000..53f21e6f --- /dev/null +++ b/include/fmt/std.h @@ -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 + +#ifdef __cpp_lib_filesystem +# include + +namespace fmt { + +template <> struct formatter : formatter { + template + auto format(const path& p, FormatContext& ctx) const -> + typename FormatContext::iterator { + return formatter::format(p.string(), ctx); + } +}; + +} // namespace fmt +#endif + +#endif // FMT_STD_H_ diff --git a/test/std-test.cc b/test/std-test.cc new file mode 100644 index 00000000..36ce4ae3 --- /dev/null +++ b/test/std-test.cc @@ -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 +}