void DOMTokenList::removeInternal(const AtomicString& token) { // Check using contains first since it uses AtomicString comparisons instead // of character by character testing. if (!containsInternal(token)) return; setValue(removeToken(value(), token)); }
bool DOMTokenList::toggle(const AtomicString& token, ExceptionState& exceptionState) { if (!validateToken(token, exceptionState)) return false; if (containsInternal(token)) { removeInternal(token); return false; } addInternal(token); return true; }
void DOMTokenList::add(const Vector<String>& tokens, ExceptionState& es) { Vector<String> filteredTokens; for (size_t i = 0; i < tokens.size(); ++i) { if (!validateToken(tokens[i], es)) return; if (!containsInternal(tokens[i])) filteredTokens.append(tokens[i]); } if (filteredTokens.isEmpty()) return; setValue(addTokens(value(), filteredTokens)); }
// Optimally, this should take a Vector<AtomicString> const ref in argument but // the bindings generator does not handle that. void DOMTokenList::add(const Vector<String>& tokens, ExceptionState& exceptionState) { Vector<String> filteredTokens; filteredTokens.reserveCapacity(tokens.size()); for (const auto& token : tokens) { if (!validateToken(token, exceptionState)) return; if (containsInternal(AtomicString(token))) continue; if (filteredTokens.contains(token)) continue; filteredTokens.append(token); } if (!filteredTokens.isEmpty()) setValue(addTokens(value(), filteredTokens)); }
// Optimally, this should take a Vector<AtomicString> const ref in argument but the // bindings generator does not handle that. void DOMTokenList::remove(const Vector<String>& tokens, ExceptionState& exceptionState) { if (!validateTokens(tokens, exceptionState)) return; // Check using containsInternal first since it is a lot faster than going // through the string character by character. bool found = false; for (size_t i = 0; i < tokens.size(); ++i) { if (containsInternal(AtomicString(tokens[i]))) { found = true; break; } } if (found) setValue(removeTokens(value(), tokens)); }
void DOMTokenList::addInternal(const AtomicString& token) { if (!containsInternal(token)) setValue(addToken(value(), token)); }
bool DOMTokenList::contains(const AtomicString& token, ExceptionState& exceptionState) const { if (!validateToken(token, exceptionState)) return false; return containsInternal(token); }