Hey everyone
I'm making a program that formats code,but I can't seem to solve certain problems.
Code:
while ((finder = str.find(';', finder)) != std::string::npos)
{
if (str[finder + 1] != '\n')
{
str.insert(str.begin() + finder + 1, '\n');
}
else ++finder;
}
This code is supposed to add a new line after finding a";" character.
The problem is,whenever it finds a for loop which contains two such characters it ruins the indention.How can I form an if statement to avoid this?
I also have problem with this:
Code:
while ((finder = str.find('\n', finder)) != std::string::npos)
{
if ((str[finder + 1] != '\t') && (str[finder + 1] != '{') && (str[finder + 1] != '}')&&(str[finder+1]!=' '))
{
str.insert(str.begin() + finder + 1, '\t');
}
else ++finder;
}
I want to add a tabulation if there doesn't exist one already,but it ends up adding one anyway.
Aside of that,is this an acceptable way of making a code beautifier?
Thanks in advance
Edit:Oops,there's supposed to be "while" in the topic