FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nativeapi/src/url_opener.cpp at main · libnativeapi/nativeapi · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
libnativeapi
/
nativeapi
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
32
Code
Issues
4
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nativeapi
/
src
/
url_opener.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (84 loc) · 2.65 KB
Breadcrumbs
nativeapi
/
src
/
url_opener.cpp
Copy path
File metadata and controls
103 lines (84 loc) · 2.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
url_opener.h
"
#
include
<
algorithm
>
#
include
<
cctype
>
namespace
nativeapi
{
namespace
{
std::string
Trim
(
const
std::string& value) {
size_t
start =
0
;
while
(start < value.
size
() &&
std::isspace
(
static_cast
<
unsigned
char
>(value[start]))) {
++start;
}
size_t
end = value.
size
();
while
(end > start &&
std::isspace
(
static_cast
<
unsigned
char
>(value[end -
1
]))) {
--end;
}
return
value.
substr
(start, end - start);
}
std::string
ToLower
(std::string value) {
std::transform
(value.
begin
(), value.
end
(), value.
begin
(), [](
unsigned
char
c) {
return
static_cast
<
char
>(
std::tolower
(c));
});
return
value;
}
UrlOpenResult
ValidateUrl
(
const
std::string& raw_url) {
const
std::string url =
Trim
(raw_url);
if
(url.
empty
()) {
UrlOpenResult result;
result.
success
=
false
;
result.
error_code
= UrlOpenErrorCode::
kInvalidUrlEmpty
;
result.
error_message
=
"
URL is empty.
"
;
return
result;
}
const
size_t
scheme_separator = url.
find
(
'
:
'
);
if
(scheme_separator == std::string::npos || scheme_separator ==
0
) {
UrlOpenResult result;
result.
success
=
false
;
result.
error_code
= UrlOpenErrorCode::
kInvalidUrlMissingScheme
;
result.
error_message
=
"
URL must include an explicit scheme (http or https).
"
;
return
result;
}
const
std::string scheme =
ToLower
(url.
substr
(
0
, scheme_separator));
if
(scheme !=
"
http
"
&& scheme !=
"
https
"
) {
UrlOpenResult result;
result.
success
=
false
;
result.
error_code
= UrlOpenErrorCode::
kInvalidUrlUnsupportedScheme
;
result.
error_message
=
"
Only http and https URLs are supported.
"
;
return
result;
}
UrlOpenResult ok;
ok.
success
=
true
;
ok.
error_code
= UrlOpenErrorCode::
kNone
;
return
ok;
}
}
//
namespace
//
---------------------------------------------------------------------------
//
UrlOpener::Impl
//
---------------------------------------------------------------------------
bool
UrlOpener::Impl::CanOpen
(
const
std::string& url)
const
{
(
void
)url;
return
true
;
}
//
---------------------------------------------------------------------------
//
UrlOpener
//
---------------------------------------------------------------------------
UrlOpener&
UrlOpener::GetInstance
() {
static
UrlOpener instance;
return
instance;
}
bool
UrlOpener::CanOpen
(
const
std::string& url)
const
{
if
(!
ValidateUrl
(url).
success
) {
return
false
;
}
return
pimpl_->
CanOpen
(url);
}
UrlOpenResult
UrlOpener::Open
(
const
std::string& url)
const
{
UrlOpenResult result =
ValidateUrl
(url);
if
(!result.
success
) {
return
result;
}
return
pimpl_->
Open
(url);
}
bool
UrlOpener::IsSupported
()
const
{
return
pimpl_->
IsSupported
();
}
}
//
namespace nativeapi
Back
|
FazBrowse Home
|
New Git URL