util/StringView: add method EndsWith()

This commit is contained in:
Max Kellermann 2017-05-17 12:39:01 +02:00
parent 3bcabad28c
commit cdd2d4cc1d
1 changed files with 8 additions and 1 deletions

View File

@ -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
* modification, are permitted provided that the following conditions
@ -92,6 +92,13 @@ struct StringView : ConstBuffer<char> {
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
bool Equals(StringView other) const noexcept {
return size == other.size &&