Commit 28e6a40f authored by Milo Yip's avatar Milo Yip

Change indentation to space

parent 48e0675e
...@@ -10,56 +10,56 @@ ...@@ -10,56 +10,56 @@
using namespace rapidjson; using namespace rapidjson;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: schemavalidator schema.json < input.json\n"); fprintf(stderr, "Usage: schemavalidator schema.json < input.json\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Read a JSON schema from file into Document // Read a JSON schema from file into Document
Document d; Document d;
char buffer[4096]; char buffer[4096];
{ {
FILE *fp = fopen(argv[1], "r"); FILE *fp = fopen(argv[1], "r");
if (!fp) { if (!fp) {
printf("Schema file '%s' not found\n", argv[1]); printf("Schema file '%s' not found\n", argv[1]);
return -1; return -1;
} }
FileReadStream fs(fp, buffer, sizeof(buffer)); FileReadStream fs(fp, buffer, sizeof(buffer));
d.ParseStream(fs); d.ParseStream(fs);
if (d.HasParseError()) { if (d.HasParseError()) {
fprintf(stderr, "Schema file '%s' is not a valid JSON\n", argv[1]); fprintf(stderr, "Schema file '%s' is not a valid JSON\n", argv[1]);
fprintf(stderr, "Error(offset %u): %s\n", fprintf(stderr, "Error(offset %u): %s\n",
static_cast<unsigned>(d.GetErrorOffset()), static_cast<unsigned>(d.GetErrorOffset()),
GetParseError_En(d.GetParseError())); GetParseError_En(d.GetParseError()));
fclose(fp); fclose(fp);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
fclose(fp); fclose(fp);
} }
// Then convert the Document into SchemaDocument // Then convert the Document into SchemaDocument
SchemaDocument sd(d); SchemaDocument sd(d);
// Use reader to parse the JSON in stdin, and forward SAX events to validator // Use reader to parse the JSON in stdin, and forward SAX events to validator
SchemaValidator validator(sd); SchemaValidator validator(sd);
Reader reader; Reader reader;
FileReadStream is(stdin, buffer, sizeof(buffer)); FileReadStream is(stdin, buffer, sizeof(buffer));
if (!reader.Parse(is, validator) && reader.GetParseErrorCode() != kParseErrorTermination) { if (!reader.Parse(is, validator) && reader.GetParseErrorCode() != kParseErrorTermination) {
// Schema validator error would cause kParseErrorTermination, which will handle it in next step. // Schema validator error would cause kParseErrorTermination, which will handle it in next step.
fprintf(stderr, "Input is not a valid JSON\n"); fprintf(stderr, "Input is not a valid JSON\n");
fprintf(stderr, "Error(offset %u): %s\n", fprintf(stderr, "Error(offset %u): %s\n",
static_cast<unsigned>(reader.GetErrorOffset()), static_cast<unsigned>(reader.GetErrorOffset()),
GetParseError_En(reader.GetParseErrorCode())); GetParseError_En(reader.GetParseErrorCode()));
} }
// Check the validation result // Check the validation result
if (validator.IsValid()) { if (validator.IsValid()) {
printf("Input JSON is valid.\n"); printf("Input JSON is valid.\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
else { else {
printf("Input JSON is invalid.\n"); printf("Input JSON is invalid.\n");
StringBuffer sb; StringBuffer sb;
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb); validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
fprintf(stderr, "Invalid schema: %s\n", sb.GetString()); fprintf(stderr, "Invalid schema: %s\n", sb.GetString());
...@@ -67,6 +67,6 @@ int main(int argc, char *argv[]) { ...@@ -67,6 +67,6 @@ int main(int argc, char *argv[]) {
sb.Clear(); sb.Clear();
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb); validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
fprintf(stderr, "Invalid document: %s\n", sb.GetString()); fprintf(stderr, "Invalid document: %s\n", sb.GetString());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment