From 5487ff0f501619e1b87e8a1f2c03bcc4a87ef375 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 11 May 2007 20:55:24 +0000 Subject: [PATCH] use const wxMBConv& instead of wxMBConv& in public methods so that it's possible to pass in temporary objects; don't use global wxConvUTF8 object internally, it may be unavailable at static objects destruction time git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45973 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/config.tex | 2 +- docs/latex/wx/datistrm.tex | 2 +- docs/latex/wx/datostrm.tex | 2 +- docs/latex/wx/ffile.tex | 4 ++-- docs/latex/wx/file.tex | 2 +- docs/latex/wx/fileconf.tex | 4 ++-- docs/latex/wx/tempfile.tex | 2 +- docs/latex/wx/textfile.tex | 6 +++--- docs/latex/wx/txtstrm.tex | 4 ++-- docs/latex/wx/wxstring.tex | 14 +++++++------- include/wx/archive.h | 2 ++ include/wx/file.h | 4 ++-- include/wx/memtext.h | 2 +- include/wx/string.h | 17 +++++++++-------- src/common/strconv.cpp | 6 +++--- src/common/string.cpp | 14 +++++++------- 16 files changed, 45 insertions(+), 42 deletions(-) diff --git a/docs/latex/wx/config.tex b/docs/latex/wx/config.tex index d7f6d8efcd..b7cd63b6cb 100644 --- a/docs/latex/wx/config.tex +++ b/docs/latex/wx/config.tex @@ -353,7 +353,7 @@ The following functions control this option: \param{const wxString\& }{localFilename = wxEmptyString}, \param{const wxString\& }{globalFilename = wxEmptyString}, \param{long}{ style = 0}, - \param{wxMBConv\&}{ conv = wxConvUTF8}} + \param{const wxMBConv\&}{ conv = wxConvAuto()}} This is the default and only constructor of the wxConfigBase class, and derived classes. diff --git a/docs/latex/wx/datistrm.tex b/docs/latex/wx/datistrm.tex index 4c30437f70..19fcc76465 100644 --- a/docs/latex/wx/datistrm.tex +++ b/docs/latex/wx/datistrm.tex @@ -43,7 +43,7 @@ None \func{}{wxDataInputStream}{\param{wxInputStream\&}{ stream}} -\func{}{wxDataInputStream}{\param{wxInputStream\&}{ stream}, \param{wxMBConv\&}{ conv = wxMBConvUTF8}} +\func{}{wxDataInputStream}{\param{wxInputStream\&}{ stream}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Constructs a datastream object from an input stream. Only read methods will be available. The second form is only available in Unicode build of wxWidgets. diff --git a/docs/latex/wx/datostrm.tex b/docs/latex/wx/datostrm.tex index 3045a75eca..23855001c8 100644 --- a/docs/latex/wx/datostrm.tex +++ b/docs/latex/wx/datostrm.tex @@ -27,7 +27,7 @@ None \func{}{wxDataOutputStream}{\param{wxOutputStream\&}{ stream}} -\func{}{wxDataOutputStream}{\param{wxOutputStream\&}{ stream}, \param{wxMBConv\&}{ conv = wxMBConvUTF8}} +\func{}{wxDataOutputStream}{\param{wxOutputStream\&}{ stream}, \param{const wxMBConv\&}{ conv = wxConvAuto(){} Constructs a datastream object from an output stream. Only write methods will be available. The second form is only available in Unicode build of wxWidgets. diff --git a/docs/latex/wx/ffile.tex b/docs/latex/wx/ffile.tex index e4b09dbb03..789a462ada 100644 --- a/docs/latex/wx/ffile.tex +++ b/docs/latex/wx/ffile.tex @@ -210,7 +210,7 @@ The number of bytes read. \membersection{wxFFile::ReadAll}\label{wxffilereadall} -\func{bool}{ReadAll}{\param{wxString *}{ str}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\func{bool}{ReadAll}{\param{wxString *}{ str}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Reads the entire contents of the file into a string. @@ -277,7 +277,7 @@ Number of bytes written. \membersection{wxFFile::Write}\label{wxffilewrites} -\func{bool}{Write}{\param{const wxString\& }{s}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\func{bool}{Write}{\param{const wxString\& }{s}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Writes the contents of the string to the file, returns \true on success. diff --git a/docs/latex/wx/file.tex b/docs/latex/wx/file.tex index 7977c6d67b..bf5cde3d8f 100644 --- a/docs/latex/wx/file.tex +++ b/docs/latex/wx/file.tex @@ -335,7 +335,7 @@ the number of bytes actually written \membersection{wxFile::Write}\label{wxfilewrites} -\func{bool}{Write}{\param{const wxString\& }{s}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\func{bool}{Write}{\param{const wxString\& }{s}, \param{const wxMBConv\&}{ conv = wxConvUTF8}} Writes the contents of the string to the file, returns true on success. diff --git a/docs/latex/wx/fileconf.tex b/docs/latex/wx/fileconf.tex index 0c2003d678..402952cee5 100644 --- a/docs/latex/wx/fileconf.tex +++ b/docs/latex/wx/fileconf.tex @@ -34,7 +34,7 @@ Windows. \membersection{wxFileConfig::wxFileConfig}\label{wxfileconfigctor} -\func{}{wxFileConfig}{\param{wxInputStream\& }{is}, \param{wxMBConv\& }{conv = wxConvUTF8}} +\func{}{wxFileConfig}{\param{wxInputStream\& }{is}, \param{const wxMBConv\& }{conv = wxConvAuto()}} Read the config data from the specified stream instead of the associated file, as usual. @@ -72,7 +72,7 @@ path name. \membersection{wxFileConfig::Save}\label{wxfileconfigsave} -\func{bool}{Save}{\param{wxOutputStream\& }{os}, \param{wxMBConv\& }{conv = wxConvUTF8}} +\func{bool}{Save}{\param{wxOutputStream\& }{os}, \param{const wxMBConv\& }{conv = wxConvAuto()}} Saves all config data to the given stream, returns \true if data was saved successfully or \false on error. diff --git a/docs/latex/wx/tempfile.tex b/docs/latex/wx/tempfile.tex index e7c0c98f68..60776d386d 100644 --- a/docs/latex/wx/tempfile.tex +++ b/docs/latex/wx/tempfile.tex @@ -107,7 +107,7 @@ Write to the file, return {\tt true} on success, {\tt false} on failure. \membersection{wxTempFile::Write}\label{wxtempfilewrites} -\func{bool}{Write}{\param{const wxString\& }{str}, \param{wxMBConv\&}{ conv = wxConvLibc}} +\func{bool}{Write}{\param{const wxString\& }{str}, \param{const wxMBConv\&}{ conv = wxConvUTF8}} Write to the file, return {\tt true} on success, {\tt false} on failure. diff --git a/docs/latex/wx/textfile.tex b/docs/latex/wx/textfile.tex index c139c6262a..0d6c69c236 100644 --- a/docs/latex/wx/textfile.tex +++ b/docs/latex/wx/textfile.tex @@ -262,9 +262,9 @@ Insert a line before the line number {\it n}. \membersection{wxTextFile::Open}\label{wxtextfileopen} -\constfunc{bool}{Open}{\param{wxMBConv\&}{ conv = wxConvUTF8}} +\constfunc{bool}{Open}{\param{const wxMBConv\&}{ conv = wxConvAuto()}} -\constfunc{bool}{Open}{\param{const wxString\& }{strFile}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\constfunc{bool}{Open}{\param{const wxString\& }{strFile}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Open() opens the file with the given name or the name which was given in the \helpref{constructor}{wxtextfilector} and also loads file in memory on @@ -288,7 +288,7 @@ Delete all lines from the file, set current line number to 0. \membersection{wxTextFile::Write}\label{wxtextfilewrite} -\constfunc{bool}{Write}{\param{wxTextFileType }{typeNew = wxTextFileType\_None}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\constfunc{bool}{Write}{\param{wxTextFileType }{typeNew = wxTextFileType\_None}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Change the file on disk. The {\it typeNew} parameter allows you to change the file format (default argument means "don't change type") and may be used to diff --git a/docs/latex/wx/txtstrm.tex b/docs/latex/wx/txtstrm.tex index 70afd2cca0..d85ea16e8d 100644 --- a/docs/latex/wx/txtstrm.tex +++ b/docs/latex/wx/txtstrm.tex @@ -45,7 +45,7 @@ For example: \membersection{wxTextInputStream::wxTextInputStream}\label{wxtextinputstreamctor} \func{}{wxTextInputStream}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ sep=" $\backslash$t"}, - \param{wxMBConv\&}{ conv = wxConvUTF8} } + \param{const wxMBConv\&}{ conv = wxConvAuto()} } Constructs a text stream associated to the given input stream. @@ -216,7 +216,7 @@ and Unix in their native formats (concerning the line ending). \membersection{wxTextOutputStream::wxTextOutputStream}\label{wxtextoutputstreamctor} -\func{}{wxTextOutputStream}{\param{wxOutputStream\&}{ stream}, \param{wxEOL}{ mode = wxEOL\_NATIVE}, \param{wxMBConv\&}{ conv = wxConvUTF8}} +\func{}{wxTextOutputStream}{\param{wxOutputStream\&}{ stream}, \param{wxEOL}{ mode = wxEOL\_NATIVE}, \param{const wxMBConv\&}{ conv = wxConvAuto()}} Constructs a text stream object associated to the given output stream. diff --git a/docs/latex/wx/wxstring.tex b/docs/latex/wx/wxstring.tex index 57504f03e6..6b175c1455 100644 --- a/docs/latex/wx/wxstring.tex +++ b/docs/latex/wx/wxstring.tex @@ -454,7 +454,7 @@ For ANSI builds only (note the use of {\tt char} instead of {\tt wxChar}). The following constructors allow you to construct wxString from a wide string in ANSI build or from a C string in Unicode build. -\func{}{wxString}{\param{const wchar\_t*}{ psz}, \param{wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} +\func{}{wxString}{\param{const wchar\_t*}{ psz}, \param{const wxMBConv\&}{ conv}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} Initializes the string from first \arg{nLength} characters of wide string. The default value of {\tt wxSTRING\_MAXLEN} means take all the string. @@ -462,7 +462,7 @@ In ANSI build, \arg{conv}'s \helpref{WC2MB}{wxmbconvwc2mb} method is called to convert \arg{psz} to wide string. It is ignored in Unicode build. -\func{}{wxString}{\param{const char*}{ psz}, \param{wxMBConv\&}{ conv = wxConvLibc}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} +\func{}{wxString}{\param{const char*}{ psz}, \param{const wxMBConv\&}{ conv = wxConvLibc}, \param{size\_t}{ nLength = wxSTRING\_MAXLEN}} Initializes the string from first \arg{nLength} characters of C string. The default value of {\tt wxSTRING\_MAXLEN} means take all the string. @@ -586,7 +586,7 @@ to a function expecting non-const pointer. \membersection{wxString::char\_str}\label{wxstringcharstr} -\constfunc{wxWritableCharBuffer}{char\_str}{\param{wxMBConv\&}{ conv = wxConvLibc}} +\constfunc{wxWritableCharBuffer}{char\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}} Returns an object with string data that is implicitly convertible to {\tt char*} pointer. Note that any change to the returned buffer is lost and so @@ -980,9 +980,9 @@ Returns \true if the string contents matches a mask containing '*' and '?'. \membersection{wxString::mb\_str}\label{wxstringmbstr} -\constfunc{const char*}{mb\_str}{\param{wxMBConv\&}{ conv = wxConvLibc}} +\constfunc{const char*}{mb\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}} -\constfunc{const wxCharBuffer}{mb\_str}{\param{wxMBConv\&}{ conv = wxConvLibc}} +\constfunc{const wxCharBuffer}{mb\_str}{\param{const wxMBConv\&}{ conv = wxConvLibc}} Returns multibyte (C string) representation of the string. In Unicode build, converts using \arg{conv}'s \helpref{cWC2MB}{wxmbconvcwc2mb} @@ -1350,9 +1350,9 @@ UTF-8 build. \membersection{wxString::wc\_str}\label{wxstringwcstr} -\constfunc{const wchar\_t*}{wc\_str}{\param{wxMBConv\&}{ conv}} +\constfunc{const wchar\_t*}{wc\_str}{\param{const wxMBConv\&}{ conv}} -\constfunc{const wxWCharBuffer}{wc\_str}{\param{wxMBConv\&}{ conv}} +\constfunc{const wxWCharBuffer}{wc\_str}{\param{const wxMBConv\&}{ conv}} Returns wide character representation of the string. In ANSI build, converts using \arg{conv}'s \helpref{cMB2WC}{wxmbconvcmb2wc} diff --git a/include/wx/archive.h b/include/wx/archive.h index 7acebd1e28..f814b8f3b8 100644 --- a/include/wx/archive.h +++ b/include/wx/archive.h @@ -341,6 +341,8 @@ public: const wxString& name, wxPathFormat format = wxPATH_NATIVE) const = 0; + // FIXME-UTF8: remove these from this file, they are used for ANSI + // build only void SetConv(wxMBConv& conv) { m_pConv = &conv; } wxMBConv& GetConv() const { if (m_pConv) return *m_pConv; else return wxConvLocal; } diff --git a/include/wx/file.h b/include/wx/file.h index 9b81e4c786..631f12c3c1 100644 --- a/include/wx/file.h +++ b/include/wx/file.h @@ -97,7 +97,7 @@ public: // returns the number of bytes written size_t Write(const void *pBuf, size_t nCount); // returns true on success - bool Write(const wxString& s, const wxMBConv& conv = wxConvUTF8); + bool Write(const wxString& s, const wxMBConv& conv = wxMBConvUTF8()); // flush data not yet written bool Flush(); @@ -167,7 +167,7 @@ public: // I/O (both functions return true on success, false on failure) bool Write(const void *p, size_t n) { return m_file.Write(p, n) == n; } - bool Write(const wxString& str, const wxMBConv& conv = wxConvUTF8) + bool Write(const wxString& str, const wxMBConv& conv = wxMBConvUTF8()) { return m_file.Write(str, conv); } // different ways to close the file diff --git a/include/wx/memtext.h b/include/wx/memtext.h index a093f40b04..23b7de18d3 100644 --- a/include/wx/memtext.h +++ b/include/wx/memtext.h @@ -41,7 +41,7 @@ protected: { return true; } virtual bool OnWrite(wxTextFileType WXUNUSED(typeNew), - const wxMBConv& WXUNUSED(conv) = wxConvUTF8) + const wxMBConv& WXUNUSED(conv) = wxMBConvUTF8()) { return true; } private: diff --git a/include/wx/string.h b/include/wx/string.h index a74b39807a..c2a60e233d 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -485,9 +485,9 @@ private: { return ConvertStr(str, n, conv); } static wxCharBuffer ImplStr(const wchar_t* str) - { return ConvertStr(str, npos, wxConvUTF8).data; } + { return ConvertStr(str, npos, wxMBConvUTF8()).data; } static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n) - { return ConvertStr(str, n, wxConvUTF8); } + { return ConvertStr(str, n, wxMBConvUTF8()); } size_t PosToImpl(size_t pos) const { @@ -1144,21 +1144,22 @@ public: const char* ToUTF8() const { return wx_str(); } #elif wxUSE_UNICODE_WCHAR static wxString FromUTF8(const char *utf8) - { return wxString(utf8, wxConvUTF8); } + { return wxString(utf8, wxMBConvUTF8()); } static wxString FromUTF8(const char *utf8, size_t len) - { return wxString(utf8, wxConvUTF8, len); } - const wxCharBuffer utf8_str() const { return mb_str(wxConvUTF8); } + { return wxString(utf8, wxMBConvUTF8(), len); } + const wxCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); } const wxCharBuffer ToUTF8() const { return utf8_str(); } #else // ANSI static wxString FromUTF8(const char *utf8) - { return wxString(wxConvUTF8.cMB2WC(utf8)); } + { return wxString(wxMBConvUTF8().cMB2WC(utf8)); } static wxString FromUTF8(const char *utf8, size_t len) { size_t wlen; - wxWCharBuffer buf(wxConvUTF8.cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen)); + wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen)); return wxString(buf.data(), wlen); } - const wxCharBuffer utf8_str() const { return wxConvUTF8.cWC2MB(wc_str()); } + const wxCharBuffer utf8_str() const + { return wxMBConvUTF8().cWC2MB(wc_str()); } const wxCharBuffer ToUTF8() const { return utf8_str(); } #endif diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 2a0cb613c6..cd673cd72d 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -2035,12 +2035,12 @@ public: // http://msdn.microsoft.com/library/en-us/intl/unicode_17si.asp if ( m_CodePage == CP_UTF8 ) { - return wxConvUTF8.MB2WC(buf, psz, n); + return wxMBConvUTF8().MB2WC(buf, psz, n); } if ( m_CodePage == CP_UTF7 ) { - return wxConvUTF7.MB2WC(buf, psz, n); + return wxMBConvUTF7().MB2WC(buf, psz, n); } int flags = 0; @@ -3626,7 +3626,7 @@ wxWCharBuffer wxSafeConvertMB2WX(const char *s) wxWCharBuffer wbuf(wxConvLibc.cMB2WX(s)); if ( !wbuf ) - wbuf = wxConvUTF8.cMB2WX(s); + wbuf = wxMBConvUTF8().cMB2WX(s); if ( !wbuf ) wbuf = wxConvISO8859_1.cMB2WX(s); diff --git a/src/common/string.cpp b/src/common/string.cpp index 3ae68d82e6..5d080e9129 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -340,7 +340,7 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength, return SubstrBufFromMB("", 0); // and then to UTF-8: - SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxConvUTF8)); + SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxMBConvUTF8())); // widechar -> UTF-8 conversion isn't supposed to ever fail: wxASSERT_MSG( buf.data, _T("conversion to UTF-8 failed") ); @@ -382,9 +382,9 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const const wxWCharBuffer wxString::wc_str() const { - return wxConvUTF8.cMB2WC(m_impl.c_str(), - m_impl.length() + 1 /* size, not length */, - NULL); + return wxMBConvUTF8().cMB2WC(m_impl.c_str(), + m_impl.length() + 1 /* size, not length */, + NULL); } const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const @@ -396,9 +396,9 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const size_t wcLen; wxWCharBuffer wcBuf( - wxConvUTF8.cMB2WC(m_impl.c_str(), - m_impl.length() + 1 /* size, not length */, - &wcLen)); + wxMBConvUTF8().cMB2WC(m_impl.c_str(), + m_impl.length() + 1 /* size, not length */, + &wcLen)); if ( !wcLen ) return wxCharBuffer(""); -- 2.45.2