don't use wxString::FromASCII() with possibly non-ASCII strings (fixes asserts when testing Japanese locale in the internat sample)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1307,52 +1307,56 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName,
|
|||||||
// plural forms formula from it:
|
// plural forms formula from it:
|
||||||
|
|
||||||
const char* headerData = StringAtOfs(m_pOrigTable, 0);
|
const char* headerData = StringAtOfs(m_pOrigTable, 0);
|
||||||
if (headerData && headerData[0] == 0)
|
if ( headerData && headerData[0] == '\0' )
|
||||||
{
|
{
|
||||||
// Extract the charset:
|
// Extract the charset:
|
||||||
wxString header = wxString::FromAscii(StringAtOfs(m_pTransTable, 0));
|
const char * const header = StringAtOfs(m_pTransTable, 0);
|
||||||
int begin = header.Find(wxS("Content-Type: text/plain; charset="));
|
const char *
|
||||||
if (begin != wxNOT_FOUND)
|
cset = strstr(header, "Content-Type: text/plain; charset=");
|
||||||
|
if ( cset )
|
||||||
{
|
{
|
||||||
begin += 34; //strlen("Content-Type: text/plain; charset=")
|
cset += 34; // strlen("Content-Type: text/plain; charset=")
|
||||||
size_t end = header.find('\n', begin);
|
|
||||||
if (end != size_t(-1))
|
const char * const csetEnd = strchr(cset, '\n');
|
||||||
|
if ( csetEnd )
|
||||||
{
|
{
|
||||||
m_charset.assign(header, begin, end - begin);
|
m_charset = wxString(cset, csetEnd - cset);
|
||||||
if (m_charset == wxS("CHARSET"))
|
if ( m_charset == wxS("CHARSET") )
|
||||||
{
|
{
|
||||||
// "CHARSET" is not valid charset, but lazy translator
|
// "CHARSET" is not valid charset, but lazy translator
|
||||||
m_charset.Clear();
|
m_charset.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else: incorrectly filled Content-Type header
|
// else: incorrectly filled Content-Type header
|
||||||
|
|
||||||
// Extract plural forms:
|
// Extract plural forms:
|
||||||
begin = header.Find(wxS("Plural-Forms:"));
|
const char * plurals = strstr(header, "Plural-Forms:");
|
||||||
if (begin != wxNOT_FOUND)
|
if ( plurals )
|
||||||
{
|
{
|
||||||
begin += 13;
|
plurals += 13; // strlen("Plural-Forms:")
|
||||||
size_t end = header.find('\n', begin);
|
const char * const pluralsEnd = strchr(plurals, '\n');
|
||||||
if (end != size_t(-1))
|
if ( pluralsEnd )
|
||||||
{
|
{
|
||||||
wxString pfs(header, begin, end - begin);
|
const size_t pluralsLen = pluralsEnd - plurals;
|
||||||
wxPluralFormsCalculator* pCalculator = wxPluralFormsCalculator
|
wxCharBuffer buf(pluralsLen);
|
||||||
::make(pfs.ToAscii());
|
strncpy(buf.data(), plurals, pluralsLen);
|
||||||
if (pCalculator != 0)
|
wxPluralFormsCalculator * const
|
||||||
|
pCalculator = wxPluralFormsCalculator::make(buf);
|
||||||
|
if ( pCalculator )
|
||||||
{
|
{
|
||||||
rPluralFormsCalculator.reset(pCalculator);
|
rPluralFormsCalculator.reset(pCalculator);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxLogVerbose(_("Cannot parse Plural-Forms:'%s'"), pfs.c_str());
|
wxLogVerbose(_("Failed to parse Plural-Forms: '%s'"),
|
||||||
|
buf.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rPluralFormsCalculator.get() == NULL)
|
|
||||||
{
|
if ( !rPluralFormsCalculator.get() )
|
||||||
rPluralFormsCalculator.reset(wxPluralFormsCalculator::make());
|
rPluralFormsCalculator.reset(wxPluralFormsCalculator::make());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// everything is fine
|
// everything is fine
|
||||||
|
Reference in New Issue
Block a user