]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
expat define MACOS_CLASSIC added
[wxWidgets.git] / include / wx / strconv.h
CommitLineData
6001e347
RR
1///////////////////////////////////////////////////////////////////////////////
2// Name: strconv.h
3// Purpose: conversion routines for char sets any Unicode
4// Author: Robert Roebling, Ove Kaaven
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Ove Kaaven, Robert Roebling, Vadim Zeitlin
371a5b4e 9// Licence: wxWindows licence
6001e347
RR
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WXSTRCONVH__
13#define _WX_WXSTRCONVH__
14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
6001e347
RR
16 #pragma interface "strconv.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/wxchar.h"
21#include "wx/buffer.h"
22
7db39dd6
CE
23#ifdef __DIGITALMARS__
24#include "typeinfo.h"
25#endif
26
9dea36ef
DW
27#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
28# undef __BSEXCPT__
29#endif
dccce9ea 30
6001e347
RR
31#include <stdlib.h>
32
33#if wxUSE_WCHAR_T
34
e90c1d2a 35// ----------------------------------------------------------------------------
6001e347 36// wxMBConv (base class for conversions, using libc conversion itself)
e90c1d2a 37// ----------------------------------------------------------------------------
6001e347 38
bddd7a8d 39class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
40{
41public:
e90c1d2a
VZ
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;
45
46 // No longer inline since BC++ complains.
47 const wxWCharBuffer cMB2WC(const char *psz) const;
48 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
6001e347 49
6001e347 50#if wxUSE_UNICODE
e90c1d2a
VZ
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; }
f6bcfd97 54 const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
e90c1d2a
VZ
55#else // ANSI
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
2b5f62a0
VZ
61
62 // virtual dtor for any base class
63 virtual ~wxMBConv();
6001e347
RR
64};
65
bddd7a8d 66WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc;
6001e347 67
e90c1d2a 68// ----------------------------------------------------------------------------
6001e347 69// wxMBConvUTF7 (for conversion using UTF7 encoding)
e90c1d2a 70// ----------------------------------------------------------------------------
6001e347 71
bddd7a8d 72class WXDLLIMPEXP_BASE wxMBConvUTF7 : public wxMBConv
6001e347
RR
73{
74public:
e90c1d2a
VZ
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;
6001e347
RR
77};
78
bddd7a8d 79WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF7) wxConvUTF7;
6001e347 80
e90c1d2a 81// ----------------------------------------------------------------------------
6001e347 82// wxMBConvUTF8 (for conversion using UTF8 encoding)
e90c1d2a 83// ----------------------------------------------------------------------------
6001e347 84
bddd7a8d 85class WXDLLIMPEXP_BASE wxMBConvUTF8 : public wxMBConv
6001e347
RR
86{
87public:
e90c1d2a
VZ
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;
6001e347
RR
90};
91
bddd7a8d 92WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF8) wxConvUTF8;
6001e347 93
e90c1d2a
VZ
94// ----------------------------------------------------------------------------
95// wxCSConv (for conversion based on loadable char sets)
96// ----------------------------------------------------------------------------
6001e347 97
bddd7a8d 98class WXDLLIMPEXP_BASE wxCharacterSet;
e90c1d2a 99
bddd7a8d 100class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
6001e347 101{
6001e347 102public:
e90c1d2a 103 wxCSConv(const wxChar *charset);
54380f29 104 wxCSConv(const wxCSConv& conv);
e90c1d2a
VZ
105 virtual ~wxCSConv();
106
54380f29 107 wxCSConv& operator=(const wxCSConv& conv);
2b5f62a0 108
e90c1d2a
VZ
109 void LoadNow();
110
111 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
112 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
113
65e50848
JS
114 void Clear() ;
115
e90c1d2a
VZ
116private:
117 void SetName(const wxChar *charset);
118
dccce9ea
VZ
119 // note that we can't use wxString here because of compilation
120 // dependencies: we're included from wx/string.h
e90c1d2a
VZ
121 wxChar *m_name;
122 wxCharacterSet *m_cset;
123 bool m_deferred;
6001e347
RR
124};
125
b1ac3b56 126#define wxConvFile wxConvLocal
bddd7a8d
VZ
127WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvLocal;
128WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvISO8859_1;
129WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347 130
e90c1d2a 131// ----------------------------------------------------------------------------
6001e347 132// filename conversion macros
e90c1d2a 133// ----------------------------------------------------------------------------
6001e347
RR
134
135// filenames are multibyte on Unix and probably widechar on Windows?
c4e41ce3 136#if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
e90c1d2a 137 #define wxMBFILES 1
6001e347 138#else
e90c1d2a 139 #define wxMBFILES 0
6001e347
RR
140#endif
141
80df4d31 142#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
143 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
144 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 145#else
e90c1d2a
VZ
146 #define wxFNCONV(name) name
147 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
148#endif
149
150#else
151 // !wxUSE_WCHAR_T
152
e90c1d2a 153// ----------------------------------------------------------------------------
6001e347 154// stand-ins in absence of wchar_t
e90c1d2a 155// ----------------------------------------------------------------------------
6001e347 156
bddd7a8d 157class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
158{
159public:
e90c1d2a
VZ
160 const char* cMB2WX(const char *psz) const { return psz; }
161 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 162};
e90c1d2a 163
bddd7a8d
VZ
164WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc, wxConvFile, wxConvLocal, wxConvISO8859_1, wxConvUTF8;
165WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347
RR
166
167#define wxFNCONV(name) name
e90c1d2a 168#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
169
170#endif
171 // wxUSE_WCHAR_T
172
e90c1d2a
VZ
173// ----------------------------------------------------------------------------
174// macros for the most common conversions
175// ----------------------------------------------------------------------------
176
177#if wxUSE_UNICODE
178 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
179 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
180#else // ANSI
181 // no conversions to do
182 #define wxConvertWX2MB(s) (s)
183 #define wxConvertMB2WX(s) (s)
184#endif // Unicode/ANSI
185
186#endif
6001e347
RR
187 // _WX_WXSTRCONVH__
188