mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
AK: Resolve format related circular dependencies properly.
With this commit, <AK/Format.h> has a more supportive role and isn't
used directly.
Essentially, there now is a public 'vformat' function ('v' for vector)
which takes already type erased parameters. The name is choosen to
indicate that this function behaves similar to C-style functions taking
a va_list equivalent.
The interface for frontend users are now 'String::formatted' and
'StringBuilder::appendff'.
This commit is contained in:
@@ -216,7 +216,7 @@ Optional<unsigned> String::to_uint() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
String String::number(T value) { return AK::format("{}", value); }
|
||||
String String::number(T value) { return formatted("{}", value); }
|
||||
|
||||
template String String::number(unsigned char);
|
||||
template String String::number(unsigned short);
|
||||
@@ -228,8 +228,6 @@ template String String::number(short);
|
||||
template String String::number(int);
|
||||
template String String::number(long);
|
||||
template String String::number(long long);
|
||||
|
||||
// C++ is weird.
|
||||
template String String::number(signed char);
|
||||
|
||||
String String::format(const char* fmt, ...)
|
||||
@@ -458,4 +456,34 @@ StringView String::view() const
|
||||
return { characters(), length() };
|
||||
}
|
||||
|
||||
InputStream& operator>>(InputStream& stream, String& string)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
for (;;) {
|
||||
char next_char;
|
||||
stream >> next_char;
|
||||
|
||||
if (stream.has_any_error()) {
|
||||
stream.set_fatal_error();
|
||||
string = nullptr;
|
||||
return stream;
|
||||
}
|
||||
|
||||
if (next_char) {
|
||||
builder.append(next_char);
|
||||
} else {
|
||||
string = builder.to_string();
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String String::vformatted(StringView fmtstr, Span<const TypeErasedParameter> parameters)
|
||||
{
|
||||
StringBuilder builder;
|
||||
vformat(builder, fmtstr, parameters);
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user