summaryrefslogtreecommitdiff
path: root/src/lines.cpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2019-10-25 14:10:45 +0300
committerAleksey Veresov <aleksey@veresov.pro>2019-10-25 14:10:45 +0300
commit1de3a9aae84ec71c4fd83604ea9c45204efb9baf (patch)
tree99246ae8cbb19864657360b513f501d796a92db5 /src/lines.cpp
parent2c12c0652d2b8c8440e1e908f004826840ed14ab (diff)
downloadtexo-1de3a9aae84ec71c4fd83604ea9c45204efb9baf.tar
texo-1de3a9aae84ec71c4fd83604ea9c45204efb9baf.tar.xz
texo-1de3a9aae84ec71c4fd83604ea9c45204efb9baf.zip
.
Diffstat (limited to 'src/lines.cpp')
-rw-r--r--src/lines.cpp87
1 files changed, 87 insertions, 0 deletions
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);
+}