#include <ctype.h>
#include <string.h>
#include <stdlib.h>
-#ifdef HAVE_LANGINFO_H
- #include <langinfo.h>
-#endif
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
#define wxHAVE_WIN32_MB2WC
output = *input;
return 1;
}
- else if ((input[1]<0xdc00) || (input[1]>=0xdfff))
+ else if ((input[1]<0xdc00) || (input[1]>0xdfff))
{
output = *input;
return (size_t)-1;
}
//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;
}
return wxWC2MB(buf, psz, n);
}
-#ifdef __WXGTK20__
+#ifdef __UNIX__
// ----------------------------------------------------------------------------
-// wxConvBrokenFileNames is made for GTK2 in Unicode mode when
-// files are accidentally written in an encoding which is not
-// the system encoding. Typically, the system encoding will be
-// UTF8 but there might be files stored in ISO8859-1 on disk.
+// wxConvBrokenFileNames
// ----------------------------------------------------------------------------
-class wxConvBrokenFileNames : public wxMBConv
+wxConvBrokenFileNames::wxConvBrokenFileNames(const wxChar *charset)
{
-public:
- wxConvBrokenFileNames();
- virtual ~wxConvBrokenFileNames() { delete m_conv; }
-
- virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
- virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
-
-private:
- // the conversion object we forward to
- wxMBConv *m_conv;
-};
-
-wxConvBrokenFileNames::wxConvBrokenFileNames()
-{
- // 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
- const wxChar *encName = wxGetenv(_T("G_FILENAME_ENCODING"));
- if ( encName )
- {
- m_conv = new wxCSConv(encName);
- }
- else // no G_FILENAME_ENCODING
- {
- // (2) if a non default locale is set, assume that the user wants his
- // filenames in this locale too
- switch ( wxLocale::GetSystemEncoding() )
- {
- default:
- m_conv = new wxMBConvLibc;
- break;
-
- // (3) finally use UTF-8 by default
- case wxFONTENCODING_SYSTEM:
- case wxFONTENCODING_UTF8:
- m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL);
- break;
- }
- }
+ 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
return m_conv->WC2MB( outputBuf, psz, outputSize );
}
-#endif // __WXGTK20__
+#endif
// ----------------------------------------------------------------------------
// UTF-7
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]) )
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 ) ;
static wxMBConvUTF7 wxConvUTF7Obj;
static wxMBConvUTF8 wxConvUTF8Obj;
-#ifdef __WXGTK20__
- static wxConvBrokenFileNames wxConvBrokenFileNamesObj;
-#endif
-
WXDLLIMPEXP_DATA_BASE(wxMBConv&) wxConvLibc = wxConvLibcObj;
WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvLocal = wxConvLocalObj;
WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvISO8859_1 = wxConvISO8859_1Obj;
WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = &
#ifdef __WXOSX__
wxConvUTF8Obj;
-#elif __WXGTK20__
- wxConvBrokenFileNamesObj;
#else
wxConvLibcObj;
#endif