[Scummvm-git-logs] scummvm master -> 721b7376bbf386690915fcbae32d5f38752ed6e3

SupSuper supsuper at gmail.com
Mon May 31 22:04:35 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
721b7376bb COMMON: Clean up ReadStream::readString


Commit: 721b7376bbf386690915fcbae32d5f38752ed6e3
    https://github.com/scummvm/scummvm/commit/721b7376bbf386690915fcbae32d5f38752ed6e3
Author: SupSuper (supsuper at gmail.com)
Date: 2021-05-31T23:04:06+01:00

Commit Message:
COMMON: Clean up ReadStream::readString

Changed paths:
    common/stream.cpp


diff --git a/common/stream.cpp b/common/stream.cpp
index d78bb4e122..07f6d26805 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -55,16 +55,18 @@ SeekableReadStream *ReadStream::readStream(uint32 dataSize) {
 Common::String ReadStream::readString(char terminator, size_t len) {
 	Common::String result;
 	char c;
+	bool end = false;
+	size_t bytesRead = 0;
 
-	while ((c = (char)readByte()) != terminator && result.size() < len && !eos())
-		result += c;
-
-	// If the string terminated early, skip the remaining bytes
-	if (!eos() && len != Common::String::npos && result.size() < len - 1) {
-		size_t skipBytes = len - result.size() - 1; // skip terminator
-		for (size_t i = 0; i < skipBytes; i++) {
-			readByte();
-		}
+	while (bytesRead < len && !(end && len == Common::String::npos)) {
+		c = (char)readByte();
+		if (eos())
+			break;
+		if (c == terminator)
+			end = true;
+		if (!end)
+			result += c;
+		bytesRead++;
 	}
 
 	return result;




More information about the Scummvm-git-logs mailing list