From 2eae362fd3f50325067fa3d7e13db6882df80e76 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 27 Sep 2019 18:09:07 +0300 Subject: Texo initial. --- src/plain.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/plain.cpp (limited to 'src/plain.cpp') diff --git a/src/plain.cpp b/src/plain.cpp new file mode 100644 index 0000000..d8bc1b1 --- /dev/null +++ b/src/plain.cpp @@ -0,0 +1,55 @@ +#include "plain.hpp" + + +TexoPlainProducer::TexoPlainProducer(TexoExporter &exporter): + TexoProducer(exporter) +{} + +void TexoPlainProducer::Put(const Texo &piece) +{ + switch (piece.type) { + case Texo::character: exporter.Put(piece.c); + default: break; + } +} + + +TexoPlainImporter::TexoPlainImporter(TexoProducer &producer): + TexoImporter(producer), first(true), space(0), newline(false) +{} + +void TexoPlainImporter::Put(const char c) +{ + if (first) { + first = false; + producer.Put(Texo(Texo::paragraph_begin)); + } + if (c == ' ') { + ++space; + } else if (c == '\n') { + if (newline) { + newline = false; + producer.Put(Texo(Texo::paragraph_end)); + producer.Put(Texo(Texo::paragraph_begin)); + } else { + newline = true; + } + } else if (!c) { + producer.Put(Texo(Texo::paragraph_end)); + } else { + if (newline) { + newline = false; + if (space) { + space = 0; + producer.Put(Texo(Texo::newline)); + } else { + producer.Put(Texo(' ')); + } + } + while (space) { + producer.Put(Texo(' ')); + --space; + } + producer.Put(Texo(c)); + } +} -- cgit v1.2.3