| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_JSON_JSON_WRITER_H_ | 5 #ifndef BASE_JSON_JSON_WRITER_H_ |
| 6 #define BASE_JSON_JSON_WRITER_H_ | 6 #define BASE_JSON_JSON_WRITER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // or appending a '.0') as long as the value is within the range of a | 30 // or appending a '.0') as long as the value is within the range of a |
| 31 // 64-bit int. | 31 // 64-bit int. |
| 32 OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 1, | 32 OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 1, |
| 33 | 33 |
| 34 // Return a slightly nicer formatted json string (pads with whitespace to | 34 // Return a slightly nicer formatted json string (pads with whitespace to |
| 35 // help with readability). | 35 // help with readability). |
| 36 OPTIONS_PRETTY_PRINT = 1 << 2, | 36 OPTIONS_PRETTY_PRINT = 1 << 2, |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Given a root node, generates a JSON string and puts it into |json|. | 39 // Given a root node, generates a JSON string and puts it into |json|. |
| 40 // The output string is overwritten and not appended. |
| 41 // |
| 40 // TODO(tc): Should we generate json if it would be invalid json (e.g., | 42 // TODO(tc): Should we generate json if it would be invalid json (e.g., |
| 41 // |node| is not a DictionaryValue/ListValue or if there are inf/-inf float | 43 // |node| is not a DictionaryValue/ListValue or if there are inf/-inf float |
| 42 // values)? Return true on success and false on failure. | 44 // values)? Return true on success and false on failure. |
| 43 static bool Write(const Value& node, std::string* json); | 45 static bool Write(const Value& node, std::string* json); |
| 44 | 46 |
| 45 // Same as above but with |options| which is a bunch of JSONWriter::Options | 47 // Same as above but with |options| which is a bunch of JSONWriter::Options |
| 46 // bitwise ORed together. Return true on success and false on failure. | 48 // bitwise ORed together. Return true on success and false on failure. |
| 47 static bool WriteWithOptions(const Value& node, | 49 static bool WriteWithOptions(const Value& node, |
| 48 int options, | 50 int options, |
| 49 std::string* json); | 51 std::string* json); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 | 66 |
| 65 // Where we write JSON data as we generate it. | 67 // Where we write JSON data as we generate it. |
| 66 std::string* json_string_; | 68 std::string* json_string_; |
| 67 | 69 |
| 68 DISALLOW_COPY_AND_ASSIGN(JSONWriter); | 70 DISALLOW_COPY_AND_ASSIGN(JSONWriter); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 } // namespace base | 73 } // namespace base |
| 72 | 74 |
| 73 #endif // BASE_JSON_JSON_WRITER_H_ | 75 #endif // BASE_JSON_JSON_WRITER_H_ |
| OLD | NEW |