-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlNodeExtension.cs
114 lines (95 loc) · 2.88 KB
/
XmlNodeExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using SkiaSharpOpenGLBenchmark.css;
namespace SkiaSharpOpenGLBenchmark
{
public static class XmlNodeExtensions
{
private static readonly Dictionary<XmlNode, CssNodeData> _data = new Dictionary<XmlNode, CssNodeData>();
// select.c:1752
// get_libcss_node_data()
public static CssNodeData GetNodeData(this XmlNode node)
{
if (_data.TryGetValue(node, out CssNodeData data))
{
return data;
}
return null;
}
// select.c:1732
// set_libcss_node_data()
public static void SetNodeData(this XmlNode node, CssNodeData data)
{
_data[node] = data;
}
//TODO: Implement a method to remove data if necessary
public static bool HasClass(this XmlNode node, string name)
{
var classes = node.Attributes["class"];
if (classes == null) return false;
var classesArray = classes.Value.Split(' ');
foreach (var c in classesArray)
{
if (c == name) return true;
}
return false;
}
public static bool HasId(this XmlNode node, string name)
{
var classes = node.Attributes["id"];
if (classes == null) return false;
var classesArray = classes.Value.Split(' ');
foreach (var c in classesArray)
{
if (c == name) return true;
}
return false;
}
public static bool IsLink(this XmlNode node)
{
return string.Equals(node.Name, "a", StringComparison.OrdinalIgnoreCase);
}
public static bool IsVisited(this XmlNode node)
{
return false;
}
public static bool IsHover(this XmlNode node)
{
return false;
}
public static bool IsActive(this XmlNode node)
{
return false;
}
public static bool IsFocus(this XmlNode node)
{
return false;
}
public static bool IsRoot(this XmlNode node)
{
if (node.ParentNode == null)
return true;
else
return false;
}
public static bool IsEmpty(this XmlNode node)
{
Log.Unimplemented();
return false;
}
// Just for debugging
public static void Dump(this XmlNode node)
{
Console.Write($"Node: {node.Name} ({node.GetHashCode()}), type: {node.NodeType }");
var data = GetNodeData(node);
if (data != null )
{
Console.Write($" {data.ToString()}");
}
Console.WriteLine();
}
}
}