wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
{
// first get necessary size
-
- size_t nLen = conv.MB2WC((wchar_t *) NULL, psz, 0);
+ size_t nLen = psz ? conv.MB2WC((wchar_t *) NULL, psz, 0) : 0;
// nLength is number of *Unicode* characters here!
if (nLen > nLength)
wxString::wxString(const wchar_t *pwz)
{
// first get necessary size
-
- size_t nLen = wxWC2MB((char *) NULL, pwz, 0);
+ size_t nLen = pwz ? wxWC2MB((char *) NULL, pwz, 0) : 0;
// empty?
if ( nLen != 0 ) {
if (s.Len() < min_width)
s.Pad(min_width - s.Len(), _T(' '), adj_left);
*this += s;
- done = TRUE;
}
+ done = TRUE;
break;
case _T('n'):
if (ilen == 0) {
static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
{
+ if (!charset) return (wxCharacterSet *)NULL;
wxLoadCharacterSets();
for (size_t n=0; n<wxCharsets.GetCount(); n++)
if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
wxCSConv::wxCSConv(const wxChar *charset)
{
- if (!charset) {
-#ifdef __UNIX__
- wxChar *lang = wxGetenv(_T("LANG"));
- wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
- if (dot) charset = dot+1;
-#endif
- }
+ m_name = (wxChar *) NULL;
m_cset = (wxCharacterSet *) NULL;
- m_deferred = FALSE;
+ m_deferred = TRUE;
+ SetName(charset);
+}
+
+wxCSConv::~wxCSConv()
+{
+ if (m_name) free(m_name);
+}
+
+void wxCSConv::SetName(const wxChar *charset)
+{
if (charset) {
#ifdef __UNIX__
// first, convert the character set name to standard form
}
}
-wxCSConv::~wxCSConv()
-{
- free(m_name);
-}
-
void wxCSConv::LoadNow()
{
// wxPrintf(_T("Conversion request\n"));
if (m_deferred) {
+ if (!m_name) {
+#ifdef __UNIX__
+ wxChar *lang = wxGetenv(_T("LANG"));
+ wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
+ if (dot) SetName(dot+1);
+#endif
+ }
m_cset = wxFindCharacterSet(m_name);
m_deferred = FALSE;
}
((wxCSConv *)this)->LoadNow(); // discard constness
if (buf) {
if (m_cset) {
- for (size_t c=0; c<=n; c++)
+ for (size_t c=0; c<n; c++)
buf[c] = m_cset->data[psz[c]];
} else {
// latin-1 (direct)
- for (size_t c=0; c<=n; c++)
+ for (size_t c=0; c<n; c++)
buf[c] = psz[c];
}
+ return n;
}
- return n;
+ return strlen(psz);
}
size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
((wxCSConv *)this)->LoadNow(); // discard constness
if (buf) {
if (m_cset) {
- for (size_t c=0; c<=n; c++) {
+ for (size_t c=0; c<n; c++) {
size_t n;
for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
buf[c] = (n>0xff) ? '?' : n;
}
} else {
// latin-1 (direct)
- for (size_t c=0; c<=n; c++)
+ for (size_t c=0; c<n; c++)
buf[c] = (psz[c]>0xff) ? '?' : psz[c];
}
+ return n;
}
- return n;
+ return wcslen(psz);
}
-