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
ce577346
Commit
ce577346
authored
Nov 17, 2018
by
Dominik Charousset
Committed by
Dominik Charousset
Nov 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add to_lowercase convenience function for atoms
parent
be020998
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
15 deletions
+42
-15
libcaf_core/caf/atom.hpp
libcaf_core/caf/atom.hpp
+4
-0
libcaf_core/src/atom.cpp
libcaf_core/src/atom.cpp
+38
-15
No files found.
libcaf_core/caf/atom.hpp
View file @
ce577346
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include <type_traits>
#include <type_traits>
#include "caf/detail/atom_val.hpp"
#include "caf/detail/atom_val.hpp"
#include "caf/fwd.hpp"
namespace
caf
{
namespace
caf
{
...
@@ -36,6 +37,9 @@ enum class atom_value : uint64_t {
...
@@ -36,6 +37,9 @@ enum class atom_value : uint64_t {
/// @relates atom_value
/// @relates atom_value
std
::
string
to_string
(
const
atom_value
&
what
);
std
::
string
to_string
(
const
atom_value
&
what
);
/// @relates atom_value
atom_value
to_lowercase
(
atom_value
x
);
atom_value
atom_from_string
(
const
std
::
string
&
x
);
atom_value
atom_from_string
(
const
std
::
string
&
x
);
/// Creates an atom from given string literal.
/// Creates an atom from given string literal.
...
...
libcaf_core/src/atom.cpp
View file @
ce577346
...
@@ -18,34 +18,57 @@
...
@@ -18,34 +18,57 @@
#include "caf/atom.hpp"
#include "caf/atom.hpp"
#include <array>
#include <cstring>
#include <cstring>
#include "caf/string_view.hpp"
namespace
caf
{
namespace
caf
{
atom_value
atom_from_string
(
const
std
::
string
&
x
)
{
namespace
{
if
(
x
.
size
()
>
10
)
return
atom
(
""
);
char
buf
[
11
];
memcpy
(
buf
,
x
.
c_str
(),
x
.
size
());
buf
[
x
.
size
()]
=
'\0'
;
return
atom
(
buf
);
}
std
::
string
to_string
(
const
atom_value
&
what
)
{
/// A buffer for decoding atom values.
using
atom_value_buf
=
std
::
array
<
char
,
11
>
;
size_t
decode
(
atom_value_buf
&
buf
,
atom_value
what
)
{
size_t
pos
=
0
;
auto
x
=
static_cast
<
uint64_t
>
(
what
);
auto
x
=
static_cast
<
uint64_t
>
(
what
);
std
::
string
result
;
// Don't read characters before we found the leading 0xF.
result
.
reserve
(
11
);
// don't read characters before we found the leading 0xF
// first four bits set?
bool
read_chars
=
((
x
&
0xF000000000000000
)
>>
60
)
==
0xF
;
bool
read_chars
=
((
x
&
0xF000000000000000
)
>>
60
)
==
0xF
;
uint64_t
mask
=
0x0FC0000000000000
;
uint64_t
mask
=
0x0FC0000000000000
;
for
(
int
bitshift
=
54
;
bitshift
>=
0
;
bitshift
-=
6
,
mask
>>=
6
)
{
for
(
int
bitshift
=
54
;
bitshift
>=
0
;
bitshift
-=
6
,
mask
>>=
6
)
{
if
(
read_chars
)
if
(
read_chars
)
result
+
=
detail
::
decoding_table
[(
x
&
mask
)
>>
bitshift
];
buf
[
pos
++
]
=
detail
::
decoding_table
[(
x
&
mask
)
>>
bitshift
];
else
if
(((
x
&
mask
)
>>
bitshift
)
==
0xF
)
else
if
(((
x
&
mask
)
>>
bitshift
)
==
0xF
)
read_chars
=
true
;
read_chars
=
true
;
}
}
return
result
;
buf
[
pos
]
=
'\0'
;
return
pos
;
}
}
// namespace <anonymous>
atom_value
to_lowercase
(
atom_value
x
)
{
atom_value_buf
buf
;
decode
(
buf
,
x
);
for
(
auto
ch
=
buf
.
data
();
*
ch
!=
'\0'
;
++
ch
)
*
ch
=
static_cast
<
char
>
(
tolower
(
*
ch
));
return
static_cast
<
atom_value
>
(
detail
::
atom_val
(
buf
.
data
()));
}
atom_value
atom_from_string
(
const
std
::
string
&
x
)
{
if
(
x
.
size
()
>
10
)
return
atom
(
""
);
char
buf
[
11
];
memcpy
(
buf
,
x
.
c_str
(),
x
.
size
());
buf
[
x
.
size
()]
=
'\0'
;
return
atom
(
buf
);
}
std
::
string
to_string
(
const
atom_value
&
x
)
{
atom_value_buf
str
;
auto
len
=
decode
(
str
,
x
);
return
std
::
string
(
str
.
begin
(),
str
.
begin
()
+
len
);
}
}
}
// namespace caf
}
// namespace caf
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