Browse Source

Fixed issue #222.

Бранимир Караџић 6 years ago
parent
commit
1680ef418a
2 changed files with 14 additions and 11 deletions
  1. 2 11
      src/string.cpp
  2. 12 0
      tests/string_test.cpp

+ 2 - 11
src/string.cpp

@@ -420,18 +420,9 @@ namespace bx
 				}
 			}
 
-			// Set pointers.
-			const char* string = ptr;
-			const char* search = _find;
-
-			// Start comparing.
-			while (fn(*string++) == fn(*search++) )
+			if (0 == strCmp<fn>(ptr, _findMax, _find, _findMax) )
 			{
-				// If end of the 'search' string is reached, all characters match.
-				if ('\0' == *search)
-				{
-					return ptr;
-				}
+				return ptr;
 			}
 		}
 

+ 12 - 0
tests/string_test.cpp

@@ -226,6 +226,18 @@ TEST_CASE("strFind", "")
 
 		REQUIRE(bx::strFind("vgd", 'a').isEmpty() );
 	}
+
+	{
+		bx::StringView test = bx::strFind("a", "a");
+		REQUIRE(test.getLength() == 1);
+		REQUIRE(*test.getPtr() == 'a');
+	}
+
+	{
+		bx::StringView test = bx::strFind("a", bx::StringView("a ", 1) );
+		REQUIRE(test.getLength() == 1);
+		REQUIRE(*test.getPtr() == 'a');
+	}
 }
 
 TEST_CASE("strSkip", "")