Skip to content

Commit 05ae105

Browse files
committed
used string_id instead of string
1 parent b9368a4 commit 05ae105

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

include/litehtml/element.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace litehtml
3737
element::ptr _add_before_after(int type, const style& style);
3838

3939
private:
40-
std::map<string, int> m_counter_values;
40+
std::map<string_id, int> m_counter_values;
4141

4242
public:
4343
explicit element(const std::shared_ptr<document>& doc);
@@ -149,13 +149,13 @@ namespace litehtml
149149

150150
string get_counter_value(const string& counter_name);
151151
string get_counters_value(const string_vector& parameters);
152-
void increment_counter(const string& counter_name, const int increment = 1);
153-
void reset_counter(const string& counter_name, const int value = 0);
152+
void increment_counter(const string_id& counter_name_id, const int increment = 1);
153+
void reset_counter(const string_id& counter_name_id, const int value = 0);
154154

155155
private:
156156
std::vector<element::ptr> get_siblings_before() const;
157-
bool find_counter(const string& counter_name, std::map<string, int>::iterator& map_iterator);
158-
void parse_counter_tokens(const string_vector& tokens, const int default_value, std::function<void(const string&, const int)> handler) const;
157+
bool find_counter(const string_id& counter_name_id, std::map<string_id, int>::iterator& map_iterator);
158+
void parse_counter_tokens(const string_vector& tokens, const int default_value, std::function<void(const string_id&, const int)> handler) const;
159159
};
160160

161161
//////////////////////////////////////////////////////////////////////////

src/element.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ bool element::is_block_formatting_context() const
290290

291291
litehtml::string litehtml::element::get_counter_value(const string& counter_name)
292292
{
293-
std::map<string, int>::iterator i;
294-
if (find_counter(counter_name, i))
293+
std::map<string_id, int>::iterator i;
294+
if (find_counter(_id(counter_name), i))
295295
{
296296
return std::to_string(i->second);
297297
}
@@ -302,7 +302,7 @@ string litehtml::element::get_counters_value(const string_vector& parameters)
302302
{
303303
string result = "";
304304
if (parameters.size() >= 2) {
305-
const string& counter_name = parameters[0];
305+
const string_id counter_name_id = _id(parameters[0]);
306306
string delims = parameters[1];
307307
litehtml::trim(delims, "\"'");
308308

@@ -311,15 +311,15 @@ string litehtml::element::get_counters_value(const string_vector& parameters)
311311
element::ptr current = shared_from_this();
312312
while (current != nullptr)
313313
{
314-
auto map_iterator = current->m_counter_values.find(counter_name);
314+
auto map_iterator = current->m_counter_values.find(counter_name_id);
315315
if (map_iterator != current->m_counter_values.end()) {
316316
values.push_back(std::to_string(map_iterator->second));
317317
}
318318
current = current->parent();
319319
}
320320
if (values.empty()) {
321-
// if no counter is found, instancieate one with value '0'
322-
shared_from_this()->m_counter_values[counter_name] = 0;
321+
// if no counter is found, instanciate one with value '0'
322+
shared_from_this()->m_counter_values[counter_name_id] = 0;
323323
result = "0";
324324
}
325325
else {
@@ -331,13 +331,13 @@ string litehtml::element::get_counters_value(const string_vector& parameters)
331331
}
332332

333333

334-
bool litehtml::element::find_counter(const string& counter_name, std::map<string, int>::iterator& map_iterator) {
334+
bool litehtml::element::find_counter(const string_id& counter_name_id, std::map<string_id, int>::iterator& map_iterator) {
335335
element::ptr current = shared_from_this();
336336

337337
// search upwards
338338
while (current != nullptr)
339339
{
340-
map_iterator = current->m_counter_values.find(counter_name);
340+
map_iterator = current->m_counter_values.find(counter_name_id);
341341
if (map_iterator != current->m_counter_values.end()) {
342342
return true;
343343
}
@@ -346,7 +346,7 @@ bool litehtml::element::find_counter(const string& counter_name, std::map<string
346346
std::vector<element::ptr> siblings = current->get_siblings_before();
347347
std::reverse(siblings.begin(), siblings.end());
348348
for (const element::ptr& sibling : siblings) {
349-
map_iterator = sibling->m_counter_values.find(counter_name);
349+
map_iterator = sibling->m_counter_values.find(counter_name_id);
350350
if (map_iterator != sibling->m_counter_values.end()) {
351351
return true;
352352
}
@@ -372,7 +372,7 @@ std::vector<element::ptr> litehtml::element::get_siblings_before() const
372372
}
373373

374374

375-
void litehtml::element::parse_counter_tokens(const string_vector& tokens, const int default_value, std::function<void(const string&, const int)> handler) const {
375+
void litehtml::element::parse_counter_tokens(const string_vector& tokens, const int default_value, std::function<void(const string_id&, const int)> handler) const {
376376
int pos = 0;
377377
while (pos < tokens.size()) {
378378
string name = tokens[pos];
@@ -384,25 +384,25 @@ void litehtml::element::parse_counter_tokens(const string_vector& tokens, const
384384
else {
385385
pos += 1;
386386
}
387-
handler(name, value);
387+
handler(_id(name), value);
388388
}
389389
}
390390

391-
void litehtml::element::increment_counter(const string& counter_name, const int increment)
391+
void litehtml::element::increment_counter(const string_id& counter_name_id, const int increment)
392392
{
393-
std::map<string, int>::iterator i;
394-
if (find_counter(counter_name, i)) {
393+
std::map<string_id, int>::iterator i;
394+
if (find_counter(counter_name_id, i)) {
395395
i->second = i->second + increment;
396396
}
397397
else {
398398
// if counter is not found, initialize one on this element
399-
m_counter_values[counter_name] = increment;
399+
m_counter_values[counter_name_id] = increment;
400400
}
401401
}
402402

403-
void litehtml::element::reset_counter(const string& counter_name, const int value)
403+
void litehtml::element::reset_counter(const string_id& counter_name_id, const int value)
404404
{
405-
m_counter_values[counter_name] = value;
405+
m_counter_values[counter_name_id] = value;
406406
}
407407

408408
const background* element::get_background(bool own_only) LITEHTML_RETURN_FUNC(nullptr)

src/html_tag.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,17 +1553,17 @@ void litehtml::html_tag::handle_counter_properties()
15531553
{
15541554
const auto& reset_property = m_style.get_property(string_id::_counter_reset_);
15551555
if (reset_property.m_type == prop_type_string_vector) {
1556-
auto reset_function = [&](const string&name, const int value) {
1557-
reset_counter(name, value);
1556+
auto reset_function = [&](const string_id&name_id, const int value) {
1557+
reset_counter(name_id, value);
15581558
};
15591559
parse_counter_tokens(reset_property.m_string_vector, 0, reset_function);
15601560
return;
15611561
}
15621562

15631563
const auto& inc_property = m_style.get_property(string_id::_counter_increment_);
15641564
if (inc_property.m_type == prop_type_string_vector) {
1565-
auto inc_function = [&](const string&name, const int value) {
1566-
increment_counter(name, value);
1565+
auto inc_function = [&](const string_id&name_id, const int value) {
1566+
increment_counter(name_id, value);
15671567
};
15681568
parse_counter_tokens(inc_property.m_string_vector, 1, inc_function);
15691569
return;

0 commit comments

Comments
 (0)