|
>+ if ( buf )
</span><span class="cx"> {
*buf++ = ((char*)psz)[1];
*buf++ = ((char*)psz)[0];
}
</span><span class="rem">- len += sizeof(wxUint16);
</span><span class="add">+ len += 2;
</span><span class="cx"> psz++;
}
</span><span class="rem">- if (buf &amp;&amp; len&lt;=n-sizeof(wxUint16)) *(wxUint16*)buf=0;
</span><span class="cx">
</span><span class="add">+ if ( buf &amp;&amp; len &lt; n )
+ *buf = '\0';
+
</span><span class="cx"> return len;
}
</span><span class="lines">@@ -1336,6 +1352,8 @@
</span><span class="cx"> #endif
private:
</span><span class="add">+ virtual const char *GetMBNul(size_t *nulLen) const;
+
</span><span class="cx"> // the name (for iconv_open()) of a wide char charset -- if none is
// available on this machine, it will remain NULL
static wxString ms_wcCharsetName;
</span><span class="lines">@@ -1343,6 +1361,10 @@
</span><span class="cx"> // true if the wide char encoding we use (i.e. ms_wcCharsetName) has
// different endian-ness than the native one
static bool ms_wcNeedsSwap;
</span><span class="add">+
+ // NUL representation
+ size_t m_nulLen;
+ char m_nulBuf[8];
</span><span class="cx"> };
// make the constructor available for unit testing
</span><span class="lines">@@ -1362,6 +1384,8 @@
</span><span class="cx">
wxMBConv_iconv::wxMBConv_iconv(const wxChar *name)
{
</span><span class="add">+ m_nulLen = (size_t)-2;
+
</span><span class="cx"> // iconv operates with chars, not wxChars, but luckily it uses only ASCII
// names for the charsets
const wxCharBuffer cname(wxString(name).ToAscii());
</span><span class="lines">@@ -1618,6 +1642,36 @@
</span><span class="cx"> return res;
}
</span><span class="add">+const char *wxMBConv_iconv::GetMBNul(size_t *nulLen) const
+{
+ if ( m_nulLen == (size_t)-2 )
+ {
+ wxMBConv_iconv * const self = wxConstCast(this, wxMBConv_iconv);
+
+#if wxUSE_THREADS
+ // NB: explained in MB2WC
+ wxMutexLocker lock(self-&gt;m_iconvMutex);
+#endif
+
+ wchar_t *wnul = L&quot;&quot;;
+ size_t inLen = sizeof(wchar_t),
+ outLen = WXSIZEOF(m_nulBuf);
+ const char *in = (char *)wnul;
+ char *out = self-&gt;m_nulBuf;
+ if ( iconv(w2m, &amp;in, &amp;inLen, &amp;out, &amp;outLen) == (size_t)-1 )
+ {
+ self-&gt;m_nulLen = (size_t)-1;
+ }
+ else // ok
+ {
+ self-&gt;m_nulLen = out - m_nulBuf;
+ }
+ }
+
+ *nulLen = m_nulLen;
+ return m_nulBuf;
+}
+
</span><span class="cx"> #endif // HAVE_ICONV
</span><span class="lines">@@ -1639,19 +1693,22 @@
</span><span class="cx"> wxMBConv_win32()
{
m_CodePage = CP_ACP;
</span><span class="add">+ m_nulLen = (size_t)-2;
</span><span class="cx"> }
#if wxUSE_FONTMAP
wxMBConv_win32(const wxChar* name)
{
m_CodePage = wxCharsetToCodepage(name);
</span><span class="add">+ m_nulLen = (size_t)- we can compute the input size if we were not given it: notice that
+ // in this case the string must be properly NUL-terminated, of course, as
+ // otherwise we have no way of knowing how long it is
+ if ( inLen == (size_t)-1 )
</span><span class="cx"> {
</span><span class="rem">- wxASSERT(szPos &lt; szEnd); //something is _really_ screwed up if this rings true
</span><span class="add">+ // not the most efficient algorithm but it shouldn't matter as normally
+ // there are not many NULs in the string and so normally memcmp()
+ // should stop on the first character
+ const char *p = in;
+ while ( memcmp(p, nul, nulLen) != 0 )
+ p++;
</span><spate();
&lt;/span&gt;&lt;span class="add"&gt;+ wxString srcMid = m_WParser-&amp;gt;GetInnerSource(tag);
+ ParseInnerSource(HtmlizeWhitespaces(srcMid));
&lt;/span&gt;&lt;span class="cx"&gt;
m_WParser-&amp;gt;CloseContainer();
m_WParser-&amp;gt;CloseContainer();
&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
|
|