util/StringView: add method EndsWith()
This commit is contained in:
parent
3bcabad28c
commit
cdd2d4cc1d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013-2015 Max Kellermann <max.kellermann@gmail.com>
|
* Copyright (C) 2013-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -92,6 +92,13 @@ struct StringView : ConstBuffer<char> {
|
|||||||
memcmp(data, needle.data, needle.size) == 0;
|
memcmp(data, needle.data, needle.size) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcc_pure
|
||||||
|
bool EndsWith(StringView needle) const noexcept {
|
||||||
|
return size >= needle.size &&
|
||||||
|
memcmp(data + size - needle.size,
|
||||||
|
needle.data, needle.size) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool Equals(StringView other) const noexcept {
|
bool Equals(StringView other) const noexcept {
|
||||||
return size == other.size &&
|
return size == other.size &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user