mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:27:35 +00:00
LibJS: Add a convenience StringView accessor to PrimitiveString
This commit is contained in:
parent
0a1874c203
commit
4235c59397
2 changed files with 9 additions and 5 deletions
|
@ -90,6 +90,12 @@ ThrowCompletionOr<String> PrimitiveString::utf8_string() const
|
||||||
return *m_utf8_string;
|
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
|
ThrowCompletionOr<DeprecatedString> PrimitiveString::deprecated_string() const
|
||||||
{
|
{
|
||||||
TRY(resolve_rope_if_needed());
|
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.
|
// Get the UTF-8 representations for both strings.
|
||||||
auto current_string_as_utf8_string = TRY(current->utf8_string());
|
auto current_string_as_utf8 = TRY(current->utf8_string_view());
|
||||||
auto current_string_as_utf8 = current_string_as_utf8_string.bytes_as_string_view();
|
auto previous_string_as_utf8 = TRY(previous->utf8_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();
|
|
||||||
|
|
||||||
// NOTE: Now we need to look at the end of the previous string and the start
|
// 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.
|
// of the current string, to see if they should be combined into a surrogate.
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
u32 hash() const;
|
u32 hash() const;
|
||||||
|
|
||||||
ThrowCompletionOr<String> utf8_string() const;
|
ThrowCompletionOr<String> utf8_string() const;
|
||||||
|
ThrowCompletionOr<StringView> utf8_string_view() const;
|
||||||
bool has_utf8_string() const { return m_utf8_string.has_value(); }
|
bool has_utf8_string() const { return m_utf8_string.has_value(); }
|
||||||
|
|
||||||
ThrowCompletionOr<DeprecatedString> deprecated_string() const;
|
ThrowCompletionOr<DeprecatedString> deprecated_string() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue