1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: conversion routines for char sets any Unicode
4 // Author: Robert Roebling, Ove Kaaven
8 // Copyright: (c) 1998 Ove Kaaven, Robert Roebling, Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WXSTRCONVH__
13 #define _WX_WXSTRCONVH__
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "strconv.h"
20 #include "wx/wxchar.h"
21 #include "wx/buffer.h"
23 #ifdef __DIGITALMARS__
27 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
35 // ----------------------------------------------------------------------------
36 // wxMBConv (base class for conversions, using libc conversion itself)
37 // ----------------------------------------------------------------------------
39 class WXDLLIMPEXP_BASE wxMBConv
42 // the actual conversion takes place here
43 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
44 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
46 // No longer inline since BC++ complains.
47 const wxWCharBuffer
cMB2WC(const char *psz
) const;
48 const wxCharBuffer
cWC2MB(const wchar_t *psz
) const;
51 const wxWCharBuffer
cMB2WX(const char *psz
) const { return cMB2WC(psz
); }
52 const wxCharBuffer
cWX2MB(const wchar_t *psz
) const { return cWC2MB(psz
); }
53 const wchar_t* cWC2WX(const wchar_t *psz
) const { return psz
; }
54 const wchar_t* cWX2WC(const wchar_t *psz
) const { return psz
; }
56 const char* cMB2WX(const char *psz
) const { return psz
; }
57 const char* cWX2MB(const char *psz
) const { return psz
; }
58 const wxCharBuffer
cWC2WX(const wchar_t *psz
) const { return cWC2MB(psz
); }
59 const wxWCharBuffer
cWX2WC(const char *psz
) const { return cMB2WC(psz
); }
60 #endif // Unicode/ANSI
62 // virtual dtor for any base class
66 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
) wxConvLibc
;
68 // ----------------------------------------------------------------------------
69 // wxMBConvUTF7 (for conversion using UTF7 encoding)
70 // ----------------------------------------------------------------------------
72 class WXDLLIMPEXP_BASE wxMBConvUTF7
: public wxMBConv
75 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
76 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
79 WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF7
) wxConvUTF7
;
81 // ----------------------------------------------------------------------------
82 // wxMBConvUTF8 (for conversion using UTF8 encoding)
83 // ----------------------------------------------------------------------------
85 class WXDLLIMPEXP_BASE wxMBConvUTF8
: public wxMBConv
88 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
89 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
92 WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF8
) wxConvUTF8
;
94 // ----------------------------------------------------------------------------
95 // wxMBConvUTF16LE (for conversion using UTF16 Little Endian encoding)
96 // ----------------------------------------------------------------------------
98 class WXDLLIMPEXP_BASE wxMBConvUTF16LE
: public wxMBConv
101 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
102 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
105 // ----------------------------------------------------------------------------
106 // wxMBConvUTF16BE (for conversion using UTF16 Big Endian encoding)
107 // ----------------------------------------------------------------------------
109 class WXDLLIMPEXP_BASE wxMBConvUTF16BE
: public wxMBConv
112 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
113 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
116 // ----------------------------------------------------------------------------
117 // wxMBConvUCS4LE (for conversion using UTF32 Little Endian encoding)
118 // ----------------------------------------------------------------------------
120 class WXDLLIMPEXP_BASE wxMBConvUTF32LE
: public wxMBConv
123 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
124 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
127 // ----------------------------------------------------------------------------
128 // wxMBConvUCS4BE (for conversion using UTF32 Big Endian encoding)
129 // ----------------------------------------------------------------------------
131 class WXDLLIMPEXP_BASE wxMBConvUTF32BE
: public wxMBConv
134 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
135 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
138 // ----------------------------------------------------------------------------
139 // wxCSConv (for conversion based on loadable char sets)
140 // ----------------------------------------------------------------------------
142 #include "wx/fontenc.h"
144 class WXDLLIMPEXP_BASE wxCharacterSet
;
146 class WXDLLIMPEXP_BASE wxCSConv
: public wxMBConv
149 wxCSConv(const wxChar
*charset
);
150 wxCSConv(wxFontEncoding encoding
);
151 wxCSConv(const wxCSConv
& conv
);
154 wxCSConv
& operator=(const wxCSConv
& conv
);
158 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
159 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
164 // common part of all ctors
167 void SetName(const wxChar
*charset
);
169 // note that we can't use wxString here because of compilation
170 // dependencies: we're included from wx/string.h
172 wxCharacterSet
*m_cset
;
173 wxFontEncoding m_encoding
;
177 #define wxConvFile wxConvLocal
178 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvLocal
;
179 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvISO8859_1
;
180 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
182 // ----------------------------------------------------------------------------
183 // filename conversion macros
184 // ----------------------------------------------------------------------------
186 // filenames are multibyte on Unix and probably widechar on Windows?
187 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
193 #if wxMBFILES && wxUSE_UNICODE
194 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
195 #define wxFNSTRINGCAST wxMBSTRINGCAST
197 #define wxFNCONV(name) name
198 #define wxFNSTRINGCAST WXSTRINGCAST
204 // ----------------------------------------------------------------------------
205 // stand-ins in absence of wchar_t
206 // ----------------------------------------------------------------------------
208 class WXDLLIMPEXP_BASE wxMBConv
211 const char* cMB2WX(const char *psz
) const { return psz
; }
212 const char* cWX2MB(const char *psz
) const { return psz
; }
215 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
) wxConvLibc
,
220 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
222 #define wxFNCONV(name) name
223 #define wxFNSTRINGCAST WXSTRINGCAST
228 // ----------------------------------------------------------------------------
229 // macros for the most common conversions
230 // ----------------------------------------------------------------------------
233 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
234 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
236 // no conversions to do
237 #define wxConvertWX2MB(s) (s)
238 #define wxConvertMB2WX(s) (s)
239 #endif // Unicode/ANSI