Skip to content

Commit cdd2d4c

Browse files
committed
util/StringView: add method EndsWith()
1 parent 3bcabad commit cdd2d4c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/util/StringView.hxx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013-2015 Max Kellermann <max.kellermann@gmail.com>
2+
* Copyright (C) 2013-2017 Max Kellermann <max.kellermann@gmail.com>
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -92,6 +92,13 @@ struct StringView : ConstBuffer<char> {
9292
memcmp(data, needle.data, needle.size) == 0;
9393
}
9494

95+
gcc_pure
96+
bool EndsWith(StringView needle) const noexcept {
97+
return size >= needle.size &&
98+
memcmp(data + size - needle.size,
99+
needle.data, needle.size) == 0;
100+
}
101+
95102
gcc_pure
96103
bool Equals(StringView other) const noexcept {
97104
return size == other.size &&

0 commit comments

Comments
 (0)