replaced boost functionality to find nth string occurences

This commit is contained in:
devZoGok
2024-10-10 20:30:25 +03:00
parent f7ea59259e
commit 341ada95b8
3 changed files with 17 additions and 7 deletions
+5 -7
View File
@@ -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 <boost/algorithm/string/find.hpp>
#include <glm.hpp>
#include <glm/gtc/matrix_inverse.hpp>
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);
+11
View File
@@ -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;
}
}
+1
View File
@@ -23,6 +23,7 @@ namespace vb01{
void readFile(std::string, std::vector<std::string>&, 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);