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
5dbdd362
Commit
5dbdd362
authored
Sep 12, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringView: add struct BasicStringView
parent
96b557c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
25 deletions
+48
-25
StringView.cxx
src/util/StringView.cxx
+6
-2
StringView.hxx
src/util/StringView.hxx
+42
-23
No files found.
src/util/StringView.cxx
View file @
5dbdd362
...
...
@@ -30,16 +30,20 @@
#include "StringView.hxx"
#include "CharUtil.hxx"
template
<
typename
T
>
void
StringView
::
StripLeft
()
noexcept
BasicStringView
<
T
>
::
StripLeft
()
noexcept
{
while
(
!
IsEmpty
()
&&
IsWhitespaceOrNull
(
front
()))
pop_front
();
}
template
<
typename
T
>
void
StringView
::
StripRight
()
noexcept
BasicStringView
<
T
>
::
StripRight
()
noexcept
{
while
(
!
IsEmpty
()
&&
IsWhitespaceOrNull
(
back
()))
pop_back
();
}
template
struct
BasicStringView
<
char
>
;
src/util/StringView.hxx
View file @
5dbdd362
...
...
@@ -33,50 +33,65 @@
#include "ConstBuffer.hxx"
#include "StringAPI.hxx"
struct
StringView
:
ConstBuffer
<
char
>
{
StringView
()
=
default
;
template
<
typename
T
>
struct
BasicStringView
:
ConstBuffer
<
T
>
{
typedef
typename
ConstBuffer
<
T
>::
size_type
size_type
;
typedef
typename
ConstBuffer
<
T
>::
value_type
value_type
;
typedef
typename
ConstBuffer
<
T
>::
pointer_type
pointer_type
;
constexpr
StringView
(
pointer_type
_data
,
size_type
_size
)
noexcept
:
ConstBuffer
(
_data
,
_size
)
{}
using
ConstBuffer
<
T
>::
data
;
using
ConstBuffer
<
T
>::
size
;
constexpr
StringView
(
pointer_type
_begin
,
pointer_type
_end
)
noexcept
:
ConstBuffer
(
_begin
,
_end
-
_begin
)
{}
BasicStringView
()
=
default
;
StringView
(
pointer_type
_data
)
noexcept
:
ConstBuffer
(
_data
,
_data
!=
nullptr
?
StringLength
(
_data
)
:
0
)
{}
constexpr
BasicStringView
(
pointer_type
_data
,
size_type
_size
)
noexcept
:
ConstBuffer
<
T
>
(
_data
,
_size
)
{}
constexpr
StringView
(
std
::
nullptr_t
n
)
noexcept
:
ConstBuffer
(
n
)
{}
constexpr
BasicStringView
(
pointer_type
_begin
,
pointer_type
_end
)
noexcept
:
ConstBuffer
<
T
>
(
_begin
,
_end
-
_begin
)
{}
BasicStringView
(
pointer_type
_data
)
noexcept
:
ConstBuffer
<
T
>
(
_data
,
_data
!=
nullptr
?
StringLength
(
_data
)
:
0
)
{}
constexpr
BasicStringView
(
std
::
nullptr_t
n
)
noexcept
:
ConstBuffer
<
T
>
(
n
)
{}
using
ConstBuffer
<
T
>::
IsEmpty
;
using
ConstBuffer
<
T
>::
front
;
using
ConstBuffer
<
T
>::
back
;
using
ConstBuffer
<
T
>::
pop_front
;
using
ConstBuffer
<
T
>::
pop_back
;
gcc_pure
pointer_type
Find
(
value_type
ch
)
const
noexcept
{
return
StringFind
(
data
,
ch
,
size
);
return
StringFind
(
data
,
ch
,
this
->
size
);
}
gcc_pure
bool
StartsWith
(
StringView
needle
)
const
noexcept
{
return
size
>=
needle
.
size
&&
bool
StartsWith
(
BasicStringView
<
T
>
needle
)
const
noexcept
{
return
this
->
size
>=
needle
.
size
&&
StringIsEqual
(
data
,
needle
.
data
,
needle
.
size
);
}
gcc_pure
bool
EndsWith
(
StringView
needle
)
const
noexcept
{
return
size
>=
needle
.
size
&&
StringIsEqual
(
data
+
size
-
needle
.
size
,
bool
EndsWith
(
BasicStringView
<
T
>
needle
)
const
noexcept
{
return
this
->
size
>=
needle
.
size
&&
StringIsEqual
(
data
+
this
->
size
-
needle
.
size
,
needle
.
data
,
needle
.
size
);
}
gcc_pure
bool
Equals
(
StringView
other
)
const
noexcept
{
return
size
==
other
.
size
&&
StringIsEqual
(
data
,
other
.
data
,
size
);
bool
Equals
(
BasicStringView
<
T
>
other
)
const
noexcept
{
return
this
->
size
==
other
.
size
&&
StringIsEqual
(
data
,
other
.
data
,
this
->
size
);
}
gcc_pure
bool
EqualsIgnoreCase
(
StringView
other
)
const
noexcept
{
return
size
==
other
.
size
&&
StringIsEqualIgnoreCase
(
data
,
other
.
data
,
size
);
bool
EqualsIgnoreCase
(
BasicStringView
<
T
>
other
)
const
noexcept
{
return
this
->
size
==
other
.
size
&&
StringIsEqualIgnoreCase
(
data
,
other
.
data
,
this
->
size
);
}
/**
...
...
@@ -95,4 +110,8 @@ struct StringView : ConstBuffer<char> {
}
};
struct
StringView
:
BasicStringView
<
char
>
{
using
BasicStringView
::
BasicStringView
;
};
#endif
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