Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
c9fa6304
Commit
c9fa6304
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
string utils: add concat
Change-Id: I3b0fd2a34289545dbf06b85c2e825fbf87bb42ad
parent
32b777f9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/string_utils.h
+52
-51
52 additions, 51 deletions
src/string_utils.h
with
52 additions
and
51 deletions
src/string_utils.h
+
52
−
51
View file @
c9fa6304
...
...
@@ -32,57 +32,6 @@
#include
<WTypes.h>
#endif
// Add string operators crucially missing from standard
// see https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/1RcShRhrmRc
namespace
std
{
inline
string
operator
+
(
const
string
&
s
,
const
string_view
&
sv
)
{
string
ret
;
ret
.
reserve
(
s
.
size
()
+
sv
.
size
());
ret
.
append
(
s
);
ret
.
append
(
sv
);
return
ret
;
}
inline
string
operator
+
(
const
string_view
&
sv
,
const
string
&
s
)
{
string
ret
;
ret
.
reserve
(
s
.
size
()
+
sv
.
size
());
ret
.
append
(
sv
);
ret
.
append
(
s
);
return
ret
;
}
using
svmatch
=
match_results
<
string_view
::
const_iterator
>
;
using
svsub_match
=
sub_match
<
string_view
::
const_iterator
>
;
constexpr
string_view
svsub_match_view
(
const
svsub_match
&
submatch
)
noexcept
{
return
string_view
(
&*
submatch
.
first
,
submatch
.
second
-
submatch
.
first
);
}
inline
bool
regex_match
(
string_view
sv
,
svmatch
&
m
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_match
(
sv
.
begin
(),
sv
.
end
(),
m
,
e
,
flags
);
}
inline
bool
regex_match
(
string_view
sv
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_match
(
sv
.
begin
(),
sv
.
end
(),
e
,
flags
);
}
inline
bool
regex_search
(
string_view
sv
,
svmatch
&
m
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_search
(
sv
.
begin
(),
sv
.
end
(),
m
,
e
,
flags
);
}
}
// namespace std
namespace
jami
{
constexpr
static
const
char
TRUE_STR
[]
=
"true"
;
...
...
@@ -116,6 +65,15 @@ stod(const std::string& str)
return
std
::
stod
(
str
);
}
template
<
typename
...
Args
>
std
::
string
concat
(
Args
&&
...
args
){
static_assert
((
std
::
is_constructible_v
<
std
::
string_view
,
Args
&&>
&&
...));
std
::
string
s
;
s
.
reserve
((
std
::
string_view
{
args
}.
size
()
+
...));
(
s
.
append
(
std
::
forward
<
Args
>
(
args
)),
...);
return
s
;
}
std
::
string_view
trim
(
std
::
string_view
s
);
/**
...
...
@@ -188,3 +146,46 @@ std::string string_join(const std::set<std::string>& set, std::string_view separ
std
::
set
<
std
::
string
>
string_split_set
(
std
::
string
&
str
,
std
::
string_view
separator
=
"/"
);
}
// namespace jami
// Add string operators crucially missing from standard
// see https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/1RcShRhrmRc
namespace
std
{
inline
string
operator
+
(
const
string
&
s
,
const
string_view
&
sv
)
{
return
jami
::
concat
(
s
,
sv
);
}
inline
string
operator
+
(
const
string_view
&
sv
,
const
string
&
s
)
{
return
jami
::
concat
(
sv
,
s
);
}
using
svmatch
=
match_results
<
string_view
::
const_iterator
>
;
using
svsub_match
=
sub_match
<
string_view
::
const_iterator
>
;
constexpr
string_view
svsub_match_view
(
const
svsub_match
&
submatch
)
noexcept
{
return
string_view
(
&*
submatch
.
first
,
submatch
.
second
-
submatch
.
first
);
}
inline
bool
regex_match
(
string_view
sv
,
svmatch
&
m
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_match
(
sv
.
begin
(),
sv
.
end
(),
m
,
e
,
flags
);
}
inline
bool
regex_match
(
string_view
sv
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_match
(
sv
.
begin
(),
sv
.
end
(),
e
,
flags
);
}
inline
bool
regex_search
(
string_view
sv
,
svmatch
&
m
,
const
regex
&
e
,
regex_constants
::
match_flag_type
flags
=
regex_constants
::
match_default
)
{
return
regex_search
(
sv
.
begin
(),
sv
.
end
(),
m
,
e
,
flags
);
}
}
// namespace std
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment