BJson: Use the normal "input, output" argument ordering instead of the reverse.
Update all in-tree consumers of the BJson API to match. Also added const-qualifiers to the BString versions of the API, and added the leading "_" to the header guards.
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
* Copyright 2014, Augustin Cavalier (waddlesplash)
|
* Copyright 2014, Augustin Cavalier (waddlesplash)
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef JSON_H
|
#ifndef _JSON_H
|
||||||
#define JSON_H
|
#define _JSON_H
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@@ -18,14 +18,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static status_t Parse(BMessage& message, const char* JSON);
|
static status_t Parse(const char* JSON, BMessage& message);
|
||||||
static status_t Parse(BMessage& message, BString& JSON);
|
static status_t Parse(const BString& JSON, BMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void _Parse(BMessage& message, BString& JSON);
|
static void _Parse(const BString& JSON, BMessage& message);
|
||||||
static BString _ParseString(BString& JSON, int32& pos);
|
static BString _ParseString(const BString& JSON, int32& pos);
|
||||||
static double _ParseNumber(BString& JSON, int32& pos);
|
static double _ParseNumber(const BString& JSON, int32& pos);
|
||||||
static bool _ParseConstant(BString& JSON, int32& pos,
|
static bool _ParseConstant(const BString& JSON, int32& pos,
|
||||||
const char* constant);
|
const char* constant);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,4 +33,4 @@ private:
|
|||||||
|
|
||||||
using BPrivate::BJson;
|
using BPrivate::BJson;
|
||||||
|
|
||||||
#endif // JSON_H
|
#endif // _JSON_H
|
||||||
|
|||||||
@@ -252,9 +252,8 @@ status_t
|
|||||||
ServerIconExportUpdateProcess::_PopulateIconMetaData(IconMetaData& iconMetaData,
|
ServerIconExportUpdateProcess::_PopulateIconMetaData(IconMetaData& iconMetaData,
|
||||||
BString& jsonString) const
|
BString& jsonString) const
|
||||||
{
|
{
|
||||||
BJson parser;
|
|
||||||
BMessage infoMetaDataMessage;
|
BMessage infoMetaDataMessage;
|
||||||
status_t result = parser.Parse(infoMetaDataMessage, jsonString);
|
status_t result = BJson::Parse(jsonString, infoMetaDataMessage);
|
||||||
|
|
||||||
if (result == B_OK)
|
if (result == B_OK)
|
||||||
return _PopulateIconMetaData(iconMetaData, infoMetaDataMessage);
|
return _PopulateIconMetaData(iconMetaData, infoMetaDataMessage);
|
||||||
|
|||||||
@@ -679,8 +679,7 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
|||||||
if (jsonString.Length() == 0)
|
if (jsonString.Length() == 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
BJson parser;
|
status_t status = BJson::Parse(jsonString, reply);
|
||||||
status_t status = parser.Parse(reply, jsonString);
|
|
||||||
if (ServerSettings::UrlConnectionTraceLoggingEnabled() &&
|
if (ServerSettings::UrlConnectionTraceLoggingEnabled() &&
|
||||||
status == B_BAD_DATA) {
|
status == B_BAD_DATA) {
|
||||||
printf("Parser choked on JSON:\n%s\n", jsonString.String());
|
printf("Parser choked on JSON:\n%s\n", jsonString.String());
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ BGeolocation::LocateSelf(float& latitude, float& longitude)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BMessage data;
|
BMessage data;
|
||||||
result = BJson::Parse(data, (char*)listener.result.Buffer());
|
result = BJson::Parse((char*)listener.result.Buffer(), data);
|
||||||
delete http;
|
delete http;
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -60,18 +60,18 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BJson::Parse(BMessage& message, const char* JSON)
|
BJson::Parse(const char* JSON, BMessage& message)
|
||||||
{
|
{
|
||||||
BString temp(JSON);
|
BString temp(JSON);
|
||||||
return Parse(message, temp);
|
return Parse(temp, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BJson::Parse(BMessage& message, BString& JSON)
|
BJson::Parse(const BString& JSON, BMessage& message)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
_Parse(message, JSON);
|
_Parse(JSON, message);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.PrintToStream();
|
e.PrintToStream();
|
||||||
@@ -85,7 +85,7 @@ BJson::Parse(BMessage& message, BString& JSON)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BJson::_Parse(BMessage& message, BString& JSON)
|
BJson::_Parse(const BString& JSON, BMessage& message)
|
||||||
{
|
{
|
||||||
BMessageBuilder builder(message);
|
BMessageBuilder builder(message);
|
||||||
int32 pos = 0;
|
int32 pos = 0;
|
||||||
@@ -315,7 +315,7 @@ BJson::_Parse(BMessage& message, BString& JSON)
|
|||||||
|
|
||||||
|
|
||||||
BString
|
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.
|
if (JSON[pos] != '"') // Verify we're at the start of a string.
|
||||||
return BString("");
|
return BString("");
|
||||||
@@ -379,7 +379,7 @@ BJson::_ParseString(BString& JSON, int32& pos)
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
BJson::_ParseNumber(BString& JSON, int32& pos)
|
BJson::_ParseNumber(const BString& JSON, int32& pos)
|
||||||
{
|
{
|
||||||
BString value;
|
BString value;
|
||||||
bool isDouble = false;
|
bool isDouble = false;
|
||||||
@@ -429,7 +429,7 @@ BJson::_ParseNumber(BString& JSON, int32& pos)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BJson::_ParseConstant(BString& JSON, int32& pos, const char* constant)
|
BJson::_ParseConstant(const BString& JSON, int32& pos, const char* constant)
|
||||||
{
|
{
|
||||||
BString value;
|
BString value;
|
||||||
JSON.CopyInto(value, pos, strlen(constant));
|
JSON.CopyInto(value, pos, strlen(constant));
|
||||||
|
|||||||
Reference in New Issue
Block a user