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"
27 // ----------------------------------------------------------------------------
28 // wxMBConv (base class for conversions, using libc conversion itself)
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxMBConv
34 // the actual conversion takes place here
35 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
36 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
38 // No longer inline since BC++ complains.
39 const wxWCharBuffer
cMB2WC(const char *psz
) const;
40 const wxCharBuffer
cWC2MB(const wchar_t *psz
) const;
43 const wxWCharBuffer
cMB2WX(const char *psz
) const { return cMB2WC(psz
); }
44 const wxCharBuffer
cWX2MB(const wchar_t *psz
) const { return cWC2MB(psz
); }
45 const wchar_t* cWC2WX(const wchar_t *psz
) const { return psz
; }
46 const wchar_t* cMB2WC(const wchar_t *psz
) const { return psz
; }
48 const char* cMB2WX(const char *psz
) const { return psz
; }
49 const char* cWX2MB(const char *psz
) const { return psz
; }
50 const wxCharBuffer
cWC2WX(const wchar_t *psz
) const { return cWC2MB(psz
); }
51 const wxWCharBuffer
cWX2WC(const char *psz
) const { return cMB2WC(psz
); }
52 #endif // Unicode/ANSI
55 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
;
57 // ----------------------------------------------------------------------------
58 // wxMBConvFile (for conversion to filenames)
59 // ----------------------------------------------------------------------------
61 class WXDLLEXPORT wxMBConvFile
: public wxMBConv
64 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
65 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
68 WXDLLEXPORT_DATA(extern wxMBConvFile
) wxConvFile
;
70 // ----------------------------------------------------------------------------
71 // wxMBConvUTF7 (for conversion using UTF7 encoding)
72 // ----------------------------------------------------------------------------
74 class WXDLLEXPORT wxMBConvUTF7
: public wxMBConv
77 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
78 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
81 WXDLLEXPORT_DATA(extern wxMBConvUTF7
) wxConvUTF7
;
83 // ----------------------------------------------------------------------------
84 // wxMBConvUTF8 (for conversion using UTF8 encoding)
85 // ----------------------------------------------------------------------------
87 class WXDLLEXPORT wxMBConvUTF8
: public wxMBConv
90 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
91 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
94 WXDLLEXPORT_DATA(extern wxMBConvUTF8
) wxConvUTF8
;
98 // ----------------------------------------------------------------------------
99 // wxMBConvUTF8 (for conversion using GDK's internal converions)
100 // ----------------------------------------------------------------------------
102 class WXDLLEXPORT wxMBConvGdk
: public wxMBConv
105 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
106 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
109 WXDLLEXPORT_DATA(extern wxMBConvGdk
) wxConvGdk
;
113 // ----------------------------------------------------------------------------
114 // wxCSConv (for conversion based on loadable char sets)
115 // ----------------------------------------------------------------------------
117 class WXDLLEXPORT wxCharacterSet
;
119 class WXDLLEXPORT wxCSConv
: public wxMBConv
122 wxCSConv(const wxChar
*charset
);
127 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
128 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
131 void SetName(const wxChar
*charset
);
134 wxCharacterSet
*m_cset
;
138 WXDLLEXPORT_DATA(extern wxCSConv
) wxConvLocal
;
139 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
141 // ----------------------------------------------------------------------------
142 // filename conversion macros
143 // ----------------------------------------------------------------------------
145 // filenames are multibyte on Unix and probably widechar on Windows?
146 #if defined(__UNIX__) || defined(__BORLANDC__)
152 #if wxMBFILES && wxUSE_UNICODE
153 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
154 #define wxFNSTRINGCAST wxMBSTRINGCAST
156 #define wxFNCONV(name) name
157 #define wxFNSTRINGCAST WXSTRINGCAST
163 // ----------------------------------------------------------------------------
164 // stand-ins in absence of wchar_t
165 // ----------------------------------------------------------------------------
167 class WXDLLEXPORT wxMBConv
170 const char* cMB2WX(const char *psz
) const { return psz
; }
171 const char* cWX2MB(const char *psz
) const { return psz
; }
174 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
, wxConvFile
;
175 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
177 #define wxFNCONV(name) name
178 #define wxFNSTRINGCAST WXSTRINGCAST
183 // ----------------------------------------------------------------------------
184 // macros for the most common conversions
185 // ----------------------------------------------------------------------------
188 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
189 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
191 // no conversions to do
192 #define wxConvertWX2MB(s) (s)
193 #define wxConvertMB2WX(s) (s)
194 #endif // Unicode/ANSI