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

Side by Side Diff: third_party/WebKit/Source/core/editing/serializers/MarkupFormatter.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) 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // or createContextualFragment. It does not necessarily align with 171 // or createContextualFragment. It does not necessarily align with
172 // which elements should be serialized w/o end tags. 172 // which elements should be serialized w/o end tags.
173 return toHTMLElement(node).ieForbidsInsertHTML(); 173 return toHTMLElement(node).ieForbidsInsertHTML();
174 } 174 }
175 175
176 void MarkupFormatter::appendEndMarkup(StringBuilder& result, const Element& elem ent) 176 void MarkupFormatter::appendEndMarkup(StringBuilder& result, const Element& elem ent)
177 { 177 {
178 if (shouldSelfClose(element) || (!element.hasChildren() && elementCannotHave EndTag(element))) 178 if (shouldSelfClose(element) || (!element.hasChildren() && elementCannotHave EndTag(element)))
179 return; 179 return;
180 180
181 result.appendLiteral("</"); 181 result.append("</");
182 result.append(element.tagQName().toString()); 182 result.append(element.tagQName().toString());
183 result.append('>'); 183 result.append('>');
184 } 184 }
185 185
186 void MarkupFormatter::appendAttributeValue(StringBuilder& result, const String& attribute, bool documentIsHTML) 186 void MarkupFormatter::appendAttributeValue(StringBuilder& result, const String& attribute, bool documentIsHTML)
187 { 187 {
188 appendCharactersReplacingEntities(result, attribute, 0, attribute.length(), 188 appendCharactersReplacingEntities(result, attribute, 0, attribute.length(),
189 documentIsHTML ? EntityMaskInHTMLAttributeValue : EntityMaskInAttributeV alue); 189 documentIsHTML ? EntityMaskInHTMLAttributeValue : EntityMaskInAttributeV alue);
190 } 190 }
191 191
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 AtomicString foundURI = namespaces.get(lookupKey); 227 AtomicString foundURI = namespaces.get(lookupKey);
228 if (foundURI != namespaceURI) { 228 if (foundURI != namespaceURI) {
229 namespaces.set(lookupKey, namespaceURI); 229 namespaces.set(lookupKey, namespaceURI);
230 result.append(' '); 230 result.append(' ');
231 result.append(xmlnsAtom.getString()); 231 result.append(xmlnsAtom.getString());
232 if (!prefix.isEmpty()) { 232 if (!prefix.isEmpty()) {
233 result.append(':'); 233 result.append(':');
234 result.append(prefix); 234 result.append(prefix);
235 } 235 }
236 236
237 result.appendLiteral("=\""); 237 result.append("=\"");
238 appendAttributeValue(result, namespaceURI, false); 238 appendAttributeValue(result, namespaceURI, false);
239 result.append('"'); 239 result.append('"');
240 } 240 }
241 } 241 }
242 242
243 void MarkupFormatter::appendText(StringBuilder& result, Text& text) 243 void MarkupFormatter::appendText(StringBuilder& result, Text& text)
244 { 244 {
245 const String& str = text.data(); 245 const String& str = text.data();
246 appendCharactersReplacingEntities(result, str, 0, str.length(), entityMaskFo rText(text)); 246 appendCharactersReplacingEntities(result, str, 0, str.length(), entityMaskFo rText(text));
247 } 247 }
248 248
249 void MarkupFormatter::appendComment(StringBuilder& result, const String& comment ) 249 void MarkupFormatter::appendComment(StringBuilder& result, const String& comment )
250 { 250 {
251 // FIXME: Comment content is not escaped, but XMLSerializer (and possibly ot her callers) should raise an exception if it includes "-->". 251 // FIXME: Comment content is not escaped, but XMLSerializer (and possibly ot her callers) should raise an exception if it includes "-->".
252 result.appendLiteral("<!--"); 252 result.append("<!--");
253 result.append(comment); 253 result.append(comment);
254 result.appendLiteral("-->"); 254 result.append("-->");
255 } 255 }
256 256
257 void MarkupFormatter::appendXMLDeclaration(StringBuilder& result, const Document & document) 257 void MarkupFormatter::appendXMLDeclaration(StringBuilder& result, const Document & document)
258 { 258 {
259 if (!document.hasXMLDeclaration()) 259 if (!document.hasXMLDeclaration())
260 return; 260 return;
261 261
262 result.appendLiteral("<?xml version=\""); 262 result.append("<?xml version=\"");
263 result.append(document.xmlVersion()); 263 result.append(document.xmlVersion());
264 const String& encoding = document.xmlEncoding(); 264 const String& encoding = document.xmlEncoding();
265 if (!encoding.isEmpty()) { 265 if (!encoding.isEmpty()) {
266 result.appendLiteral("\" encoding=\""); 266 result.append("\" encoding=\"");
267 result.append(encoding); 267 result.append(encoding);
268 } 268 }
269 if (document.xmlStandaloneStatus() != Document::StandaloneUnspecified) { 269 if (document.xmlStandaloneStatus() != Document::StandaloneUnspecified) {
270 result.appendLiteral("\" standalone=\""); 270 result.append("\" standalone=\"");
271 if (document.xmlStandalone()) 271 if (document.xmlStandalone())
272 result.appendLiteral("yes"); 272 result.append("yes");
273 else 273 else
274 result.appendLiteral("no"); 274 result.append("no");
275 } 275 }
276 276
277 result.appendLiteral("\"?>"); 277 result.append("\"?>");
278 } 278 }
279 279
280 void MarkupFormatter::appendDocumentType(StringBuilder& result, const DocumentTy pe& n) 280 void MarkupFormatter::appendDocumentType(StringBuilder& result, const DocumentTy pe& n)
281 { 281 {
282 if (n.name().isEmpty()) 282 if (n.name().isEmpty())
283 return; 283 return;
284 284
285 result.appendLiteral("<!DOCTYPE "); 285 result.append("<!DOCTYPE ");
286 result.append(n.name()); 286 result.append(n.name());
287 if (!n.publicId().isEmpty()) { 287 if (!n.publicId().isEmpty()) {
288 result.appendLiteral(" PUBLIC \""); 288 result.append(" PUBLIC \"");
289 result.append(n.publicId()); 289 result.append(n.publicId());
290 result.append('"'); 290 result.append('"');
291 if (!n.systemId().isEmpty()) { 291 if (!n.systemId().isEmpty()) {
292 result.appendLiteral(" \""); 292 result.append(" \"");
293 result.append(n.systemId()); 293 result.append(n.systemId());
294 result.append('"'); 294 result.append('"');
295 } 295 }
296 } else if (!n.systemId().isEmpty()) { 296 } else if (!n.systemId().isEmpty()) {
297 result.appendLiteral(" SYSTEM \""); 297 result.append(" SYSTEM \"");
298 result.append(n.systemId()); 298 result.append(n.systemId());
299 result.append('"'); 299 result.append('"');
300 } 300 }
301 result.append('>'); 301 result.append('>');
302 } 302 }
303 303
304 void MarkupFormatter::appendProcessingInstruction(StringBuilder& result, const S tring& target, const String& data) 304 void MarkupFormatter::appendProcessingInstruction(StringBuilder& result, const S tring& target, const String& data)
305 { 305 {
306 // FIXME: PI data is not escaped, but XMLSerializer (and possibly other call ers) this should raise an exception if it includes "?>". 306 // FIXME: PI data is not escaped, but XMLSerializer (and possibly other call ers) this should raise an exception if it includes "?>".
307 result.appendLiteral("<?"); 307 result.append("<?");
308 result.append(target); 308 result.append(target);
309 result.append(' '); 309 result.append(' ');
310 result.append(data); 310 result.append(data);
311 result.appendLiteral("?>"); 311 result.append("?>");
312 } 312 }
313 313
314 void MarkupFormatter::appendOpenTag(StringBuilder& result, const Element& elemen t, Namespaces* namespaces) 314 void MarkupFormatter::appendOpenTag(StringBuilder& result, const Element& elemen t, Namespaces* namespaces)
315 { 315 {
316 result.append('<'); 316 result.append('<');
317 result.append(element.tagQName().toString()); 317 result.append(element.tagQName().toString());
318 if (!serializeAsHTMLDocument(element) && namespaces && shouldAddNamespaceEle ment(element, *namespaces)) 318 if (!serializeAsHTMLDocument(element) && namespaces && shouldAddNamespaceEle ment(element, *namespaces))
319 appendNamespace(result, element.prefix(), element.namespaceURI(), *names paces); 319 appendNamespace(result, element.prefix(), element.namespaceURI(), *names paces);
320 } 320 }
321 321
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } else { 390 } else {
391 result.append('"'); 391 result.append('"');
392 appendAttributeValue(result, attribute.value(), documentIsHTML); 392 appendAttributeValue(result, attribute.value(), documentIsHTML);
393 result.append('"'); 393 result.append('"');
394 } 394 }
395 } 395 }
396 396
397 void MarkupFormatter::appendCDATASection(StringBuilder& result, const String& se ction) 397 void MarkupFormatter::appendCDATASection(StringBuilder& result, const String& se ction)
398 { 398 {
399 // FIXME: CDATA content is not escaped, but XMLSerializer (and possibly othe r callers) should raise an exception if it includes "]]>". 399 // FIXME: CDATA content is not escaped, but XMLSerializer (and possibly othe r callers) should raise an exception if it includes "]]>".
400 result.appendLiteral("<![CDATA["); 400 result.append("<![CDATA[");
401 result.append(section); 401 result.append(section);
402 result.appendLiteral("]]>"); 402 result.append("]]>");
403 } 403 }
404 404
405 bool MarkupFormatter::shouldAddNamespaceElement(const Element& element, Namespac es& namespaces) const 405 bool MarkupFormatter::shouldAddNamespaceElement(const Element& element, Namespac es& namespaces) const
406 { 406 {
407 // Don't add namespace attribute if it is already defined for this elem. 407 // Don't add namespace attribute if it is already defined for this elem.
408 const AtomicString& prefix = element.prefix(); 408 const AtomicString& prefix = element.prefix();
409 if (prefix.isEmpty()) { 409 if (prefix.isEmpty()) {
410 if (element.hasAttribute(xmlnsAtom)) { 410 if (element.hasAttribute(xmlnsAtom)) {
411 namespaces.set(emptyAtom, element.namespaceURI()); 411 namespaces.set(emptyAtom, element.namespaceURI());
412 return false; 412 return false;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 465 }
466 466
467 bool MarkupFormatter::serializeAsHTMLDocument(const Node& node) const 467 bool MarkupFormatter::serializeAsHTMLDocument(const Node& node) const
468 { 468 {
469 if (m_serializationType == SerializationType::ForcedXML) 469 if (m_serializationType == SerializationType::ForcedXML)
470 return false; 470 return false;
471 return node.document().isHTMLDocument(); 471 return node.document().isHTMLDocument();
472 } 472 }
473 473
474 } // namespace blink 474 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698