]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
removed mark #pragmas
[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
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
8b04d4c4
VZ
98#include "wx/fontenc.h"
99
bddd7a8d 100class WXDLLIMPEXP_BASE wxCharacterSet;
e90c1d2a 101
bddd7a8d 102class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
6001e347 103{
6001e347 104public:
e90c1d2a 105 wxCSConv(const wxChar *charset);
8b04d4c4 106 wxCSConv(wxFontEncoding encoding);
54380f29 107 wxCSConv(const wxCSConv& conv);
e90c1d2a
VZ
108 virtual ~wxCSConv();
109
54380f29 110 wxCSConv& operator=(const wxCSConv& conv);
2b5f62a0 111
e90c1d2a
VZ
112 void LoadNow();
113
114 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
115 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
116
65e50848
JS
117 void Clear() ;
118
e90c1d2a 119private:
8b04d4c4
VZ
120 // common part of all ctors
121 void Init();
122
e90c1d2a
VZ
123 void SetName(const wxChar *charset);
124
dccce9ea
VZ
125 // note that we can't use wxString here because of compilation
126 // dependencies: we're included from wx/string.h
e90c1d2a
VZ
127 wxChar *m_name;
128 wxCharacterSet *m_cset;
8b04d4c4 129 wxFontEncoding m_encoding;
e90c1d2a 130 bool m_deferred;
6001e347
RR
131};
132
b1ac3b56 133#define wxConvFile wxConvLocal
bddd7a8d
VZ
134WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvLocal;
135WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvISO8859_1;
136WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347 137
e90c1d2a 138// ----------------------------------------------------------------------------
6001e347 139// filename conversion macros
e90c1d2a 140// ----------------------------------------------------------------------------
6001e347
RR
141
142// filenames are multibyte on Unix and probably widechar on Windows?
c4e41ce3 143#if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
e90c1d2a 144 #define wxMBFILES 1
6001e347 145#else
e90c1d2a 146 #define wxMBFILES 0
6001e347
RR
147#endif
148
80df4d31 149#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
150 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
151 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 152#else
e90c1d2a
VZ
153 #define wxFNCONV(name) name
154 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
155#endif
156
157#else
158 // !wxUSE_WCHAR_T
159
e90c1d2a 160// ----------------------------------------------------------------------------
6001e347 161// stand-ins in absence of wchar_t
e90c1d2a 162// ----------------------------------------------------------------------------
6001e347 163
bddd7a8d 164class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
165{
166public:
e90c1d2a
VZ
167 const char* cMB2WX(const char *psz) const { return psz; }
168 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 169};
e90c1d2a 170
8b04d4c4
VZ
171WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc,
172 wxConvFile,
173 wxConvLocal,
174 wxConvISO8859_1,
175 wxConvUTF8;
bddd7a8d 176WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347
RR
177
178#define wxFNCONV(name) name
e90c1d2a 179#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
180
181#endif
182 // wxUSE_WCHAR_T
183
e90c1d2a
VZ
184// ----------------------------------------------------------------------------
185// macros for the most common conversions
186// ----------------------------------------------------------------------------
187
188#if wxUSE_UNICODE
189 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
190 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
191#else // ANSI
192 // no conversions to do
193 #define wxConvertWX2MB(s) (s)
194 #define wxConvertMB2WX(s) (s)
195#endif // Unicode/ANSI
196
197#endif
6001e347
RR
198 // _WX_WXSTRCONVH__
199