File: convert.h

package info (click to toggle)
turqstat 3.0-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 2,112 kB
  • ctags: 1,328
  • sloc: cpp: 17,929; perl: 252; makefile: 223; ansic: 75; sh: 16
file content (144 lines) | stat: -rw-r--r-- 4,064 bytes parent folder | download
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
136
137
138
139
140
141
142
143
144
// Copyright (c) 2001-2005 Peter Karlsson
//
// 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, version 2
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef __CONVERT_H
#define __CONVERT_H

#ifdef HAVE_WORKING_WSTRING
# define __ENABLE_WSTRING
# include <wchar.h>
#else
# include "utility.h"
#endif
#include <string>

#if !defined(HAVE_IMPLICIT_NAMESPACE)
using namespace std;
#endif

/**
 * Class used to decode character data from a legacy character set. It converts
 * it into Unicode for internal use.
 */
class Decoder
{
public:
    /**
     * Identify the character set used in a Fidonet text and return the
     * appropriate Decoder object.
     * @param kludges Kludges for this message.
     * @return Decoder object for this character set. NULL if unknown.
     */
    static Decoder *GetDecoderByKludges(const char *kludges);

    /**
     * Identify the character set used in a Usenet text and return the
     * appropriate Decoder object.
     * @param headers Headers for this message.
     * @return Decoder object for this character set. NULL if unknown.
     */
    static Decoder *GetDecoderByMIMEHeaders(const char *headers);

    /**
     * Get a Decoder object for converting into Unicode for a specified
     * character set. The name can be given using the Fidonet or MIME
     * name of the character set. If in conflict, the Fidonet name takes
     * precedence.
     * @param charset Name of character set.
     * @return Decoder object for this character set.
     */
    static Decoder *GetDecoderByName(const char *charset);

    /**
     * Decode character data.
     * @param input Legacy encoded data to decode.
     * @return Unicode version of data.
     */
    virtual wstring Decode(const string &input) = 0;

    /**
     * Virtual destructor to avoid compiler warnings.
     */
    virtual ~Decoder() {}
};

struct reversemap;

/**
 * Class used to encode character data into a legacy character set. It converts
 * it from Unicode for external use.
 */
class Encoder
{
public:
    /**
     * Get an Encoder object for converting from Unicode to a specified
     * character set. The name can be given using the Fidonet or MIME
     * name of the character set. If in conflict, the Fidonet name takes
     * precedence.
     * @param charset Name of character set.
     * @return Encoder object for this character set.
     */
    static Encoder *GetEncoderByName(const string &charset);

    /**
     * Encode character data.
     * @param input Unicode data to encode.
     * @return Legacy version of data.
     */
    virtual string Encode(const wstring &input) = 0;

    /**
     * Virtual destructor to avoid compiler warnings.
     */
    virtual ~Encoder() {}
};

struct tablemap;

/**
 * Class used to enumerate all available character sets.
 */
class CharsetEnumerator
{
public:
    /**
     * Selection of available sets of character set names.
     */
    enum names_e { Fidonet, Usenet };

    /**
     * Create a character set enumerator object, enumerating the character
     * sets for the selected name space.
     * @param namespace Which character set names to use.
     */
    CharsetEnumerator(names_e);

    /**
     * Get next character set name in the enumeration list.
     * @return NULL when end of list is reached, otherwise name of next
     *         character set.
     */
    const char *Next();

private:
    /** Pointer to character set map we are enumerating. */
    const struct tablemap *map;

    /** Current enumeration index. */
    int current;
};

#endif