mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:47:36 +00:00
LibJS: Use String::formatted() in various other places
This commit is contained in:
parent
2e2571743b
commit
123f98201e
7 changed files with 23 additions and 22 deletions
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue