mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Cleanup.
This commit is contained in:
@@ -263,7 +263,10 @@ namespace bx
|
||||
int32_t write(WriterI* _writer, const StringView& _str, Error* _err = NULL);
|
||||
|
||||
///
|
||||
int32_t write(WriterI* _writer, Error* _err, const char* _format, ...);
|
||||
int32_t write(WriterI* _writer, const StringView& _format, va_list _argList, Error* _err);
|
||||
|
||||
///
|
||||
int32_t write(WriterI* _writer, Error* _err, const StringView& _format, ...);
|
||||
|
||||
/// Write repeat the same value.
|
||||
int32_t writeRep(WriterI* _writer, uint8_t _byte, int32_t _size, Error* _err = NULL);
|
||||
|
||||
@@ -891,9 +891,9 @@ namespace bx
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
int32_t write(WriterI* _writer, const char* _format, va_list _argList, Error* _err)
|
||||
int32_t write(WriterI* _writer, const StringView& _format, va_list _argList, Error* _err)
|
||||
{
|
||||
MemoryReader reader(_format, uint32_t(strLen(_format) ) );
|
||||
MemoryReader reader(_format.getPtr(), _format.getLength() );
|
||||
|
||||
int32_t size = 0;
|
||||
|
||||
@@ -1103,15 +1103,13 @@ namespace bx
|
||||
}
|
||||
}
|
||||
|
||||
size += write(_writer, '\0', _err);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t write(WriterI* _writer, Error* _err, const char* _format, ...)
|
||||
int32_t write(WriterI* _writer, Error* _err, const StringView& _format, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, _format);
|
||||
va_start(argList, &_format);
|
||||
int32_t total = write(_writer, _format, argList, _err);
|
||||
va_end(argList);
|
||||
return total;
|
||||
@@ -1132,6 +1130,7 @@ namespace bx
|
||||
|
||||
if (err.isOk() )
|
||||
{
|
||||
size += write(&writer, '\0', &err);
|
||||
return size - 1 /* size without '\0' terminator */;
|
||||
}
|
||||
}
|
||||
@@ -1143,7 +1142,7 @@ namespace bx
|
||||
int32_t size = write(&sizer, _format, argListCopy, &err);
|
||||
va_end(argListCopy);
|
||||
|
||||
return size - 1 /* size without '\0' terminator */;
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t vsnprintf(char* _out, int32_t _max, const char* _format, va_list _argList)
|
||||
|
||||
@@ -464,6 +464,5 @@ TEST_CASE("strFindBlock", "")
|
||||
const bx::StringView test1(test0, 1);
|
||||
|
||||
bx::StringView result = bx::strFindBlock(test1, '{', '}');
|
||||
printf("%.*s", result.getLength(), result.getPtr() );
|
||||
REQUIRE(19 == result.getLength() );
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "test.h"
|
||||
#include <bx/string.h>
|
||||
#include <bx/readerwriter.h>
|
||||
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -173,3 +175,18 @@ TEST_CASE("vsnprintf", "")
|
||||
, world.getLength(), world.getPtr()
|
||||
) );
|
||||
}
|
||||
|
||||
TEST_CASE("vsnprintf write")
|
||||
{
|
||||
char tmp[64];
|
||||
bx::StaticMemoryBlock mb(tmp, sizeof(tmp));
|
||||
bx::MemoryWriter writer(&mb);
|
||||
|
||||
bx::Error err;
|
||||
int32_t len = bx::write(&writer, &err, "%d", 1389);
|
||||
REQUIRE(err.isOk());
|
||||
REQUIRE(len == 4);
|
||||
|
||||
bx::StringView str(tmp, len);
|
||||
REQUIRE(0 == bx::strCmp(str, "1389"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user