From 6001e347baf63a91be525f3b9beeefde4bc16f19 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 8 Aug 1999 11:31:18 +0000 Subject: [PATCH] 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 --- distrib/msw/tmake/filelist.txt | 6 +- include/wx/Makefile.am | 3 +- include/wx/strconv.h | 182 +++++++++ include/wx/string.h | 91 +---- include/wx/{zipstream.h => zipstrm.h} | 0 src/common/fs_zip.cpp | 2 +- src/common/strconv.cpp | 463 ++++++++++++++++++++++ src/common/string.cpp | 420 -------------------- src/common/{zipstream.cpp => zipstrm.cpp} | 2 +- src/gtk/Makefile.am | 3 +- src/gtk1/Makefile.am | 3 +- src/motif/Makefile.am | 3 +- src/msw/Makefile.am | 7 +- 13 files changed, 666 insertions(+), 519 deletions(-) create mode 100644 include/wx/strconv.h rename include/wx/{zipstream.h => zipstrm.h} (100%) create mode 100644 src/common/strconv.cpp rename src/common/{zipstream.cpp => zipstrm.cpp} (99%) diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 8a5e3e4885..026b607aea 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -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 diff --git a/include/wx/Makefile.am b/include/wx/Makefile.am index 2260a93f00..e3e3d0501d 100644 --- a/include/wx/Makefile.am +++ b/include/wx/Makefile.am @@ -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 diff --git a/include/wx/strconv.h b/include/wx/strconv.h new file mode 100644 index 0000000000..3ff2d7a8db --- /dev/null +++ b/include/wx/strconv.h @@ -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 + +#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__ + diff --git a/include/wx/string.h b/include/wx/string.h index 88adfa8ffb..993e8a9283 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -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...) diff --git a/include/wx/zipstream.h b/include/wx/zipstrm.h similarity index 100% rename from include/wx/zipstream.h rename to include/wx/zipstrm.h diff --git a/src/common/fs_zip.cpp b/src/common/fs_zip.cpp index a77a338dff..e7765395d5 100644 --- a/src/common/fs_zip.cpp +++ b/src/common/fs_zip.cpp @@ -24,7 +24,7 @@ #endif #include "wx/filesys.h" -#include "wx/zipstream.h" +#include "wx/zipstrm.h" #include "wx/fs_zip.h" diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp new file mode 100644 index 0000000000..e61b9fd56c --- /dev/null +++ b/src/common/strconv.cpp @@ -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 +#include +#include + +#ifdef __SALFORDC__ + #include +#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 + +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>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 && (lenutf8_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 && (lennames.Add(token.GetNextToken()); + } + else if (cmd == _T("")) + cset->names.Add(token.GetNextToken()); + else if (cmd == _T("")) + comchar = token.GetNextToken(); + else if (cmd == _T("")) + escchar = token.GetNextToken(); + else if (cmd == _T("")) { + 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: /x00 NULL (NUL) + // /x41 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("=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; n4) { + 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; cdata[(unsigned char)(psz[c])]; + } else { + // latin-1 (direct) + for (size_t c=0; cLoadNow(); // discard constness + if (buf) { + if (m_cset) { + for (size_t c=0; cdata[n] != psz[c]); n++); + buf[c] = (n>0xff) ? '?' : n; + } + } else { + // latin-1 (direct) + for (size_t c=0; c0xff) ? '?' : psz[c]; + } + return n; + } + return wcslen(psz); +} + +#endif + //wxUSE_WCHAR_T + + diff --git a/src/common/string.cpp b/src/common/string.cpp index 47729557c6..b7221a429a 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -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 - -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>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 && (lenutf8_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 && (lennames.Add(token.GetNextToken()); - } - else if (cmd == _T("")) - cset->names.Add(token.GetNextToken()); - else if (cmd == _T("")) - comchar = token.GetNextToken(); - else if (cmd == _T("")) - escchar = token.GetNextToken(); - else if (cmd == _T("")) { - 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: /x00 NULL (NUL) - // /x41 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("=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; n4) { - 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; cdata[(unsigned char)(psz[c])]; - } else { - // latin-1 (direct) - for (size_t c=0; cLoadNow(); // discard constness - if (buf) { - if (m_cset) { - for (size_t c=0; cdata[n] != psz[c]); n++); - buf[c] = (n>0xff) ? '?' : n; - } - } else { - // latin-1 (direct) - for (size_t c=0; c0xff) ? '?' : 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 - diff --git a/src/common/zipstream.cpp b/src/common/zipstrm.cpp similarity index 99% rename from src/common/zipstream.cpp rename to src/common/zipstrm.cpp index 31dc722b8d..d334dd8c58 100644 --- a/src/common/zipstream.cpp +++ b/src/common/zipstrm.cpp @@ -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__ diff --git a/src/gtk/Makefile.am b/src/gtk/Makefile.am index 9eae458950..355a96d1ae 100644 --- a/src/gtk/Makefile.am +++ b/src/gtk/Makefile.am @@ -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 \ diff --git a/src/gtk1/Makefile.am b/src/gtk1/Makefile.am index 9eae458950..355a96d1ae 100644 --- a/src/gtk1/Makefile.am +++ b/src/gtk1/Makefile.am @@ -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 \ diff --git a/src/motif/Makefile.am b/src/motif/Makefile.am index 63081cea04..0cdd387cf9 100644 --- a/src/motif/Makefile.am +++ b/src/motif/Makefile.am @@ -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 \ diff --git a/src/msw/Makefile.am b/src/msw/Makefile.am index 6bc505d2d3..2923f8b3c5 100644 --- a/src/msw/Makefile.am +++ b/src/msw/Makefile.am @@ -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 \ -- 2.45.2