X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/210f4bcd661c968e7cd068ab9b551623d92a3dac..c932709d31bf359c994dc2050bec1b3b986bbd62:/src/common/wxchar.cpp diff --git a/src/common/wxchar.cpp b/src/common/wxchar.cpp index d1e12530da..b7e5c75272 100644 --- a/src/common/wxchar.cpp +++ b/src/common/wxchar.cpp @@ -5,7 +5,7 @@ // Modified by: Ron Lee // Created: 09/04/99 // RCS-ID: $Id$ -// Copyright: (c) wxWindows copyright +// Copyright: (c) wxWidgets copyright // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -604,23 +604,23 @@ int WXDLLEXPORT wxSnprintf_(wxChar *buf, size_t len, const wxChar *format, ...) // implement the standard IO functions for wide char if libc doesn't have them // ---------------------------------------------------------------------------- -#ifdef wxNEED_FPUTWC - +#ifdef wxNEED_FPUTS int wxFputs(const wchar_t *ws, FILE *stream) { // counting the number of wide characters written isn't worth the trouble, // simply distinguish between ok and error return fputs(wxConvLibc.cWC2MB(ws), stream) == -1 ? -1 : 0; } +#endif // wxNEED_FPUTS +#ifdef wxNEED_PUTC int /* not wint_t */ wxPutc(wchar_t wc, FILE *stream) { wchar_t ws[2] = { wc, L'\0' }; return wxFputs(ws, stream); } - -#endif // wxNEED_FPUTWC +#endif // wxNEED_PUTC // NB: we only implement va_list functions here, the ones taking ... are // defined below for wxNEED_PRINTF_CONVERSION case anyhow and we reuse @@ -704,7 +704,7 @@ int vwprintf(const wxChar *format, va_list argptr) So to use native functions in order to get our semantics we must do the following translations in Unicode mode (nothing to do in ANSI mode): - wxWindows specifier POSIX specifier + wxWidgets specifier POSIX specifier ---------------------------------------- %hc, %C, %hC %c @@ -774,10 +774,10 @@ private: ch == _T('0') || ch == _T(' ') || ch == _T('#'); } - void SkipDigits(const wxChar **ppc) + void SkipDigits(const wxChar **ptpc) { - while ( **ppc >= _T('0') && **ppc <= _T('9') ) - CopyFmtChar(*(*ppc)++); + while ( **ptpc >= _T('0') && **ptpc <= _T('9') ) + CopyFmtChar(*(*ptpc)++); } // the translated format @@ -962,9 +962,9 @@ int wxSprintf( wxChar *str, const wxChar *format, ... ) va_list argptr; va_start(argptr, format); - // note that wxString::Format() uses wxVsnprintf(), not wxSprintf(), so + // note that wxString::FormatV() uses wxVsnprintf(), not wxSprintf(), so // it's safe to implement this one in terms of it - wxString s(wxString::Format(format, argptr)); + wxString s(wxString::FormatV(format, argptr)); wxStrcpy(str, s); va_end(argptr); @@ -1329,36 +1329,16 @@ long WXDLLEXPORT wxAtol(const wxChar *psz) wxChar * WXDLLEXPORT wxGetenv(const wxChar *name) { - static wxHashTable env; - - // check if we already have stored the converted env var - wxObject *data = env.Get(name); - if (!data) - { - // nope, retrieve it, -#if wxUSE_UNICODE - wxCharBuffer buffer = wxConvLocal.cWX2MB(name); - // printf( "buffer %s\n", (const char*) buffer ); - const char *val = getenv( (const char *)buffer ); -#else - const char *val = getenv( name ); -#endif - - if (!val) return (wxChar *)NULL; - // printf( "home %s\n", val ); - - // convert it, #if wxUSE_UNICODE - data = (wxObject *)new wxString(val, wxConvLocal); + // NB: buffer returned by getenv() is allowed to be overwritten next + // time getenv() is called, so it is OK to use static string + // buffer to hold the data. + static wxWCharBuffer value((wxChar*)NULL); + value = wxConvLocal.cMB2WX(getenv(wxConvLocal.cWX2MB(name))); + return value.data(); #else - data = (wxObject *)new wxString(val); + return getenv(name); #endif - - // and store it - env.Put(name, data); - } - // return converted env var - return (wxChar *)((wxString *)data)->c_str(); } int WXDLLEXPORT wxSystem(const wxChar *psz)