mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +00:00
Update betweenChars function
To make more efficient and allow for strings with special characters as function arguments
This commit is contained in:
parent
86af2af61a
commit
63ba06713c
@ -190,20 +190,25 @@ string betweenChars(const string& str, const char& openChar, const char& closeCh
|
|||||||
{
|
{
|
||||||
string content = "";
|
string content = "";
|
||||||
|
|
||||||
int waitingForClose = 0;
|
int startPos = 0;
|
||||||
|
int endPos = (int)str.size();
|
||||||
|
|
||||||
for (int i = 0; i < (int)str.size(); i++)
|
for (int i = 0; i < (int)str.size(); i++)
|
||||||
{
|
{
|
||||||
if (waitingForClose > 0 && !(str[i] == closeChar && waitingForClose == 1))
|
if (str[i] == openChar){
|
||||||
content += str[i];
|
startPos = i+1;
|
||||||
|
break;
|
||||||
if (str[i] == openChar)
|
}
|
||||||
waitingForClose++;
|
}
|
||||||
else if (str[i] == closeChar)
|
for (int i = (int)str.size()-1; i >=0; i--)
|
||||||
waitingForClose--;
|
{
|
||||||
|
if (str[i] == closeChar){
|
||||||
|
endPos = i-(startPos-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return str.substr(startPos, endPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startsWith(const string& str, const string& lookFor)
|
bool startsWith(const string& str, const string& lookFor)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user