Added strconv
Renamed zipstream -> zipstrm Updated makefiles etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3314 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
3f1aaa1635
commit
6001e347ba
@ -130,6 +130,7 @@ sckipc.cpp C S
|
||||
sckstrm.cpp C S
|
||||
socket.cpp C S
|
||||
stream.cpp C
|
||||
strconv.cpp C
|
||||
string.cpp C
|
||||
tbarbase.cpp C
|
||||
tbarsmpl.cpp C 16
|
||||
@ -150,7 +151,7 @@ wfstream.cpp C
|
||||
wincmn.cpp C
|
||||
wxchar.cpp C
|
||||
wxexpr.cpp C
|
||||
zipstream.cpp C
|
||||
zipstrm.cpp C
|
||||
zstream.cpp C
|
||||
|
||||
accel.cpp M
|
||||
@ -466,6 +467,7 @@ statbox.h I WX
|
||||
statline.h I WX
|
||||
stattext.h I WX
|
||||
statusbr.h I WX
|
||||
strconv.h I WX
|
||||
stream.h I WX
|
||||
string.h I WX
|
||||
tab.h I WX
|
||||
@ -507,7 +509,7 @@ wxexpr.h I WX
|
||||
wxhtml.h I WX
|
||||
wxprec.h I WX
|
||||
xpmhand.h I WX
|
||||
zipstream.h I WX
|
||||
zipstrm.h I WX
|
||||
zstream.h I WX
|
||||
|
||||
accel.h I GTK
|
||||
|
@ -147,6 +147,7 @@ wx_include_HEADERS = \
|
||||
stattext.h \
|
||||
statusbr.h \
|
||||
stream.h \
|
||||
strconv.h \
|
||||
string.h \
|
||||
tab.h \
|
||||
tabctrl.h \
|
||||
@ -187,7 +188,7 @@ wx_include_HEADERS = \
|
||||
wxhtml.h \
|
||||
wxprec.h \
|
||||
xpmhand.h \
|
||||
zipstream.h \
|
||||
zipstrm.h \
|
||||
zstream.h
|
||||
|
||||
# setup.h is installed in another directory because several versions of wxwin
|
||||
|
182
include/wx/strconv.h
Normal file
182
include/wx/strconv.h
Normal file
@ -0,0 +1,182 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if wxUSE_WCHAR_T
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxMBConv (base class for conversions, using libc conversion itself)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConv
|
||||
{
|
||||
public:
|
||||
|
||||
// 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;
|
||||
#if wxUSE_UNICODE
|
||||
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; }
|
||||
const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
|
||||
#else
|
||||
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
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxMBConvFile (for conversion to filenames)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConvFile: public wxMBConv
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxMBConvUTF7 (for conversion using UTF7 encoding)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConvUTF7: public wxMBConv
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxMBConvUTF8 (for conversion using UTF8 encoding)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConvUTF8: public wxMBConv
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
|
||||
|
||||
#ifdef __WXGTK12__
|
||||
//---------------------------------------------------------------------------
|
||||
// wxMBConvUTF8 (for conversion using GDK's internal converions)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConvGdk: public wxMBConv
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// wxCSConv (for conversion based on laodable char sets)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxCharacterSet;
|
||||
|
||||
class WXDLLEXPORT wxCSConv: public wxMBConv
|
||||
{
|
||||
private:
|
||||
wxChar *m_name;
|
||||
wxCharacterSet *m_cset;
|
||||
bool m_deferred;
|
||||
void SetName(const wxChar *charset);
|
||||
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
|
||||
#define wxConv_local wxConvLocal
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
||||
#define wxConv_current wxConvCurrent
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// filename conversion macros
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// filenames are multibyte on Unix and probably widechar on Windows?
|
||||
#if defined(__UNIX__) || defined(__BORLANDC__)
|
||||
#define wxMBFILES 1
|
||||
#else
|
||||
#define wxMBFILES 0
|
||||
#endif
|
||||
|
||||
#if wxMBFILES
|
||||
#define wxFNCONV(name) wxConvFile.cWX2MB(name)
|
||||
#define FNSTRINGCAST MBSTRINGCAST
|
||||
#else
|
||||
#define wxFNCONV(name) name
|
||||
#define FNSTRINGCAST WXSTRINGCAST
|
||||
#endif
|
||||
|
||||
#else
|
||||
// !wxUSE_WCHAR_T
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// stand-ins in absence of wchar_t
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMBConv
|
||||
{
|
||||
public:
|
||||
const char* cMB2WX(const char *psz) const { return psz; }
|
||||
const char* cWX2MB(const char *psz) const { return psz; }
|
||||
};
|
||||
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
|
||||
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
||||
|
||||
#define wxFNCONV(name) name
|
||||
#define FNSTRINGCAST WXSTRINGCAST
|
||||
|
||||
#endif
|
||||
// wxUSE_WCHAR_T
|
||||
|
||||
#endif
|
||||
// _WX_WXSTRCONVH__
|
||||
|
@ -77,6 +77,9 @@ const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100;
|
||||
// implementation only
|
||||
#define ASSERT_VALID_INDEX(i) wxASSERT( (unsigned)(i) <= Len() )
|
||||
|
||||
// include conversion classes
|
||||
#include "wx/strconv.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global functions complementing standard C string library replacements for
|
||||
// strlen() and portable strcasecmp()
|
||||
@ -175,94 +178,6 @@ struct WXDLLEXPORT wxStringData
|
||||
bool IsValid() const { return (nRefs != 0); }
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// types of multibyte<->Unicode conversions
|
||||
// ---------------------------------------------------------------------------
|
||||
#if wxUSE_WCHAR_T
|
||||
class WXDLLEXPORT wxMBConv
|
||||
{
|
||||
public:
|
||||
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;
|
||||
#if wxUSE_UNICODE
|
||||
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; }
|
||||
const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
|
||||
#else
|
||||
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
|
||||
};
|
||||
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
|
||||
|
||||
#define wxANOTHER_MBCONV(type) \
|
||||
class type : public wxMBConv { \
|
||||
public: \
|
||||
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; \
|
||||
}
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvFile)) wxConvFile;
|
||||
WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvUTF7)) wxConvUTF7;
|
||||
WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvUTF8)) wxConvUTF8;
|
||||
#ifdef __WXGTK12__
|
||||
WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvGdk)) wxConvGdk;
|
||||
#endif
|
||||
|
||||
class wxCharacterSet;
|
||||
class WXDLLEXPORT wxCSConv : public wxMBConv
|
||||
{
|
||||
private:
|
||||
wxChar *m_name;
|
||||
wxCharacterSet *m_cset;
|
||||
bool m_deferred;
|
||||
void SetName(const wxChar *charset);
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
|
||||
#define wxConv_local wxConvLocal
|
||||
|
||||
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
||||
#define wxConv_current wxConvCurrent
|
||||
|
||||
// filenames are multibyte on Unix and probably widechar on Windows?
|
||||
#if defined(__UNIX__) || defined(__BORLANDC__)
|
||||
#define wxMBFILES 1
|
||||
#else
|
||||
#define wxMBFILES 0
|
||||
#endif
|
||||
|
||||
#if wxMBFILES
|
||||
#define wxFNCONV(name) wxConvFile.cWX2MB(name)
|
||||
#define FNSTRINGCAST MBSTRINGCAST
|
||||
#else
|
||||
#define wxFNCONV(name) name
|
||||
#define FNSTRINGCAST WXSTRINGCAST
|
||||
#endif
|
||||
#else//!wxUSE_WCHAR_T
|
||||
class WXDLLEXPORT wxMBConv {
|
||||
public:
|
||||
const char* cMB2WX(const char *psz) const { return psz; }
|
||||
const char* cWX2MB(const char *psz) const { return psz; }
|
||||
};
|
||||
WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
|
||||
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
||||
#define wxFNCONV(name) name
|
||||
#define FNSTRINGCAST WXSTRINGCAST
|
||||
#endif//wxUSE_WCHAR_T
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// This is (yet another one) String class for C++ programmers. It doesn't use
|
||||
// any of "advanced" C++ features (i.e. templates, exceptions, namespaces...)
|
||||
|
@ -24,7 +24,7 @@
|
||||
#endif
|
||||
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/zipstream.h"
|
||||
#include "wx/zipstrm.h"
|
||||
#include "wx/fs_zip.h"
|
||||
|
||||
|
||||
|
463
src/common/strconv.cpp
Normal file
463
src/common/strconv.cpp
Normal file
@ -0,0 +1,463 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: strconv.cpp
|
||||
// Purpose: Unicode conversion classes
|
||||
// Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 29/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1999 Ove Kaaven, Robert Roebling, Vadim Zeitlin
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "strconv.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __SALFORDC__
|
||||
#include <clib.h>
|
||||
#endif
|
||||
|
||||
#include "wx/debug.h"
|
||||
#include "wx/strconv.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxConvCurrent
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
|
||||
|
||||
#if !wxUSE_WCHAR_T
|
||||
//----------------------------------------------------------------------------
|
||||
// stand-ins in absence of wchar_t
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile;
|
||||
|
||||
#else
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxMBConv
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConv) wxConvLibc;
|
||||
|
||||
size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
return wxMB2WC(buf, psz, n);
|
||||
}
|
||||
|
||||
size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
return wxWC2MB(buf, psz, n);
|
||||
}
|
||||
|
||||
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
|
||||
{
|
||||
if (psz)
|
||||
{
|
||||
size_t nLen = MB2WC((wchar_t *) NULL, psz, 0);
|
||||
wxWCharBuffer buf(nLen);
|
||||
MB2WC((wchar_t *)(const wchar_t *) buf, psz, nLen);
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
return wxWCharBuffer((wchar_t *) NULL);
|
||||
}
|
||||
|
||||
const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
|
||||
{
|
||||
if (psz)
|
||||
{
|
||||
size_t nLen = WC2MB((char *) NULL, psz, 0);
|
||||
wxCharBuffer buf(nLen);
|
||||
WC2MB((char *)(const char *) buf, psz, nLen);
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
return wxCharBuffer((char *) NULL);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// standard file conversion
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile;
|
||||
|
||||
// just use the libc conversion for now
|
||||
size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
return wxMB2WC(buf, psz, n);
|
||||
}
|
||||
|
||||
size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
return wxWC2MB(buf, psz, n);
|
||||
}
|
||||
|
||||
#ifdef __WXGTK12__
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// standard gdk conversion
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvGdk) wxConvGdk;
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
size_t wxMBConvGdk::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
if (buf) {
|
||||
return gdk_mbstowcs((GdkWChar *)buf, psz, n);
|
||||
} else {
|
||||
GdkWChar *nbuf = new GdkWChar[n=strlen(psz)];
|
||||
size_t len = gdk_mbstowcs(nbuf, psz, n);
|
||||
delete [] nbuf;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxMBConvGdk::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
char *mbstr = gdk_wcstombs((GdkWChar *)psz);
|
||||
size_t len = mbstr ? strlen(mbstr) : 0;
|
||||
if (buf) {
|
||||
if (len > n) len = n;
|
||||
memcpy(buf, psz, len);
|
||||
if (len < n) buf[len] = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif // GTK > 1.0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// UTF-7
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvUTF7) wxConvUTF7;
|
||||
|
||||
#if 0
|
||||
static char utf7_setD[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789'(),-./:?";
|
||||
static char utf7_setO[]="!\"#$%&*;<=>@[]^_`{|}";
|
||||
static char utf7_setB[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
#endif
|
||||
|
||||
// TODO: write actual implementations of UTF-7 here
|
||||
size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf),
|
||||
const char * WXUNUSED(psz),
|
||||
size_t WXUNUSED(n)) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf),
|
||||
const wchar_t * WXUNUSED(psz),
|
||||
size_t WXUNUSED(n)) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// UTF-8
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvUTF8) wxConvUTF8;
|
||||
|
||||
static unsigned long utf8_max[]={0x7f,0x7ff,0xffff,0x1fffff,0x3ffffff,0x7fffffff,0xffffffff};
|
||||
|
||||
size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*psz && ((!buf) || (len<n))) {
|
||||
unsigned char cc=*psz++, fc=cc;
|
||||
unsigned cnt;
|
||||
for (cnt=0; fc&0x80; cnt++) fc<<=1;
|
||||
if (!cnt) {
|
||||
// plain ASCII char
|
||||
if (buf) *buf++=cc;
|
||||
len++;
|
||||
} else {
|
||||
cnt--;
|
||||
if (!cnt) {
|
||||
// invalid UTF-8 sequence
|
||||
return (size_t)-1;
|
||||
} else {
|
||||
unsigned ocnt=cnt-1;
|
||||
unsigned long res=cc&(0x3f>>cnt);
|
||||
while (cnt--) {
|
||||
cc = *psz++;
|
||||
if ((cc&0xC0)!=0x80) {
|
||||
// invalid UTF-8 sequence
|
||||
return (size_t)-1;
|
||||
}
|
||||
res=(res<<6)|(cc&0x3f);
|
||||
}
|
||||
if (res<=utf8_max[ocnt]) {
|
||||
// illegal UTF-8 encoding
|
||||
return (size_t)-1;
|
||||
}
|
||||
if (buf) *buf++=res;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf && (len<n)) *buf = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*psz && ((!buf) || (len<n))) {
|
||||
unsigned long cc=(*psz++)&0x7fffffff;
|
||||
unsigned cnt;
|
||||
for (cnt=0; cc>utf8_max[cnt]; cnt++);
|
||||
if (!cnt) {
|
||||
// plain ASCII char
|
||||
if (buf) *buf++=cc;
|
||||
len++;
|
||||
} else {
|
||||
len+=cnt+1;
|
||||
if (buf) {
|
||||
*buf++=(-128>>cnt)|((cc>>(cnt*6))&(0x3f>>cnt));
|
||||
while (cnt--)
|
||||
*buf++=0x80|((cc>>(cnt*6))&0x3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf && (len<n)) *buf = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// specified character set
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/textfile.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/utils.h"
|
||||
#endif
|
||||
|
||||
class wxCharacterSet
|
||||
{
|
||||
public:
|
||||
wxArrayString names;
|
||||
wchar_t *data;
|
||||
};
|
||||
|
||||
WX_DECLARE_OBJARRAY(wxCharacterSet, wxCSArray);
|
||||
#include "wx/arrimpl.cpp"
|
||||
WX_DEFINE_OBJARRAY(wxCSArray);
|
||||
|
||||
static wxCSArray wxCharsets;
|
||||
|
||||
static void wxLoadCharacterSets(void)
|
||||
{
|
||||
static bool already_loaded = FALSE;
|
||||
|
||||
if (already_loaded) return;
|
||||
|
||||
already_loaded = TRUE;
|
||||
#if defined(__UNIX__) && wxUSE_TEXTFILE
|
||||
// search through files in /usr/share/i18n/charmaps
|
||||
wxString fname;
|
||||
for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
|
||||
!fname.IsEmpty();
|
||||
fname = ::wxFindNextFile()) {
|
||||
wxTextFile cmap(fname);
|
||||
if (cmap.Open()) {
|
||||
wxCharacterSet *cset = new wxCharacterSet;
|
||||
wxString comchar,escchar;
|
||||
bool in_charset = FALSE;
|
||||
|
||||
// wxFprintf(stderr,_T("Loaded: %s\n"),fname.c_str());
|
||||
|
||||
wxString line;
|
||||
for (line = cmap.GetFirstLine();
|
||||
!cmap.Eof();
|
||||
line = cmap.GetNextLine()) {
|
||||
// wxFprintf(stderr,_T("line contents: %s\n"),line.c_str());
|
||||
wxStringTokenizer token(line);
|
||||
wxString cmd = token.GetNextToken();
|
||||
if (cmd == comchar) {
|
||||
if (token.GetNextToken() == _T("alias"))
|
||||
cset->names.Add(token.GetNextToken());
|
||||
}
|
||||
else if (cmd == _T("<code_set_name>"))
|
||||
cset->names.Add(token.GetNextToken());
|
||||
else if (cmd == _T("<comment_char>"))
|
||||
comchar = token.GetNextToken();
|
||||
else if (cmd == _T("<escape_char>"))
|
||||
escchar = token.GetNextToken();
|
||||
else if (cmd == _T("<mb_cur_min>")) {
|
||||
delete cset;
|
||||
cset = (wxCharacterSet *) NULL;
|
||||
break; // we don't support multibyte charsets ourselves (yet)
|
||||
}
|
||||
else if (cmd == _T("CHARMAP")) {
|
||||
cset->data = (wchar_t *)calloc(256, sizeof(wchar_t));
|
||||
in_charset = TRUE;
|
||||
}
|
||||
else if (cmd == _T("END")) {
|
||||
if (token.GetNextToken() == _T("CHARMAP"))
|
||||
in_charset = FALSE;
|
||||
}
|
||||
else if (in_charset) {
|
||||
// format: <NUL> /x00 <U0000> NULL (NUL)
|
||||
// <A> /x41 <U0041> LATIN CAPITAL LETTER A
|
||||
wxString hex = token.GetNextToken();
|
||||
// skip whitespace (why doesn't wxStringTokenizer do this?)
|
||||
while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken();
|
||||
wxString uni = token.GetNextToken();
|
||||
// skip whitespace again
|
||||
while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken();
|
||||
if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == _T('x')) &&
|
||||
(uni.Left(2) == _T("<U"))) {
|
||||
hex.MakeUpper(); uni.MakeUpper();
|
||||
int pos = ::wxHexToDec(hex.Mid(2,2));
|
||||
if (pos>=0) {
|
||||
unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2));
|
||||
unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2));
|
||||
cset->data[pos] = (uni1 << 16) | uni2;
|
||||
// wxFprintf(stderr,_T("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cset) {
|
||||
cset->names.Shrink();
|
||||
wxCharsets.Add(cset);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
wxCharsets.Shrink();
|
||||
}
|
||||
|
||||
static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
|
||||
{
|
||||
if (!charset) return (wxCharacterSet *)NULL;
|
||||
wxLoadCharacterSets();
|
||||
for (size_t n=0; n<wxCharsets.GetCount(); n++)
|
||||
if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
|
||||
return &(wxCharsets[n]);
|
||||
return (wxCharacterSet *)NULL;
|
||||
}
|
||||
|
||||
WXDLLEXPORT_DATA(wxCSConv) wxConvLocal((const wxChar *)NULL);
|
||||
|
||||
wxCSConv::wxCSConv(const wxChar *charset)
|
||||
{
|
||||
m_name = (wxChar *) NULL;
|
||||
m_cset = (wxCharacterSet *) NULL;
|
||||
m_deferred = TRUE;
|
||||
SetName(charset);
|
||||
}
|
||||
|
||||
wxCSConv::~wxCSConv()
|
||||
{
|
||||
if (m_name) free(m_name);
|
||||
}
|
||||
|
||||
void wxCSConv::SetName(const wxChar *charset)
|
||||
{
|
||||
if (charset) {
|
||||
#ifdef __UNIX__
|
||||
// first, convert the character set name to standard form
|
||||
wxString codeset;
|
||||
if (wxString(charset,3).CmpNoCase(_T("ISO")) == 0) {
|
||||
// make sure it's represented in the standard form: ISO_8859-1
|
||||
codeset = _T("ISO_");
|
||||
charset += 3;
|
||||
if ((*charset == _T('-')) || (*charset == _T('_'))) charset++;
|
||||
if (wxStrlen(charset)>4) {
|
||||
if (wxString(charset,4) == _T("8859")) {
|
||||
codeset << _T("8859-");
|
||||
if (*charset == _T('-')) charset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
codeset << charset;
|
||||
codeset.MakeUpper();
|
||||
m_name = wxStrdup(codeset.c_str());
|
||||
m_deferred = TRUE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void wxCSConv::LoadNow()
|
||||
{
|
||||
// wxPrintf(_T("Conversion request\n"));
|
||||
if (m_deferred) {
|
||||
if (!m_name) {
|
||||
#ifdef __UNIX__
|
||||
wxChar *lang = wxGetenv(_T("LANG"));
|
||||
wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
|
||||
if (dot) SetName(dot+1);
|
||||
#endif
|
||||
}
|
||||
m_cset = wxFindCharacterSet(m_name);
|
||||
m_deferred = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||
if (buf) {
|
||||
if (m_cset) {
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = m_cset->data[(unsigned char)(psz[c])];
|
||||
} else {
|
||||
// latin-1 (direct)
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = (unsigned char)(psz[c]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return strlen(psz);
|
||||
}
|
||||
|
||||
size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||
if (buf) {
|
||||
if (m_cset) {
|
||||
for (size_t c=0; c<n; c++) {
|
||||
size_t n;
|
||||
for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
|
||||
buf[c] = (n>0xff) ? '?' : n;
|
||||
}
|
||||
} else {
|
||||
// latin-1 (direct)
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = (psz[c]>0xff) ? '?' : psz[c];
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return wcslen(psz);
|
||||
}
|
||||
|
||||
#endif
|
||||
//wxUSE_WCHAR_T
|
||||
|
||||
|
@ -1933,423 +1933,3 @@ void wxArrayString::DoSort()
|
||||
qsort(m_pItems, m_nCount, sizeof(wxChar *), wxStringCompareFunction);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MBConv
|
||||
// ============================================================================
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
|
||||
#if !wxUSE_WCHAR_T
|
||||
WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile;
|
||||
#endif
|
||||
|
||||
#if wxUSE_WCHAR_T
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// standard libc conversion
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConv) wxConvLibc;
|
||||
|
||||
size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
return wxMB2WC(buf, psz, n);
|
||||
}
|
||||
|
||||
size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
return wxWC2MB(buf, psz, n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// standard file conversion
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile;
|
||||
|
||||
// just use the libc conversion for now
|
||||
size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
return wxMB2WC(buf, psz, n);
|
||||
}
|
||||
|
||||
size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
return wxWC2MB(buf, psz, n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// standard gdk conversion
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __WXGTK12__
|
||||
WXDLLEXPORT_DATA(wxMBConvGdk) wxConvGdk;
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
size_t wxMBConvGdk::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
if (buf) {
|
||||
return gdk_mbstowcs((GdkWChar *)buf, psz, n);
|
||||
} else {
|
||||
GdkWChar *nbuf = new GdkWChar[n=strlen(psz)];
|
||||
size_t len = gdk_mbstowcs(nbuf, psz, n);
|
||||
delete [] nbuf;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxMBConvGdk::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
char *mbstr = gdk_wcstombs((GdkWChar *)psz);
|
||||
size_t len = mbstr ? strlen(mbstr) : 0;
|
||||
if (buf) {
|
||||
if (len > n) len = n;
|
||||
memcpy(buf, psz, len);
|
||||
if (len < n) buf[len] = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif // GTK > 1.0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// UTF-7
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvUTF7) wxConvUTF7;
|
||||
|
||||
#if 0
|
||||
static char utf7_setD[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789'(),-./:?";
|
||||
static char utf7_setO[]="!\"#$%&*;<=>@[]^_`{|}";
|
||||
static char utf7_setB[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
#endif
|
||||
|
||||
// TODO: write actual implementations of UTF-7 here
|
||||
size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf),
|
||||
const char * WXUNUSED(psz),
|
||||
size_t WXUNUSED(n)) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf),
|
||||
const wchar_t * WXUNUSED(psz),
|
||||
size_t WXUNUSED(n)) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// UTF-8
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WXDLLEXPORT_DATA(wxMBConvUTF8) wxConvUTF8;
|
||||
|
||||
static unsigned long utf8_max[]={0x7f,0x7ff,0xffff,0x1fffff,0x3ffffff,0x7fffffff,0xffffffff};
|
||||
|
||||
size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*psz && ((!buf) || (len<n))) {
|
||||
unsigned char cc=*psz++, fc=cc;
|
||||
unsigned cnt;
|
||||
for (cnt=0; fc&0x80; cnt++) fc<<=1;
|
||||
if (!cnt) {
|
||||
// plain ASCII char
|
||||
if (buf) *buf++=cc;
|
||||
len++;
|
||||
} else {
|
||||
cnt--;
|
||||
if (!cnt) {
|
||||
// invalid UTF-8 sequence
|
||||
return (size_t)-1;
|
||||
} else {
|
||||
unsigned ocnt=cnt-1;
|
||||
unsigned long res=cc&(0x3f>>cnt);
|
||||
while (cnt--) {
|
||||
cc = *psz++;
|
||||
if ((cc&0xC0)!=0x80) {
|
||||
// invalid UTF-8 sequence
|
||||
return (size_t)-1;
|
||||
}
|
||||
res=(res<<6)|(cc&0x3f);
|
||||
}
|
||||
if (res<=utf8_max[ocnt]) {
|
||||
// illegal UTF-8 encoding
|
||||
return (size_t)-1;
|
||||
}
|
||||
if (buf) *buf++=res;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf && (len<n)) *buf = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*psz && ((!buf) || (len<n))) {
|
||||
unsigned long cc=(*psz++)&0x7fffffff;
|
||||
unsigned cnt;
|
||||
for (cnt=0; cc>utf8_max[cnt]; cnt++);
|
||||
if (!cnt) {
|
||||
// plain ASCII char
|
||||
if (buf) *buf++=cc;
|
||||
len++;
|
||||
} else {
|
||||
len+=cnt+1;
|
||||
if (buf) {
|
||||
*buf++=(-128>>cnt)|((cc>>(cnt*6))&(0x3f>>cnt));
|
||||
while (cnt--)
|
||||
*buf++=0x80|((cc>>(cnt*6))&0x3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf && (len<n)) *buf = 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// specified character set
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxCharacterSet
|
||||
{
|
||||
public:
|
||||
wxArrayString names;
|
||||
wchar_t *data;
|
||||
};
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/filefn.h"
|
||||
#include "wx/textfile.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/utils.h"
|
||||
#endif
|
||||
|
||||
WX_DECLARE_OBJARRAY(wxCharacterSet, wxCSArray);
|
||||
#include "wx/arrimpl.cpp"
|
||||
WX_DEFINE_OBJARRAY(wxCSArray);
|
||||
|
||||
static wxCSArray wxCharsets;
|
||||
|
||||
static void wxLoadCharacterSets(void)
|
||||
{
|
||||
static bool already_loaded = FALSE;
|
||||
|
||||
if (already_loaded) return;
|
||||
|
||||
already_loaded = TRUE;
|
||||
#if defined(__UNIX__) && wxUSE_TEXTFILE
|
||||
// search through files in /usr/share/i18n/charmaps
|
||||
wxString fname;
|
||||
for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
|
||||
!fname.IsEmpty();
|
||||
fname = ::wxFindNextFile()) {
|
||||
wxTextFile cmap(fname);
|
||||
if (cmap.Open()) {
|
||||
wxCharacterSet *cset = new wxCharacterSet;
|
||||
wxString comchar,escchar;
|
||||
bool in_charset = FALSE;
|
||||
|
||||
// wxFprintf(stderr,_T("Loaded: %s\n"),fname.c_str());
|
||||
|
||||
wxString line;
|
||||
for (line = cmap.GetFirstLine();
|
||||
!cmap.Eof();
|
||||
line = cmap.GetNextLine()) {
|
||||
// wxFprintf(stderr,_T("line contents: %s\n"),line.c_str());
|
||||
wxStringTokenizer token(line);
|
||||
wxString cmd = token.GetNextToken();
|
||||
if (cmd == comchar) {
|
||||
if (token.GetNextToken() == _T("alias"))
|
||||
cset->names.Add(token.GetNextToken());
|
||||
}
|
||||
else if (cmd == _T("<code_set_name>"))
|
||||
cset->names.Add(token.GetNextToken());
|
||||
else if (cmd == _T("<comment_char>"))
|
||||
comchar = token.GetNextToken();
|
||||
else if (cmd == _T("<escape_char>"))
|
||||
escchar = token.GetNextToken();
|
||||
else if (cmd == _T("<mb_cur_min>")) {
|
||||
delete cset;
|
||||
cset = (wxCharacterSet *) NULL;
|
||||
break; // we don't support multibyte charsets ourselves (yet)
|
||||
}
|
||||
else if (cmd == _T("CHARMAP")) {
|
||||
cset->data = (wchar_t *)calloc(256, sizeof(wchar_t));
|
||||
in_charset = TRUE;
|
||||
}
|
||||
else if (cmd == _T("END")) {
|
||||
if (token.GetNextToken() == _T("CHARMAP"))
|
||||
in_charset = FALSE;
|
||||
}
|
||||
else if (in_charset) {
|
||||
// format: <NUL> /x00 <U0000> NULL (NUL)
|
||||
// <A> /x41 <U0041> LATIN CAPITAL LETTER A
|
||||
wxString hex = token.GetNextToken();
|
||||
// skip whitespace (why doesn't wxStringTokenizer do this?)
|
||||
while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken();
|
||||
wxString uni = token.GetNextToken();
|
||||
// skip whitespace again
|
||||
while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken();
|
||||
if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == _T('x')) &&
|
||||
(uni.Left(2) == _T("<U"))) {
|
||||
hex.MakeUpper(); uni.MakeUpper();
|
||||
int pos = ::wxHexToDec(hex.Mid(2,2));
|
||||
if (pos>=0) {
|
||||
unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2));
|
||||
unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2));
|
||||
cset->data[pos] = (uni1 << 16) | uni2;
|
||||
// wxFprintf(stderr,_T("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cset) {
|
||||
cset->names.Shrink();
|
||||
wxCharsets.Add(cset);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
wxCharsets.Shrink();
|
||||
}
|
||||
|
||||
static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
|
||||
{
|
||||
if (!charset) return (wxCharacterSet *)NULL;
|
||||
wxLoadCharacterSets();
|
||||
for (size_t n=0; n<wxCharsets.GetCount(); n++)
|
||||
if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
|
||||
return &(wxCharsets[n]);
|
||||
return (wxCharacterSet *)NULL;
|
||||
}
|
||||
|
||||
WXDLLEXPORT_DATA(wxCSConv) wxConvLocal((const wxChar *)NULL);
|
||||
|
||||
wxCSConv::wxCSConv(const wxChar *charset)
|
||||
{
|
||||
m_name = (wxChar *) NULL;
|
||||
m_cset = (wxCharacterSet *) NULL;
|
||||
m_deferred = TRUE;
|
||||
SetName(charset);
|
||||
}
|
||||
|
||||
wxCSConv::~wxCSConv()
|
||||
{
|
||||
if (m_name) free(m_name);
|
||||
}
|
||||
|
||||
void wxCSConv::SetName(const wxChar *charset)
|
||||
{
|
||||
if (charset) {
|
||||
#ifdef __UNIX__
|
||||
// first, convert the character set name to standard form
|
||||
wxString codeset;
|
||||
if (wxString(charset,3).CmpNoCase(_T("ISO")) == 0) {
|
||||
// make sure it's represented in the standard form: ISO_8859-1
|
||||
codeset = _T("ISO_");
|
||||
charset += 3;
|
||||
if ((*charset == _T('-')) || (*charset == _T('_'))) charset++;
|
||||
if (wxStrlen(charset)>4) {
|
||||
if (wxString(charset,4) == _T("8859")) {
|
||||
codeset << _T("8859-");
|
||||
if (*charset == _T('-')) charset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
codeset << charset;
|
||||
codeset.MakeUpper();
|
||||
m_name = wxStrdup(codeset.c_str());
|
||||
m_deferred = TRUE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void wxCSConv::LoadNow()
|
||||
{
|
||||
// wxPrintf(_T("Conversion request\n"));
|
||||
if (m_deferred) {
|
||||
if (!m_name) {
|
||||
#ifdef __UNIX__
|
||||
wxChar *lang = wxGetenv(_T("LANG"));
|
||||
wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
|
||||
if (dot) SetName(dot+1);
|
||||
#endif
|
||||
}
|
||||
m_cset = wxFindCharacterSet(m_name);
|
||||
m_deferred = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||
if (buf) {
|
||||
if (m_cset) {
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = m_cset->data[(unsigned char)(psz[c])];
|
||||
} else {
|
||||
// latin-1 (direct)
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = (unsigned char)(psz[c]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return strlen(psz);
|
||||
}
|
||||
|
||||
size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
((wxCSConv *)this)->LoadNow(); // discard constness
|
||||
if (buf) {
|
||||
if (m_cset) {
|
||||
for (size_t c=0; c<n; c++) {
|
||||
size_t n;
|
||||
for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
|
||||
buf[c] = (n>0xff) ? '?' : n;
|
||||
}
|
||||
} else {
|
||||
// latin-1 (direct)
|
||||
for (size_t c=0; c<n; c++)
|
||||
buf[c] = (psz[c]>0xff) ? '?' : psz[c];
|
||||
}
|
||||
return n;
|
||||
}
|
||||
return wcslen(psz);
|
||||
}
|
||||
|
||||
#endif//wxUSE_WCHAR_T
|
||||
|
||||
#if wxUSE_WCHAR_T
|
||||
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
|
||||
{
|
||||
if (psz) {
|
||||
size_t nLen = MB2WC((wchar_t *) NULL, psz, 0);
|
||||
wxWCharBuffer buf(nLen);
|
||||
MB2WC(WCSTRINGCAST buf, psz, nLen);
|
||||
return buf;
|
||||
} else return wxWCharBuffer((wchar_t *) NULL);
|
||||
}
|
||||
|
||||
const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
|
||||
{
|
||||
if (psz) {
|
||||
size_t nLen = WC2MB((char *) NULL, psz, 0);
|
||||
wxCharBuffer buf(nLen);
|
||||
WC2MB(MBSTRINGCAST buf, psz, nLen);
|
||||
return buf;
|
||||
} else return wxCharBuffer((char *) NULL);
|
||||
}
|
||||
|
||||
#endif//wxUSE_WCHAR_T
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "wx/intl.h"
|
||||
#include "wx/stream.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/zipstream.h"
|
||||
#include "wx/zipstrm.h"
|
||||
|
||||
/* Not the right solution (paths in makefiles) but... */
|
||||
#ifdef __BORLANDC__
|
@ -86,6 +86,7 @@ libwx_gtk_la_SOURCES = \
|
||||
sckstrm.cpp \
|
||||
serbase.cpp \
|
||||
socket.cpp \
|
||||
strconv.cpp \
|
||||
stream.cpp \
|
||||
string.cpp \
|
||||
tbarbase.cpp \
|
||||
@ -108,7 +109,7 @@ libwx_gtk_la_SOURCES = \
|
||||
wxchar.cpp \
|
||||
wxexpr.cpp \
|
||||
zstream.cpp \
|
||||
zipstream.cpp \
|
||||
zipstrm.cpp \
|
||||
\
|
||||
db.cpp \
|
||||
dbtable.cpp \
|
||||
|
@ -86,6 +86,7 @@ libwx_gtk_la_SOURCES = \
|
||||
sckstrm.cpp \
|
||||
serbase.cpp \
|
||||
socket.cpp \
|
||||
strconv.cpp \
|
||||
stream.cpp \
|
||||
string.cpp \
|
||||
tbarbase.cpp \
|
||||
@ -108,7 +109,7 @@ libwx_gtk_la_SOURCES = \
|
||||
wxchar.cpp \
|
||||
wxexpr.cpp \
|
||||
zstream.cpp \
|
||||
zipstream.cpp \
|
||||
zipstrm.cpp \
|
||||
\
|
||||
db.cpp \
|
||||
dbtable.cpp \
|
||||
|
@ -43,6 +43,7 @@ libwx_motif_la_SOURCES = \
|
||||
memory.cpp \
|
||||
module.cpp \
|
||||
object.cpp \
|
||||
strconv.cpp \
|
||||
string.cpp \
|
||||
timercmn.cpp \
|
||||
utilscmn.cpp \
|
||||
@ -112,7 +113,7 @@ libwx_motif_la_SOURCES = \
|
||||
wincmn.cpp \
|
||||
wxexpr.cpp \
|
||||
unzip.c \
|
||||
zipstream.cpp \
|
||||
zipstrm.cpp \
|
||||
zstream.cpp \
|
||||
\
|
||||
busyinfo.cpp \
|
||||
|
@ -4,8 +4,8 @@
|
||||
##
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS =
|
||||
# 1.3 no-dependencies
|
||||
AUTOMAKE_OPTIONS = 1.3
|
||||
# no-dependencies
|
||||
|
||||
SUFFIXES = .cpp .c
|
||||
|
||||
@ -41,6 +41,7 @@ libwx_msw_la_SOURCES = \
|
||||
module.cpp \
|
||||
object.cpp \
|
||||
string.cpp \
|
||||
strconv.cpp \
|
||||
timercmn.cpp \
|
||||
utilscmn.cpp \
|
||||
tokenzr.cpp \
|
||||
@ -104,7 +105,7 @@ libwx_msw_la_SOURCES = \
|
||||
wfstream.cpp \
|
||||
wincmn.cpp \
|
||||
wxexpr.cpp \
|
||||
zipstream.cpp \
|
||||
zipstrm.cpp \
|
||||
zstream.cpp \
|
||||
\
|
||||
busyinfo.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user