41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <format>
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "Error.h"
|
|
|
|
template <>
|
|
struct std::formatter<llvm::StringRef> : std::formatter<std::string_view> {
|
|
using Base = std::formatter<std::string_view>;
|
|
|
|
template <typename ParseContext>
|
|
constexpr auto parse(ParseContext& ctx) {
|
|
return Base::parse(ctx);
|
|
}
|
|
|
|
template <typename FormatContext>
|
|
auto format(llvm::StringRef s, FormatContext& ctx) const {
|
|
return Base::format(std::string_view(s.str()), ctx);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct std::formatter<llvm::Error> : std::formatter<llvm::StringRef> {
|
|
using Base = std::formatter<llvm::StringRef>;
|
|
|
|
template <typename ParseContext>
|
|
constexpr auto parse(ParseContext& ctx) {
|
|
return Base::parse(ctx);
|
|
}
|
|
|
|
template <typename FormatContext>
|
|
auto format(const llvm::Error& e, FormatContext& ctx) const {
|
|
llvm::SmallString<128> buffer;
|
|
llvm::raw_svector_ostream os(buffer);
|
|
os << e;
|
|
return Base::format(buffer, ctx);
|
|
}
|
|
};
|
|
|