/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifndef FOLLY_JSON_H_
#define FOLLY_JSON_H_
-#include "folly/dynamic.h"
-#include "folly/FBString.h"
-#include "folly/Range.h"
+#include <folly/dynamic.h>
+#include <folly/FBString.h>
+#include <folly/Range.h>
namespace folly {
namespace json {
+ //////////////////////////////////////////////////////////////////////
+
+ struct ParseError : std::runtime_error {
+ explicit ParseError(int line)
+ : std::runtime_error(to<std::string>("json parse error on line ", line))
+ {}
+
+ explicit ParseError(int line, std::string const& context,
+ std::string const& expected)
+ : std::runtime_error(to<std::string>("json parse error on line ", line,
+ !context.empty() ? to<std::string>(" near `", context, '\'')
+ : "",
+ ": ", expected))
+ {}
+
+ explicit ParseError(std::string const& msg)
+ : std::runtime_error("json parse error: " + msg)
+ {}
+ };
+
+
struct serialization_opts {
explicit serialization_opts()
: allow_non_string_keys(false)
, allow_trailing_comma(false)
, sort_keys(false)
, skip_invalid_utf8(false)
+ , allow_nan_inf(false)
+ , double_mode(double_conversion::DoubleToStringConverter::SHORTEST)
+ , double_num_digits(0) // ignored when mode is SHORTEST
{}
// If true, keys in an object can be non-strings. (In strict
// Replace invalid utf8 characters with U+FFFD and continue
bool skip_invalid_utf8;
+
+ // true to allow NaN or INF values
+ bool allow_nan_inf;
+
+ // Options for how to print floating point values. See Conv.h
+ // toAppend implementation for floating point for more info
+ double_conversion::DoubleToStringConverter::DtoaMode double_mode;
+ unsigned int double_num_digits;
};
/*
void escapeString(StringPiece input,
fbstring& out,
const serialization_opts& opts);
+
+ /*
+ * Strip all C99-like comments (i.e. // and / * ... * /)
+ */
+ fbstring stripComments(StringPiece jsonC);
}
//////////////////////////////////////////////////////////////////////