From 957ba97a3336ed653a1bbb6d9febc457e388bc78 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Fri, 16 Jun 2017 02:24:19 +0300 Subject: [PATCH] Make it possible for the Buffer wrapper to detect the length of a raw string if the requested length is negative. --- source/Library/Utils/Buffer.cpp | 21 ++++++++++++++++++++- source/Library/Utils/Buffer.hpp | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/Library/Utils/Buffer.cpp b/source/Library/Utils/Buffer.cpp index 9208d594..7f1a5415 100644 --- a/source/Library/Utils/Buffer.cpp +++ b/source/Library/Utils/Buffer.cpp @@ -218,10 +218,29 @@ Object SqBuffer::ReadString() } // ------------------------------------------------------------------------------------------------ -Object SqBuffer::ReadRawString(Uint32 len) +Object SqBuffer::ReadRawString(SQInteger length) { // Validate the managed buffer reference 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 if ((m_Buffer->Position() + len) > m_Buffer->Capacity()) { diff --git a/source/Library/Utils/Buffer.hpp b/source/Library/Utils/Buffer.hpp index 13ab12b0..508d9abb 100644 --- a/source/Library/Utils/Buffer.hpp +++ b/source/Library/Utils/Buffer.hpp @@ -779,7 +779,7 @@ public: /* -------------------------------------------------------------------------------------------- * Read a raw string from the buffer. */ - Object ReadRawString(Uint32 len); + Object ReadRawString(SQInteger length); /* -------------------------------------------------------------------------------------------- * Read a AABB from the buffer.