Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netrunner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sharinigma
netrunner
Commits
f68e8f65
Commit
f68e8f65
authored
7 years ago
by
Nubben
Browse files
Options
Downloads
Patches
Plain Diff
Add merge to URL (can merge absolute paths with relative paths)
parent
d59c9310
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/URL.cpp
+45
-3
45 additions, 3 deletions
src/URL.cpp
src/URL.h
+6
-3
6 additions, 3 deletions
src/URL.h
with
51 additions
and
6 deletions
src/URL.cpp
+
45
−
3
View file @
f68e8f65
...
@@ -2,21 +2,55 @@
...
@@ -2,21 +2,55 @@
#include
"StringUtils.h"
#include
"StringUtils.h"
URL
::
URL
()
{
protocol
=
""
;
host
=
""
;
document
=
""
;
}
URL
::
URL
(
std
::
string
const
&
url
)
{
URL
::
URL
(
std
::
string
const
&
url
)
{
construct
(
url
);
construct
(
url
);
}
}
std
::
string
URL
::
toString
()
{
std
::
string
URL
::
toString
()
const
{
if
(
isRelative
())
{
if
(
isRelative
())
{
return
document
;
return
document
;
}
}
return
protocol
+
"://"
+
host
+
document
;
return
protocol
+
"://"
+
host
+
document
;
}
}
bool
URL
::
isRelative
()
{
bool
URL
::
isRelative
()
const
{
return
protocol
.
size
()
==
0
;
return
protocol
.
size
()
==
0
;
}
}
URL
URL
::
merge
(
URL
const
&
url
)
const
{
if
(
!
url
.
isRelative
())
{
return
url
.
copy
();
}
URL
returnURL
=
copy
();
if
(
url
.
document
[
0
]
==
'/'
&&
url
.
document
[
1
]
==
'/'
)
{
auto
slashPos
=
url
.
document
.
find
(
'/'
,
2
);
returnURL
.
host
=
url
.
document
.
substr
(
2
,
slashPos
-
2
);
if
(
slashPos
==
std
::
string
::
npos
)
{
returnURL
.
document
=
"/"
;
}
else
{
returnURL
.
document
=
url
.
document
.
substr
(
slashPos
);
}
}
else
if
(
url
.
document
[
0
]
==
'/'
)
{
returnURL
.
document
=
url
.
document
;
}
else
{
if
(
returnURL
.
document
.
back
()
!=
'/'
)
{
auto
finalSlashPos
=
returnURL
.
document
.
find_last_of
(
'/'
);
returnURL
.
document
.
erase
(
finalSlashPos
+
1
);
}
returnURL
.
document
+=
url
.
document
;
}
return
returnURL
;
}
void
URL
::
construct
(
std
::
string
const
&
url
)
{
void
URL
::
construct
(
std
::
string
const
&
url
)
{
protocol
=
getProtocolFromURL
(
url
);
protocol
=
getProtocolFromURL
(
url
);
if
(
protocol
.
size
()
!=
0
)
{
if
(
protocol
.
size
()
!=
0
)
{
...
@@ -33,7 +67,15 @@ void URL::construct(std::string const& url) {
...
@@ -33,7 +67,15 @@ void URL::construct(std::string const& url) {
}
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
URL
&
url
)
{
URL
URL
::
copy
()
const
{
URL
url
;
url
.
protocol
=
protocol
;
url
.
host
=
host
;
url
.
document
=
document
;
return
url
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
URL
const
&
url
)
{
out
<<
url
.
toString
();
out
<<
url
.
toString
();
return
out
;
return
out
;
}
}
This diff is collapsed.
Click to expand it.
src/URL.h
+
6
−
3
View file @
f68e8f65
...
@@ -5,10 +5,12 @@
...
@@ -5,10 +5,12 @@
#include
<iostream>
#include
<iostream>
struct
URL
{
struct
URL
{
URL
();
URL
(
std
::
string
const
&
url
);
URL
(
std
::
string
const
&
url
);
std
::
string
toString
();
std
::
string
toString
()
const
;
bool
isRelative
();
bool
isRelative
()
const
;
URL
merge
(
URL
const
&
url
)
const
;
std
::
string
protocol
;
std
::
string
protocol
;
std
::
string
host
;
std
::
string
host
;
...
@@ -16,8 +18,9 @@ struct URL {
...
@@ -16,8 +18,9 @@ struct URL {
private:
private:
void
construct
(
std
::
string
const
&
url
);
void
construct
(
std
::
string
const
&
url
);
URL
copy
()
const
;
};
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
URL
&
url
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
URL
const
&
url
);
#endif
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment