summaryrefslogtreecommitdiffstats
path: root/src/kile/convert.h
blob: 38575a7090a9b7d5203d7b29ce1cf147f341f535 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/***************************************************************************
    begin                : Sun Feb 29 2004
    copyright            : (C) 2004 by Jeroen Wijnhout
    email                : Jeroen.Wijnhout@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqstring.h>
#include <tqstringlist.h>
#include <tqmap.h>

#include <kurl.h>

namespace Kate { class Document; }

class ConvertMap
{
protected:
	ConvertMap(const TQString & encoding);

public:
	const TQString & encoding() const { return m_aliases[0]; }
	const TQString & isoName() const { return m_aliases[1]; }

	TQChar toEncoding(const TQString & enc) { return m_toEncoding[enc]; }
	TQString toASCII(const TQChar & c) { return m_toASCII[c]; }

	void addPair(TQChar c, const TQString & enc);

	bool canDecode(const TQChar & c) { return ( m_toASCII.contains(c) > 0 ); }
	bool canEncode(const TQString & enc) { return ( m_toEncoding.contains(enc) > 0 ); }

	bool load();

private:
	bool commandIsTerminated(const TQString &);

private:
	TQStringList				m_aliases;
	TQMap<TQChar, TQString>		m_toASCII;
	TQMap<TQString, TQChar>		m_toEncoding;

//static members
public:
	static bool create(const TQString & encoding);
	static TQString encodingNameFor(const TQString &);
	static TQString isoNameFor(const TQString &);
	static ConvertMap * mapFor(const TQString & enc) { return g_maps[enc]; }

private:
	static TQMap<TQString, ConvertMap*>	g_maps;
};

class ConvertIO
{
public:
	ConvertIO(Kate::Document *doc);
	virtual ~ConvertIO() {}

	virtual void nextLine(); //read next line
	virtual TQString & currentLine();
	virtual TQString & text() { return m_text; }
	virtual void writeText();
	virtual uint current(); //current line number
	virtual bool done();

protected:
	Kate::Document	*m_doc;
	TQString			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 TQString & encoding, ConvertIO * io);
	virtual ~ConvertBase() {};

public:
	virtual bool convert();

protected:
	virtual bool setMap();

	virtual TQString mapNext(uint &);

	ConvertIO		*m_io;
	TQString			m_encoding;
	ConvertMap		*m_map;
};

class ConvertEncToASCII : public ConvertBase
{
public:
	ConvertEncToASCII(const TQString & encoding, ConvertIO * io) : ConvertBase(encoding, io) {}

protected:
	TQString mapNext(uint &);
};

class ConvertASCIIToEnc : public ConvertBase
{
public:
	ConvertASCIIToEnc(const TQString & encoding, ConvertIO * io) : ConvertBase(encoding, io) {}

protected:
	TQString getSequence(uint &);
	TQString nextSequence(uint &);
	bool isModifier(const TQString &);
	TQString mapNext(uint &);
};

#endif