Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. template<class T>
  2. std::vector<std::string> MapEvaluator<T>::extractVariables(std::string expression) {
  3.  
  4. expression = expression + " ";
  5. std::vector<std::string> variables = {};
  6. std::string substring;
  7. size_t consecutiveCharsCaps = 0;
  8. bool previousCharCaps = false;
  9.  
  10. for (size_t i = 0; i < expression.length(); i++)
  11. {
  12. if (isCapital(expression[i]))
  13. {
  14. consecutiveCharsCaps++;
  15. previousCharCaps = true;
  16. }
  17. else {
  18. if(previousCharCaps) {
  19. substring = expression.substr(i - consecutiveCharsCaps, consecutiveCharsCaps);
  20. variables.push_back(substring);
  21. consecutiveCharsCaps = 0;
  22. previousCharCaps = false;
  23. }
  24. }
  25. }
  26.  
  27. unique(variables);
  28. return variables;
  29. }
  30.  
  31. template <class T>
  32. void MapEvaluator<T>::unique(std::vector<std::string> &vec)
  33. {
  34. auto end = vec.end();
  35. for (auto it = vec.begin(); it != end; ++it) {
  36. end = std::remove(it + 1, end, *it);
  37. }
  38. vec.erase(end, vec.end());
  39. }
  40.  
  41. template<class T>
  42. bool MapEvaluator<T>::isCapital(char c) {
  43. return (c >='A' && c <= 'Z');
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement