[libc-commits] [PATCH] D155902: [wip][libc] Overload integer_to_string methods for fixed size buffers
Guillaume Chatelet via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jul 25 08:13:30 PDT 2023
gchatelet added inline comments.
================
Comment at: libc/src/__support/libc_assert.h:35
// dec returns an optional, will always be valid for this size buffer
auto line_number = IntegerToString::dec(line, line_str);
__llvm_libc::write_to_stderr(filename);
----------------
[nit] `cpp::string_view` let's be explicit
================
Comment at: libc/test/UnitTest/LibcTest.cpp:52
+ cpp::string_view view = IntegerToString::hex(Value, buf, false);
+ return "0x" + cpp::string(view.data(), view.size());
}
----------------
Not directly related to this patch but I think we should offer prefixing as part of the API. This would simplify client code.
================
Comment at: libc/test/src/__support/integer_to_string_test.cpp:22
TEST(LlvmLibcIntegerToStringTest, UINT8) {
- char buf[IntegerToString::dec_bufsize<uint8_t>()];
+ char buf[IntegerToString::dec_bufsize<uint8_t>() + 1];
EXPECT_EQ(*IntegerToString::dec(uint8_t(0), buf), string_view("0"));
----------------
The required size changes if we pass in an array or a span, this is confusing.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155902/new/
https://reviews.llvm.org/D155902
More information about the libc-commits
mailing list