summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/lines.cpp26
-rw-r--r--examples/markdown.cpp28
-rw-r--r--examples/plain.cpp26
-rw-r--r--src/exporter.cpp4
-rw-r--r--src/exporter.hpp2
-rw-r--r--src/file.cpp4
-rw-r--r--src/file.hpp6
-rw-r--r--src/html.cpp82
-rw-r--r--src/html.hpp15
-rw-r--r--src/importer.cpp15
-rw-r--r--src/importer.hpp14
-rw-r--r--src/lines.cpp4
-rw-r--r--src/lines.hpp6
-rw-r--r--src/markdown.cpp266
-rw-r--r--src/markdown.hpp20
-rw-r--r--src/plain.cpp60
-rw-r--r--src/plain.hpp6
-rw-r--r--src/producer.cpp123
-rw-r--r--src/producer.hpp180
-rw-r--r--src/script.cpp4
-rw-r--r--src/script.hpp6
21 files changed, 591 insertions, 306 deletions
diff --git a/examples/lines.cpp b/examples/lines.cpp
index 7c46a6e..96da19a 100644
--- a/examples/lines.cpp
+++ b/examples/lines.cpp
@@ -1,18 +1,18 @@
-#include <stdio.h>
+#include <file.hpp>
#include <html.hpp>
-#include <plain.hpp>
#include <lines.hpp>
#include <markdown.hpp>
-#include <file.hpp>
+#include <plain.hpp>
+#include <stdio.h>
void plain()
{
fputs(" ---- Lines to Plain ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerPlain producer(exporter);
TexoImporterLines importer(producer);
- FILE *file = fopen("lines.txt", "r");
+ FILE * file = fopen("lines.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -21,10 +21,10 @@ void plain()
void html()
{
fputs("\n ---- Lines to HTML ----\n", stdout);
- TexoExporterFile exporter(stdout);
- TexoProducerHTML producer(exporter);
+ TexoExporterFile exporter(stdout);
+ TexoProducerHTML producer(exporter);
TexoImporterLines importer(producer);
- FILE *file = fopen("lines.txt", "r");
+ FILE * file = fopen("lines.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -33,10 +33,10 @@ void html()
void markdown()
{
fputs("\n ---- Lines to Markdown ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerMarkdown producer(exporter);
- TexoImporterLines importer(producer);
- FILE *file = fopen("lines.txt", "r");
+ TexoImporterLines importer(producer);
+ FILE * file = fopen("lines.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -45,10 +45,10 @@ void markdown()
void lines()
{
fputs("\n ---- Lines to Lines ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerLines producer(exporter);
TexoImporterLines importer(producer);
- FILE *file = fopen("lines.txt", "r");
+ FILE * file = fopen("lines.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
diff --git a/examples/markdown.cpp b/examples/markdown.cpp
index c1677f3..75a32ca 100644
--- a/examples/markdown.cpp
+++ b/examples/markdown.cpp
@@ -1,18 +1,18 @@
-#include <stdio.h>
+#include <file.hpp>
#include <html.hpp>
-#include <plain.hpp>
#include <lines.hpp>
#include <markdown.hpp>
-#include <file.hpp>
+#include <plain.hpp>
+#include <stdio.h>
void plain()
{
fputs(" ---- Markdown to Plain ----\n", stdout);
- TexoExporterFile exporter(stdout);
- TexoProducerPlain producer(exporter);
+ TexoExporterFile exporter(stdout);
+ TexoProducerPlain producer(exporter);
TexoImporterMarkdown importer(producer);
- FILE *file = fopen("markdown.md", "r");
+ FILE * file = fopen("markdown.md", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -21,10 +21,10 @@ void plain()
void html()
{
fputs("\n ---- Markdown to HTML ----\n", stdout);
- TexoExporterFile exporter(stdout);
- TexoProducerHTML producer(exporter);
+ TexoExporterFile exporter(stdout);
+ TexoProducerHTML producer(exporter);
TexoImporterMarkdown importer(producer);
- FILE *file = fopen("markdown.md", "r");
+ FILE * file = fopen("markdown.md", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -33,10 +33,10 @@ void html()
void markdown()
{
fputs("\n ---- Markdown to Markdown ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerMarkdown producer(exporter);
TexoImporterMarkdown importer(producer);
- FILE *file = fopen("markdown.md", "r");
+ FILE * file = fopen("markdown.md", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -45,10 +45,10 @@ void markdown()
void lines()
{
fputs("\n ---- Markdown to Lines ----\n", stdout);
- TexoExporterFile exporter(stdout);
- TexoProducerLines producer(exporter);
+ TexoExporterFile exporter(stdout);
+ TexoProducerLines producer(exporter);
TexoImporterMarkdown importer(producer);
- FILE *file = fopen("markdown.md", "r");
+ FILE * file = fopen("markdown.md", "r");
importer.Put(file);
importer.End();
fclose(file);
diff --git a/examples/plain.cpp b/examples/plain.cpp
index bf48472..71648cc 100644
--- a/examples/plain.cpp
+++ b/examples/plain.cpp
@@ -1,18 +1,18 @@
-#include <stdio.h>
+#include <file.hpp>
#include <html.hpp>
-#include <plain.hpp>
#include <lines.hpp>
#include <markdown.hpp>
-#include <file.hpp>
+#include <plain.hpp>
+#include <stdio.h>
void plain()
{
fputs(" ---- Plain to Plain ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerPlain producer(exporter);
TexoImporterPlain importer(producer);
- FILE *file = fopen("plain.txt", "r");
+ FILE * file = fopen("plain.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -21,10 +21,10 @@ void plain()
void html()
{
fputs("\n ---- Plain to HTML ----\n", stdout);
- TexoExporterFile exporter(stdout);
- TexoProducerHTML producer(exporter);
+ TexoExporterFile exporter(stdout);
+ TexoProducerHTML producer(exporter);
TexoImporterPlain importer(producer);
- FILE *file = fopen("plain.txt", "r");
+ FILE * file = fopen("plain.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -33,10 +33,10 @@ void html()
void markdown()
{
fputs("\n ---- Plain to Markdown ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerMarkdown producer(exporter);
- TexoImporterPlain importer(producer);
- FILE *file = fopen("plain.txt", "r");
+ TexoImporterPlain importer(producer);
+ FILE * file = fopen("plain.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
@@ -45,10 +45,10 @@ void markdown()
void lines()
{
fputs("\n ---- Plain to Lines ----\n", stdout);
- TexoExporterFile exporter(stdout);
+ TexoExporterFile exporter(stdout);
TexoProducerLines producer(exporter);
TexoImporterPlain importer(producer);
- FILE *file = fopen("plain.txt", "r");
+ FILE * file = fopen("plain.txt", "r");
importer.Put(file);
importer.End();
fclose(file);
diff --git a/src/exporter.cpp b/src/exporter.cpp
index b9a5b3f..6a190ee 100644
--- a/src/exporter.cpp
+++ b/src/exporter.cpp
@@ -4,9 +4,9 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Exporter
*/
-bool TexoExporter::Put(const ScriptVariable &str)
+bool TexoExporter::Put(const ScriptVariable & str)
{
- bool ok = true;
+ bool ok = true;
const int len = str.Length();
for (int i = 0; ok && i < len; ++i) {
ok = Put(str[i]);
diff --git a/src/exporter.hpp b/src/exporter.hpp
index a20f695..18a2e5d 100644
--- a/src/exporter.hpp
+++ b/src/exporter.hpp
@@ -11,7 +11,7 @@
class TexoExporter {
public:
virtual bool Put(char c) = 0;
- virtual bool Put(const ScriptVariable &str);
+ virtual bool Put(const ScriptVariable & str);
};
diff --git a/src/file.cpp b/src/file.cpp
index 221ff81..c46a1f2 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -4,7 +4,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo File Exporter
*/
-TexoExporterFile::TexoExporterFile(FILE *file): file(file)
+TexoExporterFile::TexoExporterFile(FILE * file): file(file)
{}
@@ -14,7 +14,7 @@ bool TexoExporterFile::Put(char c)
return !ferror(file);
}
-bool TexoExporterFile::Put(const ScriptVariable &str)
+bool TexoExporterFile::Put(const ScriptVariable & str)
{
fwrite(str.c_str(), 1, str.Length(), file);
return !ferror(file);
diff --git a/src/file.hpp b/src/file.hpp
index 5f8adb6..171e6d3 100644
--- a/src/file.hpp
+++ b/src/file.hpp
@@ -11,15 +11,15 @@
*/
class TexoExporterFile: public TexoExporter {
public:
- TexoExporterFile(FILE *file);
+ TexoExporterFile(FILE * file);
bool Put(char c);
- bool Put(const ScriptVariable &str);
+ bool Put(const ScriptVariable & str);
private:
- FILE *file;
+ FILE * file;
};
diff --git a/src/html.cpp b/src/html.cpp
index ed67781..fb2fb5e 100644
--- a/src/html.cpp
+++ b/src/html.cpp
@@ -1,7 +1,7 @@
#include "html.hpp"
-TexoProducerHTML::TexoProducerHTML(TexoExporter &exporter):
+TexoProducerHTML::TexoProducerHTML(TexoExporter & exporter):
TexoProducerStrict(exporter)
{}
@@ -9,10 +9,17 @@ TexoProducerHTML::TexoProducerHTML(TexoExporter &exporter):
bool TexoProducerHTML::TruePut(char c)
{
switch (c) {
- case '<': return exporter.Put("&lt;"); break;
- case '>': return exporter.Put("&gt;"); break;
- case '&': return exporter.Put("&amp;"); break;
- default: return exporter.Put(c);
+ case '<':
+ return exporter.Put("&lt;");
+ break;
+ case '>':
+ return exporter.Put("&gt;");
+ break;
+ case '&':
+ return exporter.Put("&amp;");
+ break;
+ default:
+ return exporter.Put(c);
}
}
@@ -82,22 +89,50 @@ bool TexoProducerHTML::CloseQuote()
}
-bool TexoProducerHTML::StartBold() { return exporter.Put("<b>"); }
-bool TexoProducerHTML::StartItalic() { return exporter.Put("<i>"); }
-bool TexoProducerHTML::StartMono() { return exporter.Put("<code>"); }
-bool TexoProducerHTML::StartStrike() { return exporter.Put("<del>"); }
-bool TexoProducerHTML::StartUnderline() { return exporter.Put("<ins>"); }
+bool TexoProducerHTML::StartBold()
+{
+ return exporter.Put("<b>");
+}
+bool TexoProducerHTML::StartItalic()
+{
+ return exporter.Put("<i>");
+}
+bool TexoProducerHTML::StartMono()
+{
+ return exporter.Put("<code>");
+}
+bool TexoProducerHTML::StartStrike()
+{
+ return exporter.Put("<del>");
+}
+bool TexoProducerHTML::StartUnderline()
+{
+ return exporter.Put("<ins>");
+}
-bool TexoProducerHTML::CloseBold() { return exporter.Put("</b>"); }
-bool TexoProducerHTML::CloseItalic() { return exporter.Put("</i>"); }
-bool TexoProducerHTML::CloseMono() { return exporter.Put("</code>"); }
-bool TexoProducerHTML::CloseStrike() { return exporter.Put("</del>"); }
-bool TexoProducerHTML::CloseUnderline() { return exporter.Put("</ins>"); }
+bool TexoProducerHTML::CloseBold()
+{
+ return exporter.Put("</b>");
+}
+bool TexoProducerHTML::CloseItalic()
+{
+ return exporter.Put("</i>");
+}
+bool TexoProducerHTML::CloseMono()
+{
+ return exporter.Put("</code>");
+}
+bool TexoProducerHTML::CloseStrike()
+{
+ return exporter.Put("</del>");
+}
+bool TexoProducerHTML::CloseUnderline()
+{
+ return exporter.Put("</ins>");
+}
bool TexoProducerHTML::StartLink(
- const ScriptVariable &link,
- const ScriptVariable &title
-)
+ const ScriptVariable & link, const ScriptVariable & title)
{
bool ok = true;
if (link != "") {
@@ -113,9 +148,7 @@ bool TexoProducerHTML::StartLink(
}
bool TexoProducerHTML::CloseLink(
- const ScriptVariable &link,
- const ScriptVariable &title
-)
+ const ScriptVariable & link, const ScriptVariable & title)
{
if (link != "") {
return exporter.Put("</a>");
@@ -125,11 +158,8 @@ bool TexoProducerHTML::CloseLink(
}
-bool TexoProducerHTML::TruePutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
-)
+bool TexoProducerHTML::TruePutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
{
bool ok = true;
if (src != "") {
diff --git a/src/html.hpp b/src/html.hpp
index aa22cf1..c32b119 100644
--- a/src/html.hpp
+++ b/src/html.hpp
@@ -2,13 +2,13 @@
#define TEXO_INCLUDED_HTML
#include "exporter.hpp"
-#include "producer.hpp"
#include "importer.hpp"
+#include "producer.hpp"
class TexoProducerHTML: public TexoProducerStrict {
public:
- TexoProducerHTML(TexoExporter &exporter);
+ TexoProducerHTML(TexoExporter & exporter);
protected:
bool TruePut(char c);
@@ -35,14 +35,11 @@ protected:
bool CloseStrike();
bool CloseUnderline();
- bool StartLink(const ScriptVariable &link, const ScriptVariable &title);
- bool CloseLink(const ScriptVariable &link, const ScriptVariable &title);
+ bool StartLink(const ScriptVariable & link, const ScriptVariable & title);
+ bool CloseLink(const ScriptVariable & link, const ScriptVariable & title);
- bool TruePutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
- );
+ bool TruePutImage(const ScriptVariable & src, const ScriptVariable & alt,
+ const ScriptVariable & title);
bool TruePutHorizontalRule();
};
diff --git a/src/importer.cpp b/src/importer.cpp
index 73ff060..bab7f8b 100644
--- a/src/importer.cpp
+++ b/src/importer.cpp
@@ -4,11 +4,14 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Importer
*/
-TexoImporter::TexoImporter(TexoProducer &producer):
+TexoImporter::TexoImporter(TexoProducer & producer):
producer(producer), ok(true)
{}
-TexoImporter::~TexoImporter() { End(); }
+TexoImporter::~TexoImporter()
+{
+ End();
+}
bool TexoImporter::End()
@@ -21,12 +24,12 @@ bool TexoImporter::Put(char c)
return ok = ok && TruePut(c);
}
-bool TexoImporter::Put(const ScriptVariable &s)
+bool TexoImporter::Put(const ScriptVariable & s)
{
return ok = ok && TruePut(s);
}
-bool TexoImporter::Put(FILE *f)
+bool TexoImporter::Put(FILE * f)
{
return ok = ok && TruePut(f);
}
@@ -38,7 +41,7 @@ bool TexoImporter::TrueEnd()
}
-bool TexoImporter::TruePut(const ScriptVariable &str)
+bool TexoImporter::TruePut(const ScriptVariable & str)
{
const int len = str.Length();
for (int i = 0; ok && i < len; ++i) {
@@ -47,7 +50,7 @@ bool TexoImporter::TruePut(const ScriptVariable &str)
return ok;
}
-bool TexoImporter::TruePut(FILE *file)
+bool TexoImporter::TruePut(FILE * file)
{
if (file) {
for (int c = fgetc(file); ok && c != EOF; c = fgetc(file)) {
diff --git a/src/importer.hpp b/src/importer.hpp
index 9280a34..c5a302d 100644
--- a/src/importer.hpp
+++ b/src/importer.hpp
@@ -12,14 +12,14 @@
*/
class TexoImporter {
public:
- TexoImporter(TexoProducer &producer);
+ TexoImporter(TexoProducer & producer);
~TexoImporter();
bool End();
bool Put(char c);
- bool Put(const ScriptVariable &s);
- bool Put(FILE *f);
+ bool Put(const ScriptVariable & s);
+ bool Put(FILE * f);
protected:
@@ -27,12 +27,12 @@ protected:
virtual bool TruePut(char c) = 0;
- virtual bool TruePut(const ScriptVariable &str);
- virtual bool TruePut(FILE *file);
+ virtual bool TruePut(const ScriptVariable & str);
+ virtual bool TruePut(FILE * file);
- TexoProducer &producer;
- bool ok;
+ TexoProducer & producer;
+ bool ok;
};
diff --git a/src/lines.cpp b/src/lines.cpp
index c7b605b..3aafde5 100644
--- a/src/lines.cpp
+++ b/src/lines.cpp
@@ -4,7 +4,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Lines Producer
*/
-TexoProducerLines::TexoProducerLines(TexoExporter &exporter):
+TexoProducerLines::TexoProducerLines(TexoExporter & exporter):
TexoProducer(exporter), newline(true)
{}
@@ -57,7 +57,7 @@ bool TexoProducerLines::Quote()
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Lines Importer
*/
-TexoImporterLines::TexoImporterLines(TexoProducer &producer):
+TexoImporterLines::TexoImporterLines(TexoProducer & producer):
TexoImporter(producer), newline(true), quote(false)
{}
diff --git a/src/lines.hpp b/src/lines.hpp
index 7049919..8049d61 100644
--- a/src/lines.hpp
+++ b/src/lines.hpp
@@ -2,8 +2,8 @@
#define TEXO_INCLUDED_LINES
#include "exporter.hpp"
-#include "producer.hpp"
#include "importer.hpp"
+#include "producer.hpp"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -11,7 +11,7 @@
*/
class TexoProducerLines: public TexoProducer {
public:
- TexoProducerLines(TexoExporter &exporter);
+ TexoProducerLines(TexoExporter & exporter);
bool End();
@@ -34,7 +34,7 @@ private:
*/
class TexoImporterLines: public TexoImporter {
public:
- TexoImporterLines(TexoProducer &producer);
+ TexoImporterLines(TexoProducer & producer);
protected:
diff --git a/src/markdown.cpp b/src/markdown.cpp
index 6931461..2a88717 100644
--- a/src/markdown.cpp
+++ b/src/markdown.cpp
@@ -1,9 +1,9 @@
#include "markdown.hpp"
-TexoProducerMarkdown::TexoProducerMarkdown(TexoExporter &exporter):
- TexoProducer(exporter),
- quoted(false), newline(false), header(false), code(false), nospace(true)
+TexoProducerMarkdown::TexoProducerMarkdown(TexoExporter & exporter):
+ TexoProducer(exporter), quoted(false), newline(false), header(false),
+ code(false), nospace(true)
{}
bool TexoProducerMarkdown::End()
@@ -35,7 +35,7 @@ bool TexoProducerMarkdown::Put(char c)
if (c == '*' || c == '_' || c == '`' || c == '+' || c == '~') {
ok = exporter.Put('\\');
}
- ok = ok && exporter.Put(c);
+ ok = ok && exporter.Put(c);
newline = false;
nospace = false;
}
@@ -46,7 +46,7 @@ bool TexoProducerMarkdown::Put(char c)
bool TexoProducerMarkdown::Code()
{
bool ok = Close();
- code = true;
+ code = true;
return ok && exporter.Put("```\n");
}
@@ -78,25 +78,38 @@ bool TexoProducerMarkdown::Paragraph()
bool TexoProducerMarkdown::Quote()
{
bool ok = Close();
- quoted = true;
+ quoted = true;
return ok && exporter.Put("> ");
}
-bool TexoProducerMarkdown::Mono() { return Mod("`"); }
-bool TexoProducerMarkdown::Bold() { return Mod("**"); }
-bool TexoProducerMarkdown::Italic() { return Mod("_"); }
-bool TexoProducerMarkdown::Underline() { return Mod("++"); }
-bool TexoProducerMarkdown::Strike() { return Mod("~~"); }
+bool TexoProducerMarkdown::Mono()
+{
+ return Mod("`");
+}
+bool TexoProducerMarkdown::Bold()
+{
+ return Mod("**");
+}
+bool TexoProducerMarkdown::Italic()
+{
+ return Mod("_");
+}
+bool TexoProducerMarkdown::Underline()
+{
+ return Mod("++");
+}
+bool TexoProducerMarkdown::Strike()
+{
+ return Mod("~~");
+}
bool TexoProducerMarkdown::Link(
- const ScriptVariable &link,
- const ScriptVariable &title
-)
+ const ScriptVariable & link, const ScriptVariable & title)
{
bool ok = Link();
if (link != "") {
- ok = ok && exporter.Put('[');
+ ok = ok && exporter.Put('[');
link_link = link;
link_title = title;
}
@@ -120,11 +133,8 @@ bool TexoProducerMarkdown::Link()
}
-bool TexoProducerMarkdown::PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
-)
+bool TexoProducerMarkdown::PutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
{
bool ok = true;
if (src != "") {
@@ -151,13 +161,13 @@ bool TexoProducerMarkdown::PutHorizontalRule()
ok = ok && exporter.Put('\n');
}
nospace = true;
- return ok && exporter.Put(
- "--------------------------------------------------\n"
- );
+ return ok
+ && exporter.Put(
+ "--------------------------------------------------\n");
}
-bool TexoProducerMarkdown::Mod(const ScriptVariable &str)
+bool TexoProducerMarkdown::Mod(const ScriptVariable & str)
{
newline = false;
nospace = false;
@@ -168,7 +178,7 @@ bool TexoProducerMarkdown::Close()
{
bool ok = true;
if (code) {
- ok = exporter.Put("\n```");
+ ok = exporter.Put("\n```");
code = false;
nospace = false;
newline = false;
@@ -183,7 +193,7 @@ bool TexoProducerMarkdown::Close()
}
-TexoImporterMarkdown::TexoImporterMarkdown(TexoProducer &producer):
+TexoImporterMarkdown::TexoImporterMarkdown(TexoProducer & producer):
TexoImporter(producer), state(start)
{}
@@ -191,26 +201,66 @@ TexoImporterMarkdown::TexoImporterMarkdown(TexoProducer &producer):
bool TexoImporterMarkdown::TruePut(char c)
{
switch (state) {
- case start: Start(c); break;
- case text: Text(c); break;
- case header_text: HeaderText(c); break;
- case quote_pre: QuotePre(c); break;
- case quote_text: QuoteText(c); break;
- case quote_newline: QuoteNewline(c); break;
- case code_text: CodeText(c); break;
- case code_newline: CodeNewline(c); break;
- case code_end: CodeEnd(c); break;
- case backslash: Backslash(c); break;
- case asterisk: Asterisk(c); break;
- case underline: Underline(c); break;
- case plus: Plus(c); break;
- case tilde: Tilde(c); break;
- case newline: Newline(c); break;
- case rule: Rule(c); break;
- case paragraph: Paragraph(c); break;
- case header: Header(c); break;
- case header_pre: HeaderPre(c); break;
- case code: Code(c); break;
+ case start:
+ Start(c);
+ break;
+ case text:
+ Text(c);
+ break;
+ case header_text:
+ HeaderText(c);
+ break;
+ case quote_pre:
+ QuotePre(c);
+ break;
+ case quote_text:
+ QuoteText(c);
+ break;
+ case quote_newline:
+ QuoteNewline(c);
+ break;
+ case code_text:
+ CodeText(c);
+ break;
+ case code_newline:
+ CodeNewline(c);
+ break;
+ case code_end:
+ CodeEnd(c);
+ break;
+ case backslash:
+ Backslash(c);
+ break;
+ case asterisk:
+ Asterisk(c);
+ break;
+ case underline:
+ Underline(c);
+ break;
+ case plus:
+ Plus(c);
+ break;
+ case tilde:
+ Tilde(c);
+ break;
+ case newline:
+ Newline(c);
+ break;
+ case rule:
+ Rule(c);
+ break;
+ case paragraph:
+ Paragraph(c);
+ break;
+ case header:
+ Header(c);
+ break;
+ case header_pre:
+ HeaderPre(c);
+ break;
+ case code:
+ Code(c);
+ break;
}
return ok;
}
@@ -244,14 +294,29 @@ void TexoImporterMarkdown::Text(char c)
{
back = text;
switch (c) {
- case '\\': state = backslash; break;
- case '\n': state = newline; break;
- case '*': state = asterisk; break;
- case '_': state = underline; break;
- case '+': state = plus; break;
- case '~': state = tilde; break;
- case '`': Backquote(); break;
- default: ok = producer.Put(c);
+ case '\\':
+ state = backslash;
+ break;
+ case '\n':
+ state = newline;
+ break;
+ case '*':
+ state = asterisk;
+ break;
+ case '_':
+ state = underline;
+ break;
+ case '+':
+ state = plus;
+ break;
+ case '~':
+ state = tilde;
+ break;
+ case '`':
+ Backquote();
+ break;
+ default:
+ ok = producer.Put(c);
}
}
@@ -259,14 +324,29 @@ void TexoImporterMarkdown::HeaderText(char c)
{
back = header_text;
switch (c) {
- case '\\': state = backslash; break;
- case '\n': state = paragraph; break;
- case '*': state = asterisk; break;
- case '_': state = underline; break;
- case '+': state = plus; break;
- case '~': state = tilde; break;
- case '`': Backquote(); break;
- default: ok = producer.Put(c);
+ case '\\':
+ state = backslash;
+ break;
+ case '\n':
+ state = paragraph;
+ break;
+ case '*':
+ state = asterisk;
+ break;
+ case '_':
+ state = underline;
+ break;
+ case '+':
+ state = plus;
+ break;
+ case '~':
+ state = tilde;
+ break;
+ case '`':
+ Backquote();
+ break;
+ default:
+ ok = producer.Put(c);
}
}
@@ -282,14 +362,29 @@ void TexoImporterMarkdown::QuoteText(char c)
{
back = quote_text;
switch (c) {
- case '\\': state = backslash; break;
- case '\n': state = quote_newline; break;
- case '*': state = asterisk; break;
- case '_': state = underline; break;
- case '+': state = plus; break;
- case '~': state = tilde; break;
- case '`': Backquote(); break;
- default: ok = producer.Put(c);
+ case '\\':
+ state = backslash;
+ break;
+ case '\n':
+ state = quote_newline;
+ break;
+ case '*':
+ state = asterisk;
+ break;
+ case '_':
+ state = underline;
+ break;
+ case '+':
+ state = plus;
+ break;
+ case '~':
+ state = tilde;
+ break;
+ case '`':
+ Backquote();
+ break;
+ default:
+ ok = producer.Put(c);
}
}
@@ -308,13 +403,26 @@ void TexoImporterMarkdown::CodeText(char c)
{
back = code_text;
switch (c) {
- case '\\': state = backslash; break;
- case '\n': state = code_newline; break;
- case '*': state = asterisk; break;
- case '_': state = underline; break;
- case '+': state = plus; break;
- case '~': state = tilde; break;
- default: ok = producer.Put(c);
+ case '\\':
+ state = backslash;
+ break;
+ case '\n':
+ state = code_newline;
+ break;
+ case '*':
+ state = asterisk;
+ break;
+ case '_':
+ state = underline;
+ break;
+ case '+':
+ state = plus;
+ break;
+ case '~':
+ state = tilde;
+ break;
+ default:
+ ok = producer.Put(c);
}
}
@@ -334,7 +442,7 @@ void TexoImporterMarkdown::CodeEnd(char c)
{
if (c == '`') {
++code_quote_count;
- } else if (c == '\n') {
+ } else if (c == '\n') {
if (code_quote_count == 3) {
state = paragraph;
} else {
@@ -485,7 +593,7 @@ void TexoImporterMarkdown::Code(char c)
{
if (c == '`') {
++code_quote_count;
- } else if (c == '\n') {
+ } else if (c == '\n') {
if (code_quote_count == 3) {
ok = producer.Code();
state = code_text;
diff --git a/src/markdown.hpp b/src/markdown.hpp
index ee8aee8..d8af037 100644
--- a/src/markdown.hpp
+++ b/src/markdown.hpp
@@ -2,13 +2,13 @@
#define TEXO_INCLUDED_MARKDOWN
#include "exporter.hpp"
-#include "producer.hpp"
#include "importer.hpp"
+#include "producer.hpp"
class TexoProducerMarkdown: public TexoProducer {
public:
- TexoProducerMarkdown(TexoExporter &exporter);
+ TexoProducerMarkdown(TexoExporter & exporter);
bool End();
@@ -25,18 +25,15 @@ public:
bool Strike();
bool Underline();
- bool Link(const ScriptVariable &link, const ScriptVariable &title);
+ bool Link(const ScriptVariable & link, const ScriptVariable & title);
bool Link();
- bool PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
- );
+ bool PutImage(const ScriptVariable & src, const ScriptVariable & alt,
+ const ScriptVariable & title);
bool PutHorizontalRule();
private:
- bool Mod(const ScriptVariable &str);
+ bool Mod(const ScriptVariable & str);
bool Close();
bool CloseLink();
@@ -53,7 +50,7 @@ private:
class TexoImporterMarkdown: public TexoImporter {
public:
- TexoImporterMarkdown(TexoProducer &producer);
+ TexoImporterMarkdown(TexoProducer & producer);
protected:
@@ -82,7 +79,8 @@ private:
header,
header_pre,
code
- } state, back;
+ } state,
+ back;
int header_level;
int rule_dash_count;
int code_quote_count;
diff --git a/src/plain.cpp b/src/plain.cpp
index 9e9280e..1df6659 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)
{}
@@ -44,7 +44,7 @@ bool TexoProducerPlain::Put(char c)
bool TexoProducerPlain::Paragraph()
{
- quoted = false;
+ quoted = false;
if (!nospace) {
nospace = true;
return exporter.Put("\n\n");
@@ -70,16 +70,16 @@ 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)
{}
@@ -97,14 +97,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;
+ 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;
}
@@ -113,8 +129,12 @@ bool TexoImporterPlain::TruePut(char c)
void TexoImporterPlain::Text(char c)
{
switch (c) {
- case '\n': state = newline; break;
- default: ok = producer.Put(c); break;
+ case '\n':
+ state = newline;
+ break;
+ default:
+ ok = producer.Put(c);
+ break;
}
}
@@ -162,8 +182,12 @@ void TexoImporterPlain::QuotePre(char c)
void TexoImporterPlain::Quote(char c)
{
switch (c) {
- case '\n': state = quote_newline; break;
- default: ok = producer.Put(c); break;
+ case '\n':
+ state = quote_newline;
+ break;
+ default:
+ ok = producer.Put(c);
+ break;
}
}
diff --git a/src/plain.hpp b/src/plain.hpp
index 66ee5f1..adc5bd8 100644
--- a/src/plain.hpp
+++ b/src/plain.hpp
@@ -2,8 +2,8 @@
#define TEXO_INCLUDED_PLAIN
#include "exporter.hpp"
-#include "producer.hpp"
#include "importer.hpp"
+#include "producer.hpp"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -11,7 +11,7 @@
*/
class TexoProducerPlain: public TexoProducer {
public:
- TexoProducerPlain(TexoExporter &exporter);
+ TexoProducerPlain(TexoExporter & exporter);
bool End();
@@ -34,7 +34,7 @@ private:
*/
class TexoImporterPlain: public TexoImporter {
public:
- TexoImporterPlain(TexoProducer &producer);
+ TexoImporterPlain(TexoProducer & producer);
protected:
diff --git a/src/producer.cpp b/src/producer.cpp
index c650459..99e34e1 100644
--- a/src/producer.cpp
+++ b/src/producer.cpp
@@ -4,7 +4,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Producer
*/
-TexoProducer::TexoProducer(TexoExporter &exporter): exporter(exporter)
+TexoProducer::TexoProducer(TexoExporter & exporter): exporter(exporter)
{} // Just save exporter for future use.
@@ -23,23 +23,51 @@ bool TexoProducer::Put(char c)
// Block Signal Handlers
// By default, nothing has to be done, and no error produced,
// except for paragraphs, which must be implemented.
-bool TexoProducer::Code() { return true; }
-bool TexoProducer::Header(int level) { return true; }
-bool TexoProducer::Quote() { return true; }
+bool TexoProducer::Code()
+{
+ return true;
+}
+
+bool TexoProducer::Header(int level)
+{
+ return true;
+}
+
+bool TexoProducer::Quote()
+{
+ return true;
+}
// Modificator Signal Handlers
// By default, nothing has to be done, and no error produced.
-bool TexoProducer::Bold() { return true; }
-bool TexoProducer::Italic() { return true; }
-bool TexoProducer::Mono() { return true; }
-bool TexoProducer::Strike() { return true; }
-bool TexoProducer::Underline() { return true; }
+bool TexoProducer::Bold()
+{
+ return true;
+}
+
+bool TexoProducer::Italic()
+{
+ return true;
+}
+
+bool TexoProducer::Mono()
+{
+ return true;
+}
+
+bool TexoProducer::Strike()
+{
+ return true;
+}
+
+bool TexoProducer::Underline()
+{
+ return true;
+}
bool TexoProducer::Link(
- const ScriptVariable &link,
- const ScriptVariable &title
-)
+ const ScriptVariable & link, const ScriptVariable & title)
{
return true;
}
@@ -50,11 +78,8 @@ bool TexoProducer::Link()
}
-bool TexoProducer::PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
-)
+bool TexoProducer::PutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
{
return true;
}
@@ -68,7 +93,7 @@ bool TexoProducer::PutHorizontalRule()
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo Strict Producer
*/
-TexoProducerStrict::TexoProducerStrict(TexoExporter &exporter):
+TexoProducerStrict::TexoProducerStrict(TexoExporter & exporter):
TexoProducer(exporter), block(block_none), opened(0)
{}
@@ -155,9 +180,7 @@ bool TexoProducerStrict::Underline()
}
bool TexoProducerStrict::Link(
- const ScriptVariable &path,
- const ScriptVariable &title
-)
+ const ScriptVariable & path, const ScriptVariable & title)
{
if (IsOpened(link)) {
int closed = CloseMods(link);
@@ -186,11 +209,8 @@ bool TexoProducerStrict::Link()
return true;
}
-bool TexoProducerStrict::PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
-)
+bool TexoProducerStrict::PutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
{
return Start() && TruePutImage(src, alt, title);
}
@@ -215,11 +235,16 @@ bool TexoProducerStrict::CloseBlock()
{
if (CloseMods()) {
switch (block) {
- case block_none: return true;
- case code: return CloseCode();
- case header: return CloseHeader(header_level);
- case paragraph: return CloseParagraph();
- case quote: return CloseQuote();
+ case block_none:
+ return true;
+ case code:
+ return CloseCode();
+ case header:
+ return CloseHeader(header_level);
+ case paragraph:
+ return CloseParagraph();
+ case quote:
+ return CloseQuote();
}
return true; // Inpossible, since all cases are in switch.
} else {
@@ -246,12 +271,18 @@ bool TexoProducerStrict::OpenMod(Mod mod)
mods[opened] = mod;
++opened;
switch (mod) {
- case bold: return StartBold();
- case italic: return StartItalic();
- case link: return StartLink(*link_link, *link_title);
- case mono: return StartMono();
- case strike: return StartStrike();
- case underline: return StartUnderline();
+ case bold:
+ return StartBold();
+ case italic:
+ return StartItalic();
+ case link:
+ return StartLink(*link_link, *link_title);
+ case mono:
+ return StartMono();
+ case strike:
+ return StartStrike();
+ case underline:
+ return StartUnderline();
}
return true; // Inpossible, since all cases are in switch.
}
@@ -259,12 +290,18 @@ bool TexoProducerStrict::OpenMod(Mod mod)
bool TexoProducerStrict::CloseMod(Mod mod)
{
switch (mod) {
- case bold: return CloseBold();
- case italic: return CloseItalic();
- case link: return CloseLink(*link_link, *link_title);
- case mono: return CloseMono();
- case strike: return CloseStrike();
- case underline: return CloseUnderline();
+ case bold:
+ return CloseBold();
+ case italic:
+ return CloseItalic();
+ case link:
+ return CloseLink(*link_link, *link_title);
+ case mono:
+ return CloseMono();
+ case strike:
+ return CloseStrike();
+ case underline:
+ return CloseUnderline();
}
return true; // Inpossible, since all cases are in switch.
}
diff --git a/src/producer.hpp b/src/producer.hpp
index f55cb91..6aacddf 100644
--- a/src/producer.hpp
+++ b/src/producer.hpp
@@ -10,7 +10,7 @@
*/
class TexoProducer {
public:
- TexoProducer(TexoExporter &exporter); // Setup exporter used for output.
+ TexoProducer(TexoExporter & exporter); // Setup exporter used for output.
virtual bool End(); // Notify producer, what input is ended.
@@ -37,22 +37,17 @@ public:
// Switch link to given or switch it off, if no one is given.
virtual bool Link(
- const ScriptVariable &link,
- const ScriptVariable &title
- );
+ const ScriptVariable & link, const ScriptVariable & title);
virtual bool Link();
- virtual bool PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
- );
+ virtual bool PutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title);
virtual bool PutHorizontalRule();
protected:
- TexoExporter &exporter;
+ TexoExporter & exporter;
};
@@ -64,7 +59,7 @@ protected:
*/
class TexoProducerStrict: public TexoProducer {
public:
- TexoProducerStrict(TexoExporter &exporter);
+ TexoProducerStrict(TexoExporter & exporter);
bool End();
@@ -85,14 +80,11 @@ public:
bool Strike();
bool Underline();
- bool Link(const ScriptVariable &path, const ScriptVariable &title);
+ bool Link(const ScriptVariable & path, const ScriptVariable & title);
bool Link();
- bool PutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
- );
+ bool PutImage(const ScriptVariable & src, const ScriptVariable & alt,
+ const ScriptVariable & title);
bool PutHorizontalRule();
@@ -123,47 +115,30 @@ protected:
virtual bool CloseUnderline() = 0;
virtual bool StartLink(
- const ScriptVariable &link,
- const ScriptVariable &title
- ) = 0;
+ const ScriptVariable & link, const ScriptVariable & title)
+ = 0;
virtual bool CloseLink(
- const ScriptVariable &link,
- const ScriptVariable &title
- ) = 0;
+ const ScriptVariable & link, const ScriptVariable & title)
+ = 0;
- virtual bool TruePutImage(
- const ScriptVariable &src,
- const ScriptVariable &alt,
- const ScriptVariable &title
- ) = 0;
+ virtual bool TruePutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
+ = 0;
virtual bool TruePutHorizontalRule() = 0;
private:
- enum Block {
- block_none = 0,
- code,
- header,
- paragraph,
- quote
- } block;
+ enum Block { block_none = 0, code, header, paragraph, quote } block;
int header_level;
- enum Mod {
- bold,
- italic,
- link,
- mono,
- strike,
- underline
- } mods[6];
+ enum Mod { bold, italic, link, mono, strike, underline } mods[6];
int opened;
- const ScriptVariable *link_link;
- const ScriptVariable *link_title;
+ const ScriptVariable * link_link;
+ const ScriptVariable * link_title;
bool Start(); // Open paragraph if no block is opened.
@@ -178,7 +153,120 @@ private:
// Close all opened mods sequentially, down to (including) last,
// returning count of closed mods, or negative number in case of error.
- int CloseMods(Mod last);
+ int CloseMods(Mod last);
+
+ // Close all opened mods.
+ bool CloseMods();
+
+ bool Reopen(int closed);
+
+ bool IsOpened(Mod mod) const;
+};
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Texo Strict Producer
+ * Converts switch-signal interface of Texo Producer into
+ * sequence of start/close signals with disjoint modificator sections,
+ * as well as block sections, which are provided on top level.
+ */
+class TexoProducerStrict: public TexoProducer {
+public:
+ TexoProducerStrict(TexoExporter & exporter);
+
+
+ bool End();
+
+
+ bool Put(char c);
+
+
+ bool Code();
+ bool Header(int level);
+ bool Paragraph();
+ bool Quote();
+
+
+ bool Bold();
+ bool Italic();
+ bool Mono();
+ bool Strike();
+ bool Underline();
+
+ bool Link(const ScriptVariable & path, const ScriptVariable & title);
+ bool Link();
+
+ bool PutImage(const ScriptVariable & src, const ScriptVariable & alt,
+ const ScriptVariable & title);
+ bool PutHorizontalRule();
+
+
+protected:
+ virtual bool TruePut(char c) = 0;
+
+ virtual bool StartCode() = 0;
+ virtual bool StartHeader(int level) = 0;
+ virtual bool StartParagraph() = 0;
+ virtual bool StartQuote() = 0;
+
+ virtual bool CloseCode() = 0;
+ virtual bool CloseHeader(int level) = 0;
+ virtual bool CloseParagraph() = 0;
+ virtual bool CloseQuote() = 0;
+
+
+ virtual bool StartBold() = 0;
+ virtual bool StartItalic() = 0;
+ virtual bool StartMono() = 0;
+ virtual bool StartStrike() = 0;
+ virtual bool StartUnderline() = 0;
+
+ virtual bool CloseBold() = 0;
+ virtual bool CloseItalic() = 0;
+ virtual bool CloseMono() = 0;
+ virtual bool CloseStrike() = 0;
+ virtual bool CloseUnderline() = 0;
+
+ virtual bool StartLink(
+ const ScriptVariable & link, const ScriptVariable & title)
+ = 0;
+ virtual bool CloseLink(
+ const ScriptVariable & link, const ScriptVariable & title)
+ = 0;
+
+
+ virtual bool TruePutImage(const ScriptVariable & src,
+ const ScriptVariable & alt, const ScriptVariable & title)
+ = 0;
+ virtual bool TruePutHorizontalRule() = 0;
+
+
+private:
+ enum Block { block_none = 0, code, header, paragraph, quote } block;
+
+ int header_level;
+
+
+ enum Mod { bold, italic, link, mono, strike, underline } mods[6];
+ int opened;
+
+ const ScriptVariable * link_link;
+ const ScriptVariable * link_title;
+
+
+ bool Start(); // Open paragraph if no block is opened.
+
+ bool CloseBlock();
+
+ bool SwitchMod(Mod mod);
+
+ bool OpenMod(Mod mod);
+
+ bool CloseMod(Mod mod);
+
+ // Close all opened mods sequentially, down to (including) last,
+ // returning count of closed mods, or negative number in case of error.
+ int CloseMods(Mod last);
// Close all opened mods.
bool CloseMods();
diff --git a/src/script.cpp b/src/script.cpp
index d335ff0..2892723 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -4,7 +4,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo String Exporter
*/
-TexoExporterString::TexoExporterString(ScriptVariable &str): str(str)
+TexoExporterString::TexoExporterString(ScriptVariable & str): str(str)
{}
@@ -14,7 +14,7 @@ bool TexoExporterString::Put(char c)
return true;
}
-bool TexoExporterString::Put(const ScriptVariable &addon)
+bool TexoExporterString::Put(const ScriptVariable & addon)
{
str += addon;
return true;
diff --git a/src/script.hpp b/src/script.hpp
index 77f75df..029047d 100644
--- a/src/script.hpp
+++ b/src/script.hpp
@@ -10,15 +10,15 @@
*/
class TexoExporterString: public TexoExporter {
public:
- TexoExporterString(ScriptVariable &str);
+ TexoExporterString(ScriptVariable & str);
bool Put(char c);
- bool Put(const ScriptVariable &addon);
+ bool Put(const ScriptVariable & addon);
private:
- ScriptVariable &str;
+ ScriptVariable & str;
};