Bladeren bron

Fixed strCmp.

Бранимир Караџић 6 jaren geleden
bovenliggende
commit
bb3426030a
2 gewijzigde bestanden met toevoegingen van 10 en 1 verwijderingen
  1. 6 1
      src/string.cpp
  2. 4 0
      tests/string_test.cpp

+ 6 - 1
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)

+ 4 - 0
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/") );
 }