]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/strconv.h
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
35 // the actual conversion takes place here
36 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
37 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
39 // No longer inline since BC++ complains.
40 const wxWCharBuffer
cMB2WC(const char *psz
) const;
41 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
); }
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
;
97 //---------------------------------------------------------------------------
98 // wxMBConvUTF8 (for conversion using GDK's internal converions)
99 //---------------------------------------------------------------------------
101 class WXDLLEXPORT wxMBConvGdk
: public wxMBConv
104 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
105 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
108 WXDLLEXPORT_DATA(extern wxMBConvGdk
) wxConvGdk
;
111 //---------------------------------------------------------------------------
112 // wxCSConv (for conversion based on laodable char sets)
113 //---------------------------------------------------------------------------
115 class wxCharacterSet
;
117 class WXDLLEXPORT wxCSConv
: public wxMBConv
121 wxCharacterSet
*m_cset
;
123 void SetName(const wxChar
*charset
);
126 wxCSConv(const wxChar
*charset
);
129 virtual size_t MB2WC(wchar_t *buf
, const char *psz
, size_t n
) const;
130 virtual size_t WC2MB(char *buf
, const wchar_t *psz
, size_t n
) const;
133 WXDLLEXPORT_DATA(extern wxCSConv
) wxConvLocal
;
134 #define wxConv_local wxConvLocal
136 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
137 #define wxConv_current wxConvCurrent
139 //---------------------------------------------------------------------------
140 // filename conversion macros
141 //---------------------------------------------------------------------------
143 // filenames are multibyte on Unix and probably widechar on Windows?
144 #if defined(__UNIX__) || defined(__BORLANDC__)
151 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
152 #define FNSTRINGCAST MBSTRINGCAST
154 #define wxFNCONV(name) name
155 #define FNSTRINGCAST WXSTRINGCAST
161 //---------------------------------------------------------------------------
162 // stand-ins in absence of wchar_t
163 //---------------------------------------------------------------------------
165 class WXDLLEXPORT wxMBConv
168 const char* cMB2WX(const char *psz
) const { return psz
; }
169 const char* cWX2MB(const char *psz
) const { return psz
; }
171 WXDLLEXPORT_DATA(extern wxMBConv
) wxConvLibc
, wxConvFile
;
172 WXDLLEXPORT_DATA(extern wxMBConv
*) wxConvCurrent
;
174 #define wxFNCONV(name) name
175 #define FNSTRINGCAST WXSTRINGCAST