From 6ed3a4b5fe4984a5630e623bf5632576fb173f60 Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 6 Oct 2020 19:25:25 +0200 Subject: [PATCH] LibGUI: Add formatters for TextPosition and TextRange. --- Libraries/LibGUI/TextPosition.h | 15 +++++++++++++++ Libraries/LibGUI/TextRange.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Libraries/LibGUI/TextPosition.h b/Libraries/LibGUI/TextPosition.h index c633d138f2..53732abc63 100644 --- a/Libraries/LibGUI/TextPosition.h +++ b/Libraries/LibGUI/TextPosition.h @@ -65,3 +65,18 @@ inline const LogStream& operator<<(const LogStream& stream, const TextPosition& } } + +namespace AK { + +template<> +struct Formatter : Formatter { + void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextPosition& value) + { + if (value.is_valid()) + Formatter::format(params, builder, String::formatted("({},{})", value.line(), value.column())); + else + Formatter::format(params, builder, "GUI::TextPosition(Invalid)"); + } +}; + +} diff --git a/Libraries/LibGUI/TextRange.h b/Libraries/LibGUI/TextRange.h index 94a05230f1..4f62273e89 100644 --- a/Libraries/LibGUI/TextRange.h +++ b/Libraries/LibGUI/TextRange.h @@ -93,3 +93,18 @@ inline const LogStream& operator<<(const LogStream& stream, const TextRange& val } } + +namespace AK { + +template<> +struct Formatter : Formatter { + void format(TypeErasedFormatParams& params, FormatBuilder& builder, const GUI::TextRange& value) + { + if (value.is_valid()) + Formatter::format(params, builder, String::formatted("{}-{}", value.start(), value.end())); + else + Formatter::format(params, builder, "GUI::TextRange(Invalid)"); + } +}; + +}