Skip to content

Commit 7a0f623

Browse files
committed
remove dependency on fmt library, using std::format instead
This bumps the standard version to C++23, so that the `formattable` concept becomes available. This removes the color support from `diff.cpp`, since that is not available in std::format.
1 parent 26d4c50 commit 7a0f623

38 files changed

+479
-588
lines changed

CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ llvm_map_components_to_libnames(llvm_libs all)
119119
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
120120
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
121121

122-
# fmt
123-
find_package(fmt REQUIRED CONFIG)
124-
125122
# Duktape
126123
find_package(Duktape CONFIG)
127124
if (NOT DUKTAPE_FOUND)
@@ -214,7 +211,7 @@ list(APPEND LIB_SOURCES
214211
${CMAKE_CURRENT_BINARY_DIR}/src/lib/Lib/PublicSettings.cpp
215212
)
216213
add_library(mrdocs-core ${LIB_SOURCES})
217-
target_compile_features(mrdocs-core PUBLIC cxx_std_20)
214+
target_compile_features(mrdocs-core PUBLIC cxx_std_23)
218215
target_include_directories(mrdocs-core
219216
PUBLIC
220217
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
@@ -234,7 +231,6 @@ target_compile_definitions(
234231
# Dependencies
235232
target_include_directories(mrdocs-core SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS})
236233
target_include_directories(mrdocs-core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
237-
target_link_libraries(mrdocs-core PUBLIC fmt::fmt)
238234
target_include_directories(mrdocs-core SYSTEM PRIVATE ${DUKTAPE_INCLUDE_DIRS})
239235
target_link_libraries(mrdocs-core PRIVATE ${DUKTAPE_LIBRARY})
240236

include/mrdocs/Dom/Object.ipp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ Object::visit(F&& fn) const
149149
//------------------------------------------------
150150

151151
template<>
152-
struct fmt::formatter<clang::mrdocs::dom::Object>
153-
: fmt::formatter<std::string>
152+
struct std::formatter<clang::mrdocs::dom::Object>
153+
: std::formatter<std::string_view>
154154
{
155155
auto format(
156156
clang::mrdocs::dom::Object const& value,
157-
fmt::format_context& ctx) const
157+
std::format_context& ctx) const
158158
{
159-
return fmt::formatter<std::string>::format(
159+
return std::formatter<std::string_view>::format(
160160
toString(value), ctx);
161161
}
162162
};

include/mrdocs/Dom/String.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#ifndef MRDOCS_API_DOM_STRING_HPP
1212
#define MRDOCS_API_DOM_STRING_HPP
1313

14+
#include <format>
1415
#include <mrdocs/Platform.hpp>
1516
#include <mrdocs/Support/String.hpp>
16-
#include <fmt/format.h>
1717

1818
namespace clang {
1919
namespace mrdocs {
@@ -341,17 +341,13 @@ class MRDOCS_DECL
341341

342342
//------------------------------------------------
343343

344-
template<>
345-
struct fmt::formatter<clang::mrdocs::dom::String>
346-
: fmt::formatter<std::string_view>
347-
{
348-
auto format(
349-
clang::mrdocs::dom::String const& value,
350-
fmt::format_context& ctx) const
351-
{
352-
return fmt::formatter<std::string_view>::format(
353-
value.get(), ctx);
354-
}
344+
template <>
345+
struct std::formatter<clang::mrdocs::dom::String>
346+
: std::formatter<std::string_view> {
347+
auto format(clang::mrdocs::dom::String const &value,
348+
std::format_context &ctx) const {
349+
return std::formatter<std::string_view>::format(value.get(), ctx);
350+
}
355351
};
356352

357353
#endif

include/mrdocs/Dom/Value.hpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
#ifndef MRDOCS_API_DOM_VALUE_HPP
1212
#define MRDOCS_API_DOM_VALUE_HPP
1313

14-
#include <mrdocs/Platform.hpp>
14+
#include <charconv>
15+
#include <compare>
16+
#include <format>
17+
#include <mrdocs/ADT/Optional.hpp>
1518
#include <mrdocs/Dom/Array.hpp>
16-
#include <mrdocs/Dom/Kind.hpp>
1719
#include <mrdocs/Dom/Function.hpp>
20+
#include <mrdocs/Dom/Kind.hpp>
1821
#include <mrdocs/Dom/Object.hpp>
1922
#include <mrdocs/Dom/String.hpp>
20-
#include <mrdocs/ADT/Optional.hpp>
23+
#include <mrdocs/Platform.hpp>
2124
#include <mrdocs/Support/Error.hpp>
2225
#include <optional> // BAD
2326
#include <string>
24-
#include <charconv>
25-
#include <compare>
2627

2728
namespace clang {
2829
namespace mrdocs {
@@ -849,17 +850,13 @@ safeString(SV const& str) {
849850

850851
//------------------------------------------------
851852

852-
template<>
853-
struct fmt::formatter<clang::mrdocs::dom::Value>
854-
: public fmt::formatter<std::string>
855-
{
856-
auto format(
857-
clang::mrdocs::dom::Value const& value,
858-
fmt::format_context& ctx) const
859-
{
860-
return fmt::formatter<std::string>::format(
861-
toString(value), ctx);
862-
}
853+
template <>
854+
struct std::formatter<clang::mrdocs::dom::Value>
855+
: public std::formatter<std::string> {
856+
template <class FmtContext>
857+
auto format(clang::mrdocs::dom::Value const &value, FmtContext &ctx) const {
858+
return std::formatter<std::string>::format(toString(value), ctx);
859+
}
863860
};
864861

865862
#endif

include/mrdocs/Metadata/Javadoc.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
#ifndef MRDOCS_API_METADATA_JAVADOC_HPP
1414
#define MRDOCS_API_METADATA_JAVADOC_HPP
1515

16-
#include <mrdocs/Platform.hpp>
17-
#include <mrdocs/Metadata/SymbolID.hpp>
18-
#include <mrdocs/Support/Visitor.hpp>
19-
#include <mrdocs/Support/Concepts.hpp>
16+
#include <algorithm>
17+
#include <memory>
2018
#include <mrdocs/ADT/Polymorphic.hpp>
21-
#include <mrdocs/Dom/String.hpp>
22-
#include <mrdocs/Dom/LazyObject.hpp>
2319
#include <mrdocs/Dom/LazyArray.hpp>
24-
#include <memory>
20+
#include <mrdocs/Dom/LazyObject.hpp>
21+
#include <mrdocs/Dom/String.hpp>
22+
#include <mrdocs/Metadata/SymbolID.hpp>
23+
#include <mrdocs/Platform.hpp>
24+
#include <mrdocs/Support/Concepts.hpp>
25+
#include <mrdocs/Support/Visitor.hpp>
2526
#include <string>
2627
#include <type_traits>
2728
#include <utility>

include/mrdocs/Support/Error.hpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
#ifndef MRDOCS_API_SUPPORT_ERROR_HPP
1313
#define MRDOCS_API_SUPPORT_ERROR_HPP
1414

15-
#include <mrdocs/Platform.hpp>
16-
#include <mrdocs/Support/source_location.hpp>
17-
#include <fmt/format.h>
1815
#include <exception>
16+
#include <format>
17+
#include <functional>
1918
#include <memory>
19+
#include <mrdocs/Platform.hpp>
20+
#include <mrdocs/Support/source_location.hpp>
2021
#include <string>
2122
#include <string_view>
23+
#include <system_error>
2224
#include <type_traits>
2325
#include <utility>
2426
#include <vector>
25-
#include <functional>
2627

2728
namespace clang::mrdocs {
2829

@@ -256,28 +257,18 @@ struct std::hash<::clang::mrdocs::Error>
256257
}
257258
};
258259

259-
template<>
260-
struct fmt::formatter<clang::mrdocs::Error>
261-
: fmt::formatter<std::string_view>
262-
{
263-
auto format(
264-
clang::mrdocs::Error const& err,
265-
fmt::format_context& ctx) const
266-
{
267-
return fmt::formatter<std::string_view>::format(err.message(), ctx);
268-
}
260+
template <>
261+
struct std::formatter<clang::mrdocs::Error> : std::formatter<std::string_view> {
262+
auto format(clang::mrdocs::Error const &err, std::format_context &ctx) const {
263+
return std::formatter<std::string_view>::format(err.message(), ctx);
264+
}
269265
};
270266

271-
template<>
272-
struct fmt::formatter<std::error_code>
273-
: fmt::formatter<std::string_view>
274-
{
275-
auto format(
276-
std::error_code const& ec,
277-
fmt::format_context& ctx) const
278-
{
279-
return fmt::formatter<std::string_view>::format(ec.message(), ctx);
280-
}
267+
template <>
268+
struct std::formatter<std::error_code> : std::formatter<std::string_view> {
269+
auto format(std::error_code const &ec, std::format_context &ctx) const {
270+
return std::formatter<std::string_view>::format(ec.message(), ctx);
271+
}
281272
};
282273

283274
namespace clang::mrdocs {
@@ -353,9 +344,8 @@ formatError(
353344
Args&&... args)
354345
{
355346
std::string s;
356-
fmt::vformat_to(
357-
std::back_inserter(s),
358-
fs.fs, fmt::make_format_args(args...));
347+
std::vformat_to(std::back_inserter(s), fs.fs,
348+
std::make_format_args(args...));
359349
return Error(std::move(s), fs.loc);
360350
}
361351

include/mrdocs/Support/Expected.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
#ifndef MRDOCS_API_SUPPORT_EXPECTED_HPP
1313
#define MRDOCS_API_SUPPORT_EXPECTED_HPP
1414

15-
#include <mrdocs/Platform.hpp>
16-
#include <mrdocs/Support/source_location.hpp>
17-
#include <mrdocs/Support/Error.hpp>
18-
#include <fmt/format.h>
1915
#include <exception>
16+
#include <functional>
2017
#include <iterator>
2118
#include <memory>
19+
#include <mrdocs/Platform.hpp>
20+
#include <mrdocs/Support/Error.hpp>
21+
#include <mrdocs/Support/source_location.hpp>
2222
#include <string>
2323
#include <string_view>
2424
#include <type_traits>
2525
#include <utility>
2626
#include <vector>
27-
#include <functional>
2827

2928
namespace clang::mrdocs {
3029

include/mrdocs/Support/Handlebars.hpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
#ifndef MRDOCS_TOOL_SUPPORT_PATH_HPP
1212
#define MRDOCS_TOOL_SUPPORT_PATH_HPP
1313

14-
#include <mrdocs/Support/String.hpp>
14+
#include <format>
15+
#include <functional>
1516
#include <mrdocs/Dom.hpp>
17+
#include <mrdocs/Support/String.hpp>
1618
#include <string_view>
17-
#include <unordered_map>
18-
#include <functional>
1919
#include <type_traits>
20-
#include <vector>
20+
#include <unordered_map>
2121
#include <variant>
22+
#include <vector>
2223

2324
namespace clang {
2425
namespace mrdocs {
@@ -45,15 +46,10 @@ struct HandlebarsError
4546
HandlebarsError(std::string_view msg)
4647
: std::runtime_error(std::string(msg)) {}
4748

48-
HandlebarsError(
49-
std::string_view msg,
50-
std::size_t line_,
51-
std::size_t column_,
52-
std::size_t pos_)
53-
: std::runtime_error(fmt::format("{} - {}:{}", msg, line_, column_))
54-
, line(line_)
55-
, column(column_)
56-
, pos(pos_) {}
49+
HandlebarsError(std::string_view msg, std::size_t line_,
50+
std::size_t column_, std::size_t pos_)
51+
: std::runtime_error(std::format("{} - {}:{}", msg, line_, column_)),
52+
line(line_), column(column_), pos(pos_) {}
5753
};
5854

5955
namespace detail {
@@ -218,9 +214,9 @@ class MRDOCS_DECL OutputRef
218214
@return A reference to this object
219215
*/
220216
template <class T>
221-
requires fmt::is_formattable<T>::value
217+
requires std::formattable<T, char>
222218
friend OutputRef &operator<<(OutputRef &os, T v) {
223-
std::string s = fmt::format("{}", v);
219+
std::string s = std::format("{}", v);
224220
return os.write_impl(s);
225221
}
226222

include/mrdocs/Support/Lua.hpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
#ifndef MRDOCS_SUPPORT_LUA_HPP
1212
#define MRDOCS_SUPPORT_LUA_HPP
1313

14-
#include <mrdocs/Platform.hpp>
14+
#include <cstdlib>
15+
#include <memory>
1516
#include <mrdocs/Dom.hpp>
17+
#include <mrdocs/Platform.hpp>
1618
#include <mrdocs/Support/Error.hpp>
1719
#include <mrdocs/Support/source_location.hpp>
18-
#include <fmt/format.h>
19-
#include <cstdlib>
20-
#include <memory>
2120
#include <string>
2221
#include <string_view>
2322

@@ -470,17 +469,13 @@ class Table : public Value
470469

471470
//------------------------------------------------
472471

473-
template<>
474-
struct fmt::formatter<clang::mrdocs::lua::Value>
475-
: fmt::formatter<std::string>
476-
{
477-
auto format(
478-
clang::mrdocs::lua::Value const& value,
479-
fmt::format_context& ctx) const
480-
{
481-
return fmt::formatter<std::string>::format(
482-
value.displayString(), ctx);
483-
}
472+
template <>
473+
struct std::formatter<clang::mrdocs::lua::Value>
474+
: std::formatter<std::string_view> {
475+
auto format(clang::mrdocs::lua::Value const &value,
476+
std::format_context &ctx) const {
477+
return std::formatter<std::string_view>::format(value.displayString(), ctx);
478+
}
484479
};
485480

486481
#endif

0 commit comments

Comments
 (0)