1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

Everywhere: Avoid calling from_utf8 on FlyString or String

We already have a String :^)
This commit is contained in:
Shannon Booth 2023-12-09 09:24:41 +13:00 committed by Andreas Kling
parent 55ec1cbfb5
commit 6ce0d588ee
6 changed files with 18 additions and 30 deletions

View file

@ -256,7 +256,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_suffix(AST::ImmediateExpressi
Vector<NonnullRefPtr<AST::Node>> nodes;
for (auto& value_str : values) {
String removed = TRY(String::from_utf8(value_str));
String removed = value_str;
if (value_str.bytes_as_string_view().ends_with(suffix_str))
removed = TRY(removed.substring_from_byte_offset(0, value_str.bytes_as_string_view().length() - suffix_str.bytes_as_string_view().length()));
@ -288,7 +288,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_prefix(AST::ImmediateExpressi
Vector<NonnullRefPtr<AST::Node>> nodes;
for (auto& value_str : values) {
String removed = TRY(String::from_utf8(value_str));
String removed = value_str;
if (value_str.bytes_as_string_view().starts_with(prefix_str))
removed = TRY(removed.substring_from_byte_offset(prefix_str.bytes_as_string_view().length()));

View file

@ -213,7 +213,7 @@ void Parser::handle_heredoc_contents()
return make_ref_counted<AST::StringLiteral>(
token.position.value_or(empty_position()),
TRY(String::from_utf8(token.value)),
token.value,
AST::StringLiteral::EnclosureType::None);
}();
@ -929,7 +929,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_function_definition()
return make_ref_counted<AST::FunctionDeclaration>(
name.position.value_or(empty_position()).with_end(peek().position.value_or(empty_position())),
AST::NameWithPosition { TRY(String::from_utf8(name.value)), name.position.value_or(empty_position()) },
AST::NameWithPosition { name.value, name.position.value_or(empty_position()) },
Vector<AST::NameWithPosition> {},
body.release_nonnull());
}
@ -1603,7 +1603,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
token.position.value_or(empty_position()),
make_ref_counted<AST::StringLiteral>(
token.position.value_or(empty_position()),
TRY(String::from_utf8(x.source_expression)),
x.source_expression,
AST::StringLiteral::EnclosureType::DoubleQuotes)),
},
Optional<AST::Position> {});