summaryrefslogtreecommitdiff
path: root/src/lines.cpp
blob: f77ae4062e2aa6ebed51cb7d8f8dda0722b7b192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "lines.hpp"


TexoProducerLines::TexoProducerLines(TexoExporter &exporter):
    TexoProducer(exporter), newline(false)
{}

void TexoProducerLines::Put(const Texo &piece)
{
    if (piece.c == '\n') {
        if (!newline) {
            exporter.Put(' ');
        }
    } else {
        exporter.Put(piece.c);
        newline = false;
    }
}

void TexoProducerLines::Put(const TexoParagraph &piece)
{
    if (piece.closing) {
        exporter.Put('\n');
        newline = true;
    }
}

void TexoProducerLines::Put(const TexoQuote &piece)
{
    if (piece.closing) {
        exporter.Put('\n');
        newline = true;
    } else {
        exporter.Put('>');
    }
}

void TexoProducerLines::Put(const TexoLineBreak &piece)
{
    exporter.Put('\n');
    newline = true;
}


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);
}