diff --git a/headers/private/shared/Json.h b/headers/private/shared/Json.h index 6df2648e63..edb8e453b4 100644 --- a/headers/private/shared/Json.h +++ b/headers/private/shared/Json.h @@ -2,8 +2,8 @@ * Copyright 2014, Augustin Cavalier (waddlesplash) * Distributed under the terms of the MIT License. */ -#ifndef JSON_H -#define JSON_H +#ifndef _JSON_H +#define _JSON_H #include #include @@ -18,14 +18,14 @@ public: }; public: - static status_t Parse(BMessage& message, const char* JSON); - static status_t Parse(BMessage& message, BString& JSON); + static status_t Parse(const char* JSON, BMessage& message); + static status_t Parse(const BString& JSON, BMessage& message); private: - static void _Parse(BMessage& message, BString& JSON); - static BString _ParseString(BString& JSON, int32& pos); - static double _ParseNumber(BString& JSON, int32& pos); - static bool _ParseConstant(BString& JSON, int32& pos, + static void _Parse(const BString& JSON, BMessage& message); + static BString _ParseString(const BString& JSON, int32& pos); + static double _ParseNumber(const BString& JSON, int32& pos); + static bool _ParseConstant(const BString& JSON, int32& pos, const char* constant); }; @@ -33,4 +33,4 @@ private: using BPrivate::BJson; -#endif // JSON_H +#endif // _JSON_H diff --git a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp index 932da9b6af..c7d8de14d4 100644 --- a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp +++ b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp @@ -252,9 +252,8 @@ status_t ServerIconExportUpdateProcess::_PopulateIconMetaData(IconMetaData& iconMetaData, BString& jsonString) const { - BJson parser; BMessage infoMetaDataMessage; - status_t result = parser.Parse(infoMetaDataMessage, jsonString); + status_t result = BJson::Parse(jsonString, infoMetaDataMessage); if (result == B_OK) return _PopulateIconMetaData(iconMetaData, infoMetaDataMessage); diff --git a/src/apps/haikudepot/server/WebAppInterface.cpp b/src/apps/haikudepot/server/WebAppInterface.cpp index 4036a64f95..6ca4efaa61 100644 --- a/src/apps/haikudepot/server/WebAppInterface.cpp +++ b/src/apps/haikudepot/server/WebAppInterface.cpp @@ -679,8 +679,7 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString, if (jsonString.Length() == 0) return B_ERROR; - BJson parser; - status_t status = parser.Parse(reply, jsonString); + status_t status = BJson::Parse(jsonString, reply); if (ServerSettings::UrlConnectionTraceLoggingEnabled() && status == B_BAD_DATA) { printf("Parser choked on JSON:\n%s\n", jsonString.String()); diff --git a/src/kits/shared/Geolocation.cpp b/src/kits/shared/Geolocation.cpp index 7d2f4e8485..db712fb9d4 100644 --- a/src/kits/shared/Geolocation.cpp +++ b/src/kits/shared/Geolocation.cpp @@ -118,7 +118,7 @@ BGeolocation::LocateSelf(float& latitude, float& longitude) } BMessage data; - result = BJson::Parse(data, (char*)listener.result.Buffer()); + result = BJson::Parse((char*)listener.result.Buffer(), data); delete http; if (result != B_OK) { return result; diff --git a/src/kits/shared/Json.cpp b/src/kits/shared/Json.cpp index 739b37debd..057f25d75d 100644 --- a/src/kits/shared/Json.cpp +++ b/src/kits/shared/Json.cpp @@ -60,18 +60,18 @@ private: status_t -BJson::Parse(BMessage& message, const char* JSON) +BJson::Parse(const char* JSON, BMessage& message) { BString temp(JSON); - return Parse(message, temp); + return Parse(temp, message); } status_t -BJson::Parse(BMessage& message, BString& JSON) +BJson::Parse(const BString& JSON, BMessage& message) { try { - _Parse(message, JSON); + _Parse(JSON, message); return B_OK; } catch (ParseException e) { e.PrintToStream(); @@ -85,7 +85,7 @@ BJson::Parse(BMessage& message, BString& JSON) void -BJson::_Parse(BMessage& message, BString& JSON) +BJson::_Parse(const BString& JSON, BMessage& message) { BMessageBuilder builder(message); int32 pos = 0; @@ -315,7 +315,7 @@ BJson::_Parse(BMessage& message, BString& JSON) BString -BJson::_ParseString(BString& JSON, int32& pos) +BJson::_ParseString(const BString& JSON, int32& pos) { if (JSON[pos] != '"') // Verify we're at the start of a string. return BString(""); @@ -379,7 +379,7 @@ BJson::_ParseString(BString& JSON, int32& pos) double -BJson::_ParseNumber(BString& JSON, int32& pos) +BJson::_ParseNumber(const BString& JSON, int32& pos) { BString value; bool isDouble = false; @@ -429,7 +429,7 @@ BJson::_ParseNumber(BString& JSON, int32& pos) bool -BJson::_ParseConstant(BString& JSON, int32& pos, const char* constant) +BJson::_ParseConstant(const BString& JSON, int32& pos, const char* constant) { BString value; JSON.CopyInto(value, pos, strlen(constant));