]> git.saurik.com Git - wxWidgets.git/blob - include/wx/strconv.h
Small optical changes for MSW
[wxWidgets.git] / include / wx / strconv.h
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
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXSTRCONVH__
13 #define _WX_WXSTRCONVH__
14
15 #ifdef __GNUG__
16 #pragma interface "strconv.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/wxchar.h"
21 #include "wx/buffer.h"
22
23 #include <stdlib.h>
24
25 #if wxUSE_WCHAR_T
26
27 //---------------------------------------------------------------------------
28 // wxMBConv (base class for conversions, using libc conversion itself)
29 //---------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxMBConv
32 {
33 public:
34
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;
38
39 // No longer inline since BC++ complains.
40 const wxWCharBuffer cMB2WC(const char *psz) const;
41 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
42 #if wxUSE_UNICODE
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; }
47 #else
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
53 };
54
55 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
56
57 //---------------------------------------------------------------------------
58 // wxMBConvFile (for conversion to filenames)
59 //---------------------------------------------------------------------------
60
61 class WXDLLEXPORT wxMBConvFile: public wxMBConv
62 {
63 public:
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;
66 };
67
68 WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
69
70 //---------------------------------------------------------------------------
71 // wxMBConvUTF7 (for conversion using UTF7 encoding)
72 //---------------------------------------------------------------------------
73
74 class WXDLLEXPORT wxMBConvUTF7: public wxMBConv
75 {
76 public:
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;
79 };
80
81 WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
82
83 //---------------------------------------------------------------------------
84 // wxMBConvUTF8 (for conversion using UTF8 encoding)
85 //---------------------------------------------------------------------------
86
87 class WXDLLEXPORT wxMBConvUTF8: public wxMBConv
88 {
89 public:
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;
92 };
93
94 WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
95
96 #ifdef __WXGTK12__
97 //---------------------------------------------------------------------------
98 // wxMBConvUTF8 (for conversion using GDK's internal converions)
99 //---------------------------------------------------------------------------
100
101 class WXDLLEXPORT wxMBConvGdk: public wxMBConv
102 {
103 public:
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;
106 };
107
108 WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
109 #endif
110
111 //---------------------------------------------------------------------------
112 // wxCSConv (for conversion based on laodable char sets)
113 //---------------------------------------------------------------------------
114
115 class wxCharacterSet;
116
117 class WXDLLEXPORT wxCSConv: public wxMBConv
118 {
119 private:
120 wxChar *m_name;
121 wxCharacterSet *m_cset;
122 bool m_deferred;
123 void SetName(const wxChar *charset);
124
125 public:
126 wxCSConv(const wxChar *charset);
127 virtual ~wxCSConv();
128 void LoadNow();
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;
131 };
132
133 WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
134 #define wxConv_local wxConvLocal
135
136 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
137 #define wxConv_current wxConvCurrent
138
139 //---------------------------------------------------------------------------
140 // filename conversion macros
141 //---------------------------------------------------------------------------
142
143 // filenames are multibyte on Unix and probably widechar on Windows?
144 #if defined(__UNIX__) || defined(__BORLANDC__)
145 #define wxMBFILES 1
146 #else
147 #define wxMBFILES 0
148 #endif
149
150 #if wxMBFILES
151 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
152 #define FNSTRINGCAST MBSTRINGCAST
153 #else
154 #define wxFNCONV(name) name
155 #define FNSTRINGCAST WXSTRINGCAST
156 #endif
157
158 #else
159 // !wxUSE_WCHAR_T
160
161 //---------------------------------------------------------------------------
162 // stand-ins in absence of wchar_t
163 //---------------------------------------------------------------------------
164
165 class WXDLLEXPORT wxMBConv
166 {
167 public:
168 const char* cMB2WX(const char *psz) const { return psz; }
169 const char* cWX2MB(const char *psz) const { return psz; }
170 };
171 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
172 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
173
174 #define wxFNCONV(name) name
175 #define FNSTRINGCAST WXSTRINGCAST
176
177 #endif
178 // wxUSE_WCHAR_T
179
180 #endif
181 // _WX_WXSTRCONVH__
182