mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-09-30 08:44:13 +00:00
Make html parser use case insensitive unordered_map for attributes
This commit is contained in:
+3
-7
@@ -9,14 +9,10 @@ Json::JToken Html2JToken(std::shared_ptr<Html::HtmlNode> node) {
|
||||
} else {
|
||||
Json::JObject obj;
|
||||
obj.SetValue("Tag", node->text_or_tag);
|
||||
Json::JArray attrs;
|
||||
Json::JObject attrs;
|
||||
for (auto &item : node->attributes) {
|
||||
if (item.second)
|
||||
attrs.Add(Json::JObject(
|
||||
{{"Key", item.first}, {"Value", item.second.value()}}));
|
||||
else
|
||||
attrs.Add(
|
||||
Json::JObject({{"Key", item.first}, {"Value", nullptr}}));
|
||||
attrs.SetValue(item.first,
|
||||
item.second.value_or<Json::JToken>(nullptr));
|
||||
}
|
||||
obj.SetValue("Attributes", attrs);
|
||||
|
||||
|
||||
+7
-7
@@ -58,13 +58,13 @@ int main(int argc, char **argv) {
|
||||
html->FindNodes("meta", metaTags);
|
||||
|
||||
for (auto &meta : metaTags) {
|
||||
std::optional<std::string> prop, content;
|
||||
for (auto &[k, v] : meta->attributes) {
|
||||
if (k == "property" && v)
|
||||
prop = *v;
|
||||
if (k == "content" && v)
|
||||
content = *v;
|
||||
}
|
||||
auto prop_off = meta->attributes.find("property");
|
||||
auto content_off = meta->attributes.find("content");
|
||||
if (!(prop_off != meta->attributes.end() &&
|
||||
content_off != meta->attributes.end()))
|
||||
continue;
|
||||
auto &prop = prop_off->second;
|
||||
auto &content = content_off->second;
|
||||
|
||||
if (prop && content && prop->find("og:") == 0) {
|
||||
Tesses::Framework::Console::WriteView(prop.value());
|
||||
|
||||
Reference in New Issue
Block a user