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
0d110fbe
Unverified
Commit
0d110fbe
authored
Aug 21, 2019
by
Joseph Noir
Committed by
GitHub
Aug 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #884
Add to_string for authority type of URI class
parents
ad35a5c7
14f7489e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
63 deletions
+140
-63
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/detail/append_percent_encoded.hpp
libcaf_core/caf/detail/append_percent_encoded.hpp
+33
-0
libcaf_core/caf/detail/uri_impl.hpp
libcaf_core/caf/detail/uri_impl.hpp
+0
-4
libcaf_core/caf/uri.hpp
libcaf_core/caf/uri.hpp
+3
-0
libcaf_core/src/append_hex.cpp
libcaf_core/src/append_hex.cpp
+1
-1
libcaf_core/src/append_percent_encoded.cpp
libcaf_core/src/append_percent_encoded.cpp
+65
-0
libcaf_core/src/uri.cpp
libcaf_core/src/uri.cpp
+29
-0
libcaf_core/src/uri_impl.cpp
libcaf_core/src/uri_impl.cpp
+8
-58
No files found.
libcaf_core/CMakeLists.txt
View file @
0d110fbe
...
...
@@ -26,6 +26,7 @@ set(LIBCAF_CORE_SRCS
src/actor_system.cpp
src/actor_system_config.cpp
src/append_hex.cpp
src/append_percent_encoded.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
...
...
libcaf_core/caf/detail/append_percent_encoded.hpp
0 → 100644
View file @
0d110fbe
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/append_hex.hpp"
#include "caf/fwd.hpp"
namespace
caf
{
namespace
detail
{
// Escapes all reserved characters according to RFC 3986 in `x` and
// adds the encoded string to `str`.
void
append_percent_encoded
(
std
::
string
&
str
,
string_view
x
,
bool
is_path
=
false
);
}
// namespace detail
}
// namespace caf
libcaf_core/caf/detail/uri_impl.hpp
View file @
0d110fbe
...
...
@@ -76,10 +76,6 @@ public:
/// Assembles the human-readable string representation for this URI.
void
assemble_str
();
// Escapes all reserved characters according to RFC 3986 in `x` and
// adds the encoded string to `str`.
void
add_encoded
(
string_view
x
,
bool
is_path
=
false
);
// -- friend functions -------------------------------------------------------
friend
void
intrusive_ptr_add_ref
(
const
uri_impl
*
p
);
...
...
libcaf_core/caf/uri.hpp
View file @
0d110fbe
...
...
@@ -134,6 +134,9 @@ typename Inspector::result_type inspect(Inspector& f, uri::authority_type& x) {
/// @relates uri
std
::
string
to_string
(
const
uri
&
x
);
/// @relates uri
std
::
string
to_string
(
const
uri
::
authority_type
&
x
);
/// @relates uri
error
parse
(
string_view
str
,
uri
&
dest
);
...
...
libcaf_core/src/append_hex.cpp
View file @
0d110fbe
...
...
@@ -16,7 +16,7 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/
stringification_inspector
.hpp"
#include "caf/detail/
append_hex
.hpp"
namespace
caf
{
namespace
detail
{
...
...
libcaf_core/src/append_percent_encoded.cpp
0 → 100644
View file @
0d110fbe
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/config.hpp"
#include "caf/detail/append_hex.hpp"
#include "caf/string_view.hpp"
namespace
caf
{
namespace
detail
{
void
append_percent_encoded
(
std
::
string
&
str
,
string_view
x
,
bool
is_path
)
{
for
(
auto
ch
:
x
)
switch
(
ch
)
{
case
'/'
:
if
(
is_path
)
{
str
+=
ch
;
break
;
}
CAF_ANNOTATE_FALLTHROUGH
;
case
' '
:
case
':'
:
case
'?'
:
case
'#'
:
case
'['
:
case
']'
:
case
'@'
:
case
'!'
:
case
'$'
:
case
'&'
:
case
'\''
:
case
'"'
:
case
'('
:
case
')'
:
case
'*'
:
case
'+'
:
case
','
:
case
';'
:
case
'='
:
str
+=
'%'
;
append_hex
(
str
,
reinterpret_cast
<
uint8_t
*>
(
&
ch
),
1
);
break
;
default:
str
+=
ch
;
}
}
}
// namespace detail
}
// namespace caf
libcaf_core/src/uri.cpp
View file @
0d110fbe
...
...
@@ -19,7 +19,9 @@
#include "caf/uri.hpp"
#include "caf/deserializer.hpp"
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/detail/fnv_hash.hpp"
#include "caf/detail/overload.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/detail/uri_impl.hpp"
#include "caf/error.hpp"
...
...
@@ -101,6 +103,33 @@ std::string to_string(const uri& x) {
return
result
;
}
std
::
string
to_string
(
const
uri
::
authority_type
&
x
)
{
std
::
string
str
;
if
(
!
x
.
userinfo
.
empty
())
{
detail
::
append_percent_encoded
(
str
,
x
.
userinfo
);
str
+=
'@'
;
}
auto
f
=
caf
::
detail
::
make_overload
(
[
&
](
const
ip_address
&
addr
)
{
if
(
addr
.
embeds_v4
())
{
str
+=
to_string
(
addr
);
}
else
{
str
+=
'['
;
str
+=
to_string
(
addr
);
str
+=
']'
;
}
},
[
&
](
const
std
::
string
&
host
)
{
detail
::
append_percent_encoded
(
str
,
host
);
});
visit
(
f
,
x
.
host
);
if
(
x
.
port
!=
0
)
{
str
+=
':'
;
str
+=
std
::
to_string
(
x
.
port
);
}
return
str
;
}
error
parse
(
string_view
str
,
uri
&
dest
)
{
using
namespace
detail
::
parser
;
uri_builder
builder
;
...
...
libcaf_core/src/uri_impl.cpp
View file @
0d110fbe
...
...
@@ -18,6 +18,7 @@
#include "caf/detail/uri_impl.hpp"
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/error.hpp"
#include "caf/ip_address.hpp"
...
...
@@ -39,41 +40,26 @@ uri_impl uri_impl::default_instance;
// -- modifiers ----------------------------------------------------------------
void
uri_impl
::
assemble_str
()
{
a
dd_encoded
(
scheme
);
a
ppend_percent_encoded
(
str
,
scheme
);
str
+=
':'
;
if
(
authority
.
empty
())
{
CAF_ASSERT
(
!
path
.
empty
());
a
dd_encoded
(
path
,
true
);
a
ppend_percent_encoded
(
str
,
path
,
true
);
}
else
{
str
+=
"//"
;
if
(
!
authority
.
userinfo
.
empty
())
{
add_encoded
(
authority
.
userinfo
);
str
+=
'@'
;
}
auto
addr
=
get_if
<
ip_address
>
(
&
authority
.
host
);
if
(
addr
==
nullptr
)
{
add_encoded
(
get
<
std
::
string
>
(
authority
.
host
));
}
else
{
str
+=
'['
;
str
+=
to_string
(
*
addr
);
str
+=
']'
;
}
if
(
authority
.
port
!=
0
)
{
str
+=
':'
;
str
+=
std
::
to_string
(
authority
.
port
);
}
str
+=
to_string
(
authority
);
if
(
!
path
.
empty
())
{
str
+=
'/'
;
a
dd_encoded
(
path
,
true
);
a
ppend_percent_encoded
(
str
,
path
,
true
);
}
}
if
(
!
query
.
empty
())
{
str
+=
'?'
;
auto
i
=
query
.
begin
();
auto
add_kvp
=
[
&
](
decltype
(
*
i
)
kvp
)
{
a
dd_encoded
(
kvp
.
first
);
a
ppend_percent_encoded
(
str
,
kvp
.
first
);
str
+=
'='
;
a
dd_encoded
(
kvp
.
second
);
a
ppend_percent_encoded
(
str
,
kvp
.
second
);
};
add_kvp
(
*
i
);
for
(
++
i
;
i
!=
query
.
end
();
++
i
)
{
...
...
@@ -83,43 +69,7 @@ void uri_impl::assemble_str() {
}
if
(
!
fragment
.
empty
())
{
str
+=
'#'
;
add_encoded
(
fragment
);
}
}
void
uri_impl
::
add_encoded
(
string_view
x
,
bool
is_path
)
{
for
(
auto
ch
:
x
)
switch
(
ch
)
{
case
'/'
:
if
(
is_path
)
{
str
+=
ch
;
break
;
}
CAF_ANNOTATE_FALLTHROUGH
;
case
' '
:
case
':'
:
case
'?'
:
case
'#'
:
case
'['
:
case
']'
:
case
'@'
:
case
'!'
:
case
'$'
:
case
'&'
:
case
'\''
:
case
'"'
:
case
'('
:
case
')'
:
case
'*'
:
case
'+'
:
case
','
:
case
';'
:
case
'='
:
str
+=
'%'
;
detail
::
append_hex
(
str
,
reinterpret_cast
<
uint8_t
*>
(
&
ch
),
1
);
break
;
default:
str
+=
ch
;
append_percent_encoded
(
str
,
fragment
);
}
}
...
...
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