X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=folly%2Fjson.h;h=788587a8aa6defbabf2b8ef69b91f07f5ceee278;hb=79869083465aabfcb9d9abd7f31ecfe812e3464b;hp=3d229f3f1f61d01eff6a950a2d30c34c81f986c0;hpb=e202187f468b692b5d352142a81a5ce0229b7e8a;p=folly.git diff --git a/folly/json.h b/folly/json.h index 3d229f3f..788587a8 100644 --- a/folly/json.h +++ b/folly/json.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,14 +38,14 @@ * @author Jordan DeLong */ -#ifndef FOLLY_JSON_H_ -#define FOLLY_JSON_H_ +#pragma once #include +#include -#include -#include +#include #include +#include namespace folly { @@ -55,20 +55,20 @@ namespace json { struct serialization_opts { explicit serialization_opts() - : allow_non_string_keys(false) - , javascript_safe(false) - , pretty_formatting(false) - , encode_non_ascii(false) - , validate_utf8(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 - , double_fallback(false) - , parse_numbers_as_strings(false) - {} + : allow_non_string_keys(false), + javascript_safe(false), + pretty_formatting(false), + encode_non_ascii(false), + validate_utf8(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 + double_fallback(false), + parse_numbers_as_strings(false), + recursion_limit(100) {} // If true, keys in an object can be non-strings. (In strict // JSON, object keys must be strings.) This is used by dynamic's @@ -96,8 +96,14 @@ namespace json { bool allow_trailing_comma; // Sort keys of all objects before printing out (potentially slow) + // using dynamic::operator<. + // Has no effect if sort_keys_by is set. bool sort_keys; + // Sort keys of all objects before printing out (potentially slow) + // using the provided less functor. + Function sort_keys_by; + // Replace invalid utf8 characters with U+FFFD and continue bool skip_invalid_utf8; @@ -116,6 +122,9 @@ namespace json { // Do not parse numbers. Instead, store them as strings and leave the // conversion up to the user. bool parse_numbers_as_strings; + + // Recursion limit when parsing. + unsigned int recursion_limit; }; /* @@ -123,21 +132,22 @@ namespace json { * For the most common use cases there are simpler functions in the * main folly namespace below. */ - fbstring serialize(dynamic const&, serialization_opts const&); + std::string serialize(dynamic const&, serialization_opts const&); /* * Escape a string so that it is legal to print it in JSON text and * append the result to out. */ - void escapeString(StringPiece input, - fbstring& out, - const serialization_opts& opts); + void escapeString( + StringPiece input, + std::string& out, + const serialization_opts& opts); /* * Strip all C99-like comments (i.e. // and / * ... * /) */ - fbstring stripComments(StringPiece jsonC); + std::string stripComments(StringPiece jsonC); } ////////////////////////////////////////////////////////////////////// @@ -152,13 +162,13 @@ dynamic parseJson(StringPiece); /* * Serialize a dynamic into a json string. */ -fbstring toJson(dynamic const&); +std::string toJson(dynamic const&); /* * Same as the above, except format the json with some minimal * indentation. */ -fbstring toPrettyJson(dynamic const&); +std::string toPrettyJson(dynamic const&); /* * Printer for GTest. @@ -168,5 +178,3 @@ void PrintTo(const dynamic&, std::ostream*); ////////////////////////////////////////////////////////////////////// } - -#endif