Added wxString::FromAscii() wxString::ToAscii().
Removed wxConvFile, made it a define wxConvLocal. Exchanged some wxConvLibc to wxConvLocal calls. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16453 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -58,19 +58,6 @@ public:
|
||||
|
||||
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)
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -146,6 +133,7 @@ private:
|
||||
bool m_deferred;
|
||||
};
|
||||
|
||||
#define wxConvFile wxConvLocal
|
||||
WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
|
||||
WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
|
||||
|
||||
|
@@ -480,6 +480,18 @@ public:
|
||||
// identical to c_str()
|
||||
const wxChar* GetData() const { return m_pchData; }
|
||||
|
||||
// conversion to plain ascii: this is usefull for
|
||||
// converting numbers or strings which are certain
|
||||
// not to contain special chars (typically system
|
||||
// functions, X atoms, environment variables etc.)
|
||||
#if wxUSE_UNICODE
|
||||
static wxString FromAscii( char *ascii );
|
||||
const wxCharBuffer ToAscii() const;
|
||||
#else
|
||||
static wxString FromAscii( char *ascii ) { return wxString( ascii ); }
|
||||
const char *ToAscii() const { return m_pchData; }
|
||||
#endif
|
||||
|
||||
// conversions with (possible) format convertions: have to return a
|
||||
// buffer with temporary data
|
||||
//
|
||||
|
@@ -1112,10 +1112,10 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
|
||||
if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
|
||||
return FALSE;
|
||||
#else // !Win32
|
||||
wxStructStat fbuf;
|
||||
|
||||
wxStructStat fbuf;
|
||||
// get permissions of file1
|
||||
if ( wxStat( file1, &fbuf) != 0 )
|
||||
if ( wxStat( file1.c_str(), &fbuf) != 0 )
|
||||
{
|
||||
// the file probably doesn't exist or we haven't the rights to read
|
||||
// from it anyhow
|
||||
@@ -1146,6 +1146,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
|
||||
|
||||
// create file2 with the same permissions than file1 and open it for
|
||||
// writing
|
||||
|
||||
wxFile fileOut;
|
||||
if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
|
||||
return FALSE;
|
||||
|
@@ -225,7 +225,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
|
||||
wxString buf;
|
||||
buf.Printf(wxT("%s %s HTTP/1.0\r\n"), request, path.c_str());
|
||||
const wxWX2MBbuf pathbuf = wxConvLibc.cWX2MB(buf);
|
||||
const wxWX2MBbuf pathbuf = wxConvLocal.cWX2MB(buf);
|
||||
Write(pathbuf, strlen(wxMBSTRINGCAST pathbuf));
|
||||
SendHeaders();
|
||||
Write("\r\n", 2);
|
||||
|
@@ -153,7 +153,7 @@ int wxEntry(int argc, char **argv)
|
||||
int mb_argc = 0;
|
||||
while (mb_argc < argc)
|
||||
{
|
||||
wxTheApp->argv[mb_argc] = wxStrdup(wxConvLibc.cMB2WX(argv[mb_argc]));
|
||||
wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc]));
|
||||
mb_argc++;
|
||||
}
|
||||
wxTheApp->argv[mb_argc] = (wxChar *)NULL;
|
||||
|
@@ -1276,7 +1276,7 @@ wxString wxLocale::GetSystemEncodingName()
|
||||
}
|
||||
else
|
||||
{
|
||||
encname = wxConvLibc.cMB2WX(alang);
|
||||
encname = wxString::FromAscii( alang );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1285,24 +1285,24 @@ wxString wxLocale::GetSystemEncodingName()
|
||||
// if we can't get at the character set directly, try to see if it's in
|
||||
// the environment variables (in most cases this won't work, but I was
|
||||
// out of ideas)
|
||||
wxChar *lang = wxGetenv(wxT("LC_ALL"));
|
||||
wxChar *dot = lang ? wxStrchr(lang, wxT('.')) : (wxChar *)NULL;
|
||||
char *lang = getenv( "LC_ALL");
|
||||
char *dot = lang ? strchr(lang, '.') : (char *)NULL;
|
||||
if (!dot)
|
||||
{
|
||||
lang = wxGetenv(wxT("LC_CTYPE"));
|
||||
lang = getenv( "LC_CTYPE" );
|
||||
if ( lang )
|
||||
dot = wxStrchr(lang, wxT('.'));
|
||||
dot = strchr(lang, '.' );
|
||||
}
|
||||
if (!dot)
|
||||
{
|
||||
lang = wxGetenv(wxT("LANG"));
|
||||
lang = getenv( "LANG");
|
||||
if ( lang )
|
||||
dot = wxStrchr(lang, wxT('.'));
|
||||
dot = strchr(lang, '.');
|
||||
}
|
||||
|
||||
if ( dot )
|
||||
{
|
||||
encname = dot+1;
|
||||
encname = wxString::FromAscii( dot+1 );
|
||||
}
|
||||
}
|
||||
#endif // Win32/Unix
|
||||
|
@@ -186,14 +186,44 @@ static size_t decode_utf16(const wchar_t* input, wxUint32& output)
|
||||
// wxMBConv
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define IGNORE_LIBC 0
|
||||
|
||||
size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
#if IGNORE_LIBC
|
||||
if (buf)
|
||||
{
|
||||
for (size_t i = 0; i < strlen( psz )+1; i++)
|
||||
buf[i] = (wchar_t) psz[i];
|
||||
// printf( "libc %s\n", buf );
|
||||
return strlen( psz );
|
||||
}
|
||||
else
|
||||
{
|
||||
return strlen( psz );
|
||||
}
|
||||
#else
|
||||
return wxMB2WC(buf, psz, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
#if IGNORE_LIBC
|
||||
if (buf)
|
||||
{
|
||||
for (size_t i = 0; i < wxStrlen( psz )+1; i++)
|
||||
buf[i] = (char) psz[i];
|
||||
// printf( "libc %s\n", buf );
|
||||
return wxStrlen( psz );
|
||||
}
|
||||
else
|
||||
{
|
||||
return wxStrlen( psz );
|
||||
}
|
||||
#else
|
||||
return wxWC2MB(buf, psz, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
|
||||
@@ -220,29 +250,13 @@ const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
|
||||
return wxCharBuffer((char *) NULL);
|
||||
wxCharBuffer buf(nLen); // this allocates nLen+1
|
||||
WC2MB((char *)(const char *) buf, psz, nLen+1);
|
||||
// printf( "str %s\n", (const char*) buf );
|
||||
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);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// standard gdk conversion
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -962,8 +976,10 @@ void wxCSConv::LoadNow()
|
||||
{
|
||||
wxString name = wxLocale::GetSystemEncodingName();
|
||||
if ( !name.empty() )
|
||||
{
|
||||
SetName(name);
|
||||
}
|
||||
}
|
||||
|
||||
// wxGetCharacterSet() complains about NULL name
|
||||
m_cset = m_name ? wxGetCharacterSet(m_name) : NULL;
|
||||
|
@@ -826,6 +826,45 @@ wxString operator+(const wxChar *psz, const wxString& str)
|
||||
// other common string functions
|
||||
// ===========================================================================
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
wxString wxString::FromAscii( char *ascii )
|
||||
{
|
||||
if (!ascii)
|
||||
return wxEmptyString;
|
||||
|
||||
size_t len = strlen( ascii );
|
||||
wxString res;
|
||||
res.AllocBuffer( len );
|
||||
wchar_t *dest = (wchar_t*)(const wchar_t*) res.c_str();
|
||||
|
||||
for (size_t i = 0; i < len+1; i++)
|
||||
dest[i] = (wchar_t) ascii[i];
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const wxCharBuffer wxString::ToAscii() const
|
||||
{
|
||||
if (IsNull())
|
||||
return wxCharBuffer( (const char*)NULL );
|
||||
|
||||
size_t len = Len();
|
||||
wxCharBuffer buffer( len ); // allocates len+1
|
||||
|
||||
char *dest = (char*)(const char*) buffer;
|
||||
|
||||
for (size_t i = 0; i < len+1; i++)
|
||||
{
|
||||
if (m_pchData[i] > 127)
|
||||
dest[i] = '_';
|
||||
else
|
||||
dest[i] = (char) m_pchData[i];
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// simple sub-string extraction
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@@ -200,9 +200,9 @@ WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_pt
|
||||
#ifndef wxSetlocale
|
||||
WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale)
|
||||
{
|
||||
char *localeOld = setlocale(category, wxConvLibc.cWX2MB(locale));
|
||||
char *localeOld = setlocale(category, wxConvLocal.cWX2MB(locale));
|
||||
|
||||
return wxWCharBuffer(wxConvLibc.cMB2WC(localeOld));
|
||||
return wxWCharBuffer(wxConvLocal.cMB2WC(localeOld));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -335,7 +335,7 @@ WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr)
|
||||
}
|
||||
|
||||
wxString data(nptr, nptr-start);
|
||||
wxWX2MBbuf dat = data.mb_str(wxConvLibc);
|
||||
wxWX2MBbuf dat = data.mb_str(wxConvLocal);
|
||||
char *rdat = wxMBSTRINGCAST dat;
|
||||
double ret = strtod(dat, &rdat);
|
||||
|
||||
@@ -363,7 +363,7 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base)
|
||||
(wxIsalpha(*nptr) && (wxToupper(*nptr) - wxT('A') + 10 < base))) nptr++;
|
||||
|
||||
wxString data(nptr, nptr-start);
|
||||
wxWX2MBbuf dat = data.mb_str(wxConvLibc);
|
||||
wxWX2MBbuf dat = data.mb_str(wxConvLocal);
|
||||
char *rdat = wxMBSTRINGCAST dat;
|
||||
long int ret = strtol(dat, &rdat, base);
|
||||
|
||||
@@ -376,12 +376,20 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base)
|
||||
#ifdef wxNEED_WX_STDIO_H
|
||||
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode)
|
||||
{
|
||||
return fopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode) );
|
||||
char mode_buffer[10];
|
||||
for (size_t i = 0; i < wxStrlen(mode)+1; i++)
|
||||
mode_buffer[i] = (char) mode[i];
|
||||
|
||||
return fopen( wxConvFile.cWX2MB(path), mode_buffer );
|
||||
}
|
||||
|
||||
WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream)
|
||||
{
|
||||
return freopen( wxConvFile.cWX2MB(path), wxConvLibc.cWX2MB(mode), stream );
|
||||
char mode_buffer[10];
|
||||
for (size_t i = 0; i < wxStrlen(mode)+1; i++)
|
||||
mode_buffer[i] = (char) mode[i];
|
||||
|
||||
return freopen( wxConvFile.cWX2MB(path), mode_buffer, stream );
|
||||
}
|
||||
|
||||
WXDLLEXPORT int wxRemove(const wxChar *path)
|
||||
@@ -398,19 +406,19 @@ WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath)
|
||||
#ifndef wxAtof
|
||||
double WXDLLEXPORT wxAtof(const wxChar *psz)
|
||||
{
|
||||
return atof(wxConvLibc.cWX2MB(psz));
|
||||
return atof(wxConvLocal.cWX2MB(psz));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef wxNEED_WX_STDLIB_H
|
||||
int WXDLLEXPORT wxAtoi(const wxChar *psz)
|
||||
{
|
||||
return atoi(wxConvLibc.cWX2MB(psz));
|
||||
return atoi(wxConvLocal.cWX2MB(psz));
|
||||
}
|
||||
|
||||
long WXDLLEXPORT wxAtol(const wxChar *psz)
|
||||
{
|
||||
return atol(wxConvLibc.cWX2MB(psz));
|
||||
return atol(wxConvLocal.cWX2MB(psz));
|
||||
}
|
||||
|
||||
wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
|
||||
@@ -423,7 +431,7 @@ wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
|
||||
{
|
||||
// nope, retrieve it,
|
||||
#if wxUSE_UNICODE
|
||||
wxCharBuffer buffer = wxConvLibc.cWX2MB(name);
|
||||
wxCharBuffer buffer = wxConvLocal.cWX2MB(name);
|
||||
// printf( "buffer %s\n", (const char*) buffer );
|
||||
const char *val = getenv( (const char *)buffer );
|
||||
#else
|
||||
@@ -435,7 +443,7 @@ wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
|
||||
|
||||
// convert it,
|
||||
#ifdef wxUSE_UNICODE
|
||||
data = (wxObject *)new wxString(val, wxConvLibc);
|
||||
data = (wxObject *)new wxString(val, wxConvLocal);
|
||||
#else
|
||||
data = (wxObject *)new wxString(val);
|
||||
#endif
|
||||
@@ -449,7 +457,7 @@ wxChar * WXDLLEXPORT wxGetenv(const wxChar *name)
|
||||
|
||||
int WXDLLEXPORT wxSystem(const wxChar *psz)
|
||||
{
|
||||
return system(wxConvLibc.cWX2MB(psz));
|
||||
return system(wxConvLocal.cWX2MB(psz));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -458,13 +466,17 @@ int WXDLLEXPORT wxSystem(const wxChar *psz)
|
||||
WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm)
|
||||
{
|
||||
if (!max) return 0;
|
||||
|
||||
char *buf = (char *)malloc(max);
|
||||
size_t ret = strftime(buf, max, wxConvLibc.cWX2MB(fmt), tm);
|
||||
if (ret) {
|
||||
wxStrcpy(s, wxConvLibc.cMB2WX(buf));
|
||||
size_t ret = strftime(buf, max, wxConvLocal.cWX2MB(fmt), tm);
|
||||
if (ret)
|
||||
{
|
||||
wxStrcpy(s, wxConvLocal.cMB2WX(buf));
|
||||
free(buf);
|
||||
return wxStrlen(s);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
free(buf);
|
||||
*s = 0;
|
||||
return 0;
|
||||
|
@@ -1309,10 +1309,13 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
|
||||
wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
|
||||
int dpi = GetResolution() * 2;
|
||||
dpi = 300;
|
||||
|
||||
PangoContext *context = pango_ft2_get_context ( dpi, dpi );
|
||||
|
||||
|
||||
// What are these for?
|
||||
pango_context_set_language (context, pango_language_from_string ("en_US"));
|
||||
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
|
||||
@@ -1329,7 +1332,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
|
||||
#endif
|
||||
pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
double xx = LogicalToDeviceX(x);
|
||||
double yy = LogicalToDeviceY(y /*+ bitmap.GetHeight()*/ );
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "wx/settings.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/msgdlg.h"
|
||||
#include "wx/file.h"
|
||||
|
||||
#if wxUSE_WX_RESOURCES
|
||||
#include "wx/resource.h"
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "wx/settings.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/msgdlg.h"
|
||||
#include "wx/file.h"
|
||||
|
||||
#if wxUSE_WX_RESOURCES
|
||||
#include "wx/resource.h"
|
||||
|
Reference in New Issue
Block a user