From 341ada95b8d36753e80e529aa210696adfcb6e2b Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 10 Oct 2024 20:30:25 +0300 Subject: [PATCH] replaced boost functionality to find nth string occurences --- node.cpp | 12 +++++------- util.cpp | 11 +++++++++++ util.h | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/node.cpp b/node.cpp index f49aaaf..7b3a5f7 100755 --- a/node.cpp +++ b/node.cpp @@ -2,6 +2,7 @@ #include "bone.h" #include "mesh.h" #include "text.h" +#include "util.h" #include "light.h" #include "matrix.h" #include "material.h" @@ -11,14 +12,11 @@ #include "assetManager.h" #include "animationController.h" -#include - #include #include using namespace std; using namespace glm; -using namespace boost; namespace vb01{ Node::Node(Vector3 pos, Quaternion orientation, Vector3 scale, string name, Animatable::Type type) : Animatable(type, name){ @@ -463,13 +461,13 @@ namespace vb01{ int numLights = root->getNumLights(); string str1 = "const int numLights = " + to_string(numLights > 0 ? numLights : 1) + ";"; - int a1 = std::distance(shaderStr.begin(), find_nth(shaderStr, "\n", 0).begin()); - int a2 = std::distance(shaderStr.begin(), find_nth(shaderStr, "\n", 1).begin()); + int a1 = findNthOccurence(shaderStr, "\n", 0); + int a2 = findNthOccurence(shaderStr, "\n", 1); shaderStr.replace(a1 + 1, a2 - a1 - 1, str1); string str2 = "const bool checkLights = " + string(numLights > 0 ? "true" : "false") + ";"; - a1 = std::distance(shaderStr.begin(), find_nth(shaderStr, "\n", 1).begin()); - a2 = std::distance(shaderStr.begin(), find_nth(shaderStr, "\n", 2).begin()); + a1 = findNthOccurence(shaderStr, "\n", 1); + a2 = findNthOccurence(shaderStr, "\n", 2); shaderStr.replace(a1 + 1, a2 - a1 - 1, str2); ShaderAsset sa2(sa->path, shaderStr); diff --git a/util.cpp b/util.cpp index 10fa66d..b60ab1e 100755 --- a/util.cpp +++ b/util.cpp @@ -90,4 +90,15 @@ namespace vb01{ return str; } + + int findNthOccurence(string &str, string occ, int occId, bool forward){ + int occurenceId = (forward ? str.find(occ) : str.rfind(occ)), iteration = 0; + + while(occurenceId != -1 && iteration != occId){ + occurenceId = (forward ? str.find(occ, occurenceId + 1) : str.rfind(occ, occurenceId - 1)); + iteration++; + } + + return occurenceId; + } } diff --git a/util.h b/util.h index 5e40d5d..05b70e3 100755 --- a/util.h +++ b/util.h @@ -23,6 +23,7 @@ namespace vb01{ void readFile(std::string, std::vector&, int = 0, int = -1); void getLineData(std::string, std::string[], int, int = 0); + int findNthOccurence(std::string&, std::string, int, bool = true); int getCharId(std::string, char, bool = false); std::wstring stringToWstring(std::string str); std::string wstringToString(std::wstring wstr);