1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:08:10 +00:00

AK: Move String::ends_with implementation to StringUtils

Centralizing so it can be used by other string implementations
This commit is contained in:
Brian Gianforcaro 2020-05-26 02:58:34 -07:00 committed by Andreas Kling
parent d98e743568
commit 8e4b858b3f
3 changed files with 15 additions and 7 deletions

View file

@ -25,6 +25,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Memory.h>
#include <AK/String.h>
#include <AK/StringUtils.h>
#include <AK/StringView.h>
@ -195,6 +196,17 @@ bool equals_ignoring_case(const StringView& a, const StringView& b)
return true;
}
bool ends_with(const StringView& str, const StringView& end)
{
if (end.is_empty())
return true;
if (str.is_empty())
return false;
if (end.length() > str.length())
return false;
return !memcmp(str.characters_without_null_termination() + (str.length() - end.length()), end.characters_without_null_termination(), end.length());
}
}
}