Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
ab7b9114
Commit
ab7b9114
authored
Feb 28, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add can_convert utility function to URI
parent
025ee58e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
1 deletion
+70
-1
libcaf_core/caf/uri.hpp
libcaf_core/caf/uri.hpp
+5
-0
libcaf_core/src/uri.cpp
libcaf_core/src/uri.cpp
+59
-0
libcaf_core/test/uri.cpp
libcaf_core/test/uri.cpp
+6
-1
No files found.
libcaf_core/caf/uri.hpp
View file @
ab7b9114
...
...
@@ -121,6 +121,11 @@ public:
int
compare
(
string_view
x
)
const
noexcept
;
// -- parsing ----------------------------------------------------------------
/// Returns whether `parse` would produce a valid URI.
static
bool
can_parse
(
string_view
str
)
noexcept
;
// -- friend functions -------------------------------------------------------
friend
CAF_CORE_EXPORT
error
inspect
(
caf
::
serializer
&
dst
,
uri
&
x
);
...
...
libcaf_core/src/uri.cpp
View file @
ab7b9114
...
...
@@ -98,6 +98,65 @@ int uri::compare(string_view x) const noexcept {
return
string_view
{
str
()}.
compare
(
x
);
}
// -- parsing ------------------------------------------------------------------
namespace
{
class
nop_builder
{
public:
template
<
class
T
>
nop_builder
&
scheme
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
userinfo
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
host
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
port
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
path
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
query
(
T
&&
)
{
return
*
this
;
}
template
<
class
T
>
nop_builder
&
fragment
(
T
&&
)
{
return
*
this
;
}
};
}
// namespace
bool
uri
::
can_parse
(
string_view
str
)
noexcept
{
string_parser_state
ps
{
str
.
begin
(),
str
.
end
()};
nop_builder
builder
;
if
(
ps
.
consume
(
'<'
))
{
detail
::
parser
::
read_uri
(
ps
,
builder
);
if
(
ps
.
code
>
pec
::
trailing_character
)
return
false
;
if
(
!
ps
.
consume
(
'>'
))
return
false
;
}
else
{
detail
::
parser
::
read_uri
(
ps
,
builder
);
}
return
ps
.
code
==
pec
::
success
;
}
// -- friend functions ---------------------------------------------------------
error
inspect
(
caf
::
serializer
&
dst
,
uri
&
x
)
{
...
...
libcaf_core/test/uri.cpp
View file @
ab7b9114
...
...
@@ -209,6 +209,7 @@ uri operator "" _u(const char* cstr, size_t cstr_len) {
bool
operator
""
_i
(
const
char
*
cstr
,
size_t
cstr_len
)
{
uri
result
;
string_view
str
{
cstr
,
cstr_len
};
CAF_CHECK
(
!
uri
::
can_parse
(
str
));
auto
err
=
parse
(
str
,
result
);
return
err
!=
none
;
}
...
...
@@ -278,7 +279,11 @@ CAF_TEST(builder construction) {
CAF_CHECK_EQUAL
(
escaped
,
"hi%20there://it%27s@me%2F/file%201#%5B42%5D"
);
}
#define ROUNDTRIP(str) CAF_CHECK_EQUAL(str##_u, str)
#define ROUNDTRIP(str) \
do { \
CAF_CHECK(uri::can_parse(str)); \
CAF_CHECK_EQUAL(str##_u, str); \
} while (false)
CAF_TEST
(
from
string
)
{
// all combinations of components
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment