haiku/headers/private/shared/Json.h
Andrew Lindesay 35c4600e21 Shared: JSON Parse Perf
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>
2023-11-16 20:38:21 +00:00

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