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(__APPLE__)
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 // wxCSConv (for conversion based on loadable char sets)
96 // ----------------------------------------------------------------------------
98 class WXDLLIMPEXP_BASE wxCharacterSet
;
100 class WXDLLIMPEXP_BASE wxCSConv
: public wxMBConv
103 wxCSConv(const wxChar
*charset
);
104 wxCSConv(const wxCSConv
& conv
);
107 wxCSConv
& operator=(const wxCSConv
& conv
);
111 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
112 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
117 void SetName(const wxChar
*charset
);
119 // note that we can't use wxString here because of compilation
120 // dependencies: we're included from wx/string.h
122 wxCharacterSet
*m_cset
;
126 #define wxConvFile wxConvLocal
127 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvLocal
;
128 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvISO8859_1
;
129 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
131 // ----------------------------------------------------------------------------
132 // filename conversion macros
133 // ----------------------------------------------------------------------------
135 // filenames are multibyte on Unix and probably widechar on Windows?
136 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
142 #if wxMBFILES && wxUSE_UNICODE
143 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
144 #define wxFNSTRINGCAST wxMBSTRINGCAST
146 #define wxFNCONV(name) name
147 #define wxFNSTRINGCAST WXSTRINGCAST
153 // ----------------------------------------------------------------------------
154 // stand-ins in absence of wchar_t
155 // ----------------------------------------------------------------------------
157 class WXDLLIMPEXP_BASE wxMBConv
160 const char* cMB2WX(const char *psz
) const { return psz
; }
161 const char* cWX2MB(const char *psz
) const { return psz
; }
164 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
) wxConvLibc
, wxConvFile
, wxConvLocal
, wxConvISO8859_1
, wxConvUTF8
;
165 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
167 #define wxFNCONV(name) name
168 #define wxFNSTRINGCAST WXSTRINGCAST
173 // ----------------------------------------------------------------------------
174 // macros for the most common conversions
175 // ----------------------------------------------------------------------------
178 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
179 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
181 // no conversions to do
182 #define wxConvertWX2MB(s) (s)
183 #define wxConvertMB2WX(s) (s)
184 #endif // Unicode/ANSI