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 license
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WXSTRCONVH__
13 #define _WX_WXSTRCONVH__
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
59 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
;
61 // ----------------------------------------------------------------------------
62 // wxMBConvFile (for conversion to filenames)
63 // ----------------------------------------------------------------------------
65 class WXDLLEXPORT wxMBConvFile
: public wxMBConv
68 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
69 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
72 WXDLLEXPORT_DATA(extern wxMBConvFile
) wxConvFile
;
74 // ----------------------------------------------------------------------------
75 // wxMBConvUTF7 (for conversion using UTF7 encoding)
76 // ----------------------------------------------------------------------------
78 class WXDLLEXPORT wxMBConvUTF7
: public wxMBConv
81 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
82 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
85 WXDLLEXPORT_DATA(extern wxMBConvUTF7
) wxConvUTF7
;
87 // ----------------------------------------------------------------------------
88 // wxMBConvUTF8 (for conversion using UTF8 encoding)
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxMBConvUTF8
: public wxMBConv
94 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
95 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
98 WXDLLEXPORT_DATA(extern wxMBConvUTF8
) wxConvUTF8
;
102 // ----------------------------------------------------------------------------
103 // wxMBConvUTF8 (for conversion using GDK's internal converions)
104 // ----------------------------------------------------------------------------
106 class WXDLLEXPORT wxMBConvGdk
: public wxMBConv
109 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
110 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
113 WXDLLEXPORT_DATA(extern wxMBConvGdk
) wxConvGdk
;
117 // ----------------------------------------------------------------------------
118 // wxCSConv (for conversion based on loadable char sets)
119 // ----------------------------------------------------------------------------
121 class WXDLLEXPORT wxCharacterSet
;
123 class WXDLLEXPORT wxCSConv
: public wxMBConv
126 wxCSConv(const wxChar
*charset
);
131 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
132 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
135 void SetName(const wxChar
*charset
);
137 // note that we can't use wxString here because of compilation
138 // dependencies: we're included from wx/string.h
140 wxCharacterSet
*m_cset
;
144 WXDLLEXPORT_DATA(extern wxCSConv
) wxConvLocal
;
145 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
147 // ----------------------------------------------------------------------------
148 // filename conversion macros
149 // ----------------------------------------------------------------------------
151 // filenames are multibyte on Unix and probably widechar on Windows?
152 #if defined(__UNIX__) || defined(__BORLANDC__)
158 #if wxMBFILES && wxUSE_UNICODE
159 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
160 #define wxFNSTRINGCAST wxMBSTRINGCAST
162 #define wxFNCONV(name) name
163 #define wxFNSTRINGCAST WXSTRINGCAST
169 // ----------------------------------------------------------------------------
170 // stand-ins in absence of wchar_t
171 // ----------------------------------------------------------------------------
173 class WXDLLEXPORT wxMBConv
176 const char* cMB2WX(const char *psz
) const { return psz
; }
177 const char* cWX2MB(const char *psz
) const { return psz
; }
180 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
, wxConvFile
;
181 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
183 #define wxFNCONV(name) name
184 #define wxFNSTRINGCAST WXSTRINGCAST
189 // ----------------------------------------------------------------------------
190 // macros for the most common conversions
191 // ----------------------------------------------------------------------------
194 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
195 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
197 // no conversions to do
198 #define wxConvertWX2MB(s) (s)
199 #define wxConvertMB2WX(s) (s)
200 #endif // Unicode/ANSI