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
728e4e9a
Commit
728e4e9a
authored
Sep 06, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/StringCompare: add StringEndsWithIgnoreCase(), StringStartsWithIgnoreCase()
parent
2d6f9f9a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
0 deletions
+47
-0
StringCompare.cxx
src/util/StringCompare.cxx
+11
-0
StringCompare.hxx
src/util/StringCompare.hxx
+11
-0
WStringCompare.cxx
src/util/WStringCompare.cxx
+12
-0
WStringCompare.hxx
src/util/WStringCompare.hxx
+13
-0
No files found.
src/util/StringCompare.cxx
View file @
728e4e9a
...
...
@@ -40,6 +40,17 @@ StringEndsWith(const char *haystack, const char *needle) noexcept
needle
,
needle_length
)
==
0
;
}
bool
StringEndsWithIgnoreCase
(
const
char
*
haystack
,
const
char
*
needle
)
noexcept
{
const
size_t
haystack_length
=
StringLength
(
haystack
);
const
size_t
needle_length
=
StringLength
(
needle
);
return
haystack_length
>=
needle_length
&&
StringIsEqualIgnoreCase
(
haystack
+
haystack_length
-
needle_length
,
needle
);
}
const
char
*
FindStringSuffix
(
const
char
*
p
,
const
char
*
suffix
)
noexcept
{
...
...
src/util/StringCompare.hxx
View file @
728e4e9a
...
...
@@ -56,6 +56,10 @@ gcc_pure gcc_nonnull_all
bool
StringEndsWith
(
const
char
*
haystack
,
const
char
*
needle
)
noexcept
;
gcc_pure
gcc_nonnull_all
bool
StringEndsWithIgnoreCase
(
const
char
*
haystack
,
const
char
*
needle
)
noexcept
;
/**
* Returns the portion of the string after a prefix. If the string
* does not begin with the specified prefix, this function returns
...
...
@@ -70,6 +74,13 @@ StringAfterPrefix(const char *haystack, StringView needle) noexcept
:
nullptr
;
}
gcc_pure
gcc_nonnull_all
static
inline
bool
StringStartsWithIgnoreCase
(
const
char
*
haystack
,
StringView
needle
)
noexcept
{
return
StringIsEqualIgnoreCase
(
haystack
,
needle
.
data
,
needle
.
size
);
}
/**
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
...
...
src/util/WStringCompare.cxx
View file @
728e4e9a
...
...
@@ -39,6 +39,18 @@ StringEndsWith(const wchar_t *haystack, const wchar_t *needle) noexcept
StringIsEqual
(
haystack
+
haystack_length
-
needle_length
,
needle
);
}
bool
StringEndsWithIgnoreCase
(
const
wchar_t
*
haystack
,
const
wchar_t
*
needle
)
noexcept
{
const
size_t
haystack_length
=
StringLength
(
haystack
);
const
size_t
needle_length
=
StringLength
(
needle
);
return
haystack_length
>=
needle_length
&&
StringIsEqualIgnoreCase
(
haystack
+
haystack_length
-
needle_length
,
needle
);
}
const
wchar_t
*
FindStringSuffix
(
const
wchar_t
*
p
,
const
wchar_t
*
suffix
)
noexcept
{
...
...
src/util/WStringCompare.hxx
View file @
728e4e9a
...
...
@@ -54,6 +54,11 @@ gcc_pure gcc_nonnull_all
bool
StringEndsWith
(
const
wchar_t
*
haystack
,
const
wchar_t
*
needle
)
noexcept
;
gcc_pure
gcc_nonnull_all
bool
StringEndsWithIgnoreCase
(
const
wchar_t
*
haystack
,
const
wchar_t
*
needle
)
noexcept
;
/**
* Returns the portion of the string after a prefix. If the string
* does not begin with the specified prefix, this function returns
...
...
@@ -68,6 +73,14 @@ StringAfterPrefix(const wchar_t *haystack, WStringView needle) noexcept
:
nullptr
;
}
gcc_pure
gcc_nonnull_all
static
inline
bool
StringStartsWithIgnoreCase
(
const
wchar_t
*
haystack
,
WStringView
needle
)
noexcept
{
return
StringIsEqualIgnoreCase
(
haystack
,
needle
.
data
,
needle
.
size
);
}
/**
* Check if the given string ends with the specified suffix. If yes,
* returns the position of the suffix, and nullptr otherwise.
...
...
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