From d03b2894c76430b550f9883dddf9d7f51858a896 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 16 Sep 2025 14:39:26 +0200 Subject: Split TextFormatter methods out to a .cc --- src/text_formatter.cc | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/text_formatter.h | 51 +++++----------------------- src/wscript | 1 + 3 files changed, 103 insertions(+), 42 deletions(-) create mode 100644 src/text_formatter.cc (limited to 'src') diff --git a/src/text_formatter.cc b/src/text_formatter.cc new file mode 100644 index 00000000..2db8b602 --- /dev/null +++ b/src/text_formatter.cc @@ -0,0 +1,93 @@ +/* + Copyright (C) 2022 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include "text_formatter.h" + + +using namespace dcp; + + +TextFormatter::TextFormatter(boost::filesystem::path file) + : Formatter(file) +{ + +} + + +void +TextFormatter::heading(std::string const& text) +{ + print(text); +} + + +void +TextFormatter::subheading(std::string const& text) +{ + print(""); + print(text); +} + + +Formatter::Wrap +TextFormatter::unordered_list() +{ + _indent++; + return Wrap(this, "", [this]() { _indent--; }); +} + + +void +TextFormatter::list_item(std::string const& text, boost::optional type) +{ + LIBDCP_UNUSED(type); + for (int i = 0; i < _indent * 2; ++i) { + _file.puts(" "); + } + _file.puts("* "); + print(text); +} + + +std::function +TextFormatter::process_string() +{ + return [](std::string s) { + return s; + }; +} + + +std::function +TextFormatter::process_filename() +{ + return [](std::string s) { + return s; + }; +} + + +void +TextFormatter::print(std::string const& text) +{ + _file.puts(text.c_str()); + _file.puts("\n"); +} diff --git a/src/text_formatter.h b/src/text_formatter.h index fed2d364..5788c94b 100644 --- a/src/text_formatter.h +++ b/src/text_formatter.h @@ -28,50 +28,17 @@ namespace dcp { class TextFormatter : public Formatter { public: - TextFormatter(boost::filesystem::path file) - : Formatter(file) - {} - - void heading(std::string const& text) override { - print(text); - } - - void subheading(std::string const& text) override { - print(""); - print(text); - } - - Wrap unordered_list() override { - _indent++; - return Wrap(this, "", [this]() { _indent--; }); - } - - void list_item(std::string const& text, boost::optional type = {}) override { - LIBDCP_UNUSED(type); - for (int i = 0; i < _indent * 2; ++i) { - _file.puts(" "); - } - _file.puts("* "); - print(text); - } - - std::function process_string() override { - return [](std::string s) { - return s; - }; - } - - std::function process_filename() override { - return [](std::string s) { - return s; - }; - } + TextFormatter(boost::filesystem::path file); + + void heading(std::string const& text) override; + void subheading(std::string const& text) override; + Wrap unordered_list() override; + void list_item(std::string const& text, boost::optional type = {}) override; + std::function process_string() override; + std::function process_filename() override; private: - void print(std::string const& text) { - _file.puts(text.c_str()); - _file.puts("\n"); - } + void print(std::string const& text); int _indent = 0; }; diff --git a/src/wscript b/src/wscript index 1c75f2a4..14ce2292 100644 --- a/src/wscript +++ b/src/wscript @@ -123,6 +123,7 @@ def build(bld): text_asset.cc text_asset_internal.cc text.cc + text_formatter.cc text_image.cc subtitle_standard.cc text_string.cc -- cgit v1.2.3