blob: c767b47df47aa1563619c35e600de85fc8c8671d (
plain)
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
|
#include "tgbot/net/Url.h"
#include "tgbot/tools/StringTools.h"
using namespace std;
namespace TgBot {
Url::Url(const string& url) {
bool isProtocolParsed = false;
bool isHostParsed = false;
bool isPathParsed = false;
bool isQueryParsed = false;
for (size_t i = 0, count = url.length(); i < count; ++i) {
char c = url[i];
if (!isProtocolParsed) {
if (c == ':') {
isProtocolParsed = true;
i += 2;
} else {
protocol += c;
}
} else if (!isHostParsed) {
if (c == '/') {
isHostParsed = true;
path += '/';
} else if (c == '?') {
isHostParsed = isPathParsed = true;
path += '/';
} else if (c == '#') {
isHostParsed = isPathParsed = isQueryParsed = true;
path += '/';
} else {
host += c;
}
} else if (!isPathParsed) {
if (c == '?') {
isPathParsed = true;
} else if (c == '#') {
isPathParsed = isQueryParsed = true;
} else {
path += c;
}
} else if (!isQueryParsed) {
if (c == '#') {
isQueryParsed = true;
} else {
query += c;
}
} else {
fragment += c;
}
}
}
}
|