]> git.saurik.com Git - wxWidgets.git/blob - include/wx/encconv.h
Add exemple for redirecting cout
[wxWidgets.git] / include / wx / encconv.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: encconv.h
3 // Purpose: wxEncodingConverter class for converting between different
4 // font encodings
5 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __ENCCONV_H__
11 #define __ENCCONV_H__
12
13 #ifdef __GNUG__
14 #pragma interface "encconv.h"
15 #endif
16
17 #include "wx/defs.h"
18 #include "wx/font.h"
19 #include "wx/dynarray.h"
20
21
22
23 enum {
24 wxCONVERT_STRICT,
25 wxCONVERT_SUBSTITUTE
26 };
27
28
29 enum {
30 wxPLATFORM_CURRENT = -1,
31
32 wxPLATFORM_UNIX = 0,
33 wxPLATFORM_WINDOWS,
34 wxPLATFORM_OS2,
35 wxPLATFORM_MAC
36 };
37
38 WX_DEFINE_ARRAY(wxFontEncoding, wxFontEncodingArray);
39
40
41 //--------------------------------------------------------------------------------
42 // wxEncodingConverter
43 // This class is capable of converting strings between any two
44 // 8bit encodings/charsets. It can also convert from/to Unicode
45 //--------------------------------------------------------------------------------
46
47 class WXDLLEXPORT wxEncodingConverter : public wxObject
48 {
49 public:
50
51 wxEncodingConverter();
52 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
53
54 // Initialize convertion. Both output or input encoding may
55 // be wxFONTENCODING_UNICODE, but only if wxUSE_UNICODE is set to 1.
56 //
57 // All subsequent calls to Convert() will interpret it's argument
58 // as a string in input_enc encoding and will output string in
59 // output_enc encoding.
60 //
61 // You must call this method before calling Convert. You may call
62 // it more than once in order to switch to another conversion
63 //
64 // Method affects behaviour of Convert() in case input character
65 // cannot be converted because it does not exist in output encoding:
66 // wxCONVERT_STRICT --
67 // follow behaviour of GNU Recode - just copy unconvertable
68 // characters to output and don't change them (it's integer
69 // value will stay the same)
70 // wxCONVERT_SUBSTITUTE --
71 // try some (lossy) substitutions - e.g. replace
72 // unconvertable latin capitals with acute by ordinary
73 // capitals, replace en-dash or em-dash by '-' etc.
74 // both modes gurantee that output string will have same length
75 // as input string
76 //
77 // Returns FALSE if given conversion is impossible, TRUE otherwise
78 // (conversion may be impossible either if you try to convert
79 // to Unicode with non-Unicode build of wxWindows or if input
80 // or output encoding is not supported.)
81 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
82
83 // Convert input string according to settings passed to Init.
84 // Note that you must call Init before using Convert!
85 void Convert(const wxChar* input, wxChar* output);
86 void Convert(wxChar* str) { Convert(str, str); }
87 wxString Convert(const wxString& input);
88
89 #if wxUSE_UNICODE // otherwise wxChar === char
90 void Convert(const char* input, wxChar* output);
91 void Convert(const wxChar* input, char* output);
92 void Convert(const char* input, char* output);
93 void Convert(char* str) { Convert(str, str); }
94 #endif
95 // Return equivalent(s) for given font that are used
96 // under given platform. wxPLATFORM_CURRENT means the plaform
97 // this binary was compiled for
98 //
99 // Examples:
100 // current platform enc returned value
101 // -----------------------------------------------------
102 // unix CP1250 {ISO8859_2}
103 // unix ISO8859_2 {}
104 // windows ISO8859_2 {CP1250}
105 //
106 // Equivalence is defined in terms of convertibility:
107 // 2 encodings are equivalent if you can convert text between
108 // then without loosing information (it may - and will - happen
109 // that you loose special chars like quotation marks or em-dashes
110 // but you shouldn't loose any diacritics and language-specific
111 // characters when converting between equivalent encodings).
112 //
113 // Convert() method is not limited to converting between
114 // equivalent encodings, it can convert between arbitrary
115 // two encodings!
116 //
117 // Remember that this function does _NOT_ check for presence of
118 // fonts in system. It only tells you what are most suitable
119 // encodings. (It usually returns only one encoding)
120 //
121 // Note that argument enc itself may be present in returned array!
122 // (so that you can -- as a side effect -- detect whether the
123 // encoding is native for this platform or not)
124 static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc, int platform = wxPLATFORM_CURRENT);
125
126 // Similar to GetPlatformEquivalent, but this one will return ALL
127 // equivalent encodings, regardless the platform, including itself.
128 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
129
130 private:
131
132 wxChar *m_Table;
133 bool m_UnicodeInput, m_UnicodeOutput;
134 bool m_JustCopy;
135
136 };
137
138
139 #endif // __ENCCONV_H__
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156