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
0b956cf9
Commit
0b956cf9
authored
Sep 07, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringAPI: add memrchr() wrapper
parent
2c3eb5b8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
StringAPI.hxx
src/util/StringAPI.hxx
+21
-0
StringView.hxx
src/util/StringView.hxx
+5
-0
WStringAPI.hxx
src/util/WStringAPI.hxx
+15
-0
No files found.
src/util/StringAPI.hxx
View file @
0b956cf9
...
@@ -96,6 +96,27 @@ StringFindLast(char *haystack, char needle) noexcept
...
@@ -96,6 +96,27 @@ StringFindLast(char *haystack, char needle) noexcept
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
inline
const
char
*
static
inline
const
char
*
StringFindLast
(
const
char
*
haystack
,
char
needle
,
size_t
size
)
noexcept
{
#if defined(__GLIBC__) || defined(__BIONIC__)
/* memrchr() is a GNU extension (and also available on
Android) */
return
(
const
char
*
)
memrchr
(
haystack
,
needle
,
size
);
#else
/* emulate for everybody else */
const
auto
*
p
=
haystack
+
size
;
while
(
p
>
haystack
)
{
--
p
;
if
(
*
p
==
needle
)
return
p
;
}
return
nullptr
;
#endif
}
gcc_pure
gcc_nonnull_all
static
inline
const
char
*
StringFindAny
(
const
char
*
haystack
,
const
char
*
accept
)
noexcept
StringFindAny
(
const
char
*
haystack
,
const
char
*
accept
)
noexcept
{
{
return
strpbrk
(
haystack
,
accept
);
return
strpbrk
(
haystack
,
accept
);
...
...
src/util/StringView.hxx
View file @
0b956cf9
...
@@ -94,6 +94,11 @@ struct BasicStringView : ConstBuffer<T> {
...
@@ -94,6 +94,11 @@ struct BasicStringView : ConstBuffer<T> {
return
StringFind
(
data
,
ch
,
this
->
size
);
return
StringFind
(
data
,
ch
,
this
->
size
);
}
}
gcc_pure
pointer_type
FindLast
(
value_type
ch
)
const
noexcept
{
return
StringFindLast
(
data
,
ch
,
size
);
}
/**
/**
* Split the string at the first occurrence of the given
* Split the string at the first occurrence of the given
* character. If the character is not found, then the first
* character. If the character is not found, then the first
...
...
src/util/WStringAPI.hxx
View file @
0b956cf9
...
@@ -92,6 +92,21 @@ StringFindLast(wchar_t *haystack, wchar_t needle) noexcept
...
@@ -92,6 +92,21 @@ StringFindLast(wchar_t *haystack, wchar_t needle) noexcept
gcc_pure
gcc_nonnull_all
gcc_pure
gcc_nonnull_all
static
inline
const
wchar_t
*
static
inline
const
wchar_t
*
StringFindLast
(
const
wchar_t
*
haystack
,
wchar_t
needle
,
size_t
size
)
noexcept
{
/* there's no wmemrchr() unfortunately */
const
auto
*
p
=
haystack
+
size
;
while
(
p
>
haystack
)
{
--
p
;
if
(
*
p
==
needle
)
return
p
;
}
return
nullptr
;
}
gcc_pure
gcc_nonnull_all
static
inline
const
wchar_t
*
StringFindAny
(
const
wchar_t
*
haystack
,
const
wchar_t
*
accept
)
noexcept
StringFindAny
(
const
wchar_t
*
haystack
,
const
wchar_t
*
accept
)
noexcept
{
{
return
wcspbrk
(
haystack
,
accept
);
return
wcspbrk
(
haystack
,
accept
);
...
...
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