Coverage Report

Created: 2026-12-01 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/cpp/htmlparser/foreign.cc
Line
Count
Source
1
#include "cpp/htmlparser/foreign.h"
2
3
#include <algorithm>
4
5
#include "cpp/htmlparser/comparators.h"
6
#include "cpp/htmlparser/strings.h"
7
8
namespace htmlparser {
9
10
4.71M
bool HtmlIntegrationPoint(const Node& node) {
11
4.71M
  if (node.Type() != NodeType::ELEMENT_NODE) {
12
0
    return false;
13
0
  }
14
15
4.71M
  if (node.NameSpace() == "math") {
16
1.41M
    if (node.DataAtom() == Atom::ANNOTATION_XML) {
17
0
      for (const Attribute& attr : node.Attributes()) {
18
0
        if (attr.key == "encoding") {
19
0
          std::string value = attr.value;
20
0
          Strings::ToLower(&value);
21
0
          if (value == "text/html" || value == "application/xhtml+xml") {
22
0
            return true;
23
0
          }
24
0
        }
25
0
      }
26
0
    }
27
3.29M
  } else if (node.NameSpace() == "svg") {
28
3.29M
    if (node.DataAtom() == Atom::DESC ||
29
3.29M
        node.DataAtom() == Atom::FOREIGN_OBJECT ||
30
3.29M
        node.DataAtom() == Atom::TITLE) {
31
2.17k
      return true;
32
2.17k
    }
33
3.29M
  }
34
35
4.71M
  return false;
36
4.71M
}
37
38
4.71M
bool MathMLTextIntegrationPoint(const Node& node) {
39
4.71M
  static constexpr std::array<Atom, 5> textNodes {
40
4.71M
    Atom::MI, Atom::MO, Atom::MN, Atom::MS, Atom::MTEXT};
41
42
4.71M
  if (node.NameSpace() != "math") return false;
43
7.08M
  for (auto tn : textNodes) {
44
7.08M
    if (node.DataAtom() == tn) return true;
45
7.08M
  }
46
1.41M
  return false;
47
1.41M
}
48
49
1.65M
void AdjustSVGAttributeNames(std::vector<Attribute>* attrs) {
50
1.65M
  for (Attribute& attr : *attrs) {
51
5.82k
    if (auto iter = std::lower_bound(std::begin(kSvgAttributeAdjustments),
52
5.82k
                                     std::end(kSvgAttributeAdjustments),
53
5.82k
                                     attr.key,
54
5.82k
                                     PairComparator<std::string_view,
55
5.82k
                                                    std::string_view>());
56
5.82k
        iter != std::end(kSvgAttributeAdjustments) &&
57
5.05k
        iter->first == attr.key) {
58
259
      attr.key = iter->second.data();
59
259
    }
60
5.82k
  }
61
1.65M
}
62
63
1.15M
void AdjustMathMLAttributeNames(std::vector<Attribute>* attrs) {
64
1.15M
  for (Attribute& attr : *attrs) {
65
1.89k
    if (auto iter = std::lower_bound(std::begin(kMathMLAttributeAdjustments),
66
1.89k
                                     std::end(kMathMLAttributeAdjustments),
67
1.89k
                                     attr.key,
68
1.89k
                                     PairComparator<std::string_view,
69
1.89k
                                                    std::string_view>());
70
1.89k
        iter != std::end(kMathMLAttributeAdjustments) &&
71
1.21k
        iter->first == attr.key) {
72
0
      attr.key = iter->second.data();
73
0
    }
74
1.89k
  }
75
1.15M
}
76
77
2.80M
void AdjustForeignAttributes(std::vector<Attribute>* attrs) {
78
2.80M
  static constexpr std::array<std::string_view, 11> keys {
79
2.80M
    "xlink:actuate", "xlink:arcrole", "xlink:href", "xlink:role", "xlink:show",
80
2.80M
    "xlink:title", "xlink:type", "xml:base", "xml:lang", "xml:space",
81
2.80M
    "xmlns:xlink",
82
2.80M
  };
83
84
2.80M
  for (Attribute& attr : *attrs) {
85
7.71k
    if (attr.key.empty() || attr.key.at(0) != 'x') continue;
86
2.25k
    if (std::find(keys.begin(), keys.end(), attr.key) != keys.end()) {
87
0
      int j = attr.key.find(':');
88
0
      attr.name_space = attr.key.substr(0, j);
89
0
      attr.key = attr.key.substr(j + 1);
90
0
    }
91
2.25k
  }
92
2.80M
}
93
94
}  // namespace htmlparser