| 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 const 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, ("&")); | 75 DEFINE_STATIC_LOCAL(const CString, ampReference, ("&")); |
| 52 DEFINE_STATIC_LOCAL(const String, ltReference, ("<")); | 76 DEFINE_STATIC_LOCAL(const CString, ltReference, ("<")); |
| 53 DEFINE_STATIC_LOCAL(const String, gtReference, (">")); | 77 DEFINE_STATIC_LOCAL(const CString, gtReference, (">")); |
| 54 DEFINE_STATIC_LOCAL(const String, quotReference, (""")); | 78 DEFINE_STATIC_LOCAL(const CString, quotReference, (""")); |
| 55 DEFINE_STATIC_LOCAL(const String, nbspReference, (" ")); | 79 DEFINE_STATIC_LOCAL(const CString, nbspReference, (" ")); |
| 56 | 80 |
| 57 static const EntityDescription entityMaps[] = { | 81 static const EntityDescription entityMaps[] = { |
| 58 { '&', ampReference, EntityAmp }, | 82 { '&', ampReference, EntityAmp }, |
| 59 { '<', ltReference, EntityLt }, | 83 { '<', ltReference, EntityLt }, |
| 60 { '>', gtReference, EntityGt }, | 84 { '>', gtReference, EntityGt }, |
| 61 { '"', quotReference, EntityQuot }, | 85 { '"', quotReference, EntityQuot }, |
| 62 { noBreakSpace, nbspReference, EntityNbsp }, | 86 { noBreakSpace, nbspReference, EntityNbsp }, |
| 63 }; | 87 }; |
| 64 | 88 |
| 65 if (!(offset + length)) | 89 if (!(offset + length)) |
| 66 return; | 90 return; |
| 67 | 91 |
| 68 ASSERT(offset + length <= source.length()); | 92 ASSERT(offset + length <= source.length()); |
| 69 | 93 if (source.is8Bit()) |
| 70 if (source.is8Bit()) { | 94 appendCharactersReplacingEntitiesInternal(result, source.characters8() +
offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
| 71 const LChar* text = source.characters8() + offset; | 95 else |
| 72 | 96 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 } | 97 } |
| 102 | 98 |
| 103 MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolve
UrlsMethod, const Range* range) | 99 MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolve
UrlsMethod, const Range* range) |
| 104 : m_nodes(nodes) | 100 : m_nodes(nodes) |
| 105 , m_range(range) | 101 , m_range(range) |
| 106 , m_resolveURLsMethod(resolveUrlsMethod) | 102 , m_resolveURLsMethod(resolveUrlsMethod) |
| 107 { | 103 { |
| 108 } | 104 } |
| 109 | 105 |
| 110 MarkupAccumulator::~MarkupAccumulator() | 106 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))) | 539 if (!node->isElementNode() || shouldSelfClose(node) || (!node->hasChildNodes
() && elementCannotHaveEndTag(node))) |
| 544 return; | 540 return; |
| 545 | 541 |
| 546 result.append('<'); | 542 result.append('<'); |
| 547 result.append('/'); | 543 result.append('/'); |
| 548 result.append(toElement(node)->nodeNamePreservingCase()); | 544 result.append(toElement(node)->nodeNamePreservingCase()); |
| 549 result.append('>'); | 545 result.append('>'); |
| 550 } | 546 } |
| 551 | 547 |
| 552 } | 548 } |
| OLD | NEW |