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

Side by Side Diff: Source/core/editing/MarkupAccumulator.cpp

Issue 114103005: Use StringBuilder::appendLiteral() when possible in MarkupAccumulator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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
« no previous file with comments | « no previous file | Source/core/editing/markup.cpp » ('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) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 StringImpl* foundNS = namespaces.get(pre); 282 StringImpl* foundNS = namespaces.get(pre);
283 if (foundNS != namespaceURI.impl()) { 283 if (foundNS != namespaceURI.impl()) {
284 namespaces.set(pre, namespaceURI.impl()); 284 namespaces.set(pre, namespaceURI.impl());
285 result.append(' '); 285 result.append(' ');
286 result.append(xmlnsAtom.string()); 286 result.append(xmlnsAtom.string());
287 if (!prefix.isEmpty()) { 287 if (!prefix.isEmpty()) {
288 result.append(':'); 288 result.append(':');
289 result.append(prefix); 289 result.append(prefix);
290 } 290 }
291 291
292 result.append('='); 292 result.appendLiteral("=\"");
293 result.append('"');
294 appendAttributeValue(result, namespaceURI, false); 293 appendAttributeValue(result, namespaceURI, false);
295 result.append('"'); 294 result.append('"');
296 } 295 }
297 } 296 }
298 297
299 EntityMask MarkupAccumulator::entityMaskForText(Text* text) const 298 EntityMask MarkupAccumulator::entityMaskForText(Text* text) const
300 { 299 {
301 if (!text->document().isHTMLDocument()) 300 if (!text->document().isHTMLDocument())
302 return EntityMaskInPCDATA; 301 return EntityMaskInPCDATA;
303 302
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (n->name().isEmpty()) 350 if (n->name().isEmpty())
352 return; 351 return;
353 352
354 result.appendLiteral("<!DOCTYPE "); 353 result.appendLiteral("<!DOCTYPE ");
355 result.append(n->name()); 354 result.append(n->name());
356 if (!n->publicId().isEmpty()) { 355 if (!n->publicId().isEmpty()) {
357 result.appendLiteral(" PUBLIC \""); 356 result.appendLiteral(" PUBLIC \"");
358 result.append(n->publicId()); 357 result.append(n->publicId());
359 result.append('"'); 358 result.append('"');
360 if (!n->systemId().isEmpty()) { 359 if (!n->systemId().isEmpty()) {
361 result.append(' '); 360 result.appendLiteral(" \"");
362 result.append('"');
363 result.append(n->systemId()); 361 result.append(n->systemId());
364 result.append('"'); 362 result.append('"');
365 } 363 }
366 } else if (!n->systemId().isEmpty()) { 364 } else if (!n->systemId().isEmpty()) {
367 result.appendLiteral(" SYSTEM \""); 365 result.appendLiteral(" SYSTEM \"");
368 result.append(n->systemId()); 366 result.append(n->systemId());
369 result.append('"'); 367 result.append('"');
370 } 368 }
371 if (!n->internalSubset().isEmpty()) { 369 if (!n->internalSubset().isEmpty()) {
372 result.append(' '); 370 result.appendLiteral(" [");
373 result.append('[');
374 result.append(n->internalSubset()); 371 result.append(n->internalSubset());
375 result.append(']'); 372 result.append(']');
376 } 373 }
377 result.append('>'); 374 result.append('>');
378 } 375 }
379 376
380 void MarkupAccumulator::appendProcessingInstruction(StringBuilder& result, const String& target, const String& data) 377 void MarkupAccumulator::appendProcessingInstruction(StringBuilder& result, const String& target, const String& data)
381 { 378 {
382 // FIXME: PI data is not escaped, but XMLSerializer (and possibly other call ers) this should raise an exception if it includes "?>". 379 // FIXME: PI data is not escaped, but XMLSerializer (and possibly other call ers) this should raise an exception if it includes "?>".
383 result.append('<'); 380 result.appendLiteral("<?");
384 result.append('?');
385 result.append(target); 381 result.append(target);
386 result.append(' '); 382 result.append(' ');
387 result.append(data); 383 result.append(data);
388 result.append('?'); 384 result.appendLiteral("?>");
389 result.append('>');
390 } 385 }
391 386
392 void MarkupAccumulator::appendElement(StringBuilder& result, Element* element, N amespaces* namespaces) 387 void MarkupAccumulator::appendElement(StringBuilder& result, Element* element, N amespaces* namespaces)
393 { 388 {
394 appendOpenTag(result, element, namespaces); 389 appendOpenTag(result, element, namespaces);
395 390
396 if (element->hasAttributes()) { 391 if (element->hasAttributes()) {
397 unsigned length = element->attributeCount(); 392 unsigned length = element->attributeCount();
398 for (unsigned int i = 0; i < length; i++) 393 for (unsigned int i = 0; i < length; i++)
399 appendAttribute(result, element, *element->attributeItem(i), namespa ces); 394 appendAttribute(result, element, *element->attributeItem(i), namespa ces);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // or createContextualFragment. It does not necessarily align with 531 // or createContextualFragment. It does not necessarily align with
537 // which elements should be serialized w/o end tags. 532 // which elements should be serialized w/o end tags.
538 return toHTMLElement(node)->ieForbidsInsertHTML(); 533 return toHTMLElement(node)->ieForbidsInsertHTML();
539 } 534 }
540 535
541 void MarkupAccumulator::appendEndMarkup(StringBuilder& result, const Node* node) 536 void MarkupAccumulator::appendEndMarkup(StringBuilder& result, const Node* node)
542 { 537 {
543 if (!node->isElementNode() || shouldSelfClose(node) || (!node->hasChildNodes () && elementCannotHaveEndTag(node))) 538 if (!node->isElementNode() || shouldSelfClose(node) || (!node->hasChildNodes () && elementCannotHaveEndTag(node)))
544 return; 539 return;
545 540
546 result.append('<'); 541 result.appendLiteral("</");
547 result.append('/');
548 result.append(toElement(node)->nodeNamePreservingCase()); 542 result.append(toElement(node)->nodeNamePreservingCase());
549 result.append('>'); 543 result.append('>');
550 } 544 }
551 545
552 } 546 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/markup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698