diff --git a/include/bx/inline/string.inl b/include/bx/inline/string.inl index 60d17e5..51271e3 100644 --- a/include/bx/inline/string.inl +++ b/include/bx/inline/string.inl @@ -304,6 +304,11 @@ namespace bx return m_line; } + inline int32_t strLen(const StringView& _str, int32_t _max) + { + return min(_str.getLength(), _max); + } + inline bool hasPrefix(const StringView& _str, const StringView& _prefix) { const int32_t len = _prefix.getLength(); diff --git a/src/string.cpp b/src/string.cpp index 3896479..acfa8c7 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -302,11 +302,6 @@ namespace bx return int32_t(ptr - _str); } - int32_t strLen(const StringView& _str, int32_t _max) - { - return strLen(_str.getPtr(), min(_str.getLength(), _max) ); - } - inline int32_t strCopy(char* _dst, int32_t _dstSize, const char* _src, int32_t _num) { BX_ASSERT(NULL != _dst, "_dst can't be NULL!"); diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 3f5a076..96f653f 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -19,25 +19,31 @@ TEST_CASE("StringLiteral", "") REQUIRE(bx::isSorted(tmp, BX_COUNTOF(tmp) ) ); static_assert(4 == tmp[0].getLength() ); + REQUIRE(4 == bx::strLen(tmp[0]) ); REQUIRE(0 == bx::strCmp("1389", tmp[0]) ); static_assert(5 == tmp[1].getLength() ); + REQUIRE(5 == bx::strLen(tmp[1]) ); REQUIRE(0 == bx::strCmp("abvgd", tmp[1]) ); static_assert(3 == tmp[2].getLength() ); + REQUIRE(3 == bx::strLen(tmp[2]) ); REQUIRE(0 == bx::strCmp("mac", tmp[2]) ); static_assert(3 == tmp[3].getLength() ); + REQUIRE(3 == bx::strLen(tmp[3]) ); REQUIRE(0 == bx::strCmp("pod", tmp[3]) ); constexpr bx::StringLiteral copy = tmp[0]; static_assert(4 == copy.getLength() ); + REQUIRE(4 == bx::strLen(copy) ); REQUIRE(0 == bx::strCmp("1389", copy) ); constexpr bx::StringView sv = tmp[1]; REQUIRE(5 == sv.getLength() ); + REQUIRE(5 == bx::strLen(sv) ); REQUIRE(0 == bx::strCmp("abvgd", sv) ); }