From bb3426030ad946c86420ca1bc1321fbdd0842d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sun, 17 Feb 2019 16:09:58 -0800 Subject: [PATCH] Fixed strCmp. --- src/string.cpp | 7 ++++++- tests/string_test.cpp | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/string.cpp b/src/string.cpp index cdc2a91..104e8c8 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -188,7 +188,12 @@ namespace bx } } - return 0 == max && _lhsMax == _rhsMax ? 0 : fn(*_lhs) - fn(*_rhs); + if (0 == max) + { + return _lhsMax == _rhsMax ? 0 : _lhsMax > _rhsMax ? 1 : -1; + } + + return fn(*_lhs) - fn(*_rhs); } int32_t strCmp(const StringView& _lhs, const StringView& _rhs, int32_t _max) diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 3d58a30..5919964 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -91,6 +91,10 @@ TEST_CASE("strCat", "") TEST_CASE("strCmp", "") { + REQUIRE(0 < bx::strCmp("abvgd", "abv") ); + REQUIRE(0 < bx::strCmp("abvgd", "") ); + REQUIRE(0 > bx::strCmp("", "abvgd") ); + REQUIRE(0 != bx::strCmp(".tar.gz", ".") ); REQUIRE(0 != bx::strCmp("meh", "meh/") ); }