| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/json_writer.h" | 5 #include "base/json_writer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "base/string_escape.h" | 10 #include "base/string_escape.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 json_string_->append(real); | 70 json_string_->append(real); |
| 71 break; | 71 break; |
| 72 } | 72 } |
| 73 | 73 |
| 74 case Value::TYPE_STRING: | 74 case Value::TYPE_STRING: |
| 75 { | 75 { |
| 76 std::wstring value; | 76 std::wstring value; |
| 77 bool result = node->GetAsString(&value); | 77 bool result = node->GetAsString(&value); |
| 78 DCHECK(result); | 78 DCHECK(result); |
| 79 AppendQuotedString(value); | 79 AppendQuotedString(WideToUTF16Hack(value)); |
| 80 break; | 80 break; |
| 81 } | 81 } |
| 82 | 82 |
| 83 case Value::TYPE_LIST: | 83 case Value::TYPE_LIST: |
| 84 { | 84 { |
| 85 json_string_->append("["); | 85 json_string_->append("["); |
| 86 if (pretty_print_) | 86 if (pretty_print_) |
| 87 json_string_->append(" "); | 87 json_string_->append(" "); |
| 88 | 88 |
| 89 const ListValue* list = static_cast<const ListValue*>(node); | 89 const ListValue* list = static_cast<const ListValue*>(node); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 break; | 149 break; |
| 150 } | 150 } |
| 151 | 151 |
| 152 default: | 152 default: |
| 153 // TODO(jhughes): handle TYPE_BINARY | 153 // TODO(jhughes): handle TYPE_BINARY |
| 154 NOTREACHED() << "unknown json type"; | 154 NOTREACHED() << "unknown json type"; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 void JSONWriter::AppendQuotedString(const std::wstring& str) { | 158 void JSONWriter::AppendQuotedString(const string16& str) { |
| 159 string_escape::JavascriptDoubleQuote(WideToUTF16Hack(str), true, | 159 string_escape::JavascriptDoubleQuote(str, true, |
| 160 json_string_); | 160 json_string_); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void JSONWriter::IndentLine(int depth) { | 163 void JSONWriter::IndentLine(int depth) { |
| 164 // It may be faster to keep an indent string so we don't have to keep | 164 // It may be faster to keep an indent string so we don't have to keep |
| 165 // reallocating. | 165 // reallocating. |
| 166 json_string_->append(std::string(depth * 3, ' ')); | 166 json_string_->append(std::string(depth * 3, ' ')); |
| 167 } | 167 } |
| OLD | NEW |