Просмотр исходного кода

LibWeb: Convert CSS Token value to new FlyString

Sam Atkins 2 лет назад
Родитель
Сommit
7fc72d3838

+ 1 - 1
Userland/Libraries/LibWeb/CSS/Parser/Token.cpp

@@ -42,7 +42,7 @@ DeprecatedString Token::to_deprecated_string() const
     case Type::BadUrl:
         return "url()";
     case Type::Delim:
-        return m_value;
+        return DeprecatedString(m_value.bytes_as_string_view());
     case Type::Number:
         return DeprecatedString::number(m_number_value.value());
     case Type::Percentage:

+ 11 - 11
Userland/Libraries/LibWeb/CSS/Parser/Token.h

@@ -7,8 +7,8 @@
 
 #pragma once
 
-#include <AK/DeprecatedFlyString.h>
 #include <AK/DeprecatedString.h>
+#include <AK/FlyString.h>
 #include <AK/Utf8View.h>
 #include <LibWeb/CSS/Number.h>
 
@@ -63,37 +63,37 @@ public:
     StringView ident() const
     {
         VERIFY(m_type == Type::Ident);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     StringView function() const
     {
         VERIFY(m_type == Type::Function);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     u32 delim() const
     {
         VERIFY(m_type == Type::Delim);
-        return *Utf8View(m_value.view()).begin();
+        return *Utf8View(m_value.bytes_as_string_view()).begin();
     }
 
     StringView string() const
     {
         VERIFY(m_type == Type::String);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     StringView url() const
     {
         VERIFY(m_type == Type::Url);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     StringView at_keyword() const
     {
         VERIFY(m_type == Type::AtKeyword);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     HashType hash_type() const
@@ -104,7 +104,7 @@ public:
     StringView hash_value() const
     {
         VERIFY(m_type == Type::Hash);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
 
     Number const& number() const
@@ -126,7 +126,7 @@ public:
     StringView dimension_unit() const
     {
         VERIFY(m_type == Type::Dimension);
-        return m_value.view();
+        return m_value.bytes_as_string_view();
     }
     float dimension_value() const
     {
@@ -151,7 +151,7 @@ public:
     Position const& start_position() const { return m_start_position; }
     Position const& end_position() const { return m_end_position; }
 
-    static Token of_string(DeprecatedFlyString str)
+    static Token of_string(FlyString str)
     {
         Token token;
         token.m_type = Type::String;
@@ -178,7 +178,7 @@ public:
 private:
     Type m_type { Type::Invalid };
 
-    DeprecatedFlyString m_value;
+    FlyString m_value;
     Number m_number_value;
     HashType m_hash_type { HashType::Unrestricted };
 

+ 7 - 10
Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2020-2022, the SerenityOS developers.
- * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -356,7 +356,7 @@ Token Tokenizer::create_value_token(Token::Type type, DeprecatedString value)
 {
     Token token;
     token.m_type = type;
-    token.m_value = move(value);
+    token.m_value = FlyString::from_utf8(value.view()).release_value_but_fixme_should_propagate_errors();
     return token;
 }
 
@@ -364,10 +364,7 @@ Token Tokenizer::create_value_token(Token::Type type, u32 value)
 {
     Token token = {};
     token.m_type = type;
-    // FIXME: Avoid temporary StringBuilder here
-    StringBuilder builder;
-    builder.append_code_point(value);
-    token.m_value = builder.to_deprecated_string();
+    token.m_value = FlyString(String::from_code_point(value));
     return token;
 }
 
@@ -640,7 +637,7 @@ Token Tokenizer::consume_a_url_token()
     consume_as_much_whitespace_as_possible();
 
     auto make_token = [&]() {
-        token.m_value = builder.to_deprecated_string();
+        token.m_value = FlyString::from_utf8(builder.string_view()).release_value_but_fixme_should_propagate_errors();
         return token;
     };
 
@@ -784,7 +781,7 @@ Token Tokenizer::consume_a_numeric_token()
         auto unit = consume_an_ident_sequence();
         VERIFY(!unit.is_empty());
         // NOTE: We intentionally store this in the `value`, to save space.
-        token.m_value = move(unit);
+        token.m_value = FlyString::from_utf8(unit.view()).release_value_but_fixme_should_propagate_errors();
 
         // 3. Return the <dimension-token>.
         return token;
@@ -931,7 +928,7 @@ Token Tokenizer::consume_string_token(u32 ending_code_point)
     StringBuilder builder;
 
     auto make_token = [&]() {
-        token.m_value = builder.to_deprecated_string();
+        token.m_value = FlyString::from_utf8(builder.string_view()).release_value_but_fixme_should_propagate_errors();
         return token;
     };
 
@@ -1069,7 +1066,7 @@ Token Tokenizer::consume_a_token()
 
             // 3. Consume an ident sequence, and set the <hash-token>’s value to the returned string.
             auto name = consume_an_ident_sequence();
-            token.m_value = move(name);
+            token.m_value = FlyString::from_utf8(name.view()).release_value_but_fixme_should_propagate_errors();
 
             // 4. Return the <hash-token>.
             return token;

+ 1 - 1
Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -703,7 +703,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
                 // 1. If the attr() function has a substitution value, replace the attr() function by the substitution value.
                 if (!attr_value.is_null()) {
                     // FIXME: attr() should also accept an optional type argument, not just strings.
-                    dest.empend(Parser::Token::of_string(attr_value));
+                    dest.empend(Parser::Token::of_string(FlyString::from_utf8(attr_value).release_value_but_fixme_should_propagate_errors()));
                     continue;
                 }