From 8d9f52c4b192f0f477e954cfcce98ffbefa70c26 Mon Sep 17 00:00:00 2001 From: Symeon Huang Date: Sun, 25 Jan 2015 16:20:22 +0000 Subject: [PATCH] add an option to disable "strip" (trim). fix #2. --- lingoes.cpp | 6 +++++- lingoes.h | 3 ++- main.cpp | 10 +++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lingoes.cpp b/lingoes.cpp index 61ca52e..3ca0a29 100644 --- a/lingoes.cpp +++ b/lingoes.cpp @@ -25,7 +25,8 @@ #include #include -Lingoes::Lingoes(const QString &openFile) +Lingoes::Lingoes(const QString &openFile, bool _trim) : + trim(_trim) { ld2file = openFile; QFile file(ld2file); @@ -274,6 +275,9 @@ void Lingoes::readDefinitionData(const QByteArray &inflatedBytes, const int offs QString Lingoes::strip(const QString &xml) { + if (!trim) { + return xml; + } /* * Strip some formats characters. * TODO: strip HTML tags such as diff --git a/lingoes.h b/lingoes.h index d067dc3..c4e51bc 100644 --- a/lingoes.h +++ b/lingoes.h @@ -29,7 +29,7 @@ class Lingoes : public QObject Q_OBJECT public: - Lingoes(const QString &); + Lingoes(const QString &, bool _trim = true); void extractToFile(const QString &); int getInt(const int); int getInt(const QByteArray &, const int); @@ -39,6 +39,7 @@ Q_OBJECT QByteArray toHexString(const qint16); private: + const bool trim; int position; int inflated_pos; QString ld2file; diff --git a/main.cpp b/main.cpp index 237a8d6..da765fd 100644 --- a/main.cpp +++ b/main.cpp @@ -35,10 +35,13 @@ int main(int argc, char** argv) parser.addHelpOption(); parser.addVersionOption(); - QCommandLineOption ldxfile("i", "Input Lingoes dictionary file (default: input.ld2)", "input", "input.ld2"); - QCommandLineOption outfile("o", "Output extracted text file (default: output.txt)", "output", "output.txt"); + QCommandLineOption ldxfile("i", "Input Lingoes dictionary file (default: input.ld2).", "input", "input.ld2"); + QCommandLineOption outfile("o", "Output extracted text file (default: output.txt).", "output", "output.txt"); + QCommandLineOption notrim("disable-trim", "Disable HTML tag trimming."); + parser.addOption(ldxfile); parser.addOption(outfile); + parser.addOption(notrim); parser.process(app); @@ -50,7 +53,8 @@ int main(int argc, char** argv) } QString ld2file = ld2FileInfo.canonicalFilePath(); - Lingoes ldx(ld2file); + bool trim = !parser.isSet(notrim); + Lingoes ldx(ld2file, trim); ldx.extractToFile(parser.value(outfile)); return 0;