mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add StringView::copy_characters_to_buffer()
This commit is contained in:
parent
3237efc661
commit
8209c2b570
Notes:
sideshowbarker
2024-07-17 14:32:23 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/8209c2b570 Pull-request: https://github.com/SerenityOS/serenity/pull/13333
2 changed files with 14 additions and 0 deletions
|
@ -182,6 +182,18 @@ StringView StringView::substring_view_starting_after_substring(StringView substr
|
||||||
return { remaining_characters, remaining_length };
|
return { remaining_characters, remaining_length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StringView::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
|
||||||
|
{
|
||||||
|
// We must fit at least the NUL-terminator.
|
||||||
|
VERIFY(buffer_size > 0);
|
||||||
|
|
||||||
|
size_t characters_to_copy = min(m_length, buffer_size - 1);
|
||||||
|
__builtin_memcpy(buffer, m_characters, characters_to_copy);
|
||||||
|
buffer[characters_to_copy] = 0;
|
||||||
|
|
||||||
|
return characters_to_copy == m_length;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<T> StringView::to_int() const
|
Optional<T> StringView::to_int() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -192,6 +192,8 @@ public:
|
||||||
[[nodiscard]] StringView substring_view_starting_from_substring(StringView substring) const;
|
[[nodiscard]] StringView substring_view_starting_from_substring(StringView substring) const;
|
||||||
[[nodiscard]] StringView substring_view_starting_after_substring(StringView substring) const;
|
[[nodiscard]] StringView substring_view_starting_after_substring(StringView substring) const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool copy_characters_to_buffer(char* buffer, size_t buffer_size) const;
|
||||||
|
|
||||||
constexpr bool operator==(char const* cstring) const
|
constexpr bool operator==(char const* cstring) const
|
||||||
{
|
{
|
||||||
if (is_null())
|
if (is_null())
|
||||||
|
|
Loading…
Reference in a new issue