Core/ResourceLoader: Fix assert

Former-commit-id: 391a0ec4de1a1c5ed97ea82aee0d3d69fbbc00df
This commit is contained in:
Lynix 2016-03-30 17:49:27 +02:00
parent d2e3bb36a6
commit 5465951f87
2 changed files with 35 additions and 25 deletions

View File

@ -244,7 +244,7 @@ namespace Nz
bool ResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters) bool ResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters)
{ {
NazaraAssert(resource, "Invalid resource"); NazaraAssert(resource, "Invalid resource");
NazaraAssert(stream.GetCursorPos() >= stream.GetSize(), "No data to load"); NazaraAssert(stream.GetCursorPos() < stream.GetSize(), "No data to load");
NazaraAssert(parameters.IsValid(), "Invalid parameters"); NazaraAssert(parameters.IsValid(), "Invalid parameters");
UInt64 streamPos = stream.GetCursorPos(); UInt64 streamPos = stream.GetCursorPos();

View File

@ -1462,8 +1462,12 @@ namespace Nz
{ {
if (Detail::ToLower(*ptr) == c) if (Detail::ToLower(*ptr) == c)
{ {
if (ptr != m_sharedString->string.get() && !std::isspace(*(ptr-1))) if (ptr != m_sharedString->string.get())
continue; {
--ptr;
if (!(Unicode::GetCategory(*ptr++) & Unicode::Category_Separator))
continue;
}
const char* p = &string[1]; const char* p = &string[1];
const char* tPtr = ptr+1; const char* tPtr = ptr+1;
@ -1471,7 +1475,7 @@ namespace Nz
{ {
if (*p == '\0') if (*p == '\0')
{ {
if (*tPtr == '\0' || std::isspace(*tPtr)) if (*tPtr == '\0' || Unicode::GetCategory(*tPtr) & Unicode::Category_Separator)
return ptr-m_sharedString->string.get(); return ptr-m_sharedString->string.get();
else else
break; break;
@ -1496,8 +1500,12 @@ namespace Nz
{ {
if (*ptr == string[0]) if (*ptr == string[0])
{ {
if (ptr != m_sharedString->string.get() && !std::isspace(*(ptr-1))) if (ptr != m_sharedString->string.get())
continue; {
--ptr;
if (!(Unicode::GetCategory(*ptr++) & Unicode::Category_Separator))
continue;
}
const char* p = &string[1]; const char* p = &string[1];
const char* tPtr = ptr+1; const char* tPtr = ptr+1;
@ -1505,7 +1513,7 @@ namespace Nz
{ {
if (*p == '\0') if (*p == '\0')
{ {
if (*tPtr == '\0' || std::isspace(*tPtr)) if (*tPtr == '\0' || Unicode::GetCategory(*tPtr) & Unicode::Category_Separator)
return ptr-m_sharedString->string.get(); return ptr-m_sharedString->string.get();
else else
break; break;
@ -1655,7 +1663,8 @@ namespace Nz
{ {
if (Detail::ToLower(*ptr) == c) if (Detail::ToLower(*ptr) == c)
{ {
if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) char nextC = *(ptr + 1);
if (nextC != '\0' && (Unicode::GetCategory(nextC) & Unicode::Category_Separator_Space) == 0)
continue; continue;
const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; const char* p = &string.m_sharedString->string[string.m_sharedString->size-1];
@ -1666,7 +1675,7 @@ namespace Nz
if (p == &string.m_sharedString->string[0]) if (p == &string.m_sharedString->string[0])
{ {
if (ptr == m_sharedString->string.get() || std::isspace(*(ptr-1))) if (ptr == m_sharedString->string.get() || Unicode::GetCategory(*(ptr-1)) & Unicode::Category_Separator_Space)
return ptr-m_sharedString->string.get(); return ptr-m_sharedString->string.get();
else else
break; break;
@ -1685,7 +1694,8 @@ namespace Nz
{ {
if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1])
{ {
if (*(ptr+1) != '\0' && !std::isspace(*(ptr+1))) char nextC = *(ptr + 1);
if (nextC != '\0' && (Unicode::GetCategory(nextC) & Unicode::Category_Separator_Space) == 0)
continue; continue;
const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; const char* p = &string.m_sharedString->string[string.m_sharedString->size-1];
@ -1696,7 +1706,7 @@ namespace Nz
if (p == &string.m_sharedString->string[0]) if (p == &string.m_sharedString->string[0])
{ {
if (ptr == m_sharedString->string.get() || std::isspace(*(ptr-1))) if (ptr == m_sharedString->string.get() || Unicode::GetCategory(*(ptr - 1)) & Unicode::Category_Separator_Space)
return ptr-m_sharedString->string.get(); return ptr-m_sharedString->string.get();
else else
break; break;
@ -1834,7 +1844,7 @@ namespace Nz
{ {
if (Detail::ToLower(*ptr) == c) if (Detail::ToLower(*ptr) == c)
{ {
if (ptr != m_sharedString->string.get() && !std::isspace(*(ptr-1))) if (ptr != m_sharedString->string.get() && (Unicode::GetCategory(*(ptr - 1)) & Unicode::Category_Separator) == 0)
continue; continue;
const char* p = &string[1]; const char* p = &string[1];
@ -1843,7 +1853,7 @@ namespace Nz
{ {
if (*p == '\0') if (*p == '\0')
{ {
if (*tPtr == '\0' || std::isspace(*tPtr)) if (*tPtr == '\0' || Unicode::GetCategory(*tPtr) & Unicode::Category_Separator)
return ptr - m_sharedString->string.get(); return ptr - m_sharedString->string.get();
else else
break; break;
@ -1865,7 +1875,7 @@ namespace Nz
{ {
if (*ptr == string[0]) if (*ptr == string[0])
{ {
if (ptr != m_sharedString->string.get() && !std::isspace(*(ptr-1))) if (ptr != m_sharedString->string.get() && (Unicode::GetCategory(*(ptr-1)) & Unicode::Category_Separator) == 0)
continue; continue;
const char* p = &string[1]; const char* p = &string[1];
@ -1874,7 +1884,7 @@ namespace Nz
{ {
if (*p == '\0') if (*p == '\0')
{ {
if (*tPtr == '\0' || std::isspace(*tPtr)) if (*tPtr == '\0' || Unicode::GetCategory(*tPtr) & Unicode::Category_Separator)
return ptr - m_sharedString->string.get(); return ptr - m_sharedString->string.get();
else else
break; break;
@ -2016,7 +2026,7 @@ namespace Nz
{ {
if (Detail::ToLower(*ptr) == c) if (Detail::ToLower(*ptr) == c)
{ {
if (ptr != m_sharedString->string.get() && !std::isspace(*(ptr-1))) if (ptr != m_sharedString->string.get() && (Unicode::GetCategory(*(ptr-1)) & Unicode::Category_Separator_Space) == 0)
continue; continue;
const char* p = &string.m_sharedString->string[1]; const char* p = &string.m_sharedString->string[1];
@ -2025,7 +2035,7 @@ namespace Nz
{ {
if (*p == '\0') if (*p == '\0')
{ {
if (*tPtr == '\0' || std::isspace(*tPtr)) if (*tPtr == '\0' || Unicode::GetCategory(*tPtr) & Unicode::Category_Separator_Space)
return ptr - m_sharedString->string.get(); return ptr - m_sharedString->string.get();
else else
break; break;
@ -2046,7 +2056,7 @@ namespace Nz
while ((ptr = std::strstr(ptr, string.GetConstBuffer())) != nullptr) while ((ptr = std::strstr(ptr, string.GetConstBuffer())) != nullptr)
{ {
// If the word is really alone // If the word is really alone
if ((ptr == m_sharedString->string.get() || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) if ((ptr == m_sharedString->string.get() || Unicode::GetCategory(*(ptr-1)) & Unicode::Category_Separator_Space) && (*(ptr+m_sharedString->size) == '\0' || Unicode::GetCategory(*(ptr+m_sharedString->size)) & Unicode::Category_Separator_Space))
return ptr - m_sharedString->string.get(); return ptr - m_sharedString->string.get();
ptr++; ptr++;
@ -2221,7 +2231,7 @@ namespace Nz
{ {
do do
{ {
if (std::isspace(*ptr)) if (Unicode::GetCategory(*ptr) & Unicode::Category_Separator)
{ {
endPos = static_cast<std::intmax_t>(ptr - m_sharedString->string.get() - 1); endPos = static_cast<std::intmax_t>(ptr - m_sharedString->string.get() - 1);
break; break;
@ -2273,7 +2283,7 @@ namespace Nz
{ {
do do
{ {
if (std::isspace(*ptr)) if (Unicode::GetCategory(*ptr) & Unicode::Category_Separator)
inWord = false; inWord = false;
else else
{ {
@ -3427,7 +3437,7 @@ namespace Nz
const char* limit = &m_sharedString->string[m_sharedString->size]; const char* limit = &m_sharedString->string[m_sharedString->size];
do do
{ {
if (std::isspace(*ptr)) if (Unicode::GetCategory(*ptr) & Unicode::Category_Separator)
{ {
if (inword) if (inword)
{ {
@ -4232,7 +4242,7 @@ namespace Nz
utf8::unchecked::iterator<const char*> it(m_sharedString->string.get()); utf8::unchecked::iterator<const char*> it(m_sharedString->string.get());
do do
{ {
if (Unicode::GetCategory(*it) & Unicode::Category_Separator) if ((Unicode::GetCategory(*it) & Unicode::Category_Separator) == 0)
break; break;
} }
while (*++it); while (*++it);
@ -4247,7 +4257,7 @@ namespace Nz
utf8::unchecked::iterator<const char*> it(&m_sharedString->string[m_sharedString->size]); utf8::unchecked::iterator<const char*> it(&m_sharedString->string[m_sharedString->size]);
while ((it--).base() != m_sharedString->string.get()) while ((it--).base() != m_sharedString->string.get())
{ {
if (Unicode::GetCategory(*it) & Unicode::Category_Separator) if ((Unicode::GetCategory(*it) & Unicode::Category_Separator) == 0)
break; break;
} }
@ -4263,7 +4273,7 @@ namespace Nz
{ {
for (; startPos < m_sharedString->size; ++startPos) for (; startPos < m_sharedString->size; ++startPos)
{ {
if (!std::isspace(m_sharedString->string[startPos])) if ((Unicode::GetCategory(m_sharedString->string[startPos]) & Unicode::Category_Separator) == 0)
break; break;
} }
} }
@ -4273,7 +4283,7 @@ namespace Nz
{ {
for (; endPos > 0; --endPos) for (; endPos > 0; --endPos)
{ {
if (!std::isspace(m_sharedString->string[endPos])) if ((Unicode::GetCategory(m_sharedString->string[endPos]) & Unicode::Category_Separator) == 0)
break; break;
} }
} }