Commit cdd2d4cc authored by Max Kellermann's avatar Max Kellermann

util/StringView: add method EndsWith()

parent 3bcabad2
/* /*
* 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
...@@ -93,6 +93,13 @@ struct StringView : ConstBuffer<char> { ...@@ -93,6 +93,13 @@ struct StringView : ConstBuffer<char> {
} }
gcc_pure 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 { bool Equals(StringView other) const noexcept {
return size == other.size && return size == other.size &&
memcmp(data, other.data, size) == 0; memcmp(data, other.data, size) == 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment