Index: base/json/json_writer.h |
diff --git a/base/json/json_writer.h b/base/json/json_writer.h |
index e4a143c77807e78bf84b4804b3bae988c86533bd..94052c8034321dd28e6adf4699029e287eb93a6f 100644 |
--- a/base/json/json_writer.h |
+++ b/base/json/json_writer.h |
@@ -17,19 +17,24 @@ |
class BASE_EXPORT JSONWriter { |
public: |
enum Options { |
+ // Do not escape the string, preserving its UTF8 characters. It is useful |
+ // if you can pass the resulting string to the JSON parser in binary form |
+ // (as UTF8). |
+ OPTIONS_DO_NOT_ESCAPE = 1 << 0, |
+ |
// For values of binary type, the value (and key if within a dictionary) |
// will be omitted from the output. |
- OPTIONS_OMIT_BINARY_VALUES = 1 << 0, |
+ OPTIONS_OMIT_BINARY_VALUES = 1 << 1, |
// This option instructs the writer to write doubles that have no fractional |
// part as a normal integer (i.e., without using exponential notation |
// or appending a '.0') as long as the value is within the range of a |
// 64-bit int. |
- OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 1, |
+ OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 2, |
// Return a slightly nicer formatted json string (pads with whitespace to |
// help with readability). |
- OPTIONS_PRETTY_PRINT = 1 << 2, |
+ OPTIONS_PRETTY_PRINT = 1 << 3 |
}; |
// Given a root node, generates a JSON string and puts it into |json|. |
@@ -43,8 +48,12 @@ |
static void WriteWithOptions(const Value* const node, int options, |
std::string* json); |
+ // A static, constant JSON string representing an empty array. Useful |
+ // for empty JSON argument passing. |
+ static const char* kEmptyArray; |
+ |
private: |
- JSONWriter(bool omit_binary_values, |
+ JSONWriter(bool escape, bool omit_binary_values, |
bool omit_double_type_preservation, bool pretty_print, |
std::string* json); |
@@ -52,9 +61,13 @@ |
// json_string_ will contain the JSON. |
void BuildJSONString(const Value* const node, int depth); |
+ // Appends a quoted, escaped, version of (UTF-8) str to json_string_. |
+ void AppendQuotedString(const std::string& str); |
+ |
// Adds space to json_string_ for the indent level. |
void IndentLine(int depth); |
+ bool escape_; |
bool omit_binary_values_; |
bool omit_double_type_preservation_; |
bool pretty_print_; |