1999-08-08 11:31:18 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: strconv.h
|
|
|
|
// Purpose: conversion routines for char sets any Unicode
|
|
|
|
// Author: Robert Roebling, Ove Kaaven
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Ove Kaaven, Robert Roebling, Vadim Zeitlin
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_WXSTRCONVH__
|
|
|
|
#define _WX_WXSTRCONVH__
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "strconv.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/wxchar.h"
|
|
|
|
#include "wx/buffer.h"
|
|
|
|
|
1999-12-14 23:32:53 +00:00
|
|
|
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
|
|
|
|
# undef __BSEXCPT__
|
|
|
|
#endif
|
2001-05-31 20:27:37 +00:00
|
|
|
|
1999-08-08 11:31:18 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#if wxUSE_WCHAR_T
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// wxMBConv (base class for conversions, using libc conversion itself)
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
|
|
|
class WXDLLEXPORT wxMBConv
|
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
// the actual conversion takes place here
|
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
|
|
|
|
|
|
|
// No longer inline since BC++ complains.
|
|
|
|
const wxWCharBuffer cMB2WC(const char *psz) const;
|
|
|
|
const wxCharBuffer cWC2MB(const wchar_t *psz) const;
|
1999-08-08 11:31:18 +00:00
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
1999-10-04 20:15:38 +00:00
|
|
|
const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
|
|
|
|
const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
|
|
|
|
const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
|
2000-07-15 19:51:35 +00:00
|
|
|
const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
|
1999-10-04 20:15:38 +00:00
|
|
|
#else // ANSI
|
|
|
|
const char* cMB2WX(const char *psz) const { return psz; }
|
|
|
|
const char* cWX2MB(const char *psz) const { return psz; }
|
|
|
|
const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
|
|
|
|
const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
|
|
|
|
#endif // Unicode/ANSI
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// wxMBConvFile (for conversion to filenames)
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxMBConvFile : public wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// wxMBConvUTF7 (for conversion using UTF7 encoding)
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// wxMBConvUTF8 (for conversion using UTF8 encoding)
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
|
|
|
|
|
|
|
|
#ifdef __WXGTK12__
|
1999-10-04 20:15:38 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// wxMBConvUTF8 (for conversion using GDK's internal converions)
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxMBConvGdk : public wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
#endif // wxGTK 1.2
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxCSConv (for conversion based on loadable char sets)
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxCharacterSet;
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxCSConv : public wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
wxCSConv(const wxChar *charset);
|
|
|
|
virtual ~wxCSConv();
|
|
|
|
|
|
|
|
void LoadNow();
|
|
|
|
|
|
|
|
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
|
|
|
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetName(const wxChar *charset);
|
|
|
|
|
2001-05-31 20:27:37 +00:00
|
|
|
// note that we can't use wxString here because of compilation
|
|
|
|
// dependencies: we're included from wx/string.h
|
1999-10-04 20:15:38 +00:00
|
|
|
wxChar *m_name;
|
|
|
|
wxCharacterSet *m_cset;
|
|
|
|
bool m_deferred;
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// filename conversion macros
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
|
|
|
// filenames are multibyte on Unix and probably widechar on Windows?
|
|
|
|
#if defined(__UNIX__) || defined(__BORLANDC__)
|
1999-10-04 20:15:38 +00:00
|
|
|
#define wxMBFILES 1
|
1999-08-08 11:31:18 +00:00
|
|
|
#else
|
1999-10-04 20:15:38 +00:00
|
|
|
#define wxMBFILES 0
|
1999-08-08 11:31:18 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-28 10:29:51 +00:00
|
|
|
#if wxMBFILES && wxUSE_UNICODE
|
1999-10-04 20:15:38 +00:00
|
|
|
#define wxFNCONV(name) wxConvFile.cWX2MB(name)
|
|
|
|
#define wxFNSTRINGCAST wxMBSTRINGCAST
|
1999-08-08 11:31:18 +00:00
|
|
|
#else
|
1999-10-04 20:15:38 +00:00
|
|
|
#define wxFNCONV(name) name
|
|
|
|
#define wxFNSTRINGCAST WXSTRINGCAST
|
1999-08-08 11:31:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
// !wxUSE_WCHAR_T
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
// stand-ins in absence of wchar_t
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-08-08 11:31:18 +00:00
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
class WXDLLEXPORT wxMBConv
|
1999-08-08 11:31:18 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-10-04 20:15:38 +00:00
|
|
|
const char* cMB2WX(const char *psz) const { return psz; }
|
|
|
|
const char* cWX2MB(const char *psz) const { return psz; }
|
1999-08-08 11:31:18 +00:00
|
|
|
};
|
1999-10-04 20:15:38 +00:00
|
|
|
|
1999-08-08 11:31:18 +00:00
|
|
|
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
|
|
|
|
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
|
|
|
|
|
|
|
#define wxFNCONV(name) name
|
1999-10-04 20:15:38 +00:00
|
|
|
#define wxFNSTRINGCAST WXSTRINGCAST
|
1999-08-08 11:31:18 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
// wxUSE_WCHAR_T
|
|
|
|
|
1999-10-04 20:15:38 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// macros for the most common conversions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
#define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
|
|
|
|
#define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
|
|
|
|
#else // ANSI
|
|
|
|
// no conversions to do
|
|
|
|
#define wxConvertWX2MB(s) (s)
|
|
|
|
#define wxConvertMB2WX(s) (s)
|
|
|
|
#endif // Unicode/ANSI
|
|
|
|
|
|
|
|
#endif
|
1999-08-08 11:31:18 +00:00
|
|
|
// _WX_WXSTRCONVH__
|
|
|
|
|