mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
null char* strings format support
This commit is contained in:
@@ -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++ = '%';
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user