mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
AK: Add dbgln() format checking
This checks the following things: - No unclosed braces in format string `dbgln("a:{}}", a)` where the '}}' would be interpreted as a literal '}' `dbgln("a:{", a)` where someone with a faulty keyboard like mine could generate - No extra closed braces in format string `dbgln("a:{{}", a)` where the '{{' would interpreted as a literal '{' `dbgln("a:}", a)` where someone with a faulty keyboard could generate - No references to nonexistent arguments `dbgln("a:{} b:{}", a)` where the value of `b` is not in the arguments list - No unconsumed argument `dbgln("a:{1}", not_used, 1)` where `not_used` is extraneous
This commit is contained in:
parent
09a43969ba
commit
20765da2a4
3 changed files with 209 additions and 2 deletions
|
@ -565,6 +565,38 @@ using MakeIntegerSequence = decltype(make_integer_sequence_impl<T, N>());
|
|||
template<unsigned N>
|
||||
using MakeIndexSequence = MakeIntegerSequence<unsigned, N>;
|
||||
|
||||
template<unsigned long N>
|
||||
struct StringLiteral {
|
||||
constexpr StringLiteral(const char (&in)[N])
|
||||
: data {}
|
||||
, size { N }
|
||||
{
|
||||
for (unsigned long i = 0; i < N; ++i)
|
||||
data[i] = in[i];
|
||||
}
|
||||
|
||||
template<unsigned long Nx>
|
||||
constexpr StringLiteral& operator=(const StringLiteral<Nx>& other)
|
||||
{
|
||||
static_assert(Nx <= N, "Storing a string literal in a smaller one");
|
||||
for (unsigned long i = 0; i < Nx; ++i)
|
||||
data[i] = other[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<unsigned long Nx>
|
||||
constexpr StringLiteral& operator=(const char (&other)[Nx])
|
||||
{
|
||||
static_assert(Nx <= N, "Storing a string literal in a smaller one");
|
||||
for (unsigned long i = 0; i < Nx; ++i)
|
||||
data[i] = other[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
char data[N];
|
||||
unsigned long size;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::AddConst;
|
||||
|
@ -597,5 +629,6 @@ using AK::max;
|
|||
using AK::min;
|
||||
using AK::move;
|
||||
using AK::RemoveConst;
|
||||
using AK::StringLiteral;
|
||||
using AK::swap;
|
||||
using AK::Void;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue