Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. std::string StringUtils::filterStringByScope(const std::string &str, char cOpen, char cClose)
  2. {
  3. std::string result;
  4. unsigned countChar = 0;
  5. std::stack<char> stackChar;
  6. while (str[countChar] != cOpen)
  7. {
  8. ++countChar;
  9. if (countChar >= str.length())
  10. {
  11. return result;
  12. }
  13. }
  14. result = str[countChar];
  15. ++countChar;
  16. stackChar.push(cOpen);
  17. while(stackChar.size() > 0 && countChar < str.length())
  18. {
  19. result+= str[countChar];
  20. if (str[countChar] == cOpen) stackChar.push(cOpen);
  21. else if (str[countChar] == cClose) stackChar.pop();
  22. ++countChar;
  23. }
  24. return result;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement