summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-03-03 09:27:50 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-03 11:02:21 +0000
commit45dc3d8a3e76cb53c4c3d0b81e4f7bffe1acd201 (patch)
tree5b2a33c8a10b9d8e539bd4c478fc75e348b2f7a2 /AK
parentbfdbb4b6ed57d829960b8ff1ba366375e070b99d (diff)
downloadserenity-45dc3d8a3e76cb53c4c3d0b81e4f7bffe1acd201.zip
AK: Add String::ends_with{,_bytes}()
Diffstat (limited to 'AK')
-rw-r--r--AK/String.cpp14
-rw-r--r--AK/String.h3
2 files changed, 15 insertions, 2 deletions
diff --git a/AK/String.cpp b/AK/String.cpp
index 333a92d067..f5b3f69eaf 100644
--- a/AK/String.cpp
+++ b/AK/String.cpp
@@ -491,14 +491,24 @@ bool String::contains(char needle, CaseSensitivity case_sensitivity) const
return contains(StringView { &needle, 1 }, case_sensitivity);
}
+bool String::starts_with(u32 code_point) const
+{
+ return bytes_as_string_view().starts_with(code_point);
+}
+
bool String::starts_with_bytes(StringView bytes) const
{
return bytes_as_string_view().starts_with(bytes);
}
-bool String::starts_with(u32 code_point) const
+bool String::ends_with(u32 code_point) const
{
- return bytes_as_string_view().starts_with(code_point);
+ return bytes_as_string_view().ends_with(code_point);
+}
+
+bool String::ends_with_bytes(StringView bytes) const
+{
+ return bytes_as_string_view().ends_with(bytes);
}
bool String::is_short_string() const
diff --git a/AK/String.h b/AK/String.h
index 9b46a08d62..45ac7a99fc 100644
--- a/AK/String.h
+++ b/AK/String.h
@@ -112,6 +112,9 @@ public:
bool starts_with(u32 code_point) const;
bool starts_with_bytes(StringView) const;
+ bool ends_with(u32 code_point) const;
+ bool ends_with_bytes(StringView) const;
+
// Creates a substring with a deep copy of the specified data window.
ErrorOr<String> substring_from_byte_offset(size_t start, size_t byte_count) const;
ErrorOr<String> substring_from_byte_offset(size_t start) const;