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
2a7b5581
Unverified
Commit
2a7b5581
authored
Nov 21, 2018
by
Joseph Noir
Committed by
GitHub
Nov 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #798
Clean up string algorithms header and fix caf::split
parents
168a2a2b
567d25da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
33 deletions
+105
-33
libcaf_core/caf/string_algorithms.hpp
libcaf_core/caf/string_algorithms.hpp
+1
-27
libcaf_core/src/string_algorithms.cpp
libcaf_core/src/string_algorithms.cpp
+6
-6
libcaf_core/test/string_algorithms.cpp
libcaf_core/test/string_algorithms.cpp
+98
-0
No files found.
libcaf_core/caf/string_algorithms.hpp
View file @
2a7b5581
...
@@ -64,22 +64,10 @@ std::string join(InputIterator first, InputIterator last, string_view glue) {
...
@@ -64,22 +64,10 @@ std::string join(InputIterator first, InputIterator last, string_view glue) {
}
}
template
<
class
Container
>
template
<
class
Container
>
std
::
string
join
(
const
Container
&
c
,
const
std
::
string
&
glue
)
{
std
::
string
join
(
const
Container
&
c
,
string_view
glue
)
{
return
join
(
c
.
begin
(),
c
.
end
(),
glue
);
return
join
(
c
.
begin
(),
c
.
end
(),
glue
);
}
}
// end of recursion
inline
void
splice
(
std
::
string
&
,
string_view
)
{
// nop
}
template
<
class
T
,
class
...
Ts
>
void
splice
(
std
::
string
&
str
,
string_view
glue
,
T
&&
arg
,
Ts
&&
...
xs
)
{
str
.
insert
(
str
.
end
(),
glue
.
begin
(),
glue
.
end
());
str
+=
std
::
forward
<
T
>
(
arg
);
splice
(
str
,
glue
,
std
::
forward
<
Ts
>
(
xs
)...);
}
/// Replaces all occurrences of `what` by `with` in `str`.
/// Replaces all occurrences of `what` by `with` in `str`.
void
replace_all
(
std
::
string
&
str
,
string_view
what
,
string_view
with
);
void
replace_all
(
std
::
string
&
str
,
string_view
what
,
string_view
with
);
...
@@ -89,18 +77,4 @@ bool starts_with(string_view str, string_view prefix);
...
@@ -89,18 +77,4 @@ bool starts_with(string_view str, string_view prefix);
/// Returns whether `str` ends with `suffix`.
/// Returns whether `str` ends with `suffix`.
bool
ends_with
(
string_view
str
,
string_view
suffix
);
bool
ends_with
(
string_view
str
,
string_view
suffix
);
template
<
class
T
>
typename
std
::
enable_if
<
std
::
is_arithmetic
<
T
>::
value
,
std
::
string
>::
type
convert_to_str
(
T
value
)
{
return
std
::
to_string
(
value
);
}
inline
std
::
string
convert_to_str
(
std
::
string
value
)
{
return
value
;
}
}
// namespace caf
}
// namespace caf
libcaf_core/src/string_algorithms.cpp
View file @
2a7b5581
...
@@ -27,15 +27,15 @@ void split_impl(F consume, string_view str, string_view delims, bool keep_all) {
...
@@ -27,15 +27,15 @@ void split_impl(F consume, string_view str, string_view delims, bool keep_all) {
size_t
pos
=
0
;
size_t
pos
=
0
;
size_t
prev
=
0
;
size_t
prev
=
0
;
while
((
pos
=
str
.
find_first_of
(
delims
,
prev
))
!=
std
::
string
::
npos
)
{
while
((
pos
=
str
.
find_first_of
(
delims
,
prev
))
!=
std
::
string
::
npos
)
{
if
(
pos
>
prev
)
{
auto
substr
=
str
.
substr
(
prev
,
pos
-
prev
);
auto
substr
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
keep_all
||
!
substr
.
empty
())
if
(
!
substr
.
empty
()
||
keep_all
)
consume
(
substr
);
consume
(
substr
);
}
prev
=
pos
+
1
;
prev
=
pos
+
1
;
}
}
if
(
prev
<
str
.
size
())
if
(
prev
<
str
.
size
())
consume
(
str
.
substr
(
prev
,
std
::
string
::
npos
));
consume
(
str
.
substr
(
prev
));
else
if
(
keep_all
)
consume
(
string_view
{});
}
}
}
// namespace <anonymous>
}
// namespace <anonymous>
...
...
libcaf_core/test/string_algorithms.cpp
0 → 100644
View file @
2a7b5581
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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. *
******************************************************************************/
#define CAF_SUITE string_algorithms
#include "caf/string_algorithms.hpp"
#include "caf/test/dsl.hpp"
#include <string>
#include <vector>
using
namespace
caf
;
namespace
{
using
str_list
=
std
::
vector
<
std
::
string
>
;
str_list
split
(
string_view
str
)
{
str_list
result
;
caf
::
split
(
result
,
str
,
","
);
return
result
;
}
str_list
compressed_split
(
string_view
str
)
{
str_list
result
;
caf
::
split
(
result
,
str
,
","
,
token_compress_on
);
return
result
;
}
std
::
string
join
(
str_list
vec
)
{
return
caf
::
join
(
vec
,
","
);
}
}
// namespace <anonymous>
CAF_TEST
(
splitting
)
{
CAF_CHECK_EQUAL
(
split
(
""
),
str_list
({
""
}));
CAF_CHECK_EQUAL
(
split
(
","
),
str_list
({
""
,
""
}));
CAF_CHECK_EQUAL
(
split
(
",,"
),
str_list
({
""
,
""
,
""
}));
CAF_CHECK_EQUAL
(
split
(
",,,"
),
str_list
({
""
,
""
,
""
,
""
}));
CAF_CHECK_EQUAL
(
split
(
"a,b,c"
),
str_list
({
"a"
,
"b"
,
"c"
}));
CAF_CHECK_EQUAL
(
split
(
"a,,b,c,"
),
str_list
({
"a"
,
""
,
"b"
,
"c"
,
""
}));
}
CAF_TEST
(
compressed
splitting
)
{
CAF_CHECK_EQUAL
(
compressed_split
(
""
),
str_list
({}));
CAF_CHECK_EQUAL
(
compressed_split
(
","
),
str_list
({}));
CAF_CHECK_EQUAL
(
compressed_split
(
",,"
),
str_list
({}));
CAF_CHECK_EQUAL
(
compressed_split
(
",,,"
),
str_list
({}));
CAF_CHECK_EQUAL
(
compressed_split
(
"a,b,c"
),
str_list
({
"a"
,
"b"
,
"c"
}));
CAF_CHECK_EQUAL
(
compressed_split
(
"a,,b,c,"
),
str_list
({
"a"
,
"b"
,
"c"
}));
}
CAF_TEST
(
joining
)
{
CAF_CHECK_EQUAL
(
join
({}),
""
);
CAF_CHECK_EQUAL
(
join
({
""
}),
""
);
CAF_CHECK_EQUAL
(
join
({
""
,
""
}),
","
);
CAF_CHECK_EQUAL
(
join
({
""
,
""
,
""
}),
",,"
);
CAF_CHECK_EQUAL
(
join
({
"a"
}),
"a"
);
CAF_CHECK_EQUAL
(
join
({
"a"
,
"b"
}),
"a,b"
);
CAF_CHECK_EQUAL
(
join
({
"a"
,
"b"
,
"c"
}),
"a,b,c"
);
}
CAF_TEST
(
starts
with
)
{
CAF_CHECK
(
starts_with
(
"foobar"
,
"f"
));
CAF_CHECK
(
starts_with
(
"foobar"
,
"fo"
));
CAF_CHECK
(
starts_with
(
"foobar"
,
"fooba"
));
CAF_CHECK
(
starts_with
(
"foobar"
,
"foobar"
));
CAF_CHECK
(
!
starts_with
(
"foobar"
,
"o"
));
CAF_CHECK
(
!
starts_with
(
"foobar"
,
"fa"
));
CAF_CHECK
(
!
starts_with
(
"foobar"
,
"foobaro"
));
}
CAF_TEST
(
ends
with
)
{
CAF_CHECK
(
ends_with
(
"foobar"
,
"r"
));
CAF_CHECK
(
ends_with
(
"foobar"
,
"ar"
));
CAF_CHECK
(
ends_with
(
"foobar"
,
"oobar"
));
CAF_CHECK
(
ends_with
(
"foobar"
,
"foobar"
));
CAF_CHECK
(
!
ends_with
(
"foobar"
,
"a"
));
CAF_CHECK
(
!
ends_with
(
"foobar"
,
"car"
));
CAF_CHECK
(
!
ends_with
(
"foobar"
,
"afoobar"
));
}
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