From 1680ef418acf11f85d835d4f95365b01c13f7324 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, 24 Nov 2019 19:27:13 -0800 Subject: [PATCH] Fixed issue #222. --- src/string.cpp | 13 ++----------- tests/string_test.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/string.cpp b/src/string.cpp index 678af66..de70f41 100644 --- a/src/string.cpp +++ b/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(ptr, _findMax, _find, _findMax) ) { - // If end of the 'search' string is reached, all characters match. - if ('\0' == *search) - { - return ptr; - } + return ptr; } } diff --git a/tests/string_test.cpp b/tests/string_test.cpp index c1c4b85..650d308 100644 --- a/tests/string_test.cpp +++ b/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", "")