JSONValidator.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef JSON_VALIDATOR_H
  2. #define JSON_VALIDATOR_H
  3. #include "JSONDebug.h"
  4. #ifdef JSON_VALIDATE
  5. #ifdef JSON_SECURITY_MAX_NEST_LEVEL
  6. #define DEPTH_PARAM ,size_t depth_param
  7. #define DEPTH_ARG(arg) ,arg
  8. #define INC_DEPTH()\
  9. if (++depth_param > JSON_SECURITY_MAX_NEST_LEVEL){\
  10. JSON_FAIL(JSON_TEXT("Exceeded JSON_SECURITY_MAX_NEST_LEVEL"));\
  11. return false;\
  12. }
  13. #else
  14. #define DEPTH_PARAM
  15. #define DEPTH_ARG(arg)
  16. #define INC_DEPTH() (void)0
  17. #endif
  18. class JSONValidator {
  19. public:
  20. static bool isValidNumber(const json_char * & ptr) json_nothrow json_read_priority;
  21. static bool isValidMember(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority;
  22. static bool isValidString(const json_char * & ptr) json_nothrow json_read_priority;
  23. static bool isValidNamedObject(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority;
  24. static bool isValidObject(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority;
  25. static bool isValidArray(const json_char * & ptr DEPTH_PARAM) json_nothrow json_read_priority;
  26. static bool isValidRoot(const json_char * json) json_nothrow json_read_priority;
  27. #ifdef JSON_STREAM
  28. static bool isValidPartialRoot(const json_char * json) json_nothrow json_read_priority;
  29. #endif
  30. private:
  31. JSONValidator(void);
  32. };
  33. #endif
  34. #endif