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
9b5aa0d1
Commit
9b5aa0d1
authored
Aug 21, 2019
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add to_string for authority type of uri class
parent
bc496094
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
62 deletions
+130
-62
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+1
-0
libcaf_core/caf/detail/append_uri.hpp
libcaf_core/caf/detail/append_uri.hpp
+31
-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_uri.cpp
libcaf_core/src/append_uri.cpp
+65
-0
libcaf_core/src/uri.cpp
libcaf_core/src/uri.cpp
+22
-0
libcaf_core/src/uri_impl.cpp
libcaf_core/src/uri_impl.cpp
+8
-58
No files found.
libcaf_core/CMakeLists.txt
View file @
9b5aa0d1
...
...
@@ -26,6 +26,7 @@ set(LIBCAF_CORE_SRCS
src/actor_system.cpp
src/actor_system_config.cpp
src/append_hex.cpp
src/append_uri.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
...
...
libcaf_core/caf/detail/append_uri.hpp
0 → 100644
View file @
9b5aa0d1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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"
namespace
caf
{
namespace
detail
{
// Escapes all reserved characters according to RFC 3986 in `x` and
// adds the encoded string to `str`.
void
append_uri
(
std
::
string
&
str
,
string_view
x
,
bool
is_path
=
false
);
}
// namespacvec detail
}
// namespace caf
libcaf_core/caf/detail/uri_impl.hpp
View file @
9b5aa0d1
...
...
@@ -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 @
9b5aa0d1
...
...
@@ -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_uri.cpp
0 → 100644
View file @
9b5aa0d1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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_uri.hpp"
#include "caf/config.hpp"
#include "caf/detail/append_hex.hpp"
#include "caf/string_view.hpp"
namespace
caf
{
namespace
detail
{
void
append_uri
(
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
;
}
}
}
// namespacvec detail
}
// namespace caf
libcaf_core/src/uri.cpp
View file @
9b5aa0d1
...
...
@@ -19,6 +19,7 @@
#include "caf/uri.hpp"
#include "caf/deserializer.hpp"
#include "caf/detail/append_uri.hpp"
#include "caf/detail/fnv_hash.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/detail/uri_impl.hpp"
...
...
@@ -101,6 +102,27 @@ 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_uri
(
str
,
x
.
userinfo
);
str
+=
'@'
;
}
auto
addr
=
get_if
<
ip_address
>
(
&
x
.
host
);
if
(
addr
==
nullptr
)
{
detail
::
append_uri
(
str
,
get
<
std
::
string
>
(
x
.
host
));
}
else
{
str
+=
'['
;
str
+=
to_string
(
*
addr
);
str
+=
']'
;
}
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 @
9b5aa0d1
...
...
@@ -18,6 +18,7 @@
#include "caf/detail/uri_impl.hpp"
#include "caf/detail/append_uri.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_uri
(
str
,
scheme
);
str
+=
':'
;
if
(
authority
.
empty
())
{
CAF_ASSERT
(
!
path
.
empty
());
a
dd_encoded
(
path
,
true
);
a
ppend_uri
(
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_uri
(
str
,
path
,
true
);
}
}
if
(
!
query
.
empty
())
{
str
+=
'?'
;
auto
i
=
query
.
begin
();
auto
add_kvp
=
[
&
](
decltype
(
*
i
)
kvp
)
{
a
dd_encoded
(
kvp
.
first
);
a
ppend_uri
(
str
,
kvp
.
first
);
str
+=
'='
;
a
dd_encoded
(
kvp
.
second
);
a
ppend_uri
(
str
,
kvp
.
second
);
};
add_kvp
(
*
i
);
for
(
++
i
;
i
!=
query
.
end
();
++
i
)
{
...
...
@@ -83,46 +69,10 @@ void uri_impl::assemble_str() {
}
if
(
!
fragment
.
empty
())
{
str
+=
'#'
;
a
dd_encoded
(
fragment
);
a
ppend_uri
(
str
,
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
;
}
}
// -- friend functions ---------------------------------------------------------
void
intrusive_ptr_add_ref
(
const
uri_impl
*
p
)
{
...
...
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