Changeset 246951 in webkit
- Timestamp:
- Jun 29, 2019 2:50:00 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r246925 r246951 1 2019-06-22 Darin Adler <darin@apple.com> 2 3 Streamline some string code, focusing on functions that were using substringSharingImpl 4 https://bugs.webkit.org/show_bug.cgi?id=198898 5 6 Reviewed by Daniel Bates. 7 8 * wtf/URLHelpers.cpp: 9 (WTF::URLHelpers::applyHostNameFunctionToURLString): Change code using 10 substringSharingImpl so it could call String::find to call StringView::contains 11 instead. Also rewrote lambdas to be simpler and likely more efficient. 12 Rewrote another case using substringSharingImpl so it could call String::find 13 to call StringView::find instead. 14 15 * wtf/text/StringView.cpp: 16 (WTF::StringView::startsWith const): Added. 17 18 * wtf/text/StringView.h: Tweaked style a bit, and added an overload of 19 StringView::contains that takes a CodeUnitMatchFunction and an overload 20 of startsWith that cakes a UChar. 21 1 22 2019-06-28 Konstantin Tokarev <annulen@yandex.ru> 2 23 -
trunk/Source/WTF/wtf/URLHelpers.cpp
r246906 r246951 665 665 return; 666 666 } 667 667 668 668 // Find the host name in a hierarchical URL. 669 669 // It comes after a "://" sequence, with scheme characters preceding. … … 676 676 677 677 unsigned authorityStart = separatorIndex + strlen(separator); 678 678 679 679 // Check that all characters before the :// are valid scheme characters. 680 auto invalidSchemeCharacter = string.substringSharingImpl(0, separatorIndex).find([](UChar ch) { 681 static const char* allowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-."; 682 static size_t length = strlen(allowedCharacters); 683 for (size_t i = 0; i < length; ++i) { 684 if (allowedCharacters[i] == ch) 685 return false; 686 } 687 return true; 688 }); 689 690 if (invalidSchemeCharacter != notFound) 680 if (StringView { string }.left(separatorIndex).contains([](UChar character) { 681 return !(isASCIIAlphanumeric(character) || character == '+' || character == '-' || character == '.'); 682 })) 691 683 return; 692 693 unsigned stringLength = string.length(); 694 684 695 685 // Find terminating character. 696 auto hostNameTerminator = string.find([](UChar ch) { 697 static const char* terminatingCharacters = ":/?#"; 698 static size_t length = strlen(terminatingCharacters); 699 for (size_t i = 0; i < length; ++i) { 700 if (terminatingCharacters[i] == ch) 701 return true; 702 } 703 return false; 686 auto hostNameTerminator = string.find([](UChar character) { 687 return character == ':' || character == '/' || character == '?' || character == '#'; 704 688 }, authorityStart); 705 unsigned hostNameEnd = hostNameTerminator == notFound ? string Length: hostNameTerminator;706 689 unsigned hostNameEnd = hostNameTerminator == notFound ? string.length() : hostNameTerminator; 690 707 691 // Find "@" for the start of the host name. 708 auto userInfoTerminator = string.substringSharingImpl(0,hostNameEnd).find('@', authorityStart);692 auto userInfoTerminator = StringView { string }.left(hostNameEnd).find('@', authorityStart); 709 693 unsigned hostNameStart = userInfoTerminator == notFound ? authorityStart : userInfoTerminator + 1; 710 694 711 695 collectRangesThatNeedMapping(string, hostNameStart, hostNameEnd - hostNameStart, array, decodeFunction); 712 696 } -
trunk/Source/WTF/wtf/text/StringView.cpp
r244828 r246951 57 57 { 58 58 return ::WTF::findIgnoringASCIICase(*this, matchString, startOffset); 59 } 60 61 bool StringView::startsWith(UChar character) const 62 { 63 return m_length && (*this)[0] == character; 59 64 } 60 65 -
trunk/Source/WTF/wtf/text/StringView.h
r246490 r246951 97 97 98 98 #if USE(CF) 99 // Th is function convertsnull strings to empty strings.99 // These functions convert null strings to empty strings. 100 100 WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFString() const; 101 101 WTF_EXPORT_PRIVATE RetainPtr<CFStringRef> createCFStringWithoutCopying() const; … … 118 118 119 119 StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const; 120 StringView left(unsigned len ) const { return substring(0, len); }121 StringView right(unsigned len ) const { return substring(length() - len, len); }120 StringView left(unsigned length) const { return substring(0, length); } 121 StringView right(unsigned length) const { return substring(this->length() - length, length); } 122 122 123 123 template<typename MatchedCharacterPredicate> … … 133 133 WTF_EXPORT_PRIVATE size_t find(StringView, unsigned start) const; 134 134 135 size_t reverseFind(UChar, unsigned index = UINT_MAX) const;135 size_t reverseFind(UChar, unsigned index = std::numeric_limits<unsigned>::max()) const; 136 136 137 137 WTF_EXPORT_PRIVATE size_t findIgnoringASCIICase(const StringView&) const; … … 142 142 143 143 bool contains(UChar) const; 144 bool contains(CodeUnitMatchFunction) const; 144 145 WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&) const; 145 146 WTF_EXPORT_PRIVATE bool containsIgnoringASCIICase(const StringView&, unsigned startOffset) const; 146 147 148 WTF_EXPORT_PRIVATE bool startsWith(UChar) const; 147 149 WTF_EXPORT_PRIVATE bool startsWith(const StringView&) const; 148 150 WTF_EXPORT_PRIVATE bool startsWithIgnoringASCIICase(const StringView&) const; … … 174 176 WTF_EXPORT_PRIVATE void setUnderlyingString(const StringImpl*); 175 177 WTF_EXPORT_PRIVATE void setUnderlyingString(const StringView&); 178 void adoptUnderlyingString(UnderlyingString*); 176 179 #else 177 180 bool underlyingStringIsValid() const { return true; } … … 186 189 187 190 #if CHECK_STRINGVIEW_LIFETIME 188 void adoptUnderlyingString(UnderlyingString*);189 191 UnderlyingString* m_underlyingString { nullptr }; 190 192 #endif … … 467 469 { 468 470 return find(character) != notFound; 471 } 472 473 inline bool StringView::contains(CodeUnitMatchFunction function) const 474 { 475 return find(function) != notFound; 469 476 } 470 477 -
trunk/Source/WebCore/ChangeLog
r246950 r246951 1 2019-06-22 Darin Adler <darin@apple.com> 2 3 Streamline some string code, focusing on functions that were using substringSharingImpl 4 https://bugs.webkit.org/show_bug.cgi?id=198898 5 6 Reviewed by Daniel Bates. 7 8 * css/CSSComputedStyleDeclaration.cpp: 9 (WebCore::CSSComputedStyleDeclaration::CSSComputedStyleDeclaration): Take a StringView 10 instead of a String argument for the pseudo-element name. This prevents us from having 11 to use substringSharingImpl to strip off leading colons. 12 (WebCore::CSSComputedStyleDeclaration::create): Moved this function in here since it's 13 no longer being inlined. 14 15 * css/CSSComputedStyleDeclaration.h: Moved the create function to no longer be inlined, 16 since it's better to have the constructor be inlined in the create function instead. 17 Changed the pseudo-element name argument to be a StringView rather than a String. 18 Also initialize m_refCount in the class definition. 19 20 * css/CSSSelector.cpp: 21 (WebCore::CSSSelector::parsePseudoElementType): Take a StringView instead of a String. 22 * css/CSSSelector.h: Updated for the above change. 23 24 * css/SelectorPseudoTypeMap.h: Change both parse functions to take StringView. Before 25 one took a StringImpl and the other used const StringView&, which is not as good as 26 StringView. 27 28 * css/makeSelectorPseudoClassAndCompatibilityElementMap.py: Use StringView, not 29 const StringView&. 30 31 * css/makeSelectorPseudoElementsMap.py: Use StringView rather than StringImpl. 32 33 * css/parser/CSSParserImpl.cpp: 34 (WebCore::CSSParserImpl::parsePageSelector): Use a StringView for the pseudo-element 35 name. It was already computed as a StringView, but the old code converted it to 36 an AtomicString. 37 38 * css/parser/CSSParserSelector.cpp: 39 (WebCore::CSSParserSelector::parsePagePseudoSelector): Take a StringView, and 40 return a std::unique_ptr. 41 (WebCore::CSSParserSelector::parsePseudoElementSelector): Renamed to not mention 42 StringView in function name. Take a StringView, not a StringView&. Do the lowercasing 43 inside this function rather than having it be a caller responsibility. Don't convert 44 from a StringView to an AtomicString before starting to parse; only do it in the 45 "unknown/custom" case. Return a std::unique_ptr. 46 (WebCore::CSSParserSelector::parsePseudoClassSelector): Ditto. 47 * css/parser/CSSParserSelector.h: Make the three parse functions all take a StringView 48 and all return a std::unique_ptr. They were already creating objects, but before 49 callers just had to know to adopt. 50 * css/parser/CSSSelectorParser.cpp: 51 (WebCore::CSSSelectorParser::consumePseudo): Updated to use improved parse 52 functions above. 53 54 * page/DOMWindow.cpp: 55 (WebCore::DOMWindow::getMatchedCSSRules const): Updated to use the new 56 parsePseudoElementType above and use StringView::substring instead of 57 String::substringSharingImpl. 58 59 * platform/Length.cpp: 60 (WebCore::newCoordsArray): Local string that is "spacified" can't have any non-Latin-1 61 characters, so use LChar instead of UChar. 62 63 * rendering/RenderText.cpp: 64 (WebCore::convertNoBreakSpaceToSpace): Renamed for clarity. Also use constexpr 65 instead of inline since this is a pure function. 66 (WebCore::capitalize): Tighten up logic a bit. 67 1 68 2019-06-29 Simon Fraser <simon.fraser@apple.com> 2 69 -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r246490 r246951 1659 1659 } 1660 1660 1661 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, const String&pseudoElementName)1661 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(Element& element, bool allowVisitedStyle, StringView pseudoElementName) 1662 1662 : m_element(element) 1663 1663 , m_allowVisitedStyle(allowVisitedStyle) 1664 , m_refCount(1) 1665 { 1666 unsigned nameWithoutColonsStart = pseudoElementName[0] == ':' ? (pseudoElementName[1] == ':' ? 2 : 1) : 0; 1667 m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType( 1668 (pseudoElementName.substringSharingImpl(nameWithoutColonsStart)))); 1664 { 1665 StringView name = pseudoElementName; 1666 if (name.startsWith(':')) 1667 name = name.substring(1); 1668 if (name.startsWith(':')) 1669 name = name.substring(1); 1670 m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(name)); 1669 1671 } 1670 1672 1671 1673 CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration() = default; 1674 1675 Ref<CSSComputedStyleDeclaration> CSSComputedStyleDeclaration::create(Element& element, bool allowVisitedStyle, StringView pseudoElementName) 1676 { 1677 return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName)); 1678 } 1672 1679 1673 1680 void CSSComputedStyleDeclaration::ref() -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h
r245960 r246951 108 108 WTF_MAKE_ISO_ALLOCATED_EXPORT(CSSComputedStyleDeclaration, WEBCORE_EXPORT); 109 109 public: 110 static Ref<CSSComputedStyleDeclaration> create(Element& element, bool allowVisitedStyle = false, const String& pseudoElementName = String()) 111 { 112 return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName)); 113 } 110 WEBCORE_EXPORT static Ref<CSSComputedStyleDeclaration> create(Element&, bool allowVisitedStyle = false, StringView pseudoElementName = StringView { }); 114 111 virtual ~CSSComputedStyleDeclaration(); 115 112 … … 120 117 121 118 private: 122 WEBCORE_EXPORT CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, const String&);119 CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, StringView); 123 120 124 121 // CSSOM functions. Don't make these public. … … 145 142 PseudoId m_pseudoElementSpecifier; 146 143 bool m_allowVisitedStyle; 147 unsigned m_refCount ;144 unsigned m_refCount { 1 }; 148 145 }; 149 146 -
trunk/Source/WebCore/css/CSSSelector.cpp
r246490 r246951 309 309 } 310 310 311 CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType( const String&name)311 CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(StringView name) 312 312 { 313 313 if (name.isNull()) 314 314 return PseudoElementUnknown; 315 316 PseudoElementType type = parsePseudoElementString(*name.impl()); 315 auto type = parsePseudoElementString(name); 317 316 if (type == PseudoElementUnknown) { 318 317 if (name.startsWith("-webkit-")) … … 321 320 return type; 322 321 } 323 324 322 325 323 bool CSSSelector::operator==(const CSSSelector& other) const -
trunk/Source/WebCore/css/CSSSelector.h
r246490 r246951 224 224 }; 225 225 226 static PseudoElementType parsePseudoElementType( const String&);226 static PseudoElementType parsePseudoElementType(StringView); 227 227 static PseudoId pseudoId(PseudoElementType); 228 228 -
trunk/Source/WebCore/css/SelectorPseudoTypeMap.h
r209666 r246951 35 35 }; 36 36 37 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString( const StringView&pseudoTypeString);38 CSSSelector::PseudoElementType parsePseudoElementString( const StringImpl&pseudoTypeString);37 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString); 38 CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString); 39 39 40 40 } // namespace WebCore -
trunk/Source/WebCore/css/makeSelectorPseudoClassAndCompatibilityElementMap.py
r235935 r246951 185 185 186 186 output_file.write(""" 187 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString( const StringView&pseudoTypeString)187 PseudoClassOrCompatibilityPseudoElement parsePseudoClassAndCompatibilityElementString(StringView pseudoTypeString) 188 188 { 189 189 const SelectorPseudoClassOrCompatibilityPseudoElementEntry* entry; -
trunk/Source/WebCore/css/makeSelectorPseudoElementsMap.py
r235935 r246951 186 186 187 187 output_file.write(""" 188 CSSSelector::PseudoElementType parsePseudoElementString( const StringImpl&pseudoTypeString)188 CSSSelector::PseudoElementType parsePseudoElementString(StringView pseudoTypeString) 189 189 { 190 190 if (pseudoTypeString.is8Bit()) -
trunk/Source/WebCore/css/parser/CSSParserImpl.cpp
r246490 r246951 269 269 typeSelector = range.consume().value().toAtomString(); 270 270 271 AtomStringpseudo;271 StringView pseudo; 272 272 if (range.peek().type() == ColonToken) { 273 273 range.consume(); 274 274 if (range.peek().type() != IdentToken) 275 275 return CSSSelectorList(); 276 pseudo = range.consume().value() .toAtomString();276 pseudo = range.consume().value(); 277 277 } 278 278 -
trunk/Source/WebCore/css/parser/CSSParserSelector.cpp
r246490 r246951 33 33 namespace WebCore { 34 34 35 CSSParserSelector* CSSParserSelector::parsePagePseudoSelector(const AtomString&pseudoTypeString)35 std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePagePseudoSelector(StringView pseudoTypeString) 36 36 { 37 37 CSSSelector::PagePseudoClassType pseudoType; … … 44 44 else 45 45 return nullptr; 46 46 47 47 auto selector = std::make_unique<CSSParserSelector>(); 48 48 selector->m_selector->setMatch(CSSSelector::PagePseudoClass); 49 49 selector->m_selector->setPagePseudoType(pseudoType); 50 return selector.release(); 51 } 52 53 CSSParserSelector* CSSParserSelector::parsePseudoElementSelectorFromStringView(StringView& pseudoTypeString) 54 { 55 AtomString name = pseudoTypeString.toAtomString(); 56 57 CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(name); 50 return selector; 51 } 52 53 std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoElementSelector(StringView pseudoTypeString) 54 { 55 auto pseudoType = CSSSelector::parsePseudoElementType(pseudoTypeString); 58 56 if (pseudoType == CSSSelector::PseudoElementUnknown) { 59 57 // FIXME-NEWPARSER: We can't add "slotted" to the map without breaking the old … … 69 67 selector->m_selector->setMatch(CSSSelector::PseudoElement); 70 68 selector->m_selector->setPseudoElementType(pseudoType); 71 if (pseudoType == CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) { 72 ASSERT_WITH_MESSAGE(name == "-webkit-input-placeholder", "-webkit-input-placeholder is the only LegacyPrefix pseudo type."); 73 if (name == "-webkit-input-placeholder") 69 AtomString name; 70 if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) 71 name = pseudoTypeString.convertToASCIILowercase(); 72 else { 73 ASSERT_WITH_MESSAGE(equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"), "-webkit-input-placeholder is the only LegacyPrefix pseudo type."); 74 if (equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder")) 74 75 name = AtomString("placeholder", AtomString::ConstructFromLiteral); 76 else 77 name = pseudoTypeString.convertToASCIILowercase(); 75 78 } 76 79 selector->m_selector->setValue(name); 77 return selector .release();78 } 79 80 CSSParserSelector* CSSParserSelector::parsePseudoClassSelectorFromStringView(StringView&pseudoTypeString)81 { 82 PseudoClassOrCompatibilityPseudoElementpseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString);80 return selector; 81 } 82 83 std::unique_ptr<CSSParserSelector> CSSParserSelector::parsePseudoClassSelector(StringView pseudoTypeString) 84 { 85 auto pseudoType = parsePseudoClassAndCompatibilityElementString(pseudoTypeString); 83 86 if (pseudoType.pseudoClass != CSSSelector::PseudoClassUnknown) { 84 87 auto selector = std::make_unique<CSSParserSelector>(); 85 88 selector->m_selector->setMatch(CSSSelector::PseudoClass); 86 89 selector->m_selector->setPseudoClassType(pseudoType.pseudoClass); 87 return selector .release();90 return selector; 88 91 } 89 92 if (pseudoType.compatibilityPseudoElement != CSSSelector::PseudoElementUnknown) { … … 91 94 selector->m_selector->setMatch(CSSSelector::PseudoElement); 92 95 selector->m_selector->setPseudoElementType(pseudoType.compatibilityPseudoElement); 93 AtomString name = pseudoTypeString.toAtomString(); 94 selector->m_selector->setValue(name); 95 return selector.release(); 96 selector->m_selector->setValue(pseudoTypeString.convertToASCIILowercase()); 97 return selector; 96 98 } 97 99 return nullptr; -
trunk/Source/WebCore/css/parser/CSSParserSelector.h
r246490 r246951 22 22 23 23 #include "CSSSelector.h" 24 #include "CSSValueKeywords.h"25 #include <wtf/text/AtomString.h>26 24 #include <wtf/text/AtomStringHash.h> 27 #include <wtf/text/WTFString.h>28 25 29 26 namespace WebCore { 30 31 class CSSValue;32 class QualifiedName;33 27 34 28 enum class CSSParserSelectorCombinator { … … 42 36 WTF_MAKE_FAST_ALLOCATED; 43 37 public: 44 static CSSParserSelector* parsePseudoClassSelectorFromStringView(StringView&);45 static CSSParserSelector* parsePseudoElementSelectorFromStringView(StringView&);46 static CSSParserSelector* parsePagePseudoSelector(const AtomString&);47 38 static std::unique_ptr<CSSParserSelector> parsePseudoClassSelector(StringView); 39 static std::unique_ptr<CSSParserSelector> parsePseudoElementSelector(StringView); 40 static std::unique_ptr<CSSParserSelector> parsePagePseudoSelector(StringView); 41 48 42 CSSParserSelector(); 49 43 explicit CSSParserSelector(const QualifiedName&); … … 75 69 bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); } 76 70 77 bool isPseudoElementCueFunction() const 78 { 79 #if ENABLE(VIDEO_TRACK) 80 return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue; 81 #else 82 return false; 83 #endif 84 } 71 bool isPseudoElementCueFunction() const; 85 72 86 73 bool hasShadowDescendant() const; … … 124 111 } 125 112 113 inline bool CSSParserSelector::isPseudoElementCueFunction() const 114 { 115 #if ENABLE(VIDEO_TRACK) 116 return m_selector->match() == CSSSelector::PseudoElement && m_selector->pseudoElementType() == CSSSelector::PseudoElementCue; 117 #else 118 return false; 119 #endif 126 120 } 121 122 } -
trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp
r246490 r246951 488 488 std::unique_ptr<CSSParserSelector> selector; 489 489 490 auto lowercasedValue = token.value().convertToASCIILowercase();491 auto value = StringView { lowercasedValue };492 493 490 if (colons == 1) { 494 selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoClassSelectorFromStringView(value));491 selector = CSSParserSelector::parsePseudoClassSelector(token.value()); 495 492 #if ENABLE(ATTACHMENT_ELEMENT) 496 493 if (!m_context.attachmentEnabled && selector && selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHasAttachment) … … 498 495 #endif 499 496 } else { 500 selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoElementSelectorFromStringView(value));497 selector = CSSParserSelector::parsePseudoElementSelector(token.value()); 501 498 #if ENABLE(VIDEO_TRACK) 502 499 // Treat the ident version of cue as PseudoElementWebkitCustom. -
trunk/Source/WebCore/page/DOMWindow.cpp
r246490 r246951 1491 1491 1492 1492 unsigned colonStart = pseudoElement[0] == ':' ? (pseudoElement[1] == ':' ? 2 : 1) : 0; 1493 CSSSelector::PseudoElementType pseudoType = CSSSelector::parsePseudoElementType(pseudoElement.substringSharingImpl(colonStart));1493 auto pseudoType = CSSSelector::parsePseudoElementType(StringView { pseudoElement }.substring(colonStart)); 1494 1494 if (pseudoType == CSSSelector::PseudoElementUnknown && !pseudoElement.isEmpty()) 1495 1495 return nullptr; -
trunk/Source/WebCore/page/EventSource.cpp
r243887 r246951 350 350 else if (field == "id") { 351 351 StringView parsedEventId = { &m_receiveBuffer[position], valueLength }; 352 if (!parsedEventId.contains('\0')) 352 constexpr UChar nullCharacter = '\0'; 353 if (!parsedEventId.contains(nullCharacter)) 353 354 m_currentlyParsedEventId = parsedEventId.toString(); 354 355 } else if (field == "retry") { -
trunk/Source/WebCore/platform/Length.cpp
r243118 r246951 90 90 { 91 91 unsigned length = string.length(); 92 UChar* spacified;93 auto str = StringImpl::createUninitialized(length, spacified );92 LChar* spacifiedCharacters; 93 auto str = StringImpl::createUninitialized(length, spacifiedCharacters); 94 94 for (unsigned i = 0; i < length; i++) { 95 95 UChar cc = string[i]; 96 96 if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.')) 97 spacified [i] = ' ';97 spacifiedCharacters[i] = ' '; 98 98 else 99 spacified[i] = cc; 100 } 101 99 spacifiedCharacters[i] = cc; 100 } 102 101 str = str->simplifyWhiteSpace(); 103 102 -
trunk/Source/WebCore/rendering/RenderText.cpp
r245543 r246951 141 141 } 142 142 143 static inline UChar convertNoBreakSpace(UChar character)143 static constexpr UChar convertNoBreakSpaceToSpace(UChar character) 144 144 { 145 145 return character == noBreakSpace ? ' ' : character; … … 151 151 152 152 unsigned length = string.length(); 153 154 // Prepend the previous character, and convert NO BREAK SPACE to SPACE so ICU will see a word separator. 155 Vector<UChar> wordBreakCharacters; 156 wordBreakCharacters.grow(length + 1); 157 wordBreakCharacters[0] = convertNoBreakSpace(previousCharacter); 153 auto& stringImpl = *string.impl(); 154 155 static_assert(String::MaxLength < std::numeric_limits<unsigned>::max(), "Must be able to add one without overflowing unsigned"); 156 157 // Replace NO BREAK SPACE with a normal spaces since ICU does not treat it as a word separator. 158 Vector<UChar> stringWithPrevious(length + 1); 159 stringWithPrevious[0] = convertNoBreakSpaceToSpace(previousCharacter); 158 160 for (unsigned i = 1; i < length + 1; i++) 159 wordBreakCharacters[i] = convertNoBreakSpace(string[i - 1]);160 161 auto* b oundary = wordBreakIterator(StringView { wordBreakCharacters.data(), length + 1 });162 if (!b oundary)161 stringWithPrevious[i] = convertNoBreakSpaceToSpace(stringImpl[i - 1]); 162 163 auto* breakIterator = wordBreakIterator(StringView { stringWithPrevious.data(), length + 1 }); 164 if (!breakIterator) 163 165 return string; 164 166 … … 166 168 result.reserveCapacity(length); 167 169 170 int32_t startOfWord = ubrk_first(breakIterator); 168 171 int32_t endOfWord; 169 int32_t startOfWord = ubrk_first(boundary); 170 for (endOfWord = ubrk_next(boundary); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(boundary)) { 171 if (startOfWord) // Ignore first char of previous string 172 result.append(string[startOfWord - 1] == noBreakSpace ? noBreakSpace : u_totitle(wordBreakCharacters[startOfWord])); 172 for (endOfWord = ubrk_next(breakIterator); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(breakIterator)) { 173 if (startOfWord) // Do not append the first character, since it's the previous character, not from this string. 174 result.append(u_totitle(stringImpl[startOfWord - 1])); 173 175 for (int i = startOfWord + 1; i < endOfWord; i++) 174 result.append(string [i - 1]);176 result.append(stringImpl[i - 1]); 175 177 } 176 178
Note: See TracChangeset
for help on using the changeset viewer.