summaryrefslogtreecommitdiff
path: root/src/plain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plain.cpp')
-rw-r--r--src/plain.cpp55
1 files changed, 55 insertions, 0 deletions
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));
+ }
+}