Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
76eb5500
Commit
76eb5500
authored
5 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringView: add method Split()
parent
c1719a52
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
StringView.hxx
src/util/StringView.hxx
+19
-1
No files found.
src/util/StringView.hxx
View file @
76eb5500
/*
* Copyright
(C) 2013-2017
Max Kellermann <max.kellermann@gmail.com>
* Copyright
2013-2019
Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -33,6 +33,8 @@
#include "ConstBuffer.hxx"
#include "StringAPI.hxx"
#include <utility>
template
<
typename
T
>
struct
BasicStringView
:
ConstBuffer
<
T
>
{
typedef
typename
ConstBuffer
<
T
>::
size_type
size_type
;
...
...
@@ -65,6 +67,8 @@ struct BasicStringView : ConstBuffer<T> {
:
ConstBuffer
<
T
>
(
n
)
{}
using
ConstBuffer
<
T
>::
empty
;
using
ConstBuffer
<
T
>::
begin
;
using
ConstBuffer
<
T
>::
end
;
using
ConstBuffer
<
T
>::
front
;
using
ConstBuffer
<
T
>::
back
;
using
ConstBuffer
<
T
>::
pop_front
;
...
...
@@ -76,6 +80,20 @@ struct BasicStringView : ConstBuffer<T> {
return
StringFind
(
data
,
ch
,
this
->
size
);
}
/**
* Split the string at the first occurrence of the given
* character. If the character is not found, then the first
* value is the whole string and the second value is nullptr.
*/
gcc_pure
std
::
pair
<
BasicStringView
<
T
>
,
BasicStringView
<
T
>>
Split
(
value_type
ch
)
const
noexcept
{
const
auto
separator
=
Find
(
ch
);
if
(
separator
==
nullptr
)
return
{
*
this
,
nullptr
};
return
{{
begin
(),
separator
},
{
separator
+
1
,
end
()}};
}
gcc_pure
bool
StartsWith
(
BasicStringView
<
T
>
needle
)
const
noexcept
{
return
this
->
size
>=
needle
.
size
&&
...
...
This diff is collapsed.
Click to expand it.
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