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 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
31 // ----------------------------------------------------------------------------
32 // wxMBConv (base class for conversions, using libc conversion itself)
33 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxMBConv
38 // the actual conversion takes place here
39 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
40 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
42 // No longer inline since BC++ complains.
43 const wxWCharBuffer
cMB2WC(const char *psz
) const;
44 const wxCharBuffer
cWC2MB(const wchar_t *psz
) const;
47 const wxWCharBuffer
cMB2WX(const char *psz
) const { return cMB2WC(psz
); }
48 const wxCharBuffer
cWX2MB(const wchar_t *psz
) const { return cWC2MB(psz
); }
49 const wchar_t* cWC2WX(const wchar_t *psz
) const { return psz
; }
50 const wchar_t* cWX2WC(const wchar_t *psz
) const { return psz
; }
52 const char* cMB2WX(const char *psz
) const { return psz
; }
53 const char* cWX2MB(const char *psz
) const { return psz
; }
54 const wxCharBuffer
cWC2WX(const wchar_t *psz
) const { return cWC2MB(psz
); }
55 const wxWCharBuffer
cWX2WC(const char *psz
) const { return cMB2WC(psz
); }
56 #endif // Unicode/ANSI
58 // virtual dtor for any base class
62 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
;
64 // ----------------------------------------------------------------------------
65 // wxMBConvUTF7 (for conversion using UTF7 encoding)
66 // ----------------------------------------------------------------------------
68 class WXDLLEXPORT wxMBConvUTF7
: public wxMBConv
71 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
72 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
75 WXDLLEXPORT_DATA(extern wxMBConvUTF7
) wxConvUTF7
;
77 // ----------------------------------------------------------------------------
78 // wxMBConvUTF8 (for conversion using UTF8 encoding)
79 // ----------------------------------------------------------------------------
81 class WXDLLEXPORT wxMBConvUTF8
: public wxMBConv
84 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
85 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
88 WXDLLEXPORT_DATA(extern wxMBConvUTF8
) wxConvUTF8
;
92 // ----------------------------------------------------------------------------
93 // wxMBConvUTF8 (for conversion using GDK's internal converions)
94 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxMBConvGdk
: public wxMBConv
99 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
100 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
103 WXDLLEXPORT_DATA(extern wxMBConvGdk
) wxConvGdk
;
107 // ----------------------------------------------------------------------------
108 // wxCSConv (for conversion based on loadable char sets)
109 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxCharacterSet
;
113 class WXDLLEXPORT wxCSConv
: public wxMBConv
116 wxCSConv(const wxChar
*charset
);
117 wxCSConv(const wxCSConv
& conv
);
120 wxCSConv
& operator=(const wxCSConv
& conv
);
124 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
125 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
130 void SetName(const wxChar
*charset
);
132 // note that we can't use wxString here because of compilation
133 // dependencies: we're included from wx/string.h
135 wxCharacterSet
*m_cset
;
139 #define wxConvFile wxConvLocal
140 WXDLLEXPORT_DATA(extern wxCSConv
) wxConvLocal
;
141 WXDLLEXPORT_DATA(extern wxCSConv
) wxConvISO8859_1
;
142 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
144 // ----------------------------------------------------------------------------
145 // filename conversion macros
146 // ----------------------------------------------------------------------------
148 // filenames are multibyte on Unix and probably widechar on Windows?
149 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
155 #if wxMBFILES && wxUSE_UNICODE
156 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
157 #define wxFNSTRINGCAST wxMBSTRINGCAST
159 #define wxFNCONV(name) name
160 #define wxFNSTRINGCAST WXSTRINGCAST
166 // ----------------------------------------------------------------------------
167 // stand-ins in absence of wchar_t
168 // ----------------------------------------------------------------------------
170 class WXDLLEXPORT wxMBConv
173 const char* cMB2WX(const char *psz
) const { return psz
; }
174 const char* cWX2MB(const char *psz
) const { return psz
; }
177 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
, wxConvFile
, wxConvLocal
, wxConvISO8859_1
, wxConvUTF8
;
178 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
180 #define wxFNCONV(name) name
181 #define wxFNSTRINGCAST WXSTRINGCAST
186 // ----------------------------------------------------------------------------
187 // macros for the most common conversions
188 // ----------------------------------------------------------------------------
191 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
192 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
194 // no conversions to do
195 #define wxConvertWX2MB(s) (s)
196 #define wxConvertMB2WX(s) (s)
197 #endif // Unicode/ANSI