Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/Source/platform/JSONValues.cpp

Issue 2017053003: Remove StringBuilder::appendLiteral. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 38
39 namespace { 39 namespace {
40 40
41 const char* const nullString = "null"; 41 const char* const nullString = "null";
42 const char* const trueString = "true"; 42 const char* const trueString = "true";
43 const char* const falseString = "false"; 43 const char* const falseString = "false";
44 44
45 inline bool escapeChar(UChar c, StringBuilder* dst) 45 inline bool escapeChar(UChar c, StringBuilder* dst)
46 { 46 {
47 switch (c) { 47 switch (c) {
48 case '\b': dst->appendLiteral("\\b"); break; 48 case '\b': dst->append("\\b"); break;
49 case '\f': dst->appendLiteral("\\f"); break; 49 case '\f': dst->append("\\f"); break;
50 case '\n': dst->appendLiteral("\\n"); break; 50 case '\n': dst->append("\\n"); break;
51 case '\r': dst->appendLiteral("\\r"); break; 51 case '\r': dst->append("\\r"); break;
52 case '\t': dst->appendLiteral("\\t"); break; 52 case '\t': dst->append("\\t"); break;
53 case '\\': dst->appendLiteral("\\\\"); break; 53 case '\\': dst->append("\\\\"); break;
54 case '"': dst->appendLiteral("\\\""); break; 54 case '"': dst->append("\\\""); break;
55 default: 55 default:
56 return false; 56 return false;
57 } 57 }
58 return true; 58 return true;
59 } 59 }
60 60
61 void writeIndent(int depth, StringBuilder* output) 61 void writeIndent(int depth, StringBuilder* output)
62 { 62 {
63 for (int i = 0; i < depth; ++i) 63 for (int i = 0; i < depth; ++i)
64 output->appendLiteral(" "); 64 output->append(" ");
65 } 65 }
66 66
67 } // anonymous namespace 67 } // anonymous namespace
68 68
69 void escapeStringForJSON(const String& str, StringBuilder* dst) 69 void escapeStringForJSON(const String& str, StringBuilder* dst)
70 { 70 {
71 for (unsigned i = 0; i < str.length(); ++i) { 71 for (unsigned i = 0; i < str.length(); ++i) {
72 UChar c = str[i]; 72 UChar c = str[i];
73 if (!escapeChar(c, dst)) { 73 if (!escapeChar(c, dst)) {
74 if (c < 32 || c > 126 || c == '<' || c == '>') { 74 if (c < 32 || c > 126 || c == '<' || c == '>') {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 output->append(','); 356 output->append(',');
357 doubleQuoteStringForJSON(it->key, output); 357 doubleQuoteStringForJSON(it->key, output);
358 output->append(':'); 358 output->append(':');
359 it->value->writeJSON(output); 359 it->value->writeJSON(output);
360 } 360 }
361 output->append('}'); 361 output->append('}');
362 } 362 }
363 363
364 void JSONObject::prettyWriteJSONInternal(StringBuilder* output, int depth) const 364 void JSONObject::prettyWriteJSONInternal(StringBuilder* output, int depth) const
365 { 365 {
366 output->appendLiteral("{\n"); 366 output->append("{\n");
367 for (size_t i = 0; i < m_order.size(); ++i) { 367 for (size_t i = 0; i < m_order.size(); ++i) {
368 Dictionary::const_iterator it = m_data.find(m_order[i]); 368 Dictionary::const_iterator it = m_data.find(m_order[i]);
369 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); 369 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end());
370 if (i) 370 if (i)
371 output->appendLiteral(",\n"); 371 output->append(",\n");
372 writeIndent(depth + 1, output); 372 writeIndent(depth + 1, output);
373 doubleQuoteStringForJSON(it->key, output); 373 doubleQuoteStringForJSON(it->key, output);
374 output->appendLiteral(": "); 374 output->append(": ");
375 it->value->prettyWriteJSONInternal(output, depth + 1); 375 it->value->prettyWriteJSONInternal(output, depth + 1);
376 } 376 }
377 output->append('\n'); 377 output->append('\n');
378 writeIndent(depth, output); 378 writeIndent(depth, output);
379 output->append('}'); 379 output->append('}');
380 } 380 }
381 381
382 JSONObject::JSONObject() 382 JSONObject::JSONObject()
383 : JSONValue(TypeObject) 383 : JSONValue(TypeObject)
384 , m_data() 384 , m_data()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 m_data.append(value); 475 m_data.append(value);
476 } 476 }
477 477
478 PassRefPtr<JSONValue> JSONArray::get(size_t index) 478 PassRefPtr<JSONValue> JSONArray::get(size_t index)
479 { 479 {
480 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); 480 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
481 return m_data[index]; 481 return m_data[index];
482 } 482 }
483 483
484 } // namespace blink 484 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Decimal.cpp ('k') | third_party/WebKit/Source/platform/PODInterval.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698