null char* strings format support

This commit is contained in:
2018-10-04 19:36:51 +07:00
parent fbca178ee5
commit 9d1d039479
2 changed files with 10 additions and 0 deletions

View File

@@ -184,6 +184,9 @@ namespace e2d { namespace strings
: value_(value), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const noexcept {
if ( !value_ ) {
return 0;
}
char format[6] = {0};
char* b_format = format;
*b_format++ = '%';
@@ -204,6 +207,9 @@ namespace e2d { namespace strings
: value_(value), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const noexcept {
if ( !value_ ) {
return 0;
}
char format[6] = {0};
char* b_format = format;
*b_format++ = '%';

View File

@@ -344,6 +344,10 @@ TEST_CASE("strings") {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ==
str("0 2 1 4 3 6 7 5 8 9"));
}
{
REQUIRE(strings::rformat("%0", static_cast<char*>(nullptr)).empty());
REQUIRE(strings::rformat("%0", static_cast<const char*>(nullptr)).empty());
}
{
REQUIRE(strings::rformat("%0", strings::make_format_arg("ab", u8(4))) == " ab");
REQUIRE(strings::rformat("%0", strings::make_format_arg("ab", u8(3))) == " ab");