summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-22 12:32:40 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-22 15:47:36 +0100
commitcbe2eaebaba51e4cdb57193a6e702ae84ba4ca7e (patch)
treec0beded9efaffaf9422097da47431d5766a0d628 /Userland/Libraries/LibWeb
parent13e1232d798ae977da8c1077e9aeb07cf87283f8 (diff)
downloadserenity-cbe2eaebaba51e4cdb57193a6e702ae84ba4ca7e.zip
LibWeb: Tidy up CSS::Token::to_debug_string()
The ifs below the switch no longer functioned, so let's move everything into the switch cases. This also means we can replace the StringBuilder usage with String::formatted().
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Token.cpp131
1 files changed, 27 insertions, 104 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp
index 0a1ee2f410..ff0704a9a5 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2021, the SerenityOS developers.
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -80,140 +81,62 @@ String Token::to_string() const
String Token::to_debug_string() const
{
- StringBuilder builder;
-
switch (m_type) {
case Type::Invalid:
VERIFY_NOT_REACHED();
case Type::EndOfFile:
- builder.append("__EOF__");
- break;
+ return "__EOF__";
case Type::Ident:
- builder.append("Identifier: ");
- builder.append(m_value);
- return builder.to_string();
+ return String::formatted("Ident: {}", ident());
case Type::Function:
- builder.append("Function");
- break;
+ return String::formatted("Function: {}", function());
case Type::AtKeyword:
- builder.append("@");
- break;
+ return String::formatted("AtKeyword: {}", at_keyword());
case Type::Hash:
- builder.append("Hash: ");
- builder.append(m_value);
- return builder.to_string();
+ return String::formatted("Hash: {} (hash_type: {})", hash_value(), m_hash_type == HashType::Unrestricted ? "Unrestricted" : "Id");
case Type::String:
- builder.append("String: ");
- builder.append(m_value);
- return builder.to_string();
+ return String::formatted("String: {}", string());
case Type::BadString:
- builder.append("Invalid String");
- break;
+ return "BadString";
case Type::Url:
- builder.append("Url");
- break;
+ return String::formatted("Url: {}", url());
case Type::BadUrl:
- builder.append("Invalid Url");
- break;
+ return "BadUrl";
case Type::Delim:
- builder.append("Delimiter: ");
- builder.append(m_value);
- return builder.to_string();
+ return String::formatted("Delim: {}", m_value);
case Type::Number:
- builder.append("Number: ");
- builder.append(m_number_value.value());
- builder.append(m_number_value.is_integer() ? " (int)" : " (float)");
- return builder.to_string();
+ return String::formatted("Number: {} (number_type: {})", m_number_value.value(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Percentage:
- builder.append("Percentage: ");
- builder.append(m_value);
- builder.append('%');
- return builder.to_string();
+ return String::formatted("Percentage: {}% (number_type: {})", percentage(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Dimension:
- builder.append("Dimension: ");
- builder.append(dimension_value());
- builder.append(dimension_unit());
- return builder.to_string();
+ return String::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Whitespace:
- builder.append("Whitespace");
- break;
+ return "Whitespace";
case Type::CDO:
- builder.append("CDO");
- break;
+ return "CDO";
case Type::CDC:
- builder.append("CDC");
- break;
+ return "CDC";
case Type::Colon:
- builder.append(":");
- break;
+ return "Colon";
case Type::Semicolon:
- builder.append(";");
- break;
+ return "Semicolon";
case Type::Comma:
- builder.append(",");
- break;
+ return "Comma";
case Type::OpenSquare:
- builder.append("[");
- break;
+ return "OpenSquare";
case Type::CloseSquare:
- builder.append("]");
- break;
+ return "CloseSquare";
case Type::OpenParen:
- builder.append("(");
- break;
+ return "OpenParen";
case Type::CloseParen:
- builder.append(")");
- break;
+ return "CloseParen";
case Type::OpenCurly:
- builder.append("{");
- break;
+ return "OpenCurly";
case Type::CloseCurly:
- builder.append("}");
- break;
- }
-
- if (m_value.is_empty()) {
- return builder.to_string();
- }
-
- builder.append(" ");
-
- builder.append(" { value: '");
- builder.append(m_value);
-
- if (m_type == Token::Type::Hash) {
- builder.append("', hash_type: '");
- if (m_hash_type == Token::HashType::Unrestricted) {
- builder.append("Unrestricted");
- } else {
- builder.append("Id");
- }
+ return "CloseCurly";
}
-
- if (m_type == Token::Type::Number) {
- builder.append("', number_type: '");
- if (m_number_value.is_integer()) {
- builder.append("Integer");
- } else {
- builder.append("Number");
- }
- }
-
- if (m_type == Token::Type::Dimension) {
- builder.append("', number_type: '");
- if (m_number_value.is_integer()) {
- builder.append("Integer");
- } else {
- builder.append("Number");
- }
-
- builder.append("', unit: '");
- builder.append(dimension_unit());
- }
-
- builder.append("' }");
- return builder.to_string();
+ VERIFY_NOT_REACHED();
}
Token::Type Token::mirror_variant() const