Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 28 matching lines...) Expand all Loading... | |
| 39 #include "core/editing/Editor.h" | 39 #include "core/editing/Editor.h" |
| 40 #include "core/html/HTMLElement.h" | 40 #include "core/html/HTMLElement.h" |
| 41 #include "core/html/HTMLTemplateElement.h" | 41 #include "core/html/HTMLTemplateElement.h" |
| 42 #include "platform/weborigin/KURL.h" | 42 #include "platform/weborigin/KURL.h" |
| 43 #include "wtf/unicode/CharacterNames.h" | 43 #include "wtf/unicode/CharacterNames.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 using namespace HTMLNames; | 47 using namespace HTMLNames; |
| 48 | 48 |
| 49 struct EntityDescription { | |
| 50 UChar entity; | |
| 51 CString reference; | |
| 52 EntityMask mask; | |
| 53 }; | |
| 54 | |
| 55 template <typename CharType> | |
| 56 static inline void appendCharactersReplacingEntitiesInternal(StringBuilder& resu lt, CharType* text, unsigned length, const EntityDescription entityMaps[], unsig ned entityMapsCount, EntityMask entityMask) | |
| 57 { | |
| 58 unsigned positionAfterLastEntity = 0; | |
| 59 for (unsigned i = 0; i < length; ++i) { | |
| 60 for (unsigned entityIndex = 0; entityIndex < entityMapsCount; ++entityIn dex) { | |
| 61 if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIn dex].mask & entityMask) { | |
| 62 result.append(text + positionAfterLastEntity, i - positionAfterL astEntity); | |
| 63 const CString& replacement = entityMaps[entityIndex].reference; | |
| 64 result.append(replacement.data(), replacement.length()); | |
| 65 positionAfterLastEntity = i + 1; | |
| 66 break; | |
| 67 } | |
| 68 } | |
| 69 } | |
| 70 result.append(text + positionAfterLastEntity, length - positionAfterLastEnti ty); | |
| 71 } | |
| 72 | |
| 49 void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask) | 73 void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask) |
| 50 { | 74 { |
| 51 DEFINE_STATIC_LOCAL(const String, ampReference, ("&")); | |
|
Inactive
2014/01/07 22:28:15
Based on the clang error on the bots (error: decla
| |
| 52 DEFINE_STATIC_LOCAL(const String, ltReference, ("<")); | |
| 53 DEFINE_STATIC_LOCAL(const String, gtReference, (">")); | |
| 54 DEFINE_STATIC_LOCAL(const String, quotReference, (""")); | |
| 55 DEFINE_STATIC_LOCAL(const String, nbspReference, (" ")); | |
| 56 | |
| 57 static const EntityDescription entityMaps[] = { | 75 static const EntityDescription entityMaps[] = { |
| 58 { '&', ampReference, EntityAmp }, | 76 { '&', "&", EntityAmp }, |
| 59 { '<', ltReference, EntityLt }, | 77 { '<', "<", EntityLt }, |
| 60 { '>', gtReference, EntityGt }, | 78 { '>', ">", EntityGt }, |
| 61 { '"', quotReference, EntityQuot }, | 79 { '"', """, EntityQuot }, |
| 62 { noBreakSpace, nbspReference, EntityNbsp }, | 80 { noBreakSpace, " ", EntityNbsp }, |
| 63 }; | 81 }; |
| 64 | 82 |
| 65 if (!(offset + length)) | 83 if (!(offset + length)) |
| 66 return; | 84 return; |
| 67 | 85 |
| 68 ASSERT(offset + length <= source.length()); | 86 ASSERT(offset + length <= source.length()); |
| 69 | 87 if (source.is8Bit()) |
| 70 if (source.is8Bit()) { | 88 appendCharactersReplacingEntitiesInternal(result, source.characters8() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
| 71 const LChar* text = source.characters8() + offset; | 89 else |
| 72 | 90 appendCharactersReplacingEntitiesInternal(result, source.characters16() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
| 73 size_t positionAfterLastEntity = 0; | |
| 74 for (size_t i = 0; i < length; ++i) { | |
| 75 for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMa ps); ++entityIndex) { | |
| 76 if (text[i] == entityMaps[entityIndex].entity && entityMaps[enti tyIndex].mask & entityMask) { | |
| 77 result.append(text + positionAfterLastEntity, i - positionAf terLastEntity); | |
| 78 result.append(entityMaps[entityIndex].reference); | |
| 79 positionAfterLastEntity = i + 1; | |
| 80 break; | |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 result.append(text + positionAfterLastEntity, length - positionAfterLast Entity); | |
| 85 } else { | |
| 86 const UChar* text = source.characters16() + offset; | |
| 87 | |
| 88 size_t positionAfterLastEntity = 0; | |
| 89 for (size_t i = 0; i < length; ++i) { | |
| 90 for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMa ps); ++entityIndex) { | |
| 91 if (text[i] == entityMaps[entityIndex].entity && entityMaps[enti tyIndex].mask & entityMask) { | |
| 92 result.append(text + positionAfterLastEntity, i - positionAf terLastEntity); | |
| 93 result.append(entityMaps[entityIndex].reference); | |
| 94 positionAfterLastEntity = i + 1; | |
| 95 break; | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 result.append(text + positionAfterLastEntity, length - positionAfterLast Entity); | |
| 100 } | |
| 101 } | 91 } |
| 102 | 92 |
| 103 MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolve UrlsMethod, const Range* range) | 93 MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolve UrlsMethod, const Range* range) |
| 104 : m_nodes(nodes) | 94 : m_nodes(nodes) |
| 105 , m_range(range) | 95 , m_range(range) |
| 106 , m_resolveURLsMethod(resolveUrlsMethod) | 96 , m_resolveURLsMethod(resolveUrlsMethod) |
| 107 { | 97 { |
| 108 } | 98 } |
| 109 | 99 |
| 110 MarkupAccumulator::~MarkupAccumulator() | 100 MarkupAccumulator::~MarkupAccumulator() |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 if (!node->isElementNode() || shouldSelfClose(node) || (!node->hasChildNodes () && elementCannotHaveEndTag(node))) | 533 if (!node->isElementNode() || shouldSelfClose(node) || (!node->hasChildNodes () && elementCannotHaveEndTag(node))) |
| 544 return; | 534 return; |
| 545 | 535 |
| 546 result.append('<'); | 536 result.append('<'); |
| 547 result.append('/'); | 537 result.append('/'); |
| 548 result.append(toElement(node)->nodeNamePreservingCase()); | 538 result.append(toElement(node)->nodeNamePreservingCase()); |
| 549 result.append('>'); | 539 result.append('>'); |
| 550 } | 540 } |
| 551 | 541 |
| 552 } | 542 } |
| OLD | NEW |