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
250332a8
Commit
250332a8
authored
Mar 04, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringUtil: reorder functions
parent
39825c66
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
73 deletions
+73
-73
StringUtil.cxx
src/util/StringUtil.cxx
+45
-45
StringUtil.hxx
src/util/StringUtil.hxx
+28
-28
No files found.
src/util/StringUtil.cxx
View file @
250332a8
...
...
@@ -26,6 +26,51 @@
#include <assert.h>
#include <string.h>
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
)
{
const
size_t
length
=
strlen
(
needle
);
return
memcmp
(
haystack
,
needle
,
length
)
==
0
;
}
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
;
}
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
*
CopyString
(
char
*
gcc_restrict
dest
,
const
char
*
gcc_restrict
src
,
size_t
size
)
{
size_t
length
=
strlen
(
src
);
if
(
length
>=
size
)
length
=
size
-
1
;
char
*
p
=
std
::
copy_n
(
src
,
length
,
dest
);
*
p
=
'\0'
;
return
p
;
}
const
char
*
StripLeft
(
const
char
*
p
)
{
...
...
@@ -79,51 +124,6 @@ Strip(char *p)
}
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
)
{
const
size_t
length
=
strlen
(
needle
);
return
memcmp
(
haystack
,
needle
,
length
)
==
0
;
}
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
;
}
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
*
CopyString
(
char
*
gcc_restrict
dest
,
const
char
*
gcc_restrict
src
,
size_t
size
)
{
size_t
length
=
strlen
(
src
);
if
(
length
>=
size
)
length
=
size
-
1
;
char
*
p
=
std
::
copy_n
(
src
,
length
,
dest
);
*
p
=
'\0'
;
return
p
;
}
bool
string_array_contains
(
const
char
*
const
*
haystack
,
const
char
*
needle
)
{
assert
(
haystack
!=
nullptr
);
...
...
src/util/StringUtil.hxx
View file @
250332a8
...
...
@@ -24,6 +24,34 @@
#include <stddef.h>
gcc_pure
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
);
gcc_pure
bool
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
* truncated. This is a safer version of strncpy().
*
* @param size the size of the destination buffer (including the null
* terminator)
* @return a pointer to the null terminator
*/
gcc_nonnull_all
char
*
CopyString
(
char
*
dest
,
const
char
*
src
,
size_t
size
);
/**
* Returns a pointer to the first non-whitespace character in the
* string, or to the end of the string.
...
...
@@ -82,34 +110,6 @@ StripRight(char *p);
char
*
Strip
(
char
*
p
);
gcc_pure
bool
StringStartsWith
(
const
char
*
haystack
,
const
char
*
needle
);
gcc_pure
bool
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
* truncated. This is a safer version of strncpy().
*
* @param size the size of the destination buffer (including the null
* terminator)
* @return a pointer to the null terminator
*/
gcc_nonnull_all
char
*
CopyString
(
char
*
dest
,
const
char
*
src
,
size_t
size
);
/**
* 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