]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/strconv.h
Removed unnecessary code from utilsunx.cpp
[wxWidgets.git] / include / wx / strconv.h
... / ...
CommitLineData
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#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
24# undef __BSEXCPT__
25#endif
26#include <stdlib.h>
27
28#if wxUSE_WCHAR_T
29
30// ----------------------------------------------------------------------------
31// wxMBConv (base class for conversions, using libc conversion itself)
32// ----------------------------------------------------------------------------
33
34class WXDLLEXPORT wxMBConv
35{
36public:
37 // the actual conversion takes place here
38 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
39 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
40
41 // No longer inline since BC++ complains.
42 const wxWCharBuffer cMB2WC(const char *psz) const;
43 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
44
45#if wxUSE_UNICODE
46 const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
47 const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
48 const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
49 const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
50#else // ANSI
51 const char* cMB2WX(const char *psz) const { return psz; }
52 const char* cWX2MB(const char *psz) const { return psz; }
53 const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
54 const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
55#endif // Unicode/ANSI
56};
57
58WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
59
60// ----------------------------------------------------------------------------
61// wxMBConvFile (for conversion to filenames)
62// ----------------------------------------------------------------------------
63
64class WXDLLEXPORT wxMBConvFile : public wxMBConv
65{
66public:
67 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
68 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
69};
70
71WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
72
73// ----------------------------------------------------------------------------
74// wxMBConvUTF7 (for conversion using UTF7 encoding)
75// ----------------------------------------------------------------------------
76
77class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
78{
79public:
80 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
81 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
82};
83
84WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
85
86// ----------------------------------------------------------------------------
87// wxMBConvUTF8 (for conversion using UTF8 encoding)
88// ----------------------------------------------------------------------------
89
90class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
91{
92public:
93 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
94 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
95};
96
97WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
98
99#ifdef __WXGTK12__
100
101// ----------------------------------------------------------------------------
102// wxMBConvUTF8 (for conversion using GDK's internal converions)
103// ----------------------------------------------------------------------------
104
105class WXDLLEXPORT wxMBConvGdk : public wxMBConv
106{
107public:
108 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
109 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
110};
111
112WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
113
114#endif // wxGTK 1.2
115
116// ----------------------------------------------------------------------------
117// wxCSConv (for conversion based on loadable char sets)
118// ----------------------------------------------------------------------------
119
120class WXDLLEXPORT wxCharacterSet;
121
122class WXDLLEXPORT wxCSConv : public wxMBConv
123{
124public:
125 wxCSConv(const wxChar *charset);
126 virtual ~wxCSConv();
127
128 void LoadNow();
129
130 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
131 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
132
133private:
134 void SetName(const wxChar *charset);
135
136 wxChar *m_name;
137 wxCharacterSet *m_cset;
138 bool m_deferred;
139};
140
141WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
142WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
143
144// ----------------------------------------------------------------------------
145// filename conversion macros
146// ----------------------------------------------------------------------------
147
148// filenames are multibyte on Unix and probably widechar on Windows?
149#if defined(__UNIX__) || defined(__BORLANDC__)
150 #define wxMBFILES 1
151#else
152 #define wxMBFILES 0
153#endif
154
155#if wxMBFILES && wxUSE_UNICODE
156 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
157 #define wxFNSTRINGCAST wxMBSTRINGCAST
158#else
159 #define wxFNCONV(name) name
160 #define wxFNSTRINGCAST WXSTRINGCAST
161#endif
162
163#else
164 // !wxUSE_WCHAR_T
165
166// ----------------------------------------------------------------------------
167// stand-ins in absence of wchar_t
168// ----------------------------------------------------------------------------
169
170class WXDLLEXPORT wxMBConv
171{
172public:
173 const char* cMB2WX(const char *psz) const { return psz; }
174 const char* cWX2MB(const char *psz) const { return psz; }
175};
176
177WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
178WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
179
180#define wxFNCONV(name) name
181#define wxFNSTRINGCAST WXSTRINGCAST
182
183#endif
184 // wxUSE_WCHAR_T
185
186// ----------------------------------------------------------------------------
187// macros for the most common conversions
188// ----------------------------------------------------------------------------
189
190#if wxUSE_UNICODE
191 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
192 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
193#else // ANSI
194 // no conversions to do
195 #define wxConvertWX2MB(s) (s)
196 #define wxConvertMB2WX(s) (s)
197#endif // Unicode/ANSI
198
199#endif
200 // _WX_WXSTRCONVH__
201