mirror of
https://review.haiku-os.org/haiku
synced 2025-01-18 20:48:48 +01:00
35c4600e21
Improve the mechanics for JSON parsing by reusing text buffers during the parse. Change-Id: I7fb2cae31e6558a5a0c63fd02e1fc6fec4f9e4b3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7106 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
69 lines
2.0 KiB
C++
69 lines
2.0 KiB
C++
/*
|
|
* Copyright 2017-2023, Andrew Lindesay <apl@lindesay.co.nz>
|
|
* Copyright 2014, Augustin Cavalier (waddlesplash)
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _JSON_H
|
|
#define _JSON_H
|
|
|
|
|
|
#include "JsonEventListener.h"
|
|
|
|
#include <Message.h>
|
|
#include <String.h>
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
class JsonParseContext;
|
|
|
|
class BJson {
|
|
|
|
public:
|
|
static status_t Parse(const char* JSON, BMessage& message);
|
|
static status_t Parse(const char* JSON, size_t length,
|
|
BMessage& message);
|
|
static status_t Parse(const BString& JSON, BMessage& message);
|
|
static void Parse(BDataIO* data,
|
|
BJsonEventListener* listener);
|
|
|
|
private:
|
|
static bool NextChar(JsonParseContext& jsonParseContext,
|
|
char* c);
|
|
static bool NextNonWhitespaceChar(
|
|
JsonParseContext& jsonParseContext,
|
|
char* c);
|
|
|
|
static bool ParseAny(JsonParseContext& jsonParseContext);
|
|
static bool ParseObjectNameValuePair(
|
|
JsonParseContext& jsonParseContext);
|
|
static bool ParseObject(JsonParseContext& jsonParseContext);
|
|
static bool ParseArray(JsonParseContext& jsonParseContext);
|
|
|
|
static bool ParseEscapeUnicodeSequence(JsonParseContext& jsonParseContext);
|
|
static bool ParseStringEscapeSequence(JsonParseContext& jsonParseContext);
|
|
static bool ParseString(JsonParseContext& jsonParseContext,
|
|
json_event_type eventType);
|
|
|
|
static bool ParseExpectedVerbatimStringAndRaiseEvent(
|
|
JsonParseContext& jsonParseContext,
|
|
const char* expectedString,
|
|
size_t expectedStringLength,
|
|
char leadingChar,
|
|
json_event_type jsonEventType);
|
|
static bool ParseExpectedVerbatimString(
|
|
JsonParseContext& jsonParseContext,
|
|
const char* expectedString,
|
|
size_t expectedStringLength,
|
|
char leadingChar);
|
|
|
|
static bool IsValidNumber(const char* value);
|
|
static bool ParseNumber(JsonParseContext& jsonParseContext);
|
|
};
|
|
|
|
} // namespace BPrivate
|
|
|
|
using BPrivate::BJson;
|
|
|
|
#endif // _JSON_H
|