From 1de3a9aae84ec71c4fd83604ea9c45204efb9baf Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 25 Oct 2019 14:10:45 +0300 Subject: . --- src/lines.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/lines.cpp (limited to 'src/lines.cpp') diff --git a/src/lines.cpp b/src/lines.cpp new file mode 100644 index 0000000..05a75e4 --- /dev/null +++ b/src/lines.cpp @@ -0,0 +1,87 @@ +#include "lines.hpp" + + +TexoProducerLines::TexoProducerLines(TexoExporter &exporter): + TexoProducer(exporter) +{} + +void TexoProducerLines::Put(const Texo &piece) +{ + if (piece.c == '\n') { + exporter.Put(' '); + } else { + exporter.Put(piece.c); + } +} + +void TexoProducerLines::Put(const TexoParagraph &piece) +{ + if (piece.closing) { + exporter.Put('\n'); + } +} + +void TexoProducerLines::Put(const TexoQuote &piece) +{ + if (piece.closing) { + exporter.Put('\n'); + } else { + exporter.Put('>'); + } +} + +void TexoProducerLines::Put(const TexoLineBreak &piece) +{ + exporter.Put('\n'); +} + + +TexoImporterLines::TexoImporterLines(TexoProducer &producer): + TexoImporter(producer), quoted(false), newline(true) +{} + +TexoImporterLines::~TexoImporterLines() +{ + if (!newline) { + if (quoted) { + producer.Put(TexoQuote(true)); + } else { + producer.Put(TexoParagraph(true)); + } + } +} + +void TexoImporterLines::Put(char c) +{ + if (c == '\n') { + if (!newline) { + if (quoted) { + producer.Put(TexoQuote(true)); + quoted = false; + } else { + producer.Put(TexoParagraph(true)); + } + newline = true; + } + } else if (newline && c == '>') { + producer.Put(TexoQuote()); + newline = false; + quoted = true; + } else { + if (newline) { + producer.Put(TexoParagraph()); + newline = false; + } + producer.Put(c); + } +} + +void TexoImporterLines::Put(const ScriptVariable &str) +{ + TexoImporter::Put(str); +} + +void TexoImporterLines::Put(FILE *file) +{ + TexoImporter::Put(file); +} -- cgit v1.2.3