From 11f666a793473db3b2a96747ce13bc9572cd5f18 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 16 May 2015 10:52:16 +0800 Subject: [PATCH] Add more verbose info --- include/rapidjson/schema.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 487f7fd..236e6d5 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -49,7 +49,12 @@ RAPIDJSON_DIAG_OFF(effc++) #endif #if RAPIDJSON_SCHEMA_VERBOSE -#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) printf("Fail: %s\n", keyword) +#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) \ +RAPIDJSON_MULTILINEMACRO_BEGIN\ + StringBuffer sb;\ + context.schema->GetPointer().Stringify(sb);\ + printf("Fail schema: %s\nFail keyword: %s\n", sb.GetString(), keyword);\ +RAPIDJSON_MULTILINEMACRO_END #else #define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword) #endif @@ -1396,9 +1401,23 @@ public: return documentStack_.Empty() ? PointerType() : PointerType(documentStack_.template Bottom(), documentStack_.GetSize() / sizeof(Ch)); } +#if RAPIDJSON_SCHEMA_VERBOSE +#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() \ +RAPIDJSON_MULTILINEMACRO_BEGIN\ + *documentStack_.template Push() = '\0';\ + documentStack_.template Pop(1);\ + printf("Fail document: %s\n\n", documentStack_.template Bottom());\ +RAPIDJSON_MULTILINEMACRO_END +#else +#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() +#endif + #define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\ if (!valid_) return false; \ - if (!BeginValue() || !CurrentSchema().method arg1) return valid_ = false; + if (!BeginValue() || !CurrentSchema().method arg1) {\ + RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\ + return valid_ = false;\ + } #define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\ for (Context* context = schemaStack_.template Bottom(); context != schemaStack_.template End(); context++) {\