diff options
author | Linus Groh <mail@linusgroh.de> | 2020-10-04 15:18:52 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-04 19:22:02 +0200 |
commit | 123f98201e2447b6628487a5a753d4bcd840d554 (patch) | |
tree | 7677a87d16a06f41becb0e46f21a647602d2bbe9 | |
parent | 2e2571743b4612cbec6fd7037375abe3f43af380 (diff) | |
download | serenity-123f98201e2447b6628487a5a753d4bcd840d554.zip |
LibJS: Use String::formatted() in various other places
-rw-r--r-- | Libraries/LibJS/AST.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/BoundFunction.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Date.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/FunctionConstructor.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/JSONObject.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Object.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/StringPrototype.cpp | 7 |
7 files changed, 23 insertions, 22 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 6a0e1ed026..7ea7dedb55 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -78,7 +78,7 @@ static void update_function_name(Value& value, const FlyString& name) static String get_function_name(GlobalObject& global_object, Value value) { if (value.is_symbol()) - return String::format("[%s]", value.as_symbol().description().characters()); + return String::formatted("[{}]", value.as_symbol().description()); if (value.is_string()) return value.as_string().string(); return value.to_string(global_object); @@ -743,9 +743,9 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob String accessor_name = [&] { switch (method.kind()) { case ClassMethod::Kind::Getter: - return String::format("get %s", get_function_name(global_object, key).characters()); + return String::formatted("get {}", get_function_name(global_object, key)); case ClassMethod::Kind::Setter: - return String::format("set %s", get_function_name(global_object, key).characters()); + return String::formatted("set {}", get_function_name(global_object, key)); default: ASSERT_NOT_REACHED(); } @@ -1538,9 +1538,9 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o String name = get_function_name(global_object, key); if (property.type() == ObjectProperty::Type::Getter) { - name = String::format("get %s", name.characters()); + name = String::formatted("get {}", name); } else if (property.type() == ObjectProperty::Type::Setter) { - name = String::format("set %s", name.characters()); + name = String::formatted("set {}", name); } update_function_name(value, name); @@ -1597,9 +1597,9 @@ String MemberExpression::to_string_approximation() const if (m_object->is_identifier()) object_string = static_cast<const Identifier&>(*m_object).string(); if (is_computed()) - return String::format("%s[<computed>]", object_string.characters()); + return String::formatted("{}[<computed>]", object_string); ASSERT(m_property->is_identifier()); - return String::format("%s.%s", object_string.characters(), static_cast<const Identifier&>(*m_property).string().characters()); + return String::formatted("{}.{}", object_string, static_cast<const Identifier&>(*m_property).string()); } Value MemberExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const diff --git a/Libraries/LibJS/Runtime/BoundFunction.cpp b/Libraries/LibJS/Runtime/BoundFunction.cpp index d29f56e5f6..6aa0cbf5ae 100644 --- a/Libraries/LibJS/Runtime/BoundFunction.cpp +++ b/Libraries/LibJS/Runtime/BoundFunction.cpp @@ -33,7 +33,7 @@ BoundFunction::BoundFunction(GlobalObject& global_object, Function& target_funct : Function::Function(*global_object.function_prototype(), bound_this, move(arguments)) , m_target_function(&target_function) , m_constructor_prototype(constructor_prototype) - , m_name(String::format("bound %s", target_function.name().characters())) + , m_name(String::formatted("bound {}", target_function.name())) , m_length(length) { } diff --git a/Libraries/LibJS/Runtime/Date.h b/Libraries/LibJS/Runtime/Date.h index c1c0d160c1..d1b08aa8de 100644 --- a/Libraries/LibJS/Runtime/Date.h +++ b/Libraries/LibJS/Runtime/Date.h @@ -68,7 +68,7 @@ public: String time_string() const { return m_datetime.to_string("%T GMT+0000 (UTC)"); } String string() const { - return String::format("%s %s", date_string().characters(), time_string().characters()); + return String::formatted("{} {}", date_string(), time_string()); } String iso_date_string() const; diff --git a/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 39c91d00b6..2368635b00 100644 --- a/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -80,7 +80,7 @@ Value FunctionConstructor::construct(Function&) if (vm.exception()) return {}; } - auto source = String::format("function anonymous(%s) { %s }", parameters_source.characters(), body_source.characters()); + auto source = String::formatted("function anonymous({}) {{ {} }}", parameters_source, body_source); auto parser = Parser(Lexer(source)); auto function_expression = parser.parse_function_node<FunctionExpression>(); if (parser.has_errors()) { diff --git a/Libraries/LibJS/Runtime/JSONObject.cpp b/Libraries/LibJS/Runtime/JSONObject.cpp index 12fbc18490..b5c8ab8683 100644 --- a/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Libraries/LibJS/Runtime/JSONObject.cpp @@ -207,7 +207,7 @@ String JSONObject::serialize_json_object(GlobalObject& global_object, StringifyS state.seen_objects.set(&object); String previous_indent = state.indent; - state.indent = String::format("%s%s", state.indent.characters(), state.gap.characters()); + state.indent = String::formatted("{}{}", state.indent, state.gap); Vector<String> property_strings; auto process_property = [&](const PropertyName& key) { @@ -215,11 +215,11 @@ String JSONObject::serialize_json_object(GlobalObject& global_object, StringifyS if (vm.exception()) return; if (!serialized_property_string.is_null()) { - property_strings.append(String::format( - "%s:%s%s", - quote_json_string(key.to_string()).characters(), + property_strings.append(String::formatted( + "{}:{}{}", + quote_json_string(key.to_string()), state.gap.is_empty() ? "" : " ", - serialized_property_string.characters())); + serialized_property_string)); } }; @@ -263,7 +263,7 @@ String JSONObject::serialize_json_object(GlobalObject& global_object, StringifyS } else { builder.append('\n'); builder.append(state.indent); - auto separator = String::format(",\n%s", state.indent.characters()); + auto separator = String::formatted(",\n{}", state.indent); for (auto& property_string : property_strings) { if (!first) builder.append(separator); @@ -291,7 +291,7 @@ String JSONObject::serialize_json_array(GlobalObject& global_object, StringifySt state.seen_objects.set(&object); String previous_indent = state.indent; - state.indent = String::format("%s%s", state.indent.characters(), state.gap.characters()); + state.indent = String::formatted("{}{}", state.indent, state.gap); Vector<String> property_strings; auto length = length_of_array_like(global_object, Value(&object)); @@ -327,7 +327,7 @@ String JSONObject::serialize_json_array(GlobalObject& global_object, StringifySt } else { builder.append("[\n"); builder.append(state.indent); - auto separator = String::format(",\n%s", state.indent.characters()); + auto separator = String::formatted(",\n{}", state.indent); bool first = true; for (auto& property_string : property_strings) { if (!first) diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 5a1a17b69d..6e4ca6b98f 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -747,7 +747,7 @@ bool Object::define_native_function(const StringOrSymbol& property_name, AK::Fun if (property_name.is_string()) { function_name = property_name.as_string(); } else { - function_name = String::format("[%s]", property_name.as_symbol()->description().characters()); + function_name = String::formatted("[{}]", property_name.as_symbol()->description()); } auto* function = NativeFunction::create(global_object(), function_name, move(native_function)); function->define_property("length", Value(length), Attribute::Configurable); diff --git a/Libraries/LibJS/Runtime/StringPrototype.cpp b/Libraries/LibJS/Runtime/StringPrototype.cpp index 17eea30465..400d99a0f8 100644 --- a/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -256,9 +256,10 @@ static Value pad_string(GlobalObject& global_object, const String& string, PadPl filler_builder.append(fill_string); auto filler = filler_builder.build().substring(0, fill_length); - if (placement == PadPlacement::Start) - return js_string(vm, String::format("%s%s", filler.characters(), string.characters())); - return js_string(vm, String::format("%s%s", string.characters(), filler.characters())); + auto formatted = placement == PadPlacement::Start + ? String::formatted("{}{}", filler, string) + : String::formatted("{}{}", string, filler); + return js_string(vm, formatted); } JS_DEFINE_NATIVE_FUNCTION(StringPrototype::pad_start) |