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
4d15db01
Commit
4d15db01
authored
Nov 06, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringCompare: use StringView to simplify inline implementations
parent
0d1a5426
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
31 deletions
+14
-31
StringCompare.cxx
src/util/StringCompare.cxx
+0
-26
StringCompare.hxx
src/util/StringCompare.hxx
+14
-5
No files found.
src/util/StringCompare.cxx
View file @
4d15db01
...
...
@@ -28,17 +28,6 @@
*/
#include "StringCompare.hxx"
#include "StringAPI.hxx"
#include <assert.h>
#include <string.h>
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
)
{
const
size_t
length
=
StringLength
(
needle
);
return
StringIsEqual
(
haystack
,
needle
,
length
);
}
bool
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
)
...
...
@@ -52,21 +41,6 @@ StringEndsWith(const char *haystack, const char *needle)
}
const
char
*
StringAfterPrefix
(
const
char
*
string
,
const
char
*
prefix
)
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
assert
(
string
!=
nullptr
);
assert
(
prefix
!=
nullptr
);
#endif
size_t
prefix_length
=
strlen
(
prefix
);
return
StringIsEqual
(
string
,
prefix
,
prefix_length
)
?
string
+
prefix_length
:
nullptr
;
}
const
char
*
FindStringSuffix
(
const
char
*
p
,
const
char
*
suffix
)
{
const
size_t
p_length
=
strlen
(
p
);
...
...
src/util/StringCompare.hxx
View file @
4d15db01
...
...
@@ -30,6 +30,7 @@
#ifndef STRING_COMPARE_HXX
#define STRING_COMPARE_HXX
#include "StringView.hxx"
#include "Compiler.h"
#ifdef _UNICODE
...
...
@@ -42,9 +43,12 @@ StringIsEmpty(const char *string)
return
*
string
==
0
;
}
gcc_pure
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
);
gcc_pure
gcc_nonnull_all
static
inline
bool
StringStartsWith
(
const
char
*
haystack
,
StringView
needle
)
{
return
strncmp
(
haystack
,
needle
.
data
,
needle
.
size
)
==
0
;
}
gcc_pure
bool
...
...
@@ -56,8 +60,13 @@ StringEndsWith(const char *haystack, const char *needle);
* nullptr.
*/
gcc_pure
gcc_nonnull_all
const
char
*
StringAfterPrefix
(
const
char
*
string
,
const
char
*
prefix
);
static
inline
const
char
*
StringAfterPrefix
(
const
char
*
haystack
,
StringView
needle
)
{
return
StringStartsWith
(
haystack
,
needle
)
?
haystack
+
needle
.
size
:
nullptr
;
}
/**
* Check if the given string ends with the specified suffix. If yes,
...
...
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