1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxEncodingConverter class for converting between different
5 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_ENCCONV_H_
11 #define _WX_ENCCONV_H_
13 #if defined(__GNUG__) && !defined(__APPLE__)
14 #pragma interface "encconv.h"
21 #include "wx/object.h"
22 #include "wx/fontenc.h"
23 #include "wx/dynarray.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
38 wxPLATFORM_CURRENT
= -1,
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 WX_DEFINE_ARRAY_INT(wxFontEncoding
, wxFontEncodingArray
);
52 //--------------------------------------------------------------------------------
53 // wxEncodingConverter
54 // This class is capable of converting strings between any two
55 // 8bit encodings/charsets. It can also convert from/to Unicode
56 //--------------------------------------------------------------------------------
58 class WXDLLEXPORT wxEncodingConverter
: public wxObject
62 wxEncodingConverter();
63 ~wxEncodingConverter() { if (m_Table
) delete[] m_Table
; }
65 // Initialize convertion. Both output or input encoding may
66 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
68 // All subsequent calls to Convert() will interpret it's argument
69 // as a string in input_enc encoding and will output string in
70 // output_enc encoding.
72 // You must call this method before calling Convert. You may call
73 // it more than once in order to switch to another conversion
75 // Method affects behaviour of Convert() in case input character
76 // cannot be converted because it does not exist in output encoding:
77 // wxCONVERT_STRICT --
78 // follow behaviour of GNU Recode - just copy unconvertable
79 // characters to output and don't change them (it's integer
80 // value will stay the same)
81 // wxCONVERT_SUBSTITUTE --
82 // try some (lossy) substitutions - e.g. replace
83 // unconvertable latin capitals with acute by ordinary
84 // capitals, replace en-dash or em-dash by '-' etc.
85 // both modes gurantee that output string will have same length
88 // Returns FALSE if given conversion is impossible, TRUE otherwise
89 // (conversion may be impossible either if you try to convert
90 // to Unicode with non-Unicode build of wxWindows or if input
91 // or output encoding is not supported.)
92 bool Init(wxFontEncoding input_enc
, wxFontEncoding output_enc
, int method
= wxCONVERT_STRICT
);
94 // Convert input string according to settings passed to Init.
95 // Note that you must call Init before using Convert!
96 void Convert(const char* input
, char* output
);
97 void Convert(char* str
) { Convert(str
, str
); }
98 wxString
Convert(const wxString
& input
);
101 void Convert(const char* input
, wchar_t* output
);
102 void Convert(const wchar_t* input
, char* output
);
103 void Convert(const wchar_t* input
, wchar_t* output
);
104 void Convert(wchar_t* str
) { Convert(str
, str
); }
106 // Return equivalent(s) for given font that are used
107 // under given platform. wxPLATFORM_CURRENT means the plaform
108 // this binary was compiled for
111 // current platform enc returned value
112 // -----------------------------------------------------
113 // unix CP1250 {ISO8859_2}
115 // windows ISO8859_2 {CP1250}
117 // Equivalence is defined in terms of convertibility:
118 // 2 encodings are equivalent if you can convert text between
119 // then without loosing information (it may - and will - happen
120 // that you loose special chars like quotation marks or em-dashes
121 // but you shouldn't loose any diacritics and language-specific
122 // characters when converting between equivalent encodings).
124 // Convert() method is not limited to converting between
125 // equivalent encodings, it can convert between arbitrary
128 // Remember that this function does _NOT_ check for presence of
129 // fonts in system. It only tells you what are most suitable
130 // encodings. (It usually returns only one encoding)
132 // Note that argument enc itself may be present in returned array!
133 // (so that you can -- as a side effect -- detect whether the
134 // encoding is native for this platform or not)
135 static wxFontEncodingArray
GetPlatformEquivalents(wxFontEncoding enc
, int platform
= wxPLATFORM_CURRENT
);
137 // Similar to GetPlatformEquivalent, but this one will return ALL
138 // equivalent encodings, regardless the platform, including itself.
139 static wxFontEncodingArray
GetAllEquivalents(wxFontEncoding enc
);
148 bool m_UnicodeInput
, m_UnicodeOutput
;
153 #endif // wxUSE_FONTMAP
155 #endif // _WX_ENCCONV_H_