Ver Fonte

LibWeb: Make serializing GridTrack classes infallible

Sam Atkins há 1 ano atrás
pai
commit
2754c16e97

+ 4 - 4
Userland/Libraries/LibWeb/CSS/GridTrackPlacement.cpp

@@ -33,25 +33,25 @@ GridTrackPlacement::GridTrackPlacement()
 {
 {
 }
 }
 
 
-ErrorOr<String> GridTrackPlacement::to_string() const
+String GridTrackPlacement::to_string() const
 {
 {
     StringBuilder builder;
     StringBuilder builder;
     if (is_auto()) {
     if (is_auto()) {
         builder.append("auto"sv);
         builder.append("auto"sv);
-        return builder.to_string();
+        return MUST(builder.to_string());
     }
     }
     if (is_span()) {
     if (is_span()) {
         builder.append("span"sv);
         builder.append("span"sv);
         builder.append(" "sv);
         builder.append(" "sv);
     }
     }
     if (m_span_count_or_position != 0) {
     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);
         builder.append(" "sv);
     }
     }
     if (has_line_name()) {
     if (has_line_name()) {
         builder.append(m_line_name);
         builder.append(m_line_name);
     }
     }
-    return builder.to_string();
+    return MUST(builder.to_string());
 }
 }
 
 
 }
 }

+ 1 - 1
Userland/Libraries/LibWeb/CSS/GridTrackPlacement.h

@@ -36,7 +36,7 @@ public:
     Type type() const { return m_type; }
     Type type() const { return m_type; }
     String line_name() const { return m_line_name; }
     String line_name() const { return m_line_name; }
 
 
-    ErrorOr<String> to_string() const;
+    String to_string() const;
     bool operator==(GridTrackPlacement const& other) const
     bool operator==(GridTrackPlacement const& other) const
     {
     {
         return m_type == other.type() && m_span_count_or_position == other.raw_value();
         return m_type == other.type() && m_span_count_or_position == other.raw_value();

+ 13 - 13
Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp

@@ -81,13 +81,13 @@ Size GridSize::css_size() const
     return CSS::Size::make_percentage(m_length_percentage.percentage());
     return CSS::Size::make_percentage(m_length_percentage.percentage());
 }
 }
 
 
-ErrorOr<String> GridSize::to_string() const
+String GridSize::to_string() const
 {
 {
     switch (m_type) {
     switch (m_type) {
     case Type::LengthPercentage:
     case Type::LengthPercentage:
         return m_length_percentage.to_string();
         return m_length_percentage.to_string();
     case Type::FlexibleLength:
     case Type::FlexibleLength:
-        return String::formatted("{}fr", m_flex_factor);
+        return MUST(String::formatted("{}fr", m_flex_factor));
     case Type::MaxContent:
     case Type::MaxContent:
         return "max-content"_string;
         return "max-content"_string;
     case Type::MinContent:
     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;
     StringBuilder builder;
     builder.append("minmax("sv);
     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.append(", "sv);
-    builder.appendff("{}", TRY(m_max_grid_size.to_string()));
+    builder.appendff("{}", m_max_grid_size.to_string());
     builder.append(")"sv);
     builder.append(")"sv);
-    return builder.to_string();
+    return MUST(builder.to_string());
 }
 }
 
 
 GridRepeat::GridRepeat(GridTrackSizeList grid_track_size_list, int repeat_count)
 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;
     StringBuilder builder;
     builder.append("repeat("sv);
     builder.append("repeat("sv);
@@ -148,9 +148,9 @@ ErrorOr<String> GridRepeat::to_string() const
         VERIFY_NOT_REACHED();
         VERIFY_NOT_REACHED();
     }
     }
     builder.append(", "sv);
     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);
     builder.append(")"sv);
-    return builder.to_string();
+    return MUST(builder.to_string());
 }
 }
 
 
 ExplicitGridTrack::ExplicitGridTrack(CSS::GridMinMax grid_minmax)
 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) {
     switch (m_type) {
     case Type::MinMax:
     case Type::MinMax:
@@ -202,7 +202,7 @@ GridTrackSizeList GridTrackSizeList::make_none()
     return GridTrackSizeList();
     return GridTrackSizeList();
 }
 }
 
 
-ErrorOr<String> GridTrackSizeList::to_string() const
+String GridTrackSizeList::to_string() const
 {
 {
     StringBuilder builder;
     StringBuilder builder;
     auto print_line_names = [&](size_t index) -> void {
     auto print_line_names = [&](size_t index) -> void {
@@ -220,7 +220,7 @@ ErrorOr<String> GridTrackSizeList::to_string() const
             print_line_names(i);
             print_line_names(i);
             builder.append(" "sv);
             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)
         if (i < m_track_list.size() - 1)
             builder.append(" "sv);
             builder.append(" "sv);
     }
     }
@@ -228,7 +228,7 @@ ErrorOr<String> GridTrackSizeList::to_string() const
         builder.append(" "sv);
         builder.append(" "sv);
         print_line_names(m_track_list.size());
         print_line_names(m_track_list.size());
     }
     }
-    return builder.to_string();
+    return MUST(builder.to_string());
 }
 }
 
 
 }
 }

+ 5 - 5
Userland/Libraries/LibWeb/CSS/GridTrackSize.h

@@ -52,7 +52,7 @@ public:
 
 
     Size css_size() const;
     Size css_size() const;
 
 
-    ErrorOr<String> to_string() const;
+    String to_string() const;
     bool operator==(GridSize const& other) const
     bool operator==(GridSize const& other) const
     {
     {
         return m_type == other.type()
         return m_type == other.type()
@@ -74,7 +74,7 @@ public:
     GridSize min_grid_size() const& { return m_min_grid_size; }
     GridSize min_grid_size() const& { return m_min_grid_size; }
     GridSize max_grid_size() const& { return m_max_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
     bool operator==(GridMinMax const& other) const
     {
     {
         return m_min_grid_size == other.min_grid_size()
         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<CSS::ExplicitGridTrack> track_list() const { return m_track_list; }
     Vector<Vector<String>> line_names() const { return m_line_names; }
     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
     bool operator==(GridTrackSizeList const& other) const
     {
     {
         return m_line_names == other.line_names() && m_track_list == other.track_list();
         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; }
     GridTrackSizeList grid_track_size_list() const& { return m_grid_track_size_list; }
     Type type() const& { return m_type; }
     Type type() const& { return m_type; }
 
 
-    ErrorOr<String> to_string() const;
+    String to_string() const;
     bool operator==(GridRepeat const& other) const
     bool operator==(GridRepeat const& other) const
     {
     {
         if (m_type != other.type())
         if (m_type != other.type())
@@ -179,7 +179,7 @@ public:
 
 
     Type type() const { return m_type; }
     Type type() const { return m_type; }
 
 
-    ErrorOr<String> to_string() const;
+    String to_string() const;
     bool operator==(ExplicitGridTrack const& other) const
     bool operator==(ExplicitGridTrack const& other) const
     {
     {
         if (is_repeat() && other.is_repeat())
         if (is_repeat() && other.is_repeat())

+ 4 - 4
Userland/Libraries/LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.cpp

@@ -34,13 +34,13 @@ ErrorOr<String> GridAreaShorthandStyleValue::to_string() const
 {
 {
     StringBuilder builder;
     StringBuilder builder;
     if (!m_properties.row_start->as_grid_track_placement().grid_track_placement().is_auto())
     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())
     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())
     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())
     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();
     return builder.to_string();
 }
 }
 
 

+ 2 - 2
Userland/Libraries/LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.cpp

@@ -27,8 +27,8 @@ ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> GridTrackPlac
 ErrorOr<String> GridTrackPlacementShorthandStyleValue::to_string() const
 ErrorOr<String> GridTrackPlacementShorthandStyleValue::to_string() const
 {
 {
     if (m_properties.end->grid_track_placement().is_auto())
     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());
 }
 }
 
 
 }
 }

+ 2 - 2
Userland/Libraries/LibWeb/CSS/StyleValues/GridTrackSizeListShorthandStyleValue.cpp

@@ -32,7 +32,7 @@ ErrorOr<String> GridTrackSizeListShorthandStyleValue::to_string() const
                 }
                 }
                 TRY(builder.try_append("\" "sv));
                 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)
             if (idx < m_properties.rows->grid_track_size_list().track_list().size() - 1)
                 TRY(builder.try_append(' '));
                 TRY(builder.try_append(' '));
             idx++;
             idx++;
@@ -42,7 +42,7 @@ ErrorOr<String> GridTrackSizeListShorthandStyleValue::to_string() const
 
 
     if (m_properties.columns->grid_track_size_list().track_list().size() == 0)
     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()));
-    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());
 }
 }
 
 
 }
 }