uint32_t RuleSetPrivate::upsertRule(const Rule& match_rule, const Rule& new_rule, const bool parent_insensitive) { std::unique_lock<std::mutex> op_lock(_op_mutex); Pointer<Rule> matching_rule; for (auto& rule_ptr : _rules) { if (rule_ptr->internal()->appliesTo(match_rule, parent_insensitive)) { if (!matching_rule) { matching_rule = rule_ptr; } else { throw Exception("Rule set upsert", "rule", "Cannot upsert; multiple matching rules"); } } } if (matching_rule) { const uint32_t id = matching_rule->getRuleID(); *matching_rule = new_rule; matching_rule->setRuleID(id); return id; } else { return appendRule(new_rule, Rule::LastID, /*lock=*/false); } }
void CSSKeyframesRule::insertRule(const String& ruleText) { if (CSSStyleSheet* parent = parentStyleSheet()) { if (Document* ownerDocument = parent->ownerDocument()) ownerDocument->addConsoleMessage(MessageSource::JS, MessageLevel::Warning, ASCIILiteral("CSSKeyframesRule 'insertRule' function is deprecated. Use 'appendRule' instead.")); } appendRule(ruleText); }
void RuleSetPrivate::load(std::istream& stream) { std::unique_lock<std::mutex> lock(_io_mutex); std::string line_string; size_t line_number = 0; do { ++line_number; std::getline(stream, line_string); const Rule rule = parseRuleFromString(line_string, "", line_number); if (rule) { appendRule(rule); } } while(stream.good()); }