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
;
96 // ----------------------------------------------------------------------------
97 // wxMBConvUTF8 (for conversion using GDK's internal converions)
98 // ----------------------------------------------------------------------------
100 class WXDLLIMPEXP_BASE wxMBConvGdk
: public wxMBConv
103 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
104 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
107 WXDLLIMPEXP_DATA_BASE(extern wxMBConvGdk
) wxConvGdk
;
111 // ----------------------------------------------------------------------------
112 // wxCSConv (for conversion based on loadable char sets)
113 // ----------------------------------------------------------------------------
115 class WXDLLIMPEXP_BASE wxCharacterSet
;
117 class WXDLLIMPEXP_BASE wxCSConv
: public wxMBConv
120 wxCSConv(const wxChar
*charset
);
121 wxCSConv(const wxCSConv
& conv
);
124 wxCSConv
& operator=(const wxCSConv
& conv
);
128 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
129 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
134 void SetName(const wxChar
*charset
);
136 // note that we can't use wxString here because of compilation
137 // dependencies: we're included from wx/string.h
139 wxCharacterSet
*m_cset
;
143 #define wxConvFile wxConvLocal
144 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvLocal
;
145 WXDLLIMPEXP_DATA_BASE(extern wxCSConv
) wxConvISO8859_1
;
146 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
148 // ----------------------------------------------------------------------------
149 // filename conversion macros
150 // ----------------------------------------------------------------------------
152 // filenames are multibyte on Unix and probably widechar on Windows?
153 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
159 #if wxMBFILES && wxUSE_UNICODE
160 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
161 #define wxFNSTRINGCAST wxMBSTRINGCAST
163 #define wxFNCONV(name) name
164 #define wxFNSTRINGCAST WXSTRINGCAST
170 // ----------------------------------------------------------------------------
171 // stand-ins in absence of wchar_t
172 // ----------------------------------------------------------------------------
174 class WXDLLIMPEXP_BASE wxMBConv
177 const char* cMB2WX(const char *psz
) const { return psz
; }
178 const char* cWX2MB(const char *psz
) const { return psz
; }
181 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
) wxConvLibc
, wxConvFile
, wxConvLocal
, wxConvISO8859_1
, wxConvUTF8
;
182 WXDLLIMPEXP_DATA_BASE(extern wxMBConv
*) wxConvCurrent
;
184 #define wxFNCONV(name) name
185 #define wxFNSTRINGCAST WXSTRINGCAST
190 // ----------------------------------------------------------------------------
191 // macros for the most common conversions
192 // ----------------------------------------------------------------------------
195 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
196 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
198 // no conversions to do
199 #define wxConvertWX2MB(s) (s)
200 #define wxConvertMB2WX(s) (s)
201 #endif // Unicode/ANSI