#if wxUSE_WCHAR_T
-#ifdef __WXMSW__
- #include "wx/msw/private.h"
-#endif
-
#ifdef __WINDOWS__
+ #include "wx/msw/private.h"
#include "wx/msw/missing.h"
#endif
#include "wx/utils.h"
#ifdef __WXMAC__
+#ifndef __DARWIN__
#include <ATSUnicode.h>
#include <TextCommon.h>
#include <TextEncodingConverter.h>
+#endif
#include "wx/mac/private.h" // includes mac headers
#endif
}
//Increment to next (sub)string
- //Note that we have to use strlen here instead of nLen
- //here because XX2XX gives us the size of the output buffer,
- //not neccessarly the length of the string
+ //Note that we have to use strlen instead of nLen here
+ //because XX2XX gives us the size of the output buffer,
+ //which is not necessarily the length of the string
szPos += strlen(szPos) + 1;
}
}
//Increment to next (sub)string
- //Note that we have to use wxWcslen here instead of nLen
- //here because XX2XX gives us the size of the output buffer,
- //not neccessarly the length of the string
+ //Note that we have to use wxWcslen instead of nLen here
+ //because XX2XX gives us the size of the output buffer,
+ //which is not necessarily the length of the string
szPos += wxWcslen(szPos) + 1;
}
#ifdef __UNIX__
// ----------------------------------------------------------------------------
-// wxConvBrokenFileNames
+// wxConvBrokenFileNames
// ----------------------------------------------------------------------------
-wxConvBrokenFileNames::wxConvBrokenFileNames()
+wxConvBrokenFileNames::wxConvBrokenFileNames(const wxChar *charset)
{
- // decide which conversion to use for the file names
-
- // (1) this variable exists for the sole purpose of specifying the encoding
- // of the filenames for GTK+ programs, so use it if it is set
- wxString encName(wxGetenv(_T("G_FILENAME_ENCODING")));
- encName.MakeUpper();
- if ( !encName.empty() && encName != _T("UTF-8") && encName != _T("UTF8") )
- {
- m_conv = new wxCSConv(encName);
- }
- else // no G_FILENAME_ENCODING
- {
- if ( encName.empty() )
- encName = wxLocale::GetSystemEncodingName().Upper();
-
- // (2) if a non default locale is set, assume that the user wants his
- // filenames in this locale too
- if ( !encName.empty() && encName != _T("UTF-8") && encName != _T("UTF8") )
- {
- wxSetEnv(_T("G_FILENAME_ENCODING"), encName);
- m_conv = new wxMBConvLibc;
- }
- else
- {
- // (3) finally use UTF-8 by default
- m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL);
- }
- }
+ if ( !charset || wxStricmp(charset, _T("UTF-8")) == 0
+ || wxStricmp(charset, _T("UTF8")) == 0 )
+ m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL);
+ else
+ m_conv = new wxCSConv(charset);
}
size_t
if (buf)
*buf++ = cc;
len++;
+
+ // escape the escape character for octal escapes
+ if ((m_options & MAP_INVALID_UTF8_TO_OCTAL)
+ && cc == '\\' && (!buf || len < n))
+ {
+ if (buf)
+ *buf++ = cc;
+ len++;
+ }
}
else
{
*buf++ = (char)(cc - wxUnicodePUA);
len++;
}
+ else if ( (m_options & MAP_INVALID_UTF8_TO_OCTAL)
+ && cc == L'\\' && psz[0] == L'\\' )
+ {
+ if (buf)
+ *buf++ = (char)cc;
+ psz++;
+ len++;
+ }
else if ( (m_options & MAP_INVALID_UTF8_TO_OCTAL) &&
cc == L'\\' &&
isoctal(psz[0]) && isoctal(psz[1]) && isoctal(psz[2]) )
static bool ms_wcNeedsSwap;
};
+// make the constructor available for unit testing
+WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const wxChar* name )
+{
+ wxMBConv_iconv* result = new wxMBConv_iconv( name );
+ if ( !result->IsOk() )
+ {
+ delete result;
+ return 0;
+ }
+ return result;
+}
+
const char *wxMBConv_iconv::ms_wcCharsetName = NULL;
bool wxMBConv_iconv::ms_wcNeedsSwap = false;
UniChar* szUniBuffer = (UniChar*) szUnConv;
#if SIZEOF_WCHAR_T == 4
- wxMBConvUTF16BE converter ;
+ wxMBConvUTF16 converter ;
nBufSize = converter.WC2MB( NULL , szUnConv , 0 );
szUniBuffer = new UniChar[ (nBufSize / sizeof(UniChar)) + 1] ;
converter.WC2MB( (char*) szUniBuffer , szUnConv, nBufSize + sizeof(UniChar)) ;
// we have to terminate here, because n might be larger for the trailing zero, and if UniChar
// is not properly terminated we get random characters at the end
ubuf[byteOutLen / sizeof( UniChar ) ] = 0 ;
- wxMBConvUTF16BE converter ;
+ wxMBConvUTF16 converter ;
res = converter.MB2WC( (buf ? buf : tbuf) , (const char*)ubuf , n ) ;
free( ubuf ) ;
#else
ByteCount byteBufferLen = n ;
UniChar* ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4
- wxMBConvUTF16BE converter ;
+ wxMBConvUTF16 converter ;
size_t unicharlen = converter.WC2MB( NULL , psz , 0 ) ;
byteInLen = unicharlen ;
ubuf = (UniChar*) malloc( byteInLen + 2 ) ;
DECLARE_NO_COPY_CLASS(wxMBConv_wxwin)
};
+// make the constructors available for unit testing
+WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const wxChar* name )
+{
+ wxMBConv_wxwin* result = new wxMBConv_wxwin( name );
+ if ( !result->IsOk() )
+ {
+ delete result;
+ return 0;
+ }
+ return result;
+}
+
#endif // wxUSE_FONTMAP
// ============================================================================
#if wxUSE_FONTMAP
if ( name.empty() )
- name = wxFontMapperBase::Get()->GetEncodingName(m_encoding);
+ name = wxFontMapperBase::GetEncodingName(m_encoding);
#endif // wxUSE_FONTMAP
wxMBConv_iconv *conv = new wxMBConv_iconv(name);