mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Everywhere: Avoid calling from_utf8 on FlyString or String
We already have a String :^)
This commit is contained in:
parent
55ec1cbfb5
commit
6ce0d588ee
Notes:
sideshowbarker
2024-07-16 22:34:39 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/6ce0d588ee Pull-request: https://github.com/SerenityOS/serenity/pull/22231
6 changed files with 18 additions and 30 deletions
|
@ -2283,7 +2283,7 @@ RefPtr<StyleValue> Parser::parse_ratio_value(TokenStream<ComponentValue>& tokens
|
|||
RefPtr<StyleValue> Parser::parse_string_value(ComponentValue const& component_value)
|
||||
{
|
||||
if (component_value.is(Token::Type::String))
|
||||
return StringStyleValue::create(MUST(String::from_utf8(component_value.token().string())));
|
||||
return StringStyleValue::create(component_value.token().string().to_string());
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -4099,7 +4099,7 @@ RefPtr<StyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>&
|
|||
(void)tokens.next_token(); // String
|
||||
if (!next_is_comma_or_eof())
|
||||
return nullptr;
|
||||
font_families.append(StringStyleValue::create(MUST(String::from_utf8(peek.token().string()))));
|
||||
font_families.append(StringStyleValue::create(peek.token().string().to_string()));
|
||||
(void)tokens.next_token(); // Comma
|
||||
continue;
|
||||
}
|
||||
|
@ -5178,10 +5178,7 @@ Optional<CSS::GridRepeat> Parser::parse_repeat(Vector<ComponentValue> const& com
|
|||
TokenStream block_tokens { token.block().values() };
|
||||
while (block_tokens.has_next_token()) {
|
||||
auto current_block_token = block_tokens.next_token();
|
||||
auto maybe_string = String::from_utf8(current_block_token.token().ident());
|
||||
if (maybe_string.is_error())
|
||||
return {};
|
||||
line_names.append(maybe_string.value());
|
||||
line_names.append(current_block_token.token().ident().to_string());
|
||||
block_tokens.skip_whitespace();
|
||||
}
|
||||
line_names_list.append(line_names);
|
||||
|
@ -5289,10 +5286,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_size_list(Vector<ComponentValue> con
|
|||
block_tokens.skip_whitespace();
|
||||
while (block_tokens.has_next_token()) {
|
||||
auto current_block_token = block_tokens.next_token();
|
||||
auto maybe_string = String::from_utf8(current_block_token.token().ident());
|
||||
if (maybe_string.is_error())
|
||||
return nullptr;
|
||||
line_names.append(maybe_string.value());
|
||||
line_names.append(current_block_token.token().ident().to_string());
|
||||
block_tokens.skip_whitespace();
|
||||
}
|
||||
line_names_list.append(line_names);
|
||||
|
@ -5415,11 +5409,8 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
|||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_span(1));
|
||||
if (is_valid_integer(current_token))
|
||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line(static_cast<int>(current_token.token().number_value()), {}));
|
||||
if (is_identifier(current_token)) {
|
||||
auto maybe_string = String::from_utf8(current_token.token().ident());
|
||||
if (!maybe_string.is_error())
|
||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line({}, maybe_string.value()));
|
||||
}
|
||||
if (is_identifier(current_token))
|
||||
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_line({}, current_token.token().to_string()));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -5443,10 +5434,7 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
|
|||
}
|
||||
if (is_identifier(current_token)) {
|
||||
if (identifier_value.is_empty()) {
|
||||
auto maybe_string = String::from_utf8(current_token.token().ident());
|
||||
if (maybe_string.is_error())
|
||||
return nullptr;
|
||||
identifier_value = maybe_string.release_value();
|
||||
identifier_value = current_token.token().ident().to_string();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -5666,7 +5654,7 @@ RefPtr<StyleValue> Parser::parse_grid_template_areas_value(TokenStream<Component
|
|||
auto transaction = tokens.begin_transaction();
|
||||
while (tokens.has_next_token() && tokens.peek_token().is(Token::Type::String)) {
|
||||
Vector<String> grid_area_columns;
|
||||
auto const parts = MUST(MUST(String::from_utf8(tokens.next_token().token().string())).split(' '));
|
||||
auto const parts = MUST(tokens.next_token().token().string().to_string().split(' '));
|
||||
for (auto& part : parts) {
|
||||
grid_area_columns.append(part);
|
||||
}
|
||||
|
@ -6147,7 +6135,7 @@ Optional<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readon
|
|||
|
||||
if (peek_token.is(Token::Type::String)) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::String); property.has_value())
|
||||
return PropertyAndValue { *property, StringStyleValue::create(MUST(String::from_utf8(tokens.next_token().token().string()))) };
|
||||
return PropertyAndValue { *property, StringStyleValue::create(tokens.next_token().token().string().to_string()) };
|
||||
}
|
||||
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Url); property.has_value()) {
|
||||
|
|
|
@ -295,8 +295,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_attribute_simple_se
|
|||
dbgln_if(CSS_PARSER_DEBUG, "Expected a string or ident for the value to match attribute against, got: '{}'", value_part.to_debug_string());
|
||||
return ParseError::SyntaxError;
|
||||
}
|
||||
auto value_string_view = value_part.token().is(Token::Type::Ident) ? value_part.token().ident() : value_part.token().string();
|
||||
simple_selector.attribute().value = String::from_utf8(value_string_view).release_value_but_fixme_should_propagate_errors();
|
||||
auto const& value_string = value_part.token().is(Token::Type::Ident) ? value_part.token().ident() : value_part.token().string();
|
||||
simple_selector.attribute().value = value_string.to_string();
|
||||
|
||||
attribute_tokens.skip_whitespace();
|
||||
// Handle case-sensitivity suffixes. https://www.w3.org/TR/selectors-4/#attribute-case
|
||||
|
|
|
@ -343,7 +343,7 @@ void WindowOrWorkerGlobalScopeMixin::queue_performance_entry(JS::NonnullGCPtr<Pe
|
|||
// or whose type member equals to entryType:
|
||||
auto iterator = registered_observer->options_list().find_if([&entry_type](PerformanceTimeline::PerformanceObserverInit const& entry) {
|
||||
if (entry.entry_types.has_value())
|
||||
return entry.entry_types->contains_slow(String::from_utf8(entry_type).release_value_but_fixme_should_propagate_errors());
|
||||
return entry.entry_types->contains_slow(entry_type.to_string());
|
||||
|
||||
VERIFY(entry.type.has_value());
|
||||
return entry.type.value() == entry_type;
|
||||
|
|
|
@ -131,7 +131,7 @@ ErrorOr<void> DeviceEventLoop::register_new_device(DeviceNodeFamily::Type unix_d
|
|||
}
|
||||
auto allocated_suffix_index = possible_allocated_suffix_index.release_value();
|
||||
|
||||
auto path = TRY(String::from_utf8(path_pattern));
|
||||
auto path = path_pattern;
|
||||
if (match.path_pattern.contains("%digit"sv)) {
|
||||
auto replacement = TRY(build_suffix_with_numbers(allocated_suffix_index));
|
||||
path = TRY(path.replace("%digit"sv, replacement, ReplaceMode::All));
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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> {});
|
||||
|
|
Loading…
Add table
Reference in a new issue