mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 21:37:58 +03:00
LibJS: Add a convenience StringView accessor to PrimitiveString
This commit is contained in:
parent
0a1874c203
commit
4235c59397
Notes:
sideshowbarker
2024-07-17 02:21:14 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/4235c59397 Pull-request: https://github.com/SerenityOS/serenity/pull/17031 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
@ -90,6 +90,12 @@ ThrowCompletionOr<String> PrimitiveString::utf8_string() const
|
||||
return *m_utf8_string;
|
||||
}
|
||||
|
||||
ThrowCompletionOr<StringView> PrimitiveString::utf8_string_view() const
|
||||
{
|
||||
(void)TRY(utf8_string());
|
||||
return m_utf8_string->bytes_as_string_view();
|
||||
}
|
||||
|
||||
ThrowCompletionOr<DeprecatedString> PrimitiveString::deprecated_string() const
|
||||
{
|
||||
TRY(resolve_rope_if_needed());
|
||||
@ -281,11 +287,8 @@ ThrowCompletionOr<void> PrimitiveString::resolve_rope_if_needed() const
|
||||
}
|
||||
|
||||
// Get the UTF-8 representations for both strings.
|
||||
auto current_string_as_utf8_string = TRY(current->utf8_string());
|
||||
auto current_string_as_utf8 = current_string_as_utf8_string.bytes_as_string_view();
|
||||
|
||||
auto previous_string_as_utf8_string = TRY(previous->utf8_string());
|
||||
auto previous_string_as_utf8 = previous_string_as_utf8_string.bytes_as_string_view();
|
||||
auto current_string_as_utf8 = TRY(current->utf8_string_view());
|
||||
auto previous_string_as_utf8 = TRY(previous->utf8_string_view());
|
||||
|
||||
// NOTE: Now we need to look at the end of the previous string and the start
|
||||
// of the current string, to see if they should be combined into a surrogate.
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
u32 hash() const;
|
||||
|
||||
ThrowCompletionOr<String> utf8_string() const;
|
||||
ThrowCompletionOr<StringView> utf8_string_view() const;
|
||||
bool has_utf8_string() const { return m_utf8_string.has_value(); }
|
||||
|
||||
ThrowCompletionOr<DeprecatedString> deprecated_string() const;
|
||||
|
Loading…
Reference in New Issue
Block a user