mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Fixed strnlen.
This commit is contained in:
@@ -43,9 +43,8 @@ namespace bx
|
||||
///
|
||||
inline size_t strnlen(const char* _str, size_t _max)
|
||||
{
|
||||
const char* end = _str + _max;
|
||||
const char* ptr;
|
||||
for (ptr = _str; ptr < end && *ptr != '\0'; ++ptr) {};
|
||||
for (ptr = _str; 0 < _max && *ptr != '\0'; ++ptr, --_max) {};
|
||||
return ptr - _str;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
|
||||
bx::AllocatorI* g_allocator;
|
||||
|
||||
TEST_CASE("strnlen", "")
|
||||
{
|
||||
const char* test = "test";
|
||||
|
||||
REQUIRE(0 == bx::strnlen(test, 0) );
|
||||
REQUIRE(2 == bx::strnlen(test, 2) );
|
||||
REQUIRE(4 == bx::strnlen(test, UINT32_MAX) );
|
||||
}
|
||||
|
||||
TEST_CASE("StringView", "")
|
||||
{
|
||||
bx::StringView sv("test");
|
||||
|
||||
Reference in New Issue
Block a user