This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.h
108 lines (99 loc) · 3.89 KB
/
Functions.h
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
#pragma once
#include <ctype.h>
#include <cctype>
#include <algorithm>
#include <regex>
#include "Includes.h"
#include "Functions.h"
struct Functions {
static constexpr unsigned int SwitchString(const char* str, int h = 0)
{
return !str[h] ? 5381 : (SwitchString(str, h + 1) * 33) ^ str[h];
}
static constexpr unsigned int LeadingIntegralCount(const char* str, int h = 0) {
return (unsigned char(str[h]) >= '0' && (unsigned char)str[h] <= '9') ? LeadingIntegralCount(str, h + 1) : h;
}
static unsigned int CountFollowingWhiteSpace(std::string str, int h, int i = 0) {
return (h > 0) ? (std::isspace(str[h])) ? CountFollowingWhiteSpace(str, h - 1, i + 1) : i : CountFollowingWhiteSpace(str, str.length() - 1);
}
static int GetManagedStringLength(System::String^ str) {
return msclr::interop::marshal_as<std::string>(str).length();
}
static System::String^ SkipCharSequence(System::String^ base, const char* charSequence, int h = 0) {
return (base[h] == charSequence[h]) ? SkipCharSequence(base, charSequence, h + 1) : base->Substring(h, GetManagedStringLength(base) - h);
}
static mshtml::IHTMLElement^ GetFirstElementByClassName(System::Collections::IEnumerator^ enumerable, System::String^ className, unsigned int length) {
if (length == NULL) {
length = 0;
while (enumerable->MoveNext())
length++;
enumerable->Reset();
}
for (unsigned int idx = 0; idx < length; idx++) {
enumerable->MoveNext();
System::Console::WriteLine(safe_cast<mshtml::IHTMLElement^>(enumerable->Current)->className + "idx:" + idx + "le" + length);
if (safe_cast<mshtml::IHTMLElement^>(enumerable->Current)->className == className)
return safe_cast<mshtml::IHTMLElement^>(enumerable->Current);
}
return nullptr;
}
static mshtml::IHTMLElement^ SearchFirstElementByClassName(System::Collections::IEnumerator^ enumerable, System::String^ className, unsigned int length) {
if (length == NULL) {
length = 0;
while (enumerable->MoveNext())
length++;
enumerable->Reset();
}
for (unsigned int idx = 0; idx < length; idx++) {
enumerable->MoveNext();
if (safe_cast<mshtml::IHTMLElement^>(enumerable->Current)->className == className)
return safe_cast<mshtml::IHTMLElement^>(enumerable->Current);
}
return nullptr;
}
static VTable^ GetAllElementsByClassName(System::Collections::IEnumerator^ enumerable, System::String^ className, unsigned int length) {
VTable^ list = gcnew VTable(mshtml::IHTMLElement::typeid);
if (length == NULL) {
length = 0;
while (enumerable->MoveNext())
length++;
enumerable->Reset();
}
unsigned int i = 0;
for (unsigned int idx = 0; idx < length; idx++) {
enumerable->MoveNext();
System::Console::WriteLine(safe_cast<mshtml::IHTMLElement^>(enumerable->Current)->className);
if (safe_cast<mshtml::IHTMLElement^>(enumerable->Current)->className == className) {
list->Add((System::Object^)i, safe_cast<mshtml::IHTMLElement^>(enumerable->Current));
i++;
}
}
return list;
}
static std::smatch ManagedRegex(System::String^ str, std::string regex) {
std::smatch re;
std::string string(msclr::interop::marshal_as<std::string>(str->ToString()));
std::regex_match(string, re, std::regex(regex));
string.clear();
delete str;
regex.clear();
return re;
}
static mshtml::IHTMLElement^ depS(System::Collections::IEnumerator^ enumerable, System::String^ searchTerm, unsigned int length) {
while (enumerable->MoveNext()) {
mshtml::IHTMLElement^ ele = safe_cast<mshtml::IHTMLElement^>(enumerable->Current);
if (ele->className == searchTerm)
return ele;
else if(ele->innerHTML != nullptr) {
mshtml::IHTMLDocument^ b1 = gcnew mshtml::HTMLDocumentClass();
mshtml::IHTMLDocument2^ b2;
b2 = safe_cast<mshtml::IHTMLDocument2^>(b1);
b2->write(ele->innerHTML);
mshtml::IHTMLElement^ a = depS(b2->all->GetEnumerator(), searchTerm, b2->all->length);
if (a != nullptr)
return a;
delete b1, b2, a;
}
}
}
};