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
820debf4
Commit
820debf4
authored
Mar 02, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringUtil: add FindStringSuffix()
parent
c19292c0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
+27
-8
PlaylistFile.cxx
src/PlaylistFile.cxx
+4
-8
StringUtil.cxx
src/util/StringUtil.cxx
+15
-0
StringUtil.hxx
src/util/StringUtil.hxx
+8
-0
No files found.
src/PlaylistFile.cxx
View file @
820debf4
...
@@ -173,12 +173,9 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
...
@@ -173,12 +173,9 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
return
false
;
return
false
;
const
auto
*
const
name_fs_str
=
name_fs
.
c_str
();
const
auto
*
const
name_fs_str
=
name_fs
.
c_str
();
const
size_t
name_length
=
name_fs
.
length
();
const
auto
*
const
name_fs_end
=
FindStringSuffix
(
name_fs_str
,
PLAYLIST_FILE_SUFFIX
);
if
(
name_length
<
ARRAY_SIZE
(
PLAYLIST_FILE_SUFFIX
))
if
(
name_fs_end
==
nullptr
)
return
false
;
if
(
!
StringEndsWith
(
name_fs_str
,
PLAYLIST_FILE_SUFFIX
))
return
false
;
return
false
;
FileInfo
fi
;
FileInfo
fi
;
...
@@ -186,8 +183,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
...
@@ -186,8 +183,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
!
fi
.
IsRegular
())
!
fi
.
IsRegular
())
return
false
;
return
false
;
PathTraitsFS
::
string
name
(
name_fs_str
,
PathTraitsFS
::
string
name
(
name_fs_str
,
name_fs_end
);
name_length
+
1
-
ARRAY_SIZE
(
PLAYLIST_FILE_SUFFIX
));
std
::
string
name_utf8
=
PathToUTF8
(
name
.
c_str
());
std
::
string
name_utf8
=
PathToUTF8
(
name
.
c_str
());
if
(
name_utf8
.
empty
())
if
(
name_utf8
.
empty
())
return
false
;
return
false
;
...
...
src/util/StringUtil.cxx
View file @
820debf4
...
@@ -96,6 +96,21 @@ StringEndsWith(const char *haystack, const char *needle)
...
@@ -96,6 +96,21 @@ StringEndsWith(const char *haystack, const char *needle)
needle
,
needle_length
)
==
0
;
needle
,
needle_length
)
==
0
;
}
}
const
char
*
FindStringSuffix
(
const
char
*
p
,
const
char
*
suffix
)
{
const
size_t
p_length
=
strlen
(
p
);
const
size_t
suffix_length
=
strlen
(
suffix
);
if
(
p_length
<
suffix_length
)
return
nullptr
;
const
char
*
q
=
p
+
p_length
-
suffix_length
;
return
memcmp
(
q
,
suffix
,
suffix_length
)
==
0
?
q
:
nullptr
;
}
char
*
char
*
CopyString
(
char
*
gcc_restrict
dest
,
const
char
*
gcc_restrict
src
,
size_t
size
)
CopyString
(
char
*
gcc_restrict
dest
,
const
char
*
gcc_restrict
src
,
size_t
size
)
{
{
...
...
src/util/StringUtil.hxx
View file @
820debf4
...
@@ -91,6 +91,14 @@ bool
...
@@ -91,6 +91,14 @@ bool
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
);
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
);
/**
/**
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
*/
gcc_pure
const
char
*
FindStringSuffix
(
const
char
*
p
,
const
char
*
suffix
);
/**
* Copy a string. If the buffer is too small, then the string is
* Copy a string. If the buffer is too small, then the string is
* truncated. This is a safer version of strncpy().
* truncated. This is a safer version of strncpy().
*
*
...
...
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