1 /* 2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz> 3 * Copyright 2014, Augustin Cavalier (waddlesplash) 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _JSON_H 7 #define _JSON_H 8 9 10 #include "JsonEventListener.h" 11 12 #include <Message.h> 13 #include <String.h> 14 15 16 namespace BPrivate { 17 18 class JsonParseContext; 19 20 class BJson { 21 22 public: 23 static status_t Parse(const char* JSON, BMessage& message); 24 static status_t Parse(const BString& JSON, BMessage& message); 25 static void Parse(BDataIO* data, 26 BJsonEventListener* listener); 27 28 private: 29 static bool NextChar(JsonParseContext& jsonParseContext, 30 char* c); 31 static bool NextNonWhitespaceChar( 32 JsonParseContext& jsonParseContext, 33 char* c); 34 35 static bool ParseAny(JsonParseContext& jsonParseContext); 36 static bool ParseObjectNameValuePair( 37 JsonParseContext& jsonParseContext); 38 static bool ParseObject(JsonParseContext& jsonParseContext); 39 static bool ParseArray(JsonParseContext& jsonParseContext); 40 static bool ParseEscapeUnicodeSequence( 41 JsonParseContext& jsonParseContext, 42 BString& stringResult); 43 static bool ParseStringEscapeSequence( 44 JsonParseContext& jsonParseContext, 45 BString& stringResult); 46 static bool ParseString(JsonParseContext& jsonParseContext, 47 json_event_type eventType); 48 static bool ParseExpectedVerbatimStringAndRaiseEvent( 49 JsonParseContext& jsonParseContext, 50 const char* expectedString, 51 size_t expectedStringLength, 52 char leadingChar, 53 json_event_type jsonEventType); 54 static bool ParseExpectedVerbatimString( 55 JsonParseContext& jsonParseContext, 56 const char* expectedString, 57 size_t expectedStringLength, 58 char leadingChar); 59 60 static bool IsValidNumber(BString& number); 61 static bool ParseNumber(JsonParseContext& jsonParseContext); 62 }; 63 64 } // namespace BPrivate 65 66 using BPrivate::BJson; 67 68 #endif // _JSON_H 69