Use span in format
This commit is contained in:
1
.bazelrc
1
.bazelrc
@ -16,5 +16,6 @@ build --cxxopt=-Wno-documentation-unknown-command
|
||||
build --cxxopt=-Wno-extra-semi-stmt
|
||||
build --cxxopt=-Wno-extra-semi
|
||||
build --cxxopt=-Wno-global-constructors
|
||||
build --cxxopt=-Wno-unsafe-buffer-usage
|
||||
|
||||
test --test_output=errors
|
||||
|
@ -5,13 +5,12 @@
|
||||
void asl::format_internals::format(
|
||||
writer* writer,
|
||||
const char* fmt,
|
||||
const type_erased_arg* args,
|
||||
int64_t arg_count)
|
||||
span<const type_erased_arg> args)
|
||||
{
|
||||
formatter f(writer);
|
||||
|
||||
|
||||
int64_t arg = 0;
|
||||
const auto* arg_it = args.begin();
|
||||
const auto* arg_end = args.end();
|
||||
|
||||
const char* begin = fmt;
|
||||
while (*fmt != '\0')
|
||||
@ -20,14 +19,14 @@ void asl::format_internals::format(
|
||||
{
|
||||
if (fmt[1] == '}')
|
||||
{
|
||||
if (arg < arg_count)
|
||||
if (arg_it < arg_end)
|
||||
{
|
||||
f.write(begin, fmt - begin);
|
||||
fmt += 2;
|
||||
begin = fmt;
|
||||
|
||||
args[arg].fn(f, args[arg].data);
|
||||
arg += 1;
|
||||
arg_it->fn(f, arg_it->data);
|
||||
arg_it++; // NOLINT(*-pointer-arithmetic)
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,7 +167,7 @@ void asl::AslFormat(formatter& f, uint64_t v)
|
||||
else if (v > 0 || cursor == kMaxDigits)
|
||||
{
|
||||
ASL_ASSERT(v < 10);
|
||||
write_one('0' + (char)v);
|
||||
write_one('0' + static_cast<char>(v));
|
||||
}
|
||||
|
||||
f.write(buffer + cursor, kMaxDigits - cursor);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "asl/integers.hpp"
|
||||
#include "asl/meta.hpp"
|
||||
#include "asl/io.hpp"
|
||||
#include "asl/span.hpp"
|
||||
|
||||
namespace asl
|
||||
{
|
||||
@ -37,7 +38,7 @@ struct type_erased_arg
|
||||
};
|
||||
|
||||
// @Todo Use span
|
||||
void format(writer*, const char* fmt, const type_erased_arg* args, int64_t arg_count);
|
||||
void format(writer*, const char* fmt, span<const type_erased_arg> args);
|
||||
|
||||
} // namespace internals
|
||||
|
||||
@ -67,11 +68,11 @@ void format(writer* w, const char* fmt, const Args&... args)
|
||||
format_internals::type_erased_arg(args)...
|
||||
};
|
||||
|
||||
format_internals::format(w, fmt, type_erased_args, types_count<Args...>);
|
||||
format_internals::format(w, fmt, type_erased_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
format_internals::format(w, fmt, nullptr, 0);
|
||||
format_internals::format(w, fmt, {});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user