X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a28d23bb2c4a5967a11dd4e392aff86275ae8c66..6f841509cecded593e8e7c20d4a9e23ed29e5fa1:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 4126813a50..2d371b9fa4 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -256,8 +256,7 @@ wxString::wxString(const void *pStart, const void *pEnd) 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) @@ -279,8 +278,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t 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 ) { @@ -1187,8 +1185,8 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr) 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) { @@ -1937,27 +1935,25 @@ static void wxLoadCharacterSets(void) if (already_loaded) return; -#if defined(__UNIX__) && wxUSE_UNICODE +#if defined(__UNIX__) // search through files in /usr/share/i18n/charmaps wxString fname; - printf("Commencing load\n"); for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*")); !fname.IsEmpty(); fname = ::wxFindNextFile()) { - wxPrintf(_("Loading: %s\n"), fname.c_str()); wxTextFile cmap(fname); if (cmap.Open()) { wxCharacterSet *cset = new wxCharacterSet; wxString comchar,escchar; bool in_charset = FALSE; - wxPrintf(_T("yup, loaded %s\n"),fname.c_str()); + // wxFprintf(stderr,_T("Loaded: %s\n"),fname.c_str()); wxString line; for (line = cmap.GetFirstLine(); !cmap.Eof(); line = cmap.GetNextLine()) { - wxPrintf(_T("line contents: %s\n"),line.c_str()); + // wxFprintf(stderr,_T("line contents: %s\n"),line.c_str()); wxStringTokenizer token(line); wxString cmd = token.GetNextToken(); if (cmd == comchar) { @@ -1974,12 +1970,13 @@ static void wxLoadCharacterSets(void) comchar = token.GetNextToken(); else if (cmd == _T("")) escchar = token.GetNextToken(); - else if (cmd == _T("")) { delete cset; - goto forget_it; // we don't support multibyte charsets ourselves (yet) + cset = (wxCharacterSet *) NULL; + break; // we don't support multibyte charsets ourselves (yet) } else if (cmd == _T("CHARMAP")) { - cset->data = (wchar_t *)calloc(256, sizeof(wxChar)); + cset->data = (wchar_t *)calloc(256, sizeof(wchar_t)); in_charset = TRUE; } else if (cmd == _T("END")) { @@ -1988,19 +1985,31 @@ static void wxLoadCharacterSets(void) } else if (in_charset) { // format: /x00 NULL (NUL) + // /x41 LATIN CAPITAL LETTER A wxString hex = token.GetNextToken(); + // skip whitespace (why doesn't wxStringTokenizer do this?) + while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken(); wxString uni = token.GetNextToken(); - // just assume that we've got the right format - int pos = ::wxHexToDec(hex.Mid(2,2)); - unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2)); - unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2)); - cset->data[pos] = (uni1 << 16) | uni2; + // skip whitespace again + while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken(); + + if ((hex.GetChar(0) == escchar) && (hex.GetChar(1) == _T('x')) && + (uni.Left(2) == _T("=0) { + unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2)); + unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2)); + cset->data[pos] = (uni1 << 16) | uni2; + // wxFprintf(stderr,_T("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]); + } + } } } - cset->names.Shrink(); - wxCharsets.Add(cset); - forget_it: - continue; + if (cset) { + cset->names.Shrink(); + wxCharsets.Add(cset); + } } } #endif @@ -2010,6 +2019,7 @@ static void wxLoadCharacterSets(void) static wxCharacterSet *wxFindCharacterSet(const wxChar *charset) { + if (!charset) return (wxCharacterSet *)NULL; wxLoadCharacterSets(); for (size_t n=0; nLoadNow(); // discard constness if (buf) { if (m_cset) { - for (size_t c=0; c<=n; c++) + for (size_t c=0; cdata[psz[c]]; } else { // latin-1 (direct) - for (size_t c=0; c<=n; c++) + for (size_t c=0; cLoadNow(); // discard constness if (buf) { if (m_cset) { - for (size_t c=0; c<=n; c++) { + for (size_t c=0; cdata[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; c0xff) ? '?' : psz[c]; } + return n; } - return n; + return wcslen(psz); } -