mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +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:
parent
3224fb7d55
commit
b7a4c4482f
8 changed files with 105 additions and 100 deletions
34
AK/String.h
34
AK/String.h
|
@ -26,10 +26,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Stream.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringImpl.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/Traits.h>
|
||||
|
@ -239,6 +239,15 @@ public:
|
|||
|
||||
static String format(const char*, ...);
|
||||
|
||||
static String vformatted(StringView fmtstr, Span<const TypeErasedParameter>);
|
||||
|
||||
template<typename... Parameters>
|
||||
static String formatted(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
const auto type_erased_parameters = make_type_erased_parameters(parameters...);
|
||||
return vformatted(fmtstr, type_erased_parameters);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static String number(T);
|
||||
|
||||
|
@ -277,28 +286,7 @@ bool operator<=(const char*, const String&);
|
|||
|
||||
String escape_html_entities(const StringView& html);
|
||||
|
||||
inline 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
InputStream& operator>>(InputStream& stream, String& string);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue