root/headers/private/shared/Json.h
/*
 * 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