mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:57:44 +00:00
LibWeb: Make serializing GridTrack classes infallible
This commit is contained in:
parent
6bee81cfb6
commit
2754c16e97
7 changed files with 31 additions and 31 deletions
|
@ -33,25 +33,25 @@ GridTrackPlacement::GridTrackPlacement()
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<String> GridTrackPlacement::to_string() const
|
||||
String GridTrackPlacement::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
if (is_auto()) {
|
||||
builder.append("auto"sv);
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
if (is_span()) {
|
||||
builder.append("span"sv);
|
||||
builder.append(" "sv);
|
||||
}
|
||||
if (m_span_count_or_position != 0) {
|
||||
builder.append(TRY(String::number(m_span_count_or_position)));
|
||||
builder.append(MUST(String::number(m_span_count_or_position)));
|
||||
builder.append(" "sv);
|
||||
}
|
||||
if (has_line_name()) {
|
||||
builder.append(m_line_name);
|
||||
}
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
Type type() const { return m_type; }
|
||||
String line_name() const { return m_line_name; }
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(GridTrackPlacement const& other) const
|
||||
{
|
||||
return m_type == other.type() && m_span_count_or_position == other.raw_value();
|
||||
|
|
|
@ -81,13 +81,13 @@ Size GridSize::css_size() const
|
|||
return CSS::Size::make_percentage(m_length_percentage.percentage());
|
||||
}
|
||||
|
||||
ErrorOr<String> GridSize::to_string() const
|
||||
String GridSize::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::LengthPercentage:
|
||||
return m_length_percentage.to_string();
|
||||
case Type::FlexibleLength:
|
||||
return String::formatted("{}fr", m_flex_factor);
|
||||
return MUST(String::formatted("{}fr", m_flex_factor));
|
||||
case Type::MaxContent:
|
||||
return "max-content"_string;
|
||||
case Type::MinContent:
|
||||
|
@ -102,15 +102,15 @@ GridMinMax::GridMinMax(GridSize min_grid_size, GridSize max_grid_size)
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<String> GridMinMax::to_string() const
|
||||
String GridMinMax::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("minmax("sv);
|
||||
builder.appendff("{}", TRY(m_min_grid_size.to_string()));
|
||||
builder.appendff("{}", m_min_grid_size.to_string());
|
||||
builder.append(", "sv);
|
||||
builder.appendff("{}", TRY(m_max_grid_size.to_string()));
|
||||
builder.appendff("{}", m_max_grid_size.to_string());
|
||||
builder.append(")"sv);
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
GridRepeat::GridRepeat(GridTrackSizeList grid_track_size_list, int repeat_count)
|
||||
|
@ -130,7 +130,7 @@ GridRepeat::GridRepeat()
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<String> GridRepeat::to_string() const
|
||||
String GridRepeat::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("repeat("sv);
|
||||
|
@ -148,9 +148,9 @@ ErrorOr<String> GridRepeat::to_string() const
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
builder.append(", "sv);
|
||||
builder.appendff("{}", TRY(m_grid_track_size_list.to_string()));
|
||||
builder.appendff("{}", m_grid_track_size_list.to_string());
|
||||
builder.append(")"sv);
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(CSS::GridMinMax grid_minmax)
|
||||
|
@ -171,7 +171,7 @@ ExplicitGridTrack::ExplicitGridTrack(CSS::GridSize grid_size)
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<String> ExplicitGridTrack::to_string() const
|
||||
String ExplicitGridTrack::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::MinMax:
|
||||
|
@ -202,7 +202,7 @@ GridTrackSizeList GridTrackSizeList::make_none()
|
|||
return GridTrackSizeList();
|
||||
}
|
||||
|
||||
ErrorOr<String> GridTrackSizeList::to_string() const
|
||||
String GridTrackSizeList::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
auto print_line_names = [&](size_t index) -> void {
|
||||
|
@ -220,7 +220,7 @@ ErrorOr<String> GridTrackSizeList::to_string() const
|
|||
print_line_names(i);
|
||||
builder.append(" "sv);
|
||||
}
|
||||
builder.append(TRY(m_track_list[i].to_string()));
|
||||
builder.append(m_track_list[i].to_string());
|
||||
if (i < m_track_list.size() - 1)
|
||||
builder.append(" "sv);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ ErrorOr<String> GridTrackSizeList::to_string() const
|
|||
builder.append(" "sv);
|
||||
print_line_names(m_track_list.size());
|
||||
}
|
||||
return builder.to_string();
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
Size css_size() const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(GridSize const& other) const
|
||||
{
|
||||
return m_type == other.type()
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
GridSize min_grid_size() const& { return m_min_grid_size; }
|
||||
GridSize max_grid_size() const& { return m_max_grid_size; }
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(GridMinMax const& other) const
|
||||
{
|
||||
return m_min_grid_size == other.min_grid_size()
|
||||
|
@ -96,7 +96,7 @@ public:
|
|||
Vector<CSS::ExplicitGridTrack> track_list() const { return m_track_list; }
|
||||
Vector<Vector<String>> line_names() const { return m_line_names; }
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(GridTrackSizeList const& other) const
|
||||
{
|
||||
return m_line_names == other.line_names() && m_track_list == other.track_list();
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
GridTrackSizeList grid_track_size_list() const& { return m_grid_track_size_list; }
|
||||
Type type() const& { return m_type; }
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(GridRepeat const& other) const
|
||||
{
|
||||
if (m_type != other.type())
|
||||
|
@ -179,7 +179,7 @@ public:
|
|||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
String to_string() const;
|
||||
bool operator==(ExplicitGridTrack const& other) const
|
||||
{
|
||||
if (is_repeat() && other.is_repeat())
|
||||
|
|
|
@ -34,13 +34,13 @@ ErrorOr<String> GridAreaShorthandStyleValue::to_string() const
|
|||
{
|
||||
StringBuilder builder;
|
||||
if (!m_properties.row_start->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
TRY(builder.try_appendff("{}", TRY(m_properties.row_start->as_grid_track_placement().grid_track_placement().to_string())));
|
||||
TRY(builder.try_appendff("{}", m_properties.row_start->as_grid_track_placement().grid_track_placement().to_string()));
|
||||
if (!m_properties.column_start->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_start->as_grid_track_placement().grid_track_placement().to_string())));
|
||||
TRY(builder.try_appendff(" / {}", m_properties.column_start->as_grid_track_placement().grid_track_placement().to_string()));
|
||||
if (!m_properties.row_end->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
TRY(builder.try_appendff(" / {}", TRY(m_properties.row_end->as_grid_track_placement().grid_track_placement().to_string())));
|
||||
TRY(builder.try_appendff(" / {}", m_properties.row_end->as_grid_track_placement().grid_track_placement().to_string()));
|
||||
if (!m_properties.column_end->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_end->as_grid_track_placement().grid_track_placement().to_string())));
|
||||
TRY(builder.try_appendff(" / {}", m_properties.column_end->as_grid_track_placement().grid_track_placement().to_string()));
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> GridTrackPlac
|
|||
ErrorOr<String> GridTrackPlacementShorthandStyleValue::to_string() const
|
||||
{
|
||||
if (m_properties.end->grid_track_placement().is_auto())
|
||||
return String::formatted("{}", TRY(m_properties.start->grid_track_placement().to_string()));
|
||||
return String::formatted("{} / {}", TRY(m_properties.start->grid_track_placement().to_string()), TRY(m_properties.end->grid_track_placement().to_string()));
|
||||
return String::formatted("{}", m_properties.start->grid_track_placement().to_string());
|
||||
return String::formatted("{} / {}", m_properties.start->grid_track_placement().to_string(), m_properties.end->grid_track_placement().to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ ErrorOr<String> GridTrackSizeListShorthandStyleValue::to_string() const
|
|||
}
|
||||
TRY(builder.try_append("\" "sv));
|
||||
}
|
||||
TRY(builder.try_append(TRY(row.to_string())));
|
||||
TRY(builder.try_append(row.to_string()));
|
||||
if (idx < m_properties.rows->grid_track_size_list().track_list().size() - 1)
|
||||
TRY(builder.try_append(' '));
|
||||
idx++;
|
||||
|
@ -42,7 +42,7 @@ ErrorOr<String> GridTrackSizeListShorthandStyleValue::to_string() const
|
|||
|
||||
if (m_properties.columns->grid_track_size_list().track_list().size() == 0)
|
||||
return String::formatted("{}", TRY(construct_rows_string()));
|
||||
return String::formatted("{} / {}", TRY(construct_rows_string()), TRY(m_properties.columns->grid_track_size_list().to_string()));
|
||||
return String::formatted("{} / {}", TRY(construct_rows_string()), m_properties.columns->grid_track_size_list().to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue