Standardize iFindFirst
iFindFirst was added in the previous commit.  Move it to using
std::ranges::subrange, withi is a direct replacement for boost, rather
than inventing a new type.
Tested: Unit tests pass.
Change-Id: I6d88fc90f34ee0748b52e9fb6438635f9cdbd0a9
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/src/entity_manager/utils.cpp b/src/entity_manager/utils.cpp
index 14f3c79..9e379e9 100644
--- a/src/entity_manager/utils.cpp
+++ b/src/entity_manager/utils.cpp
@@ -91,31 +91,38 @@
     // Walking through the string to find $<templateVar>
     while (true)
     {
-        auto [firstIndex, lastIndex] = iFindFirst(*strPtr, templateChar);
-        if (firstIndex == std::string_view::npos)
+        std::ranges::subrange<std::string::const_iterator> findStart =
+            iFindFirst(*strPtr, std::string_view(templateChar));
+
+        if (!findStart)
         {
             break;
         }
 
-        size_t templateVarEndIndex = 0;
-        auto [firstSpaceIndex, _] = iFindFirst(strPtr->substr(lastIndex), " ");
-        if (firstSpaceIndex == std::string_view::npos)
+        std::ranges::subrange<std::string::iterator> searchRange(
+            strPtr->begin() + (findStart.end() - strPtr->begin()),
+            strPtr->end());
+        std::ranges::subrange<std::string::const_iterator> findSpace =
+            iFindFirst(searchRange, " ");
+
+        std::string::const_iterator templateVarEnd;
+
+        if (!findSpace)
         {
             // No space means the template var spans to the end of
             // of the keyPair value
-            templateVarEndIndex = strPtr->size();
+            templateVarEnd = strPtr->end();
         }
         else
         {
             // A space marks the end of a template var
-            templateVarEndIndex = lastIndex + firstSpaceIndex;
+            templateVarEnd = findSpace.begin();
         }
 
         lg2::error(
             "There's still template variable {VAR} un-replaced. Removing it from the string.\n",
-            "VAR",
-            strPtr->substr(firstIndex, templateVarEndIndex - firstIndex));
-        strPtr->erase(firstIndex, templateVarEndIndex - firstIndex);
+            "VAR", std::string(findStart.begin(), templateVarEnd));
+        strPtr->erase(findStart.begin(), templateVarEnd);
     }
 }
 
@@ -175,14 +182,17 @@
     for (const auto& [propName, propValue] : interface)
     {
         std::string templateName = templateChar + propName;
-        auto [start, endIdx] = iFindFirst(*strPtr, templateName);
-        if (start == std::string::npos)
+        std::ranges::subrange<std::string::const_iterator> find =
+            iFindFirst(*strPtr, templateName);
+        if (!find)
         {
             continue;
         }
 
+        size_t start = find.begin() - strPtr->begin();
+
         // check for additional operations
-        if ((start == 0U) && endIdx == strPtr->size())
+        if ((start == 0U) && find.end() == strPtr->end())
         {
             std::visit([&](auto&& val) { keyPair.value() = val; }, propValue);
             return ret;
@@ -232,7 +242,7 @@
 
         number = expression::evaluate(number, exprBegin, exprEnd);
 
-        std::string replaced(strPtr->begin() + start, strPtr->begin() + endIdx);
+        std::string replaced(find.begin(), find.end());
         while (exprBegin != exprEnd)
         {
             replaced.append(" ").append(*exprBegin++);