1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxEncodingConverter class for converting between different
5 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
14 #pragma interface "encconv.h"
19 #include "wx/dynarray.h"
30 wxPLATFORM_CURRENT
= -1,
38 WX_DEFINE_ARRAY(wxFontEncoding
, wxFontEncodingArray
);
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 //--------------------------------------------------------------------------------
47 class WXDLLEXPORT wxEncodingConverter
: public wxObject
51 wxEncodingConverter();
52 ~wxEncodingConverter() { if (m_Table
) delete[] m_Table
; }
54 // Initialize convertion. Both output or input encoding may
55 // be wxFONTENCODING_UNICODE, but only if wxUSE_UNICODE is set to 1.
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.
61 // You must call this method before calling Convert. You may call
62 // it more than once in order to switch to another conversion
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
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
);
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
);
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
); }
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
100 // current platform enc returned value
101 // -----------------------------------------------------
102 // unix CP1250 {ISO8859_2}
104 // windows ISO8859_2 {CP1250}
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).
113 // Convert() method is not limited to converting between
114 // equivalent encodings, it can convert between arbitrary
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)
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
);
126 // Similar to GetPlatformEquivalent, but this one will return ALL
127 // equivalent encodings, regardless the platform, including itself.
128 static wxFontEncodingArray
GetAllEquivalents(wxFontEncoding enc
);
133 bool m_UnicodeInput
, m_UnicodeOutput
;
139 #endif // __ENCCONV_H__