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_
14 #pragma interface "encconv.h"
18 #include "wx/object.h"
19 #include "wx/fontenc.h"
20 #include "wx/dynarray.h"
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
35 wxPLATFORM_CURRENT
= -1,
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 WX_DEFINE_ARRAY(wxFontEncoding
, wxFontEncodingArray
);
49 //--------------------------------------------------------------------------------
50 // wxEncodingConverter
51 // This class is capable of converting strings between any two
52 // 8bit encodings/charsets. It can also convert from/to Unicode
53 //--------------------------------------------------------------------------------
55 class WXDLLEXPORT wxEncodingConverter
: public wxObject
59 wxEncodingConverter();
60 ~wxEncodingConverter() { if (m_Table
) delete[] m_Table
; }
62 // Initialize convertion. Both output or input encoding may
63 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
65 // All subsequent calls to Convert() will interpret it's argument
66 // as a string in input_enc encoding and will output string in
67 // output_enc encoding.
69 // You must call this method before calling Convert. You may call
70 // it more than once in order to switch to another conversion
72 // Method affects behaviour of Convert() in case input character
73 // cannot be converted because it does not exist in output encoding:
74 // wxCONVERT_STRICT --
75 // follow behaviour of GNU Recode - just copy unconvertable
76 // characters to output and don't change them (it's integer
77 // value will stay the same)
78 // wxCONVERT_SUBSTITUTE --
79 // try some (lossy) substitutions - e.g. replace
80 // unconvertable latin capitals with acute by ordinary
81 // capitals, replace en-dash or em-dash by '-' etc.
82 // both modes gurantee that output string will have same length
85 // Returns FALSE if given conversion is impossible, TRUE otherwise
86 // (conversion may be impossible either if you try to convert
87 // to Unicode with non-Unicode build of wxWindows or if input
88 // or output encoding is not supported.)
89 bool Init(wxFontEncoding input_enc
, wxFontEncoding output_enc
, int method
= wxCONVERT_STRICT
);
91 // Convert input string according to settings passed to Init.
92 // Note that you must call Init before using Convert!
93 void Convert(const char* input
, char* output
);
94 void Convert(char* str
) { Convert(str
, str
); }
95 wxString
Convert(const wxString
& input
);
98 void Convert(const char* input
, wchar_t* output
);
99 void Convert(const wchar_t* input
, char* output
);
100 void Convert(const wchar_t* input
, wchar_t* output
);
101 void Convert(wchar_t* str
) { Convert(str
, str
); }
103 // Return equivalent(s) for given font that are used
104 // under given platform. wxPLATFORM_CURRENT means the plaform
105 // this binary was compiled for
108 // current platform enc returned value
109 // -----------------------------------------------------
110 // unix CP1250 {ISO8859_2}
112 // windows ISO8859_2 {CP1250}
114 // Equivalence is defined in terms of convertibility:
115 // 2 encodings are equivalent if you can convert text between
116 // then without loosing information (it may - and will - happen
117 // that you loose special chars like quotation marks or em-dashes
118 // but you shouldn't loose any diacritics and language-specific
119 // characters when converting between equivalent encodings).
121 // Convert() method is not limited to converting between
122 // equivalent encodings, it can convert between arbitrary
125 // Remember that this function does _NOT_ check for presence of
126 // fonts in system. It only tells you what are most suitable
127 // encodings. (It usually returns only one encoding)
129 // Note that argument enc itself may be present in returned array!
130 // (so that you can -- as a side effect -- detect whether the
131 // encoding is native for this platform or not)
132 static wxFontEncodingArray
GetPlatformEquivalents(wxFontEncoding enc
, int platform
= wxPLATFORM_CURRENT
);
134 // Similar to GetPlatformEquivalent, but this one will return ALL
135 // equivalent encodings, regardless the platform, including itself.
136 static wxFontEncodingArray
GetAllEquivalents(wxFontEncoding enc
);
145 bool m_UnicodeInput
, m_UnicodeOutput
;
151 #endif // _WX_ENCCONV_H_