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

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

Issue 482753002: Use StringBuilder::appendLiteral() / StringBuilder::append(char) when possible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/websockets/WebSocketHandshake.cpp ('k') | Source/platform/PODInterval.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28 matching lines...) Expand all
39 39
40 namespace { 40 namespace {
41 41
42 const char* const nullString = "null"; 42 const char* const nullString = "null";
43 const char* const trueString = "true"; 43 const char* const trueString = "true";
44 const char* const falseString = "false"; 44 const char* const falseString = "false";
45 45
46 inline bool escapeChar(UChar c, StringBuilder* dst) 46 inline bool escapeChar(UChar c, StringBuilder* dst)
47 { 47 {
48 switch (c) { 48 switch (c) {
49 case '\b': dst->append("\\b", 2); break; 49 case '\b': dst->appendLiteral("\\b"); break;
50 case '\f': dst->append("\\f", 2); break; 50 case '\f': dst->appendLiteral("\\f"); break;
51 case '\n': dst->append("\\n", 2); break; 51 case '\n': dst->appendLiteral("\\n"); break;
52 case '\r': dst->append("\\r", 2); break; 52 case '\r': dst->appendLiteral("\\r"); break;
53 case '\t': dst->append("\\t", 2); break; 53 case '\t': dst->appendLiteral("\\t"); break;
54 case '\\': dst->append("\\\\", 2); break; 54 case '\\': dst->appendLiteral("\\\\"); break;
55 case '"': dst->append("\\\"", 2); break; 55 case '"': dst->appendLiteral("\\\""); break;
56 default: 56 default:
57 return false; 57 return false;
58 } 58 }
59 return true; 59 return true;
60 } 60 }
61 61
62 inline void doubleQuoteString(const String& str, StringBuilder* dst) 62 inline void doubleQuoteString(const String& str, StringBuilder* dst)
63 { 63 {
64 dst->append('"'); 64 dst->append('"');
65 for (unsigned i = 0; i < str.length(); ++i) { 65 for (unsigned i = 0; i < str.length(); ++i) {
(...skipping 10 matching lines...) Expand all
76 dst->append(c); 76 dst->append(c);
77 } 77 }
78 } 78 }
79 } 79 }
80 dst->append('"'); 80 dst->append('"');
81 } 81 }
82 82
83 void writeIndent(int depth, StringBuilder* output) 83 void writeIndent(int depth, StringBuilder* output)
84 { 84 {
85 for (int i = 0; i < depth; ++i) 85 for (int i = 0; i < depth; ++i)
86 output->append(" "); 86 output->appendLiteral(" ");
87 } 87 }
88 88
89 } // anonymous namespace 89 } // anonymous namespace
90 90
91 bool JSONValue::asBoolean(bool*) const 91 bool JSONValue::asBoolean(bool*) const
92 { 92 {
93 return false; 93 return false;
94 } 94 }
95 95
96 bool JSONValue::asNumber(double*) const 96 bool JSONValue::asNumber(double*) const
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 output->append(','); 388 output->append(',');
389 doubleQuoteString(it->key, output); 389 doubleQuoteString(it->key, output);
390 output->append(':'); 390 output->append(':');
391 it->value->writeJSON(output); 391 it->value->writeJSON(output);
392 } 392 }
393 output->append('}'); 393 output->append('}');
394 } 394 }
395 395
396 void JSONObjectBase::prettyWriteJSONInternal(StringBuilder* output, int depth) c onst 396 void JSONObjectBase::prettyWriteJSONInternal(StringBuilder* output, int depth) c onst
397 { 397 {
398 output->append("{\n"); 398 output->appendLiteral("{\n");
399 for (size_t i = 0; i < m_order.size(); ++i) { 399 for (size_t i = 0; i < m_order.size(); ++i) {
400 Dictionary::const_iterator it = m_data.find(m_order[i]); 400 Dictionary::const_iterator it = m_data.find(m_order[i]);
401 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); 401 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end());
402 if (i) 402 if (i)
403 output->append(",\n"); 403 output->appendLiteral(",\n");
404 writeIndent(depth + 1, output); 404 writeIndent(depth + 1, output);
405 doubleQuoteString(it->key, output); 405 doubleQuoteString(it->key, output);
406 output->append(": "); 406 output->appendLiteral(": ");
407 it->value->prettyWriteJSONInternal(output, depth + 1); 407 it->value->prettyWriteJSONInternal(output, depth + 1);
408 } 408 }
409 output->append('\n'); 409 output->append('\n');
410 writeIndent(depth, output); 410 writeIndent(depth, output);
411 output->append('}'); 411 output->append('}');
412 } 412 }
413 413
414 JSONObjectBase::JSONObjectBase() 414 JSONObjectBase::JSONObjectBase()
415 : JSONValue(TypeObject) 415 : JSONValue(TypeObject)
416 , m_data() 416 , m_data()
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 m_data.append(value); 520 m_data.append(value);
521 } 521 }
522 522
523 PassRefPtr<JSONValue> JSONArrayBase::get(size_t index) 523 PassRefPtr<JSONValue> JSONArrayBase::get(size_t index)
524 { 524 {
525 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); 525 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
526 return m_data[index]; 526 return m_data[index];
527 } 527 }
528 528
529 } // namespace blink 529 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/websockets/WebSocketHandshake.cpp ('k') | Source/platform/PODInterval.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698