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
2b21312b
Commit
2b21312b
authored
Feb 17, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringUtil: add StringEndsWith()
Replaces g_str_has_suffix().
parent
3a818b6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
PlaylistFile.cxx
src/PlaylistFile.cxx
+2
-3
StringUtil.cxx
src/util/StringUtil.cxx
+11
-0
StringUtil.hxx
src/util/StringUtil.hxx
+4
-0
No files found.
src/PlaylistFile.cxx
View file @
2b21312b
...
...
@@ -36,11 +36,10 @@
#include "fs/Charset.hxx"
#include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx"
#include "util/StringUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include <glib.h>
#include <assert.h>
#include <sys/stat.h>
#include <string.h>
...
...
@@ -147,7 +146,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
memchr
(
name_fs_str
,
'\n'
,
name_length
)
!=
nullptr
)
return
false
;
if
(
!
g_str_has_suffix
(
name_fs_str
,
PLAYLIST_FILE_SUFFIX
))
if
(
!
StringEndsWith
(
name_fs_str
,
PLAYLIST_FILE_SUFFIX
))
return
false
;
const
auto
path_fs
=
AllocatedPath
::
Build
(
parent_path_fs
,
name_fs
);
...
...
src/util/StringUtil.cxx
View file @
2b21312b
...
...
@@ -55,6 +55,17 @@ StringStartsWith(const char *haystack, const char *needle)
}
bool
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
)
{
const
size_t
haystack_length
=
strlen
(
haystack
);
const
size_t
needle_length
=
strlen
(
needle
);
return
haystack_length
>=
needle_length
&&
memcmp
(
haystack
+
haystack_length
-
needle_length
,
needle
,
needle_length
)
==
0
;
}
bool
string_array_contains
(
const
char
*
const
*
haystack
,
const
char
*
needle
)
{
assert
(
haystack
!=
nullptr
);
...
...
src/util/StringUtil.hxx
View file @
2b21312b
...
...
@@ -51,6 +51,10 @@ gcc_pure
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
);
gcc_pure
bool
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
);
/**
* Checks whether a string array contains the specified string.
*
...
...
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