mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 20:27:13 +01:00
Make it possible for the Buffer wrapper to detect the length of a raw string if the requested length is negative.
This commit is contained in:
parent
f048950d20
commit
957ba97a33
@ -218,10 +218,29 @@ Object SqBuffer::ReadString()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Object SqBuffer::ReadRawString(Uint32 len)
|
Object SqBuffer::ReadRawString(SQInteger length)
|
||||||
{
|
{
|
||||||
// Validate the managed buffer reference
|
// Validate the managed buffer reference
|
||||||
ValidateDeeper();
|
ValidateDeeper();
|
||||||
|
// Start with a length of zero
|
||||||
|
Uint32 len = 0;
|
||||||
|
// Should we Identify the string length ourselves?
|
||||||
|
if (length < 0)
|
||||||
|
{
|
||||||
|
// Grab the buffer range to search for
|
||||||
|
CCStr ptr = &m_Buffer->Cursor(), itr = ptr, end = m_Buffer->End();
|
||||||
|
// Attempt to look for a string terminator
|
||||||
|
while (itr != end && *itr != '\0')
|
||||||
|
{
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
// If nothing was found, consider the remaining buffer part of the requested string
|
||||||
|
len = static_cast< Uint32 >(ptr - itr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = ConvTo< Uint32 >::From(length);
|
||||||
|
}
|
||||||
// Validate the obtained length
|
// Validate the obtained length
|
||||||
if ((m_Buffer->Position() + len) > m_Buffer->Capacity())
|
if ((m_Buffer->Position() + len) > m_Buffer->Capacity())
|
||||||
{
|
{
|
||||||
|
@ -779,7 +779,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Read a raw string from the buffer.
|
* Read a raw string from the buffer.
|
||||||
*/
|
*/
|
||||||
Object ReadRawString(Uint32 len);
|
Object ReadRawString(SQInteger length);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Read a AABB from the buffer.
|
* Read a AABB from the buffer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user