Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / string_id.cpp
blob9f8390303e713963b8ad6a78e7b8a0b68b288ae5
1 #include "html.h"
2 #include "string_id.h"
3 #include <assert.h>
5 #ifndef LITEHTML_NO_THREADS
6 #include <mutex>
7 static std::mutex mutex;
8 #define lock_guard std::lock_guard<std::mutex> lock(mutex)
9 #else
10 #define lock_guard
11 #endif
13 namespace litehtml
16 static std::map<string, string_id> map;
17 static std::vector<string> array;
19 static int init()
21 string_vector names;
22 split_string(initial_string_ids, names, ",");
23 for (auto& name : names)
25 trim(name);
26 assert(name[0] == '_' && name.back() == '_');
27 name = name.substr(1, name.size() - 2); // _border_color_ -> border_color
28 std::replace(name.begin(), name.end(), '_', '-'); // border_color -> border-color
29 _id(name); // this will create association _border_color_ <-> "border-color"
31 return 0;
33 static int dummy = init();
35 const string_id empty_id = _id("");
36 const string_id star_id = _id("*");
38 string_id _id(const string& str)
40 lock_guard;
41 auto it = map.find(str);
42 if (it != map.end()) return it->second;
43 // else: str not found, add it to the array and the map
44 array.push_back(str);
45 return map[str] = (string_id)(array.size() - 1);
48 const string& _s(string_id id)
50 lock_guard;
51 return array[id];
54 } // namespace litehtml