[Scummvm-git-logs] scummvm master -> c3a29cacc61b0b92d8dac19812b0d93456ecd8f4

bluegr noreply at scummvm.org
Thu Nov 6 17:38:37 UTC 2025


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

Summary:
c3a29cacc6 COMMON: Add helper function for using Strings with JSON::parse


Commit: c3a29cacc61b0b92d8dac19812b0d93456ecd8f4
    https://github.com/scummvm/scummvm/commit/c3a29cacc61b0b92d8dac19812b0d93456ecd8f4
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-11-06T19:38:33+02:00

Commit Message:
COMMON: Add helper function for using Strings with JSON::parse

Changed paths:
    backends/cloud/onedrive/onedrivetokenrefresher.cpp
    backends/cloud/savessyncrequest.cpp
    common/formats/json.h
    engines/scumm/he/net/net_lobby.cpp
    engines/scumm/he/net/net_main.cpp
    engines/twp/spritesheet.cpp
    gui/cloudconnectionwizard.cpp


diff --git a/backends/cloud/onedrive/onedrivetokenrefresher.cpp b/backends/cloud/onedrive/onedrivetokenrefresher.cpp
index 8f7d2ac7d04..c8622f47110 100644
--- a/backends/cloud/onedrive/onedrivetokenrefresher.cpp
+++ b/backends/cloud/onedrive/onedrivetokenrefresher.cpp
@@ -112,7 +112,7 @@ void OneDriveTokenRefresher::finishJson(const Common::JSONValue *json) {
 
 void OneDriveTokenRefresher::finishError(const Networking::ErrorResponse &error, Networking::RequestState state) {
 	if (error.failed) {
-		Common::JSONValue *value = Common::JSON::parse(error.response.c_str());
+		Common::JSONValue *value = Common::JSON::parse(error.response);
 
 		//somehow OneDrive returns JSON with '.' in unexpected places, try fixing it
 		if (!value) {
@@ -121,7 +121,7 @@ void OneDriveTokenRefresher::finishError(const Networking::ErrorResponse &error,
 				if (fixedResponse[i] == '.')
 					fixedResponse.replace(i, 1, " ");
 			}
-			value = Common::JSON::parse(fixedResponse.c_str());
+			value = Common::JSON::parse(fixedResponse);
 		}
 
 		if (value) {
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index 2e6969d8285..510165016a1 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -188,7 +188,7 @@ void SavesSyncRequest::directoryListedErrorCallback(const Networking::ErrorRespo
 
 	bool irrecoverable = error.interrupted || error.failed;
 	if (error.failed) {
-		Common::JSONValue *value = Common::JSON::parse(error.response.c_str());
+		Common::JSONValue *value = Common::JSON::parse(error.response);
 
 		// Somehow OneDrive returns JSON with '.' in unexpected places, try fixing it
 		if (!value) {
@@ -197,7 +197,7 @@ void SavesSyncRequest::directoryListedErrorCallback(const Networking::ErrorRespo
 				if (fixedResponse[i] == '.')
 					fixedResponse.replace(i, 1, " ");
 			}
-			value = Common::JSON::parse(fixedResponse.c_str());
+			value = Common::JSON::parse(fixedResponse);
 		}
 
 		if (value) {
diff --git a/common/formats/json.h b/common/formats/json.h
index 8dcb040e512..4ede4136be6 100644
--- a/common/formats/json.h
+++ b/common/formats/json.h
@@ -155,6 +155,9 @@ public:
 	/** Prepares raw bytes in a given stream to be parsed with Common::JSON::parse(). */
 	static char *zeroTerminateContents(Common::MemoryWriteStreamDynamic &stream);
 
+	static JSONValue *parse(const Common::String &data) {
+		return parse(data.c_str());
+	}
 	static JSONValue *parse(const char *data);
 	static String stringify(const JSONValue *value);
 protected:
diff --git a/engines/scumm/he/net/net_lobby.cpp b/engines/scumm/he/net/net_lobby.cpp
index ff4afa7e069..2b87ac3643e 100644
--- a/engines/scumm/he/net/net_lobby.cpp
+++ b/engines/scumm/he/net/net_lobby.cpp
@@ -111,7 +111,7 @@ void Lobby::receiveData() {
 
 void Lobby::processLine(Common::String line) {
 	debugC(DEBUG_NETWORK, "LOBBY: Received Data: %s", line.c_str());
-	Common::JSONValue *json = Common::JSON::parse(line.c_str());
+	Common::JSONValue *json = Common::JSON::parse(line);
 	if (!json) {
 		warning("LOBBY: Received trunciated data from server! %s", line.c_str());
 		return;
diff --git a/engines/scumm/he/net/net_main.cpp b/engines/scumm/he/net/net_main.cpp
index 08401af42a0..b438b028fd3 100644
--- a/engines/scumm/he/net/net_main.cpp
+++ b/engines/scumm/he/net/net_main.cpp
@@ -825,7 +825,7 @@ int Net::remoteSendData(int typeOfSend, int sendTypeParam, int type, Common::Str
 		reliable == true ? "true" : "false", data.c_str());
 
 	debugC(DEBUG_NETWORK, "NETWORK: Sending data: %s", res.c_str());
-	Common::JSONValue *str = Common::JSON::parse(res.c_str());
+	Common::JSONValue *str = Common::JSON::parse(res);
 	if (_isHost) {
 		_hostDataQueue.push(str);
 		_peerIndexQueue.push(sendTypeParam - 1);
@@ -975,7 +975,7 @@ void Net::serviceSessionServer() {
 void Net::handleSessionServerData(Common::String data) {
 	debugC(DEBUG_NETWORK, "NETWORK: Received data from session server.  Data: %s", data.c_str());
 
-	Common::JSONValue *json = Common::JSON::parse(data.c_str());
+	Common::JSONValue *json = Common::JSON::parse(data);
 	if (!json) {
 		warning("NETWORK: Received non-JSON string from session server, \"%s\", ignoring", data.c_str());
 		return;
@@ -1126,7 +1126,7 @@ bool Net::serviceBroadcast() {
 void Net::handleBroadcastData(Common::String data, Common::String host, int port) {
 	debugC(DEBUG_NETWORK, "NETWORK: Received data from broadcast socket.  Source: %s:%d  Data: %s", host.c_str(), port, data.c_str());
 
-	Common::JSONValue *json = Common::JSON::parse(data.c_str());
+	Common::JSONValue *json = Common::JSON::parse(data);
 	if (!json) {
 		// Just about anything could come from the broadcast address, so do not warn.
 		debugC(DEBUG_NETWORK, "NETWORK: Not a JSON string, ignoring.");
@@ -1271,7 +1271,7 @@ void Net::remoteReceiveData() {
 				break;
 			}
 
-			Common::JSONValue *json = Common::JSON::parse(data.c_str());
+			Common::JSONValue *json = Common::JSON::parse(data);
 			if (!json) {
 				// Just about anything could come from the broadcast address, so do not warn.
 				warning("NETWORK: Received non-JSON string.  Got: \"%s\"", data.c_str());
diff --git a/engines/twp/spritesheet.cpp b/engines/twp/spritesheet.cpp
index 6af2c04bc6a..20b232598a7 100644
--- a/engines/twp/spritesheet.cpp
+++ b/engines/twp/spritesheet.cpp
@@ -48,7 +48,7 @@ static void parseFrame(const Common::String &key, const Common::JSONObject &valu
 }
 
 void SpriteSheet::parseSpriteSheet(const Common::String &contents) {
-	Common::ScopedPtr<Common::JSONValue> json(Common::JSON::parse(contents.c_str()));
+	Common::ScopedPtr<Common::JSONValue> json(Common::JSON::parse(contents));
 	const Common::JSONObject &obj = json->asObject()["frames"]->asObject();
 	for (auto it = obj.begin(); it != obj.end(); it++) {
 		parseFrame(it->_key, it->_value->asObject(), _frameTable[it->_key]);
diff --git a/gui/cloudconnectionwizard.cpp b/gui/cloudconnectionwizard.cpp
index 959e3a2871a..73e42a90378 100644
--- a/gui/cloudconnectionwizard.cpp
+++ b/gui/cloudconnectionwizard.cpp
@@ -549,10 +549,7 @@ void CloudConnectionWizard::manualModeConnect() {
 	}
 
 	// parse JSON and display message if failed
-	Common::MemoryWriteStreamDynamic jsonStream(DisposeAfterUse::YES);
-	jsonStream.write(code.c_str(), code.size());
-	char *contents = Common::JSON::zeroTerminateContents(jsonStream);
-	Common::JSONValue *json = Common::JSON::parse(contents);
+	Common::JSONValue *json = Common::JSON::parse(code);
 
 	// pass JSON to the manager
 	_connecting = true;




More information about the Scummvm-git-logs mailing list