]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
Fixed compile problem and warning
[wxWidgets.git] / src / common / strconv.cpp
index 95ef4240421423b71948f04911ffcdd85067e4ad..9d093143fe7f60cade95290da2010884826be7fc 100644 (file)
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif  //__BORLANDC__
+
 #ifndef WX_PRECOMP
-    #ifdef __WXMSW__
-        #include "wx/msw/missing.h"
-    #endif
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/utils.h"
 
 #if wxUSE_WCHAR_T
 
-#ifdef __WINDOWS__
-    #include "wx/msw/private.h"
-#endif
-
 #ifndef __WXWINCE__
 #include <errno.h>
 #endif
@@ -42,6 +39,8 @@
 #include <stdlib.h>
 
 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
+    #include "wx/msw/private.h"
+    #include "wx/msw/missing.h"
     #define wxHAVE_WIN32_MB2WC
 #endif
 
@@ -3280,7 +3279,7 @@ wxMBConv *wxCSConv::DoCreate() const
     wxLogTrace(TRACE_STRCONV,
                wxT("creating conversion for %s"),
                (m_name ? m_name
-                       : wxFontMapperBase::GetEncodingName(m_encoding).c_str()));
+                       : (const wxChar*)wxFontMapperBase::GetEncodingName(m_encoding).c_str()));
 #endif // wxUSE_FONTMAP
 
     // check for the special case of ASCII or ISO8859-1 charset: as we have
@@ -3483,9 +3482,9 @@ wxMBConv *wxCSConv::DoCreate() const
                    m_name ? m_name
                       :
 #if wxUSE_FONTMAP
-                         wxFontMapperBase::GetEncodingDescription(m_encoding).c_str()
+                         (const wxChar*)wxFontMapperBase::GetEncodingDescription(m_encoding).c_str()
 #else // !wxUSE_FONTMAP
-                         wxString::Format(_("encoding %i"), m_encoding).c_str()
+                         (const wxChar*)wxString::Format(_("encoding %i"), m_encoding).c_str()
 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
               );
 
@@ -3506,7 +3505,7 @@ void wxCSConv::CreateConvIfNeeded() const
         if ( !m_name && m_encoding == wxFONTENCODING_SYSTEM )
         {
 #if wxUSE_INTL
-            self->m_name = wxStrdup(wxLocale::GetSystemEncodingName());
+            self->m_encoding = wxLocale::GetSystemEncoding();
 #else
             // fallback to some reasonable default:
             self->m_encoding = wxFONTENCODING_ISO8859_1;
@@ -3518,6 +3517,43 @@ void wxCSConv::CreateConvIfNeeded() const
     }
 }
 
+bool wxCSConv::IsOk() const
+{
+    CreateConvIfNeeded();
+
+    // special case: no convReal created for wxFONTENCODING_ISO8859_1
+    if ( m_encoding == wxFONTENCODING_ISO8859_1 )
+        return true; // always ok as we do it ourselves
+
+    // m_convReal->IsOk() is called at its own creation, so we know it must
+    // be ok if m_convReal is non-NULL
+    return m_convReal != NULL;
+}
+
+size_t wxCSConv::ToWChar(wchar_t *dst, size_t dstLen,
+                         const char *src, size_t srcLen) const
+{
+    CreateConvIfNeeded();
+
+    if (m_convReal)
+        return m_convReal->ToWChar(dst, dstLen, src, srcLen);
+
+    // latin-1 (direct)
+    return wxMBConv::ToWChar(dst, dstLen, src, srcLen);
+}
+
+size_t wxCSConv::FromWChar(char *dst, size_t dstLen,
+                           const wchar_t *src, size_t srcLen) const
+{
+    CreateConvIfNeeded();
+
+    if (m_convReal)
+        return m_convReal->FromWChar(dst, dstLen, src, srcLen);
+
+    // latin-1 (direct)
+    return wxMBConv::FromWChar(dst, dstLen, src, srcLen);
+}
+
 size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
 {
     CreateConvIfNeeded();
@@ -3613,9 +3649,39 @@ WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = &
 #else
                                     wxConvUTF8Obj;
 #endif
-#else
+#else // !__WXOSX__
                                     wxConvLibcObj;
-#endif
+#endif // __WXOSX__/!__WXOSX__
+
+#if wxUSE_UNICODE
+
+wxWCharBuffer wxSafeConvertMB2WX(const char *s)
+{
+    if ( !s )
+        return wxWCharBuffer();
+
+    wxWCharBuffer wbuf(wxConvLibc.cMB2WX(s));
+    if ( !wbuf )
+        wbuf = wxConvUTF8.cMB2WX(s);
+    if ( !wbuf )
+        wbuf = wxConvISO8859_1.cMB2WX(s);
+
+    return wbuf;
+}
+
+wxCharBuffer wxSafeConvertWX2MB(const wchar_t *ws)
+{
+    if ( !ws )
+        return wxCharBuffer();
+
+    wxCharBuffer buf(wxConvLibc.cWX2MB(ws));
+    if ( !buf )
+        buf = wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL).cWX2MB(ws);
+
+    return buf;
+}
+
+#endif // wxUSE_UNICODE
 
 #else // !wxUSE_WCHAR_T