summaryrefslogtreecommitdiffstats
path: root/src/kile/convert.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kile/convert.h')
-rw-r--r--src/kile/convert.h135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/kile/convert.h b/src/kile/convert.h
new file mode 100644
index 0000000..651d330
--- /dev/null
+++ b/src/kile/convert.h
@@ -0,0 +1,135 @@
+/***************************************************************************
+ begin : Sun Feb 29 2004
+ copyright : (C) 2004 by Jeroen Wijnhout
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef CONVERT_H
+#define CONVERT_H
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qmap.h>
+
+#include <kurl.h>
+
+namespace Kate { class Document; }
+
+class ConvertMap
+{
+protected:
+ ConvertMap(const QString & encoding);
+
+public:
+ const QString & encoding() const { return m_aliases[0]; }
+ const QString & isoName() const { return m_aliases[1]; }
+
+ QChar toEncoding(const QString & enc) { return m_toEncoding[enc]; }
+ QString toASCII(const QChar & c) { return m_toASCII[c]; }
+
+ void addPair(QChar c, const QString & enc);
+
+ bool canDecode(const QChar & c) { return ( m_toASCII.contains(c) > 0 ); }
+ bool canEncode(const QString & enc) { return ( m_toEncoding.contains(enc) > 0 ); }
+
+ bool load();
+
+private:
+ bool commandIsTerminated(const QString &);
+
+private:
+ QStringList m_aliases;
+ QMap<QChar, QString> m_toASCII;
+ QMap<QString, QChar> m_toEncoding;
+
+//static members
+public:
+ static bool create(const QString & encoding);
+ static QString encodingNameFor(const QString &);
+ static QString isoNameFor(const QString &);
+ static ConvertMap * mapFor(const QString & enc) { return g_maps[enc]; }
+
+private:
+ static QMap<QString, ConvertMap*> g_maps;
+};
+
+class ConvertIO
+{
+public:
+ ConvertIO(Kate::Document *doc);
+ virtual ~ConvertIO() {}
+
+ virtual void nextLine(); //read next line
+ virtual QString & currentLine();
+ virtual QString & text() { return m_text; }
+ virtual void writeText();
+ virtual uint current(); //current line number
+ virtual bool done();
+
+protected:
+ Kate::Document *m_doc;
+ QString m_text, m_line;
+ uint m_nLine;
+};
+
+class ConvertIOFile : public ConvertIO
+{
+public:
+ ConvertIOFile(Kate::Document *doc, const KURL & url);
+
+ void writeText();
+
+private:
+ KURL m_url;
+};
+
+class ConvertBase
+{
+public:
+ ConvertBase(const QString & encoding, ConvertIO * io);
+ virtual ~ConvertBase() {};
+
+public:
+ virtual bool convert();
+
+protected:
+ virtual bool setMap();
+
+ virtual QString mapNext(uint &);
+
+ ConvertIO *m_io;
+ QString m_encoding;
+ ConvertMap *m_map;
+};
+
+class ConvertEncToASCII : public ConvertBase
+{
+public:
+ ConvertEncToASCII(const QString & encoding, ConvertIO * io) : ConvertBase(encoding, io) {}
+
+protected:
+ QString mapNext(uint &);
+};
+
+class ConvertASCIIToEnc : public ConvertBase
+{
+public:
+ ConvertASCIIToEnc(const QString & encoding, ConvertIO * io) : ConvertBase(encoding, io) {}
+
+protected:
+ QString getSequence(uint &);
+ QString nextSequence(uint &);
+ bool isModifier(const QString &);
+ QString mapNext(uint &);
+};
+
+#endif