-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlsplit.cpp
More file actions
59 lines (48 loc) · 1.45 KB
/
urlsplit.cpp
File metadata and controls
59 lines (48 loc) · 1.45 KB
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
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string url, protocol, url_new, host, port, path;
size_t found = 0, found1 = 0;
protocol = "Absent";
port = "Absent";
path = "Absent";
cout<<"\nEnter url:";
getline (cin, url);
found = url.find_first_of(":");
if(!(found == -1) && (url.at(found+1) == '/'))
{
protocol = url.substr(0,found);
url = url.substr(found+3);
}
found = url.find_first_of(":");
if( !(found == -1) && ((url.at(found+1) == '0') || (url.at(found+1) == '1') || (url.at(found+1) == '2') || (url.at(found+1) == '3') || (url.at(found+1) == '4') || (url.at(found+1) == '5') || (url.at(found+1) == '6') || (url.at(found+1) == '7') || (url.at(found+1) == '8') || (url.at(found+1) == '9')))
{
host = url.substr(0,found);
url_new = url.substr(found+1);
found1 = url_new.find_first_of("/");
if(!(found1 == -1))
{
port = url_new.substr(0,found1);
path = url_new.substr(found1+1);
}
else
port = url_new;
}
else if (!(url.find_first_of("/") == -1))
{
found = url.find_first_of("/");
host = url.substr(0,found);
path = url.substr(found+1);
}
else
{
host = url;
}
cout<<"\nProtocol: "<<protocol; //Optional
cout<<"\nDomain(host): "<<host;
cout<<"\nPort: "<<port; //Optional
cout<<"\nPath: "<<path; //Optional
return 0;
}