Counter* Counters::GetCounter(const uni_char* name, unsigned int name_length) { for (Counter* counter = (Counter*) counter_list.First(); counter; counter = (Counter*) counter->Suc()) if (name_length == counter->GetNameLength() && uni_strncmp(counter->GetName(), name, name_length) == 0) return counter; return NULL; }
OP_STATUS Counters::SetCounters(HTML_Element* element, CSS_decl* cp, BOOL reset) { if (cp && cp->GetDeclType() == CSS_DECL_GEN_ARRAY) { short gen_arr_len = cp->ArrayValueLen(); const CSS_generic_value* gen_arr = cp->GenArrayValue(); for (int i = 0; i < gen_arr_len; i++) { if (gen_arr[i].value_type == CSS_STRING_LITERAL && gen_arr[i].value.string) { OP_ASSERT(*gen_arr[i].value.string || !"Only non-empty strings (identifiers) should be allowed by the css parser"); Counter* counter = GetCounter(gen_arr[i].value.string, uni_strlen(gen_arr[i].value.string)); if (!counter) { counter = OP_NEW(Counter, (gen_arr[i].value.string)); if (counter) counter->Into(&counter_list); else return OpStatus::ERR_NO_MEMORY; } if (!counter->GetName() || !counter->SetCounter(element, reset ? COUNTER_RESET : COUNTER_INCREMENT, i + 1 < gen_arr_len && gen_arr[i + 1].value_type == CSS_INT_NUMBER ? gen_arr[++i].value.number : (reset ? 0 : 1), add_only)) { counter->Out(); OP_DELETE(counter); return OpStatus::ERR_NO_MEMORY; } } } } return OpStatus::OK; }