Chromium Code Reviews| Index: Source/core/editing/MarkupAccumulator.cpp |
| diff --git a/Source/core/editing/MarkupAccumulator.cpp b/Source/core/editing/MarkupAccumulator.cpp |
| index 09bd7fe3c4f9ee273823cfee7c14d2c2a73efe6a..ac4a1b796548aa18518d774d802cfd09708d3f63 100644 |
| --- a/Source/core/editing/MarkupAccumulator.cpp |
| +++ b/Source/core/editing/MarkupAccumulator.cpp |
| @@ -46,58 +46,48 @@ namespace WebCore { |
| using namespace HTMLNames; |
| +struct EntityDescription { |
| + UChar entity; |
| + CString reference; |
| + EntityMask mask; |
| +}; |
| + |
| +template <typename CharType> |
| +static inline void appendCharactersReplacingEntitiesInternal(StringBuilder& result, CharType* text, unsigned length, const EntityDescription entityMaps[], unsigned entityMapsCount, EntityMask entityMask) |
| +{ |
| + unsigned positionAfterLastEntity = 0; |
| + for (unsigned i = 0; i < length; ++i) { |
| + for (unsigned entityIndex = 0; entityIndex < entityMapsCount; ++entityIndex) { |
| + if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
| + result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
| + const CString& replacement = entityMaps[entityIndex].reference; |
| + result.append(replacement.data(), replacement.length()); |
| + positionAfterLastEntity = i + 1; |
| + break; |
| + } |
| + } |
| + } |
| + result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
| +} |
| + |
| void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask) |
| { |
| - DEFINE_STATIC_LOCAL(const String, ampReference, ("&")); |
|
Inactive
2014/01/07 22:28:15
Based on the clang error on the bots (error: decla
|
| - DEFINE_STATIC_LOCAL(const String, ltReference, ("<")); |
| - DEFINE_STATIC_LOCAL(const String, gtReference, (">")); |
| - DEFINE_STATIC_LOCAL(const String, quotReference, (""")); |
| - DEFINE_STATIC_LOCAL(const String, nbspReference, (" ")); |
| - |
| static const EntityDescription entityMaps[] = { |
| - { '&', ampReference, EntityAmp }, |
| - { '<', ltReference, EntityLt }, |
| - { '>', gtReference, EntityGt }, |
| - { '"', quotReference, EntityQuot }, |
| - { noBreakSpace, nbspReference, EntityNbsp }, |
| + { '&', "&", EntityAmp }, |
| + { '<', "<", EntityLt }, |
| + { '>', ">", EntityGt }, |
| + { '"', """, EntityQuot }, |
| + { noBreakSpace, " ", EntityNbsp }, |
| }; |
| if (!(offset + length)) |
| return; |
| ASSERT(offset + length <= source.length()); |
| - |
| - if (source.is8Bit()) { |
| - const LChar* text = source.characters8() + offset; |
| - |
| - size_t positionAfterLastEntity = 0; |
| - for (size_t i = 0; i < length; ++i) { |
| - for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMaps); ++entityIndex) { |
| - if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
| - result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
| - result.append(entityMaps[entityIndex].reference); |
| - positionAfterLastEntity = i + 1; |
| - break; |
| - } |
| - } |
| - } |
| - result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
| - } else { |
| - const UChar* text = source.characters16() + offset; |
| - |
| - size_t positionAfterLastEntity = 0; |
| - for (size_t i = 0; i < length; ++i) { |
| - for (size_t entityIndex = 0; entityIndex < WTF_ARRAY_LENGTH(entityMaps); ++entityIndex) { |
| - if (text[i] == entityMaps[entityIndex].entity && entityMaps[entityIndex].mask & entityMask) { |
| - result.append(text + positionAfterLastEntity, i - positionAfterLastEntity); |
| - result.append(entityMaps[entityIndex].reference); |
| - positionAfterLastEntity = i + 1; |
| - break; |
| - } |
| - } |
| - } |
| - result.append(text + positionAfterLastEntity, length - positionAfterLastEntity); |
| - } |
| + if (source.is8Bit()) |
| + appendCharactersReplacingEntitiesInternal(result, source.characters8() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
| + else |
| + appendCharactersReplacingEntitiesInternal(result, source.characters16() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); |
| } |
| MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolveUrlsMethod, const Range* range) |