summaryrefslogtreecommitdiff
path: root/src/plain.cpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-02-03 15:53:56 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-02-03 15:53:56 +0300
commit8d4981fcc1c545396df3eac87a3c1a67f3d30038 (patch)
tree0e4f373313f7b251847fecd1186786574e8d450c /src/plain.cpp
parent3032869b86efa52f20ad9840381a37017980f587 (diff)
downloadtexo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.tar
texo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.tar.xz
texo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.zip
[texo] Abolished dependency on ScriptPP.
Diffstat (limited to 'src/plain.cpp')
-rw-r--r--src/plain.cpp84
1 files changed, 33 insertions, 51 deletions
diff --git a/src/plain.cpp b/src/plain.cpp
index dca394f..db3696d 100644
--- a/src/plain.cpp
+++ b/src/plain.cpp
@@ -4,7 +4,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Plain Producer
*/
-TexoProducerPlain::TexoProducerPlain(TexoExporter & exporter):
+TexoProducerPlain::TexoProducerPlain(TexoExporter &exporter):
TexoProducer(exporter), quoted(false), newline(false), nospace(true)
{}
@@ -70,15 +70,14 @@ bool TexoProducerPlain::PutHorizontalRule()
ok = exporter.Put('\n');
}
nospace = true;
- return ok && exporter.Put(
- "--------------------------------------------------\n");
+ return ok && exporter.Put("------------------------------------------\n");
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Plain Importer
*/
-TexoImporterPlain::TexoImporterPlain(TexoProducer & producer):
+TexoImporterPlain::TexoImporterPlain(TexoProducer &producer):
TexoImporter(producer), state(text)
{}
@@ -96,48 +95,30 @@ bool TexoImporterPlain::TrueEnd()
bool TexoImporterPlain::TruePut(char c)
{
switch (state) {
- case text:
- Text(c);
- break;
- case newline:
- Newline(c);
- break;
- case paragraph:
- Paragraph(c);
- break;
- case quote_pre:
- QuotePre(c);
- break;
- case quote:
- Quote(c);
- break;
- case quote_newline:
- QuoteNewline(c);
- break;
- case rule:
- Rule(c);
- break;
- case paragraph_rule:
- ParagraphRule(c);
- break;
- }
- return ok;
+ case text: return Text(c);
+ case newline: return Newline(c);
+ case paragraph: return Paragraph(c);
+ case quote_pre: return QuotePre(c);
+ case quote: return Quote(c);
+ case quote_newline: return QuoteNewline(c);
+ case rule: return Rule(c);
+ case paragraph_rule: return ParagraphRule(c);
+ }
+ return ok; // Impossible
}
-void TexoImporterPlain::Text(char c)
+bool TexoImporterPlain::Text(char c)
{
- switch (c) {
- case '\n':
+ if (c == '\n') {
state = newline;
- break;
- default:
+ } else {
ok = producer.Put(c);
- break;
}
+ return ok;
}
-void TexoImporterPlain::Newline(char c)
+bool TexoImporterPlain::Newline(char c)
{
if (c == '\n') {
state = paragraph;
@@ -151,9 +132,10 @@ void TexoImporterPlain::Newline(char c)
Text(c);
}
}
+ return ok;
}
-void TexoImporterPlain::Paragraph(char c)
+bool TexoImporterPlain::Paragraph(char c)
{
if (c == '>') {
ok = producer.Quote();
@@ -168,29 +150,29 @@ void TexoImporterPlain::Paragraph(char c)
Text(c);
}
}
+ return ok;
}
-void TexoImporterPlain::QuotePre(char c)
+bool TexoImporterPlain::QuotePre(char c)
{
if (c != ' ') {
state = quote;
Quote(c);
}
+ return ok;
}
-void TexoImporterPlain::Quote(char c)
+bool TexoImporterPlain::Quote(char c)
{
- switch (c) {
- case '\n':
+ if (c == '\n') {
state = quote_newline;
- break;
- default:
+ } else {
ok = producer.Put(c);
- break;
}
+ return ok;
}
-void TexoImporterPlain::QuoteNewline(char c)
+bool TexoImporterPlain::QuoteNewline(char c)
{
if (c == '>') {
ok = producer.Put('\n');
@@ -207,9 +189,10 @@ void TexoImporterPlain::QuoteNewline(char c)
Text(c);
}
}
+ return ok;
}
-void TexoImporterPlain::Rule(char c)
+bool TexoImporterPlain::Rule(char c)
{
if (c == '\n') {
ok = producer.PutHorizontalRule();
@@ -226,14 +209,13 @@ void TexoImporterPlain::Rule(char c)
Text(c);
}
}
+ return ok;
}
-void TexoImporterPlain::ParagraphRule(char c)
+bool TexoImporterPlain::ParagraphRule(char c)
{
if (c == '\n') {
ok = producer.Paragraph();
}
- if (ok) {
- Rule(c);
- }
+ return ok && Rule(c);
}