/proc/self/cwd/cpp/htmlparser/token.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "cpp/htmlparser/token.h" |
2 | | |
3 | | #include "cpp/htmlparser/strings.h" |
4 | | |
5 | | namespace htmlparser { |
6 | | |
7 | 0 | std::string Token::TagString() const { |
8 | 0 | switch (token_type) { |
9 | 0 | case TokenType::ERROR_TOKEN: |
10 | 0 | return "Error"; |
11 | 0 | case TokenType::TEXT_TOKEN: |
12 | 0 | return "Text"; |
13 | 0 | case TokenType::START_TAG_TOKEN: |
14 | 0 | return "StartTag"; |
15 | 0 | case TokenType::END_TAG_TOKEN: |
16 | 0 | return "EndTag"; |
17 | 0 | case TokenType::SELF_CLOSING_TAG_TOKEN: |
18 | 0 | return "SelfClosingTag"; |
19 | 0 | case TokenType::COMMENT_TOKEN: |
20 | 0 | return "Comment"; |
21 | 0 | case TokenType::DOCTYPE_TOKEN: |
22 | 0 | return "Doctype"; |
23 | 0 | } |
24 | 0 | return "Invalid token with no token type."; |
25 | 0 | } |
26 | | |
27 | 0 | std::string Token::String() const { |
28 | 0 | switch (token_type) { |
29 | 0 | case TokenType::ERROR_TOKEN: |
30 | 0 | return ""; |
31 | 0 | case TokenType::TEXT_TOKEN: |
32 | 0 | return Strings::EscapeString(data); |
33 | 0 | case TokenType::START_TAG_TOKEN: |
34 | 0 | return "<" + data + ">"; |
35 | 0 | case TokenType::END_TAG_TOKEN: |
36 | 0 | return "</" + data + ">"; |
37 | 0 | case TokenType::SELF_CLOSING_TAG_TOKEN: |
38 | 0 | return "<" + data + "/>"; |
39 | 0 | case TokenType::COMMENT_TOKEN: |
40 | 0 | return "<!--" + data + ">"; |
41 | 0 | case TokenType::DOCTYPE_TOKEN: |
42 | 0 | return "<!DOCTYPE " + data + ">"; |
43 | 0 | } |
44 | | |
45 | 0 | return "Invalid(token)"; |
46 | 0 | } |
47 | | |
48 | 490k | bool Attribute::operator==(const Attribute& other) const { |
49 | 490k | return (name_space == other.name_space && |
50 | 490k | key == other.key && |
51 | 490k | value == other.value); |
52 | 490k | } |
53 | | |
54 | 0 | bool Attribute::operator!=(const Attribute& other) const { |
55 | 0 | return !(operator==(other)); |
56 | 0 | } |
57 | | |
58 | 0 | std::string Attribute::String() const { |
59 | 0 | return name_space + ":" + key + ": " + value; |
60 | 0 | } |
61 | | |
62 | 0 | std::string Attribute::KeyPart() const { |
63 | 0 | if (name_space.empty()) return key; |
64 | | |
65 | 0 | return name_space + ":" + key; |
66 | 0 | } |
67 | | } // namespace htmlparser |