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
a7e4cd00
Commit
a7e4cd00
authored
Oct 19, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'topic/uri-path-parsing'
parents
a20f692d
027aede6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
17 deletions
+14
-17
libcaf_core/caf/detail/parser/read_uri.hpp
libcaf_core/caf/detail/parser/read_uri.hpp
+13
-17
libcaf_core/test/uri.cpp
libcaf_core/test/uri.cpp
+1
-0
No files found.
libcaf_core/caf/detail/parser/read_uri.hpp
View file @
a7e4cd00
...
@@ -53,6 +53,7 @@ void read_uri_percent_encoded(State& ps, std::string& str) {
...
@@ -53,6 +53,7 @@ void read_uri_percent_encoded(State& ps, std::string& str) {
if
(
ps
.
code
<=
pec
::
trailing_character
)
if
(
ps
.
code
<=
pec
::
trailing_character
)
str
+=
static_cast
<
char
>
(
char_code
);
str
+=
static_cast
<
char
>
(
char_code
);
});
});
// clang-format off
start
();
start
();
state
(
init
)
{
state
(
init
)
{
transition
(
read_nibble
,
hexadecimal_chars
,
add_ascii
<
16
>
(
char_code
,
ch
))
transition
(
read_nibble
,
hexadecimal_chars
,
add_ascii
<
16
>
(
char_code
,
ch
))
...
@@ -64,15 +65,18 @@ void read_uri_percent_encoded(State& ps, std::string& str) {
...
@@ -64,15 +65,18 @@ void read_uri_percent_encoded(State& ps, std::string& str) {
// nop
// nop
}
}
fin
();
fin
();
// clang-format on
}
}
inline
bool
uri_unprotected_char
(
char
c
)
{
inline
bool
uri_unprotected_char
(
char
c
)
{
return
in_whitelist
(
alphanumeric_chars
,
c
)
||
in_whitelist
(
"-._~"
,
c
);
return
in_whitelist
(
alphanumeric_chars
,
c
)
||
in_whitelist
(
"-._~"
,
c
);
}
}
// clang-format off
#define read_next_char(next_state, dest) \
#define read_next_char(next_state, dest) \
transition(next_state, uri_unprotected_char, dest += ch) \
transition(next_state, uri_unprotected_char, dest += ch) \
fsm_transition(read_uri_percent_encoded(ps, dest), next_state, '%')
fsm_transition(read_uri_percent_encoded(ps, dest), next_state, '%')
// clang-format on
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
>
void
read_uri_query
(
State
&
ps
,
Consumer
&&
consumer
)
{
void
read_uri_query
(
State
&
ps
,
Consumer
&&
consumer
)
{
...
@@ -87,15 +91,13 @@ void read_uri_query(State& ps, Consumer&& consumer) {
...
@@ -87,15 +91,13 @@ void read_uri_query(State& ps, Consumer&& consumer) {
swap
(
str
,
res
);
swap
(
str
,
res
);
return
res
;
return
res
;
};
};
auto
push
=
[
&
]
{
auto
push
=
[
&
]
{
result
.
emplace
(
take_str
(
key
),
take_str
(
value
));
};
result
.
emplace
(
take_str
(
key
),
take_str
(
value
));
};
// Call consumer on exit.
// Call consumer on exit.
auto
g
=
make_scope_guard
([
&
]
{
auto
g
=
make_scope_guard
([
&
]
{
if
(
ps
.
code
<=
pec
::
trailing_character
)
if
(
ps
.
code
<=
pec
::
trailing_character
)
consumer
.
query
(
std
::
move
(
result
));
consumer
.
query
(
std
::
move
(
result
));
});
});
//
FSM declaration.
//
clang-format off
start
();
start
();
// Query may be empty.
// Query may be empty.
term_state
(
init
)
{
term_state
(
init
)
{
...
@@ -110,6 +112,7 @@ void read_uri_query(State& ps, Consumer&& consumer) {
...
@@ -110,6 +112,7 @@ void read_uri_query(State& ps, Consumer&& consumer) {
transition
(
init
,
'&'
,
push
())
transition
(
init
,
'&'
,
push
())
}
}
fin
();
fin
();
// clang-format on
}
}
template
<
class
State
,
class
Consumer
>
template
<
class
State
,
class
Consumer
>
...
@@ -126,19 +129,11 @@ void read_uri(State& ps, Consumer&& consumer) {
...
@@ -126,19 +129,11 @@ void read_uri(State& ps, Consumer&& consumer) {
return
res
;
return
res
;
};
};
// Allowed character sets.
// Allowed character sets.
auto
path_char
=
[](
char
c
)
{
auto
path_char
=
[](
char
c
)
{
return
uri_unprotected_char
(
c
)
||
c
==
'/'
;
};
return
in_whitelist
(
alphanumeric_chars
,
c
)
||
c
==
'/'
;
};
// Utility setters for avoiding code duplication.
// Utility setters for avoiding code duplication.
auto
set_path
=
[
&
]
{
auto
set_path
=
[
&
]
{
consumer
.
path
(
take_str
());
};
consumer
.
path
(
take_str
());
auto
set_host
=
[
&
]
{
consumer
.
host
(
take_str
());
};
};
auto
set_userinfo
=
[
&
]
{
consumer
.
userinfo
(
take_str
());
};
auto
set_host
=
[
&
]
{
consumer
.
host
(
take_str
());
};
auto
set_userinfo
=
[
&
]
{
consumer
.
userinfo
(
take_str
());
};
// Consumer for reading IPv6 addresses.
// Consumer for reading IPv6 addresses.
struct
{
struct
{
Consumer
&
f
;
Consumer
&
f
;
...
@@ -146,7 +141,7 @@ void read_uri(State& ps, Consumer&& consumer) {
...
@@ -146,7 +141,7 @@ void read_uri(State& ps, Consumer&& consumer) {
f
.
host
(
addr
);
f
.
host
(
addr
);
}
}
}
ip_consumer
{
consumer
};
}
ip_consumer
{
consumer
};
//
FSM declaration.
//
clang-format off
start
();
start
();
state
(
init
)
{
state
(
init
)
{
epsilon
(
read_scheme
)
epsilon
(
read_scheme
)
...
@@ -228,6 +223,7 @@ void read_uri(State& ps, Consumer&& consumer) {
...
@@ -228,6 +223,7 @@ void read_uri(State& ps, Consumer&& consumer) {
// nop
// nop
}
}
fin
();
fin
();
// clang-format on
}
}
}
// namespace parser
}
// namespace parser
...
...
libcaf_core/test/uri.cpp
View file @
a7e4cd00
...
@@ -288,6 +288,7 @@ CAF_TEST(builder construction) {
...
@@ -288,6 +288,7 @@ CAF_TEST(builder construction) {
CAF_TEST
(
from
string
)
{
CAF_TEST
(
from
string
)
{
// all combinations of components
// all combinations of components
ROUNDTRIP
(
"http:file"
);
ROUNDTRIP
(
"http:file"
);
ROUNDTRIP
(
"http:foo-bar"
);
ROUNDTRIP
(
"http:file?a=1&b=2"
);
ROUNDTRIP
(
"http:file?a=1&b=2"
);
ROUNDTRIP
(
"http:file#42"
);
ROUNDTRIP
(
"http:file#42"
);
ROUNDTRIP
(
"http:file?a=1&b=2#42"
);
ROUNDTRIP
(
"http:file?a=1&b=2#42"
);
...
...
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