Update betweenChars function

To make more efficient and allow for strings with special characters as function arguments
This commit is contained in:
sam-astro 2022-05-25 09:06:47 -04:00 committed by GitHub
parent 86af2af61a
commit 63ba06713c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,20 +190,25 @@ string betweenChars(const string& str, const char& openChar, const char& closeCh
{
string content = "";
int waitingForClose = 0;
int startPos = 0;
int endPos = (int)str.size();
for (int i = 0; i < (int)str.size(); i++)
{
if (waitingForClose > 0 && !(str[i] == closeChar && waitingForClose == 1))
content += str[i];
if (str[i] == openChar)
waitingForClose++;
else if (str[i] == closeChar)
waitingForClose--;
if (str[i] == openChar){
startPos = i+1;
break;
}
}
for (int i = (int)str.size()-1; i >=0; i--)
{
if (str[i] == closeChar){
endPos = i-(startPos-1);
break;
}
}
return content;
return str.substr(startPos, endPos);
}
bool startsWith(const string& str, const string& lookFor)