Better estimateSpaceNeeded(double)
[folly.git] / folly / json.h
index 89d3b0682851a5b1d9f6ed6e907cd7dca6cc4c4f..458ab63a3b67686777aa7ee0d7ebc63b8bdeb921 100644 (file)
@@ -51,6 +51,27 @@ 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)
@@ -121,6 +142,11 @@ namespace json {
   void escapeString(StringPiece input,
                     fbstring& out,
                     const serialization_opts& opts);
+
+  /*
+   * Strip all C99-like comments (i.e. // and / * ... * /)
+   */
+  fbstring stripComments(StringPiece jsonC);
 }
 
 //////////////////////////////////////////////////////////////////////